AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
EntityPtr.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#ifndef AGXDATA_ENTITYPTR_H
18#define AGXDATA_ENTITYPTR_H
19
20#ifdef _MSC_VER
21# pragma warning( disable: 4714 )// const' marked as __forceinline not inlined
22#endif
23
24#include <agx/agx.h>
25#include <agx/Vector.h>
26#include <agx/IndexRange.h>
28#include <iosfwd>
29
30namespace agxData
31{
32 class EntityStorage;
33 class EntityModel;
34 class EntityData;
35
36 class Attribute;
37 template <typename T> class ScalarAttributeT;
38 template <typename T> class PointerAttributeT;
39 template <typename T> class VectorAttributeT;
40 template <typename T> class HashSetAttributeT;
41 template <typename T> class ArrayAttributeT;
42 template <typename T> class SharedAttributeT;
43
52 {
53 public:
54 EntityPtr();
56 EntityPtr(const agxData::EntityPtr& other) = default;
57 EntityPtr(const agxData::EntityInstance& instance);
58
59 ~EntityPtr() = default;
60
61 EntityPtr& operator=( const EntityPtr& other ) = default;
62 EntityPtr& operator=( EntityPtr&& ) = default;
63
64 static EntityPtr createWithIndex(EntityStorage *storage, agx::Index index);
65
69 agxData::EntityStorage *getStorage() const;
70
74 agxData::EntityData *getData();
75 const agxData::EntityData *getData() const;
76
77 template <typename T>
78 T& dataSet();
79
80 template <typename T>
81 const T& dataSet() const;
82
86 agxData::EntityInstance instance();
87 const agxData::EntityInstance instance() const;
88
92 agx::Index getId() const;
93
97 void init(agxData::EntityStorage *storage, agx::Index id);
98
102 void invalidate();
103
107 agx::Index calculateIndex() const;
108
109
110
114 bool isValid() const;
115
119 void verifyIndex() const;
120
124 agxData::EntityModel* getModel();
125 const agxData::EntityModel* getModel() const;
126
130 bool isInstanceOf(agxData::EntityModel *model) const;
131
135 void destroy();
136
141
142
147
152
157
161 void swapId(EntityPtr& other);
162
166 void swapIndex(EntityPtr& other);
167
171 template <typename T>
172 T& operator() (const agxData::ScalarAttributeT<T> *attribute);
173
174 template <typename T>
175 const T& operator() (const agxData::ScalarAttributeT<T> *attribute) const;
176
178 template <typename T>
179 T& operator() (const agxData::PointerAttributeT<T> *attribute);
180
181 template <typename T>
182 const T& operator() (const agxData::PointerAttributeT<T> *attribute) const;
183
185 template <typename T>
187
188 template <typename T>
189 const typename agxData::VectorAttributeT<T>::Type& operator() (const agxData::VectorAttributeT<T> *attribute) const;
190
192 template <typename T>
194
195 template <typename T>
196 const typename agxData::HashSetAttributeT<T>::Type& operator() (const agxData::HashSetAttributeT<T> *attribute) const;
197
199 template <typename T>
200 typename agxData::ArrayAttributeT<T>::Type& operator() (const agxData::ArrayAttributeT<T> *attribute);
201
202 template <typename T>
203 const typename agxData::ArrayAttributeT<T>::Type& operator() (const agxData::ArrayAttributeT<T> *attribute) const;
204
206 template <typename T>
207 T& operator() (const agxData::SharedAttributeT<T> *attribute);
208
209 template <typename T>
210 const T& operator() (const agxData::SharedAttributeT<T> *attribute) const;
211
212 // Hash function
213 agx::UInt32 hash() const;
214
215
216 bool operator!() const;
217 operator bool() const;
218
219 bool operator<( const EntityPtr& rhs ) const;
220 bool operator>( const EntityPtr& rhs ) const;
221
222 bool operator==( const EntityPtr& rhs ) const;
223 bool operator!=( const EntityPtr& rhs ) const;
224
225 void print(std::ostream& stream) const;
226 void print() const;
227
228 static void TransformToAscii(void *targetBuffer, const void *sourceBuffer, size_t numElements);
229
230 private:
231 template <typename T>
232 friend class AttributePtr;
233
234 template <typename T>
235 T& getElement(const Attribute *attribute) const;
236
237 private:
238 EntityStorage *m_storage;
239 agx::Index m_id;
240 };
241
243
244 AGXCORE_EXPORT std::ostream& operator << (std::ostream& output, const EntityPtr& entity);
245
246
248 {
249 public:
250 EntityRange();
251 EntityRange(EntityStorage *storage, size_t start, size_t end);
252
253 EntityPtr operator[] (size_t index);
254 EntityPtr at(size_t index);
255 EntityRange operator[] (agx::IndexRange subRange);
256
257 private:
258 EntityStorage *m_storage;
259 };
260
261
262
263 /* Implementation */
264 AGX_FORCE_INLINE EntityPtr::EntityPtr() : m_storage(0), m_id(agx::InvalidIndex) {}
266
267
268
270 inline const EntityInstance EntityPtr::instance() const { return EntityInstance(const_cast<EntityData *>(getData()), calculateIndex()); }
271
274
276 {
277 m_storage = nullptr;
278 m_id = agx::InvalidIndex;
279 }
280
282 {
283 return agx::hash( agx::hash( m_storage ), agx::hash( m_id ) );
284 }
285
286
287 AGX_FORCE_INLINE bool EntityPtr::isValid() const { return m_storage != nullptr; }
288 AGX_FORCE_INLINE bool EntityPtr::operator!() const { return !this->isValid(); }
289 AGX_FORCE_INLINE EntityPtr::operator bool() const { return this->isValid(); }
290
292 {
293 return this->getId() < rhs.getId();
294 }
295
297 {
298 return this->getId() > rhs.getId();
299 }
300
302 {
303 return (this->getStorage() == rhs.getStorage()) && (this->getId() == rhs.getId());
304 }
305
307 {
308 return (this->getStorage() != rhs.getStorage()) || (this->getId() != rhs.getId());
309 }
310
311}
312
313
314#endif /* AGXDATA_ENTITYPTR_H */
#define AGXCORE_EXPORT
Type-specific Array used for fast access into the data held by a Buffer.
Definition: Array.h:107
An abstract attribute description, part of an Entity.
Definition: Attribute.h:58
Entity instance provides access to a single instance in an EntityStorage.
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:64
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:52
agx::Index calculateIndex() const
Calculate the index using the indirect id.
void print(std::ostream &stream) const
EntityPtr & operator=(const EntityPtr &other)=default
agxData::EntityData * getData()
agx::UInt32 hash() const
Definition: EntityPtr.h:281
void copyAttributes(agxData::EntityPtr source)
Copy instance attributes to an existing target instance.
bool operator!() const
Definition: EntityPtr.h:288
agxData::EntityInstance instance()
Definition: EntityPtr.h:269
agx::Index getId() const
Definition: EntityPtr.h:273
~EntityPtr()=default
static void TransformToAscii(void *targetBuffer, const void *sourceBuffer, size_t numElements)
agxData::EntityStorage * getStorage() const
Definition: EntityPtr.h:272
bool operator>(const EntityPtr &rhs) const
Definition: EntityPtr.h:296
void transfer(agxData::EntityStorage *target)
Transfer instance to another storage.
bool operator<(const EntityPtr &rhs) const
Definition: EntityPtr.h:291
agxData::EntityPtr copy(agxData::EntityStorage *target)
Copy instance to another storage.
EntityPtr & operator=(EntityPtr &&)=default
void print() const
bool isValid() const
Definition: EntityPtr.h:287
bool operator==(const EntityPtr &rhs) const
Definition: EntityPtr.h:301
agxData::EntityPtr copy()
Create a copy instance in the same storage.
void destroy()
Remove the entity from the active storage.
void invalidate()
Invalidate the entity pointer.
Definition: EntityPtr.h:275
bool operator!=(const EntityPtr &rhs) const
Definition: EntityPtr.h:306
void init(agxData::EntityStorage *storage, agx::Index id)
Set the target storage and id.
EntityPtr(const agxData::EntityPtr &other)=default
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:670
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Templated vector class.
Definition: agx/Vector.h:53
#define AGX_FORCE_INLINE
Definition: macros.h:58
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::VectorPOD< EntityPtr > EntityPtrVector
Definition: EntityPtr.h:242
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
UInt32 hash(const T &key)
Definition: HashFunction.h:165
uint32_t UInt32
Definition: Integer.h:32
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
UInt32 Index
Definition: Integer.h:44