AGX Dynamics  2.38.0.2
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 
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 
210 
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_ */
agxData::AbstractArray::m_range
agx::IndexRange32 m_range
Definition: Array.h:97
agxData::Array::end
iterator end()
Definition: Buffer.h:894
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxData::Array::reference
T & reference
Definition: Array.h:113
agxData::Array::front
T & front()
Definition: Buffer.h:828
agxData::Array::find
size_t find(const T2 &element) const
The index of the first occurrence of an element that is equal to the given element.
Definition: Buffer.h:908
agxData::AbstractArray
Arrays are fast accessors into the data, or a portion of it, held by a Buffer.
Definition: Array.h:36
agx::Jacobian6DOFElementT
Definition: Jacobian.h:104
Vector.h
agxData::Array::size_type
size_t size_type
Definition: Array.h:115
agxData::getFormat
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxData::Array::const_pointer
const typedef T * const_pointer
Definition: Array.h:112
agxData::Array::value_type
T value_type
Definition: Array.h:110
agxData::Array::const_reference
const typedef T & const_reference
Definition: Array.h:114
agxData::SerializedFrame
Definition: SerializedFrame.h:41
agxData::Array::operator[]
T & operator[](size_t index)
Definition: Buffer.h:845
agxData::Array::ptr
T * ptr()
Definition: Buffer.h:900
agxData::Array::Array
Array()
Create a new invalid array.
Definition: Buffer.h:755
agxData::Format
A format is an implementation of a agxData::Type.
Definition: Format.h:63
agxData::AbstractArray::m_buffer
agxData::Buffer * m_buffer
Definition: Array.h:96
agxData::Array::raw
static agxData::Array< T > raw(T *buffer, agx::Index size)
Array creation helper method that creates an array covering the given memory area.
Definition: Buffer.h:733
agxData::Data
Generic data.
Definition: Data.h:39
GlobalResult.h
agxData::Array::slice
agxData::Array< T > slice(agx::IndexRange32 subRange) const
Definition: Buffer.h:875
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
agxData
Contains classes for low level data storage for AGX.
Definition: Container.h:23
AGX_TEMPLATED_TYPE_BINDING
#define AGX_TEMPLATED_TYPE_BINDING(_Type, _Name)
Definition: Type.h:192
agxData::Array::pointer
T * pointer
Definition: Array.h:111
agxData::Array::iterator_category
std::random_access_iterator_tag iterator_category
Definition: Array.h:118
agxData::Array::contains
bool contains(const T2 &element) const
Definition: Buffer.h:920
agxData::Array
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agx::IndexRangeT
A range of indices.
Definition: IndexRange.h:32
agxData::Array::commitResult
size_t commitResult(size_t numElements, const void *localResult, agx::Index sortIndex)
Definition: Buffer.h:578
agx::Index
UInt32 Index
Definition: Integer.h:44
agxData::Buffer
Abstract representation of a data buffer.
Definition: Buffer.h:55
agxData::Array::allocateResult
agx::GlobalResult::Transaction allocateResult(size_t numElements)
Definition: Buffer.h:572
agx::GlobalResult::Transaction
Transactions are used to reserve exclusive memory areas in which the threads can write their data.
Definition: GlobalResult.h:72
agxData::Array::iterator
T * iterator
Definition: Array.h:116
agxData::Array::const_iterator
const typedef T * const_iterator
Definition: Array.h:117
agxData::Array::back
T & back()
Definition: Buffer.h:812
agxData::Array::difference_type
ptrdiff_t difference_type
Definition: Array.h:119
agxData::Array::Type
T Type
Definition: Array.h:109
agxData::Array::getGlobalResult
agx::GlobalResult * getGlobalResult()
Definition: Buffer.h:564
agxData::Array::begin
iterator begin()
Definition: Buffer.h:888
agxData::Array::IsScalar
static const bool IsScalar
Definition: Array.h:121
agx::init
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
Data.h
agxData::Array::at
T & at(size_t index)
Definition: Buffer.h:860
agx::GlobalResult
GlobalResult is used by kernels to generate result data from different threads.
Definition: GlobalResult.h:51