AGX Dynamics  2.37.2.0
Array.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 #ifndef AGXDATA_ARRAY_H
18 #define AGXDATA_ARRAY_H
19 
20 #include <agxData/Data.h>
21 #include <agx/GlobalResult.h>
22 #include <agx/Vector.h>
23 
24 #ifdef _MSC_VER
25 # pragma warning(push)
26 # pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
27 #endif
28 
29 namespace agxData
30 {
31 
37  {
38  public:
39 
41  AbstractArray();
42 
45 
48 
50  AbstractArray(const agxData::AbstractArray& other, agx::IndexRange32 localRange);
51 
53  size_t size() const;
54 
56  bool empty() const;
57 
59  agx::IndexRange32& range();
60  const agx::IndexRange32& range() const;
61 
63  const agxData::Buffer* buffer() const;
64  agxData::Buffer* buffer();
65 
67  void init(agxData::Buffer* buffer, agx::IndexRange32 range);
68 
70  void init(agxData::Buffer* buffer);
71 
73  void init();
74 
76  void setRange(size_t startIndex, size_t endIndex);
77 
79  void setRange(agx::IndexRange32 range);
80 
83  const agxData::Format* getFormat() const;
84 
86  void sync();
87 
89  bool isValid() const;
90 
92  void _setBuffer(agxData::Buffer *buffer);
93 
94  protected:
95  friend class SerializedFrame;
98  };
99 
100 
101 
105  template <typename T>
106  class Array : public agxData::AbstractArray
107  {
108  public:
109  typedef T Type;
110  typedef T value_type;
111  typedef T* pointer;
112  typedef const T* const_pointer;
113  typedef T& reference;
114  typedef const T& const_reference;
115  typedef size_t size_type;
116  typedef T* iterator;
117  typedef const T* const_iterator;
118  typedef std::random_access_iterator_tag iterator_category;
119  typedef ptrdiff_t difference_type;
120 
121  static const bool IsScalar = false;
122 
132  static agxData::Array<T> raw(T* buffer, agx::Index size);
133  static const agxData::Array<T> raw(const T* buffer, agx::Index size);
134 
135  public:
137  Array();
138 
140  Array(agxData::Buffer* buffer);
141 
143  Array(agxData::Buffer* buffer, agx::IndexRange32 range);
144 
146  Array(const agxData::Array<T>& other, agx::IndexRange32 localRange);
147 
149  Array(agx::Vector<T>& vec);
151  Array(agx::VectorPOD<T>& vec);
153 
155  T& back();
156  const T& back() const;
157 
159  T& front();
160  const T& front() const;
161 
163  T& operator[] (size_t index);
164  const T& operator[] (size_t index) const;
165 
167  T& at(size_t index);
168  const T& at(size_t index) const;
169 
171  agxData::Array<T> slice(agx::IndexRange32 subRange) const;
172 
174  agxData::Array<T> operator[] (agx::IndexRange32 subRange) const;
175 
177  iterator begin();
178  const_iterator begin() const;
179 
181  iterator end();
182  const_iterator end() const;
183 
185  T* ptr();
186  const T* ptr() const;
187 
195  template <typename T2>
196  size_t find(const T2& element) const;
197 
199  template <typename T2>
200  bool contains(const T2& element) const;
201 
202 
203  //
204  // GlobalResult functionality used by parallel kernels that create a dynamic amount of output data.
205  // These are implemented in agxData/Buffer.h
206  //
207 
209  agx::GlobalResult* getGlobalResult();
210 
212  agx::GlobalResult::Transaction allocateResult(size_t numElements);
214  size_t commitResult(size_t numElements, const void* localResult, agx::Index sortIndex);
215  size_t commitResult(size_t numElements, const void* localResult);
216 
218  template <typename T2>
219  size_t commitResult(const T2& vector, agx::Index sortIndex);
220  template <typename T2>
221  size_t commitResult(const T2& vector);
222 
223  };
224 
225 
226  /* Implementation */
227  // See Buffer.h
228 }
229 
230 #ifdef _MSC_VER
231 # pragma warning(pop)
232 #endif
233 
235 
236 
237 #endif /* _AGXDATA_ARRAY_H_ */
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
const T * const_pointer
Definition: Array.h:112
T & reference
Definition: Array.h:113
agx::IndexRange32 m_range
Definition: Array.h:97
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
std::random_access_iterator_tag iterator_category
Definition: Array.h:118
Transactions are used to reserve exclusive memory areas in which the threads can write their data...
Definition: GlobalResult.h:72
Generic data.
Definition: Data.h:39
size_t size_type
Definition: Array.h:115
A format is an implementation of a agxData::Type.
Definition: Format.h:63
T * pointer
Definition: Array.h:111
Arrays are fast accessors into the data, or a portion of it, held by a Buffer.
Definition: Array.h:36
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agxData::Buffer * m_buffer
Definition: Array.h:96
Templated vector class.
Definition: Vector.h:52
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
GlobalResult is used by kernels to generate result data from different threads.
Definition: GlobalResult.h:51
Abstract representation of a data buffer.
Definition: Buffer.h:55
Contains classes for low level data storage for AGX.
Definition: Container.h:23
UInt32 Index
Definition: Integer.h:52
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
T * iterator
Definition: Array.h:116
A range of indices.
Definition: IndexRange.h:32
#define AGX_TEMPLATED_TYPE_BINDING(_Type, _Name)
Definition: Type.h:192
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
ptrdiff_t difference_type
Definition: Array.h:119
const T & const_reference
Definition: Array.h:114
#define AGXCORE_EXPORT
const T * const_iterator
Definition: Array.h:117