AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
BinaryData.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
25namespace agxData
26{
27
34 {
35 public:
36
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
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:
115
116 private:
117 Byte* m_data;
118 size_t m_size;
119
120 DataAllocationType m_allocationType;
122 };
123
124
125 /* Implementation */
126 AGX_FORCE_INLINE size_t BinaryData::size() const { return m_size; }
127
129 AGX_FORCE_INLINE const Byte* BinaryData::ptr() const { return m_data; }
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 */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXCORE_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
#define m_size
Definition: agx/Vector.h:429
BinaryData(Byte *data, size_t size, DataAllocationType allocationType)
Create a binary data that is a handle to an externally allocated memory area.
static BinaryData * copy(const Byte *data, size_t size)
Create a BinaryData that contains a copy of the given memory area.
void setApparentSize(size_t size)
Change the size that will be returned by calls to 'size()'.
static BinaryData * readFromFile(const agx::String &path)
Load binary data from a file.
BinaryData(size_t size)
size_t size() const
Definition: BinaryData.h:126
BinaryData(Byte *data, size_t size, agx::Referenced *reference)
ByteStream getByteStream()
Definition: BinaryData.h:130
BinaryData(size_t size, size_t alignment)
Utility class for parsing/writing a byte stream.
Definition: ByteStream.h:28
Base class providing referencing counted objects.
Definition: Referenced.h:120
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define AGX_FORCE_INLINE
Definition: macros.h:58
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::UInt8 Byte
Definition: agxData.h:45