32# pragma warning(disable: 6011)
39 class GlobalResultBuffer;
61 virtual void configure(agx::TiXmlElement *eBuffer)
override;
105 template <
typename T>
108 template <
typename T>
123 size_t capacity()
const;
133 void resize(
size_t size,
bool initializeElements =
true);
134 void presize(
size_t size,
size_t initialSize);
155 const void* ptr()
const;
157 template <
typename T>
160 template <
typename T>
161 const T *ptr()
const;
171 template <
typename T>
172 T& getElement(
size_t index);
174 template <
typename T>
175 const T& getElement(
size_t index)
const;
187 void *getElement(
size_t index);
188 const void *getElement(
size_t index)
const;
199 size_t getElementArraySize()
const;
218 static void copy(
Buffer *target,
size_t targetOffset,
const Buffer *source,
size_t sourceOffset,
size_t numElements);
229 void print(std::ostream& stream)
const;
254 Buffer *getGlobalOrderBuffer();
255 const Buffer *getGlobalOrderBuffer()
const;
263 Buffer *getElementBuffer();
264 const Buffer *getElementBuffer()
const;
313 void signalReallocation();
318 void keyFrameReserve(
size_t capacity);
333 void setOriginalBuffer(
Buffer *buffer);
364 template <
typename T>
395 template <
typename T>
399 template <
typename T2>
418 template <
typename T2>
419 bool contains(
const T2& value)
const;
421 template <
typename T2>
422 size_t find(
const T2& value)
const;
428 const T&
at(
size_t index)
const;
431 const T&
front()
const;
434 const T&
back()
const;
482 template <
typename T>
485 agxAssertN(
m_format->is(agxData::getFormat<T>()) &&
m_format->getSize() == agxData::getFormat<T>()->getSize(),
"Type mismatch! Buffer has type %s, requested array of type %s",
m_format->fullName().c_str(), agxData::getFormat<T>()->fullName().c_str());
489 template <
typename T>
492 return const_cast<Buffer *
>(
this)->getArray<T>();
502 template <
typename T>
506 return static_cast<T *
>(
m_ptr);
509 template <
typename T>
512 return const_cast<Buffer *
>(
this)->ptr<T>();
516 template <
typename T>
528 template <
typename T>
531 return const_cast<Buffer *
>(
this)->getElement<T>(index);
563 template <
typename T>
568 return m_buffer->getGlobalResult();
571 template <
typename T>
574 return this->getGlobalResult()->allocateResult(numElements);
577 template <
typename T>
580 if (numElements == 0)
583 return this->getGlobalResult()->commit(*
this, numElements, localResult, sortIndex);
586 template <
typename T>
589 if (numElements == 0)
592 return this->getGlobalResult()->commit(*
this, numElements, localResult);
595 template <
typename T>
template <
typename T2>
601 return this->getGlobalResult()->commit(*
this, vector, sortIndex);
605 template <
typename T>
template <
typename T2>
611 return this->getGlobalResult()->commit(*
this, vector);
619 template <
typename T>
622 template <
typename T>
732 template <
typename T>
737 result.
m_ptr = buffer;
743 template <
typename T>
748 result.
m_ptr = (T *)buffer;
754 template <
typename T>
759 template <
typename T>
762 #ifndef AGX_ENTITY_WRAPPER
768 template <
typename T>
771 #ifndef AGX_ENTITY_WRAPPER
776 template <
typename T>
781 template <
typename T>
784 this->m_ptr = vec.
ptr();
788 template <
typename T>
792 this->m_ptr = vec.
ptr();
793 this->m_range = range;
796 template <
typename T>
799 this->m_ptr = vec.
ptr();
803 template <
typename T>
807 this->m_ptr = vec.
ptr();
808 this->m_range = range;
811 template <
typename T>
815 agxAssert1(!m_range.empty(),
"Can not take back element of an empty array!");
816 return ((T*)m_ptr)[m_range.size()-1];
819 template <
typename T>
823 agxAssert1(!m_range.empty(),
"Can not take back element of an empty array!");
824 return ((T*)m_ptr)[m_range.size()-1];
827 template <
typename T>
831 agxAssert1(!m_range.empty(),
"Can not take front element of an empty array!");
832 return ((T*)m_ptr)[0];
835 template <
typename T>
839 agxAssert1(!m_range.empty(),
"Can not take front element of an empty array!");
840 return ((T*)m_ptr)[0];
844 template <
typename T>
847 agxAssert1(m_ptr,
"Array does not have an active buffer!");
848 agxAssertN(index < m_range.size(),
"Array index %llu is out of bounds, size is %llu", (
long long unsigned)index, (
long long unsigned)m_range.size());
849 return ((T*)m_ptr)[index];
853 template <
typename T>
856 return const_cast<Array<T>*
>(
this)->
operator[](index);
859 template <
typename T>
863 agxVerifyN(index < m_range.size(),
"Array index %llu is out of bounds, size is %llu", (
long long unsigned)index, (
long long unsigned)m_range.size());
864 return ((T*)m_ptr)[index];
867 template <
typename T>
870 return const_cast<Array<T>*
>(
this)->at(index);
874 template <
typename T>
881 template <
typename T>
884 return this->slice(subRange);
887 template <
typename T>
890 template <
typename T>
893 template <
typename T>
896 template <
typename T>
899 template <
typename T>
903 template <
typename T>
907 template <
typename T>
template <
typename T2>
910 for (
size_t i = 0, numElements = size(); i < numElements; ++i)
912 if ((*
this)[i] == element)
919 template <
typename T>
template <
typename T2>
926 template <
typename T>
929 for (
size_t i = 0; i < array.
size(); i++)
933 if (i < array.size()-1)
944 template <
typename T>
template <
typename T2>
947 const Buffer *buffer =
dynamic_cast<const Buffer *
>(object);
948 return buffer ? buffer->
getFormat() == agxData::getFormat<T>() :
false;
951 template <
typename T>
956 template <
typename T>
961 template <
typename T>
967 template <
typename T>
971 return reinterpret_cast<Array<T>&
>(m_array);
974 template <
typename T>
977 return const_cast<BufferT<T> *
>(
this)->array();
982 template <
typename T>
989 array().range().end()++;
990 ::new((
void *)&array().back()) T(value);
993 template <
typename T>
999 array().range().end()--;
1003 template <
typename T>
1006 for (
size_t i = 0; i <
m_size; ++i)
1010 array().range().end() = 0;
1013 template <
typename T>
template <
typename T2>
1016 return array().contains(value);
1019 template <
typename T>
template <
typename T2>
1022 return array().find(value);
1025 template <
typename T>
1028 return array()[index];
1031 template <
typename T>
1034 return const_cast<BufferT<T> *
>(
this)->
operator[](index);
1037 template <
typename T>
1040 return array().at(index);
1043 template <
typename T>
1046 return const_cast<BufferT<T> *
>(
this)->at(index);
1049 template <
typename T>
1052 return array().front();
1055 template <
typename T>
1058 return const_cast<BufferT<T> *
>(
this)->front();
1061 template <
typename T>
1064 return array().back();
1067 template <
typename T>
1070 return const_cast<BufferT<T> *
>(
this)->back();
1075 template <
typename T>
1078 return array().begin();
1081 template <
typename T>
1084 return array().begin();
1087 template <
typename T>
1090 return array().end();
1093 template <
typename T>
1096 return array().end();
1099 template <
typename T>
1105 template <
typename T>
1111 template <
typename T>
1117 template <
typename T>
1123 template <
typename T>
1135# pragma warning(pop)
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGX_DECLARE_VECTOR_TYPES(type)
Arrays are fast accessors into the data, or a portion of it, held by a Buffer.
const agxData::Buffer * buffer() const
void _setBuffer(agxData::Buffer *buffer)
Set the buffer while maintaining the current range, should normally not be used.
void init()
Set to empty array.
agx::IndexRange32 m_range
agx::IndexRange32 & range()
agxData::Format * getFormat()
void sync()
Updates the internal data access pointer. Called when the back end buffer is reallocated.
agxData::Buffer * m_buffer
AbstractArray()
Create a new invalid array.
void setRange(size_t startIndex, size_t endIndex)
Set the range of the buffer that the array will cover.
Type-specific Array used for fast access into the data held by a Buffer.
agx::GlobalResult::Transaction allocateResult(size_t numElements)
Array()
Create a new invalid array.
size_t commitResult(size_t numElements, const void *localResult, agx::Index sortIndex)
size_t find(const T2 &element) const
The index of the first occurrence of an element that is equal to the given element.
bool contains(const T2 &element) const
static agxData::Array< T > raw(T *buffer, agx::Index size)
Array creation helper method that creates an array covering the given memory area.
agx::GlobalResult * getGlobalResult()
T & operator[](size_t index)
agxData::Array< T > slice(agx::IndexRange32 subRange) const
An abstract attribute description, part of an Entity.
void deallocateBytes(void *buffer, size_t numBytes)
BufferProxyAllocator & operator=(const BufferProxyAllocator &other)
BufferProxyAllocator(Buffer *buffer=nullptr)
void setBuffer(Buffer *buffer)
void setContainer(agx::Container *container)
void * allocateBytes(size_t numBytes)
void push_back(const T &value)
bool contains(const T2 &value) const
size_t find(const T2 &value) const
static bool ValidateCast(const agx::Referenced *object)
T & operator[](size_t index)
Abstract representation of a data buffer.
agx::Event1< Buffer * > Event
RangeCallback m_initializer
void addListener(EventListener *listener)
agxData::Buffer * m_originalBuffer
static void copy(Buffer *target, size_t targetOffset, const Buffer *source, size_t sourceOffset, size_t numElements)
T & getElement(size_t index)
static void destroyElements(Buffer *buffer, const agx::IndexRange &range)
agxData::Value::Event::CallbackType m_resizeCallback
const agxData::Value::Event::CallbackType & getReserveCallback() const
static void copyScatter(Buffer *target, const Buffer *source, const agxData::IndexArray &indices)
void commit(agx::Index index)
agxData::Type * getType()
EntityStorage * m_storage
Buffer(const agxData::Format *format)
size_t getElementArraySize() const
static void copy(Buffer *target, const Buffer *source)
Copy one buffer to another.
agxData::Array< T > & getArray()
Convenience method to get an direct data array.
agx::UInt64 getRevision() const
agx::Callback2< Buffer *, const agx::IndexRange & > RangeCallback
Specify a custom element initializer callback.
Buffer(const agx::Name &name, const agxData::Format *format)
void commit(const agxData::IndexArray &indexList)
void presize(size_t size, size_t initialSize)
void * allocateBackBuffer()
agx::GlobalResultBuffer * getGlobalResult()
Buffer * getOriginalBuffer()
const Buffer * getOriginalBuffer() const
agxData::BufferRef m_elementBuffer
RangeCallback m_destructor
agxData::Attribute * getAttribute()
virtual void configure(agx::TiXmlElement *eBuffer) override
void * ptr()
Get access to the raw data buffer.
const agxData::Array< T > & getArray() const
agxData::EntityStorage * getStorage()
agxData::Format * getFormat()
void clear()
Clear the buffer.
void registerSharedContainer(agx::Container *container)
Buffer * clone(const agxData::IndexArray &indices) const
void setElementInitializer(const RangeCallback &callback)
static void initializeElements(Buffer *buffer, const agx::IndexRange &range)
agxData::Value * getDefaultValue()
agxData::ValueRefT< agx::UInt > capacityParameter
void print(std::ostream &stream) const
void setDefaultValue(agxData::Value *value)
Set the default element value.
Buffer * clone(const agx::IndexRange &range) const
Clone a subset of the buffer.
void print(std::ostream &stream, agx::IndexRange range) const
void reserve(size_t size)
Reserve space for future buffer expansion.
agxData::ShareHandleRef m_shareHandle
virtual void reallocate(size_t size)
void * kernelOverflowReallocation(size_t size)
agx::ByteAllocator m_allocator
static agx::UInt ALIGNMENT
agxData::ValueRef m_defaultElementValue
void swapBackBuffer(void *backBuffer)
void unregisterSharedContainer(agx::Container *container)
virtual void buildNavigationTree(agxJson::Value &eNode) const override
agx::Container * m_sharedContainer
const agxData::Value::Event::CallbackType & getResizeCallback() const
void setRevision(agx::UInt64 revision)
Event reallocationEvent
Triggered when buffer is reallocated.
agxData::Value::Event::CallbackType m_reserveCallback
Buffer * clone() const
Clone the buffer.
bool hasListener(EventListener *listener)
agx::GlobalResultBuffer * m_globalResult
void removeListener(EventListener *listener)
void initialize(const agx::IndexRange &range)
Initialize a range of elements.
virtual void snapshot(agx::TiXmlNode *eParent, const agx::String &directory) const override
static Buffer * load(agx::TiXmlElement *eBuffer, agx::Device *device)
Buffer * getElementBuffer()
If the buffer contains arrays/vectors, the actual elements are stored in another buffer.
void deleteOverflowBuffer(void *buffer, size_t numElements)
EventDispatch m_eventDispatch
agxData::BufferRef m_globalOrderBuffer
void setElementBuffer(Buffer *buffer)
Set the element buffer, internal use only.
void print(agx::IndexRange range) const
Buffer * getOrCreateGlobalOrderBuffer()
agxData::ValueRefT< agx::UInt > sizeParameter
Buffer * getGlobalOrderBuffer()
If the buffer is used as a global result, we provide a permutation buffer for parallel determinism.
void setElementDestructor(const RangeCallback &callback)
void commit(agx::IndexRange32 range)
void print() const
Print the buffer.
static agx::UInt MIN_BUFFER_CAPACITY
static agx::Model * ClassModel()
static agx::Real CAPACITY_MULTIPLIER
const AbstractArray & asArray() const
Data storage for a collection of entity instances of a specified EntityModel.
Templated value-reference.
Abstract representation of a value.
Templated callback with two arguments.
A component is an object containing other objects, enabling hierarchical structuring.
The Container is the base class for several of the container classes proided by AGX,...
An agx::Device is an abstract representation of a device on which data can be stored and processed.
An event with one argument.
Transactions are used to reserve exclusive memory areas in which the threads can write their data.
GlobalResult is used by kernels to generate result data from different threads.
A model is an abstract representation of the class of an agx::Object.
bool is(const agx::Model *other) const
Representation of a name string.
agx::String fullName() const
Base class providing referencing counted objects.
bool is() const
Subclass test.
T * ptr()
Get access to the internal data buffer.
T * ptr()
Get access to the internal data buffer.
#define agxAssert1(expr, msg)
#define agxAssertN(expr, format,...)
#define agxVerifyN(expr, format,...)
bool AGXCORE_EXPORT isShutdown()
Contains classes for low level data storage for AGX.
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
AGXCORE_EXPORT Type * getType(const agx::String &name)
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
IndexRangeT< agx::UInt32 > IndexRange32
VectorPOD< Index > IndexVector
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex