AGX Dynamics  2.37.2.0
BinaryData.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 
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 
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; }
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 m_size
Definition: Vector.h:429
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
Base class providing referencing counted objects.
Definition: Referenced.h:119
ByteStream getByteStream()
Definition: BinaryData.h:130
Contains classes for low level data storage for AGX.
Definition: Container.h:23
size_t size() const
Definition: BinaryData.h:126
agx::UInt8 Byte
Definition: agxData.h:45
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
Utility class for parsing/writing a byte stream.
Definition: ByteStream.h:27
#define AGXCORE_EXPORT