AGXDynamics
2.35.0.3
BinaryData.h
Go to the documentation of this file.
1
/*
2
Copyright 2007-2022. Algoryx Simulation AB.
3
4
All AGX source code, intellectual property, documentation, sample code,
5
tutorials, scene files and technical white papers, are copyrighted, proprietary
6
and confidential material of Algoryx Simulation AB. You may not download, read,
7
store, distribute, publish, copy or otherwise disseminate, use or expose this
8
material unless having a written signed agreement with Algoryx Simulation AB, or having been
9
advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10
valid commercial license from Algoryx Simulation AB.
11
12
Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13
from using this software, unless otherwise stated in written agreements with
14
Algoryx Simulation AB.
15
*/
16
17
18
#ifndef AGXDATA_BINARYDATA_H
19
#define AGXDATA_BINARYDATA_H
20
21
#include <
agx/Referenced.h
>
22
#include <
agx/Integer.h
>
23
#include <
agxData/ByteStream.h
>
24
25
namespace
agxData
26
{
27
31
AGX_DECLARE_POINTER_TYPES
(
BinaryData
);
32
AGX_DECLARE_VECTOR_TYPES
(
BinaryData
);
33
class
AGXCORE_EXPORT
BinaryData
:
public
agx::Referenced
34
{
35
public
:
36
37
enum
DataAllocationType
38
{
39
DATA_IS_MALLOCED
,
// m_data was allocated using malloc, will be deallocated using free.
40
DATA_IS_NEWED
,
// m_data was allocated using new, will be deallocated using delete.
41
DATA_IS_ARRAY
,
// m_data was allocated using new [], will be deallocated using delete [];
42
DATA_IS_STATIC
,
// m_data should not be deallocated at all. Not necessarily really static
43
// data, can also be used to create a BinaryData object that points into
44
// data owned by someone else. It is the responsibility of the user of this
45
// BinaryData to ensure that the memory hasn't been deallocated when the
46
// pointer returned by ptr() is used.
47
DATA_IS_ALIGNED
// m_data was allocated using the static member functions of ByteAllocator.
48
};
49
50
51
BinaryData
();
52
53
// Allocates the requested size.
54
BinaryData
(
size_t
size);
55
56
// Allocates the requested size on the specified alignment.
57
BinaryData
(
size_t
size,
size_t
alignment);
58
68
BinaryData
(
Byte
* data,
size_t
size, DataAllocationType allocationType);
69
70
BinaryData
(
Byte
* data,
size_t
size,
agx::Referenced
*reference);
71
75
static
BinaryData
*copy(
const
Byte
* data,
size_t
size);
76
80
static
BinaryData
*readFromFile(
const
agx::String
& path);
81
85
size_t
size()
const
;
86
90
Byte
* ptr();
91
const
Byte
* ptr()
const
;
92
93
// Templated
94
template
<
typename
T>
95
T* ptr();
96
97
template
<
typename
T>
98
const
T* ptr()
const
;
99
103
ByteStream
getByteStream();
104
const
ByteStream
getByteStream()
const
;
105
106
111
void
setApparentSize(
size_t
size );
112
113
protected
:
114
~
BinaryData
();
115
116
private
:
117
Byte
* m_data;
118
size_t
m_size
;
119
120
DataAllocationType m_allocationType;
121
agx::ref_ptr<agx::Referenced>
m_reference;
122
};
123
124
125
/* Implementation */
126
AGX_FORCE_INLINE
size_t
BinaryData::size
()
const
{
return
m_size; }
127
128
AGX_FORCE_INLINE
Byte
*
BinaryData::ptr
() {
return
m_data; }
129
AGX_FORCE_INLINE
const
Byte
*
BinaryData::ptr
()
const
{
return
m_data; }
130
AGX_FORCE_INLINE
ByteStream
BinaryData::getByteStream
() {
return
ByteStream
(m_data, m_data + m_size); }
131
AGX_FORCE_INLINE
const
ByteStream
BinaryData::getByteStream
()
const
{
return
ByteStream
(m_data, m_data + m_size); }
132
133
template
<
typename
T>
134
AGX_FORCE_INLINE
T*
BinaryData::ptr
() {
return
reinterpret_cast<
T *
>
(m_data); }
135
136
template
<
typename
T>
137
AGX_FORCE_INLINE
const
T*
BinaryData::ptr
()
const
{
return
static_cast<
const
T *
>
(m_data); }
138
139
140
}
141
142
143
#endif
/* AGXDATA_BINARYDATA_H */
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxData::ByteStream
Utility class for parsing/writing a byte stream.
Definition:
ByteStream.h:27
Referenced.h
agxData::BinaryData::DATA_IS_ARRAY
@ DATA_IS_ARRAY
Definition:
BinaryData.h:41
agxData
Contains classes for low level data storage for AGX.
Definition:
Container.h:23
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition:
Vector.h:34
agxData::BinaryData::ptr
Byte * ptr()
Definition:
BinaryData.h:128
agx::ref_ptr< agx::Referenced >
Integer.h
m_size
#define m_size
Definition:
Vector.h:429
agxData::Byte
agx::UInt8 Byte
Definition:
agxData.h:45
agxData::BinaryData
Definition:
BinaryData.h:33
agxData::BinaryData::DATA_IS_MALLOCED
@ DATA_IS_MALLOCED
Definition:
BinaryData.h:39
agx::Referenced
Base class providing referencing counted objects.
Definition:
Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition:
Referenced.h:248
agxData::BinaryData::DataAllocationType
DataAllocationType
Definition:
BinaryData.h:37
ByteStream.h
agxData::BinaryData::DATA_IS_STATIC
@ DATA_IS_STATIC
Definition:
BinaryData.h:42
agx::AgXString
Definition:
String.h:31
agxData::BinaryData::getByteStream
ByteStream getByteStream()
Definition:
BinaryData.h:130
agxData::BinaryData::size
size_t size() const
Definition:
BinaryData.h:126
agxData::BinaryData::DATA_IS_NEWED
@ DATA_IS_NEWED
Definition:
BinaryData.h:40
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition:
macros.h:58
include
agxData
BinaryData.h
Generated on Fri Feb 10 2023 14:06:08 for AGXDynamics by
1.8.17