AGX Dynamics  2.37.2.0
ReferencedEntity.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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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 
18 // AUTOMATICALLY GENERATED ENTITY, DO NOT EDIT! //
20 
21 #ifndef GENERATED_AGX_REFERENCED_H_PLUGIN
22 #define GENERATED_AGX_REFERENCED_H_PLUGIN
23 
24 #define AGX_ENTITY_WRAPPER 1
25 
26 
27 #ifdef _MSC_VER
28 # pragma warning(push)
29 // warning C4505: 'agxData::VectorAttributeT<T>::print' : unreferenced local function has been removed
30 # pragma warning( disable : 4505 )
31 // warning C4251: 'X' : class 'Y' needs to have dll-interface to be used by clients of class 'Z'
32 # pragma warning( disable : 4251 )
33 // warning C4355: 'this' : used in base member initializer list
34 # pragma warning( disable : 4355 )
35 // marked as __forceinline not inlined
36 # pragma warning( disable: 4714 )
37 #endif
38 
39 #include <agxData/EntityModel.h>
40 #include <agxData/EntityStorage.h>
41 #include <agxData/EntityRef.h>
42 #include <agxData/EntityPtr.h>
43 #include <agxData/EntityInstance.h>
44 #include <agx/Integer.h>
45 #include <agx/Real.h>
46 #include <agx/macros.h>
47 #include <agx/Integer.h>
48 #include <agx/SpinMutex.h>
49 
50 
51 namespace agx
52 {
53 
54  class ReferencedModel;
55  class ReferencedData;
56  class ReferencedPtr;
57  class ReferencedInstance;
58  class ReferencedSemantics;
59 
60 
62 
67  {
68  public:
70 
71  ReferencedModel(const agx::String& name = "Referenced");
72 
74  static ReferencedModel* instance();
75 
77  static ReferencedPtr createInstance();
78 
80  static agxData::EntityStorage* defaultStorage();
81 
83  virtual void shutdownCleanup() override;
84 
85 
86 
87  /* Attributes */
91 
92  protected:
93  virtual ~ReferencedModel();
94  virtual agxData::EntityData* createData(agxData::EntityStorage* storage) override;
95  virtual void configure(agx::TiXmlElement* eEntity) override;
96  virtual void initAttributeAccessors() override;
97  virtual void construct(agxData::EntityPtr instance) override;
98  void construct(agx::ReferencedPtr referenced);
99  };
100 
101 
103  #ifndef AGX_REFERENCED_DATA_SET_OVERRIDE
104  #define AGX_REFERENCED_DATA_SET
105  class AGXCORE_EXPORT ReferencedData : public agxData::EntityData
106  {
107  public:
108  ReferencedInstance operator[] (size_t index);
109 
110  public:
112  agxData::Array< agx::UInt32 > referenceCount;
113  agxData::Array< agx::SpinMutex > observerMutex;
115 
116  public:
117  typedef agx::UInt32 referenceCountType;
118  typedef agx::SpinMutex observerMutexType;
119  typedef agx::Vector< agxData::EntityPtr * > observersType;
120 
121  public:
122  ReferencedData(agxData::EntityStorage* storage);
123  ReferencedData();
124 
125  protected:
126  virtual ~ReferencedData() {}
127  virtual void setNumElements(agx::Index numElements) override;
128 
129  private:
130  ReferencedData& operator= (const ReferencedData&) { return *this; }
131 
132  };
133  #endif
135 
136 
138  class AGXCORE_EXPORT ReferencedSemantics : protected agxData::EntityPtr
139  {
140  public:
141 
142  // Automatic getters
143  agx::UInt32 const& getReferenceCount() const;
144  agx::SpinMutex const& getObserverMutex() const;
145  agx::Vector< agxData::EntityPtr * > const& getObservers() const;
146 
147  // Semantics defined by explicit kernels
148 
149  // Automatic setters
150  void setReferenceCount(agx::UInt32 const& value);
151  void setObserverMutex(agx::SpinMutex const& value);
152  void setObservers(agx::Vector< agxData::EntityPtr * > const& value);
153 
154 
155  protected:
156  friend class ReferencedPtr;
157  friend class ReferencedInstance;
158  ReferencedSemantics();
159  };
161 
162 
163 
166  class CALLABLE ReferencedPtr : public agxData::EntityPtr
167  {
168  public:
170  typedef ReferencedData DataType;
171  typedef ReferencedInstance InstanceType;
172 
173  public:
178  AGXCORE_EXPORT ReferencedPtr& operator= (const agxData::EntityPtr& ptr);
179  AGXCORE_EXPORT ReferencedPtr& operator= (const agxData::EntityInstance& instance);
180  AGXCORE_EXPORT ReferencedInstance instance();
181  AGXCORE_EXPORT const ReferencedInstance instance() const;
182 
183  AGXCORE_EXPORT ReferencedSemantics* operator->();
184  AGXCORE_EXPORT const ReferencedSemantics* operator->() const;
185 
186  ReferencedData* getData();
187  const ReferencedData* getData() const;
188 
189 
191  AGXCORE_EXPORT agx::UInt32& referenceCount();
193  AGXCORE_EXPORT agx::UInt32 const& referenceCount() const;
194 
196  AGXCORE_EXPORT agx::SpinMutex& observerMutex();
198  AGXCORE_EXPORT agx::SpinMutex const& observerMutex() const;
199 
203  AGXCORE_EXPORT agx::Vector< agxData::EntityPtr * > const& observers() const;
204 
205  };
206 
207  // Entity is Referenced
209 
210 
212  class AGXCORE_EXPORT ReferencedInstance : public agxData::EntityInstance
213  {
214  public:
215  ReferencedInstance();
216  ReferencedInstance(ReferencedData* data, agx::Index index);
217  ReferencedInstance(agxData::EntityStorage *storage, agx::Index index);
218  ReferencedInstance(const agxData::EntityInstance& other);
219  ReferencedInstance(const agxData::EntityPtr& ptr);
220 
221  ReferencedData* getData();
222  const ReferencedData* getData() const;
223 
224  public:
226  agx::UInt32& referenceCount();
228  agx::UInt32 const& referenceCount() const;
229 
231  agx::SpinMutex& observerMutex();
233  agx::SpinMutex const& observerMutex() const;
234 
238  agx::Vector< agxData::EntityPtr * > const& observers() const;
239 
240  };
242 
243 
244 
247 
248 
249 
251  /* Implementation */
252  //-----------------------------------------------------------------------------------------------------
253  //-----------------------------------------------------------------------------------------------------
254  inline ReferencedInstance agx::ReferencedData::operator[] (size_t index) { return ReferencedInstance(this, (agx::Index)index); }
255  //-----------------------------------------------------------------------------------------------------
259  {
261  "Entity type mismatch. Storage contains entity data for type \'%s\', instance pointer is of type \'%s\'",
263  }
264 
266  {
267  agxAssertN(!instance || instance.isInstanceOf(ReferencedModel::instance()),
268  "Entity type mismatch. Storage contains entity data for type \'%s\', instance pointer is of type \'%s\'",
270  }
271 
273  {
276  "Entity type mismatch. Storage contains entity data for type \'%s\', instance pointer is of type \'%s\'",
278  return *this;
279  }
280 
282  {
284  agxAssertN(!instance || instance.isInstanceOf(ReferencedModel::instance()),
285  "Entity type mismatch. Storage contains entity data for type \'%s\', instance pointer is of type \'%s\'",
287  return *this;
288  }
289 
290  inline ReferencedInstance ReferencedPtr::instance() { return agxData::EntityPtr::instance(); }
291  inline const ReferencedInstance ReferencedPtr::instance() const { return agxData::EntityPtr::instance(); }
292  AGX_FORCE_INLINE ReferencedSemantics* ReferencedPtr::operator->() { return (ReferencedSemantics* )this; }
293  AGX_FORCE_INLINE const ReferencedSemantics* ReferencedPtr::operator->() const { return (const ReferencedSemantics* )this; }
294  AGX_FORCE_INLINE ReferencedData* ReferencedPtr::getData() { return static_cast<ReferencedData* >(agxData::EntityPtr::getData()); }
295  AGX_FORCE_INLINE const ReferencedData* ReferencedPtr::getData() const { return static_cast<const ReferencedData* >(agxData::EntityPtr::getData()); }
296 
297  AGX_FORCE_INLINE agx::UInt32& ReferencedPtr::referenceCount() { verifyIndex(); return getData()->referenceCount[calculateIndex()]; }
298  AGX_FORCE_INLINE agx::UInt32 const& ReferencedPtr::referenceCount() const { verifyIndex(); return getData()->referenceCount[calculateIndex()]; }
299 
300  AGX_FORCE_INLINE agx::SpinMutex& ReferencedPtr::observerMutex() { verifyIndex(); return getData()->observerMutex[calculateIndex()]; }
301  AGX_FORCE_INLINE agx::SpinMutex const& ReferencedPtr::observerMutex() const { verifyIndex(); return getData()->observerMutex[calculateIndex()]; }
302 
303  AGX_FORCE_INLINE agx::Vector< agxData::EntityPtr * >& ReferencedPtr::observers() { verifyIndex(); return getData()->observers[calculateIndex()]; }
304  AGX_FORCE_INLINE agx::Vector< agxData::EntityPtr * > const& ReferencedPtr::observers() const { verifyIndex(); return getData()->observers[calculateIndex()]; }
305 
306  //-----------------------------------------------------------------------------------------------------
307  AGX_FORCE_INLINE ReferencedInstance::ReferencedInstance() {}
308  AGX_FORCE_INLINE ReferencedInstance::ReferencedInstance(ReferencedData* data, agx::Index index) : agxData::EntityInstance(data, index) {}
309  AGX_FORCE_INLINE ReferencedInstance::ReferencedInstance(agxData::EntityStorage* storage, agx::Index index) : agxData::EntityInstance(storage, index) {}
310  AGX_FORCE_INLINE ReferencedInstance::ReferencedInstance(const agxData::EntityInstance& other) : agxData::EntityInstance(other)
311  {
313  "Entity type mismatch. Storage contains entity data for type \'%s\', instance pointer is of type \'%s\'",
315  }
316 
317  AGX_FORCE_INLINE ReferencedInstance::ReferencedInstance(const agxData::EntityPtr& ptr) : agxData::EntityInstance(ptr)
318  {
320  "Entity type mismatch. Storage contains entity data for type \'%s\', instance pointer is of type \'%s\'",
322  }
323 
324 
325  AGX_FORCE_INLINE ReferencedData* ReferencedInstance::getData() { return static_cast<ReferencedData* >(agxData::EntityInstance::getData()); }
326  AGX_FORCE_INLINE const ReferencedData* ReferencedInstance::getData() const { return static_cast<const ReferencedData* >(agxData::EntityInstance::getData()); }
327 
328  AGX_FORCE_INLINE agx::UInt32& ReferencedInstance::referenceCount() { verifyIndex(); return getData()->referenceCount[getIndex()]; }
329  AGX_FORCE_INLINE agx::UInt32 const& ReferencedInstance::referenceCount() const { verifyIndex(); return getData()->referenceCount[getIndex()]; }
330 
331  AGX_FORCE_INLINE agx::SpinMutex& ReferencedInstance::observerMutex() { verifyIndex(); return getData()->observerMutex[getIndex()]; }
332  AGX_FORCE_INLINE agx::SpinMutex const& ReferencedInstance::observerMutex() const { verifyIndex(); return getData()->observerMutex[getIndex()]; }
333 
334  AGX_FORCE_INLINE agx::Vector< agxData::EntityPtr * >& ReferencedInstance::observers() { verifyIndex(); return getData()->observers[getIndex()]; }
335  AGX_FORCE_INLINE agx::Vector< agxData::EntityPtr * > const& ReferencedInstance::observers() const { verifyIndex(); return getData()->observers[getIndex()]; }
336 
337  //-----------------------------------------------------------------------------------------------------
338  AGX_FORCE_INLINE ReferencedSemantics::ReferencedSemantics() {}
339  //-----------------------------------------------------------------------------------------------------
341 }
342 
343 AGX_TYPE_BINDING(agx::ReferencedPtr, "ReferencedPtr")
344 AGX_TYPE_BINDING(agx::ReferencedInstance, "ReferencedInstance")
345 
346 #ifdef _MSC_VER
347 # pragma warning(pop)
348 #endif
349 
350 #undef AGX_ENTITY_WRAPPER
351 #undef AGX_ENTITY_NAMESPACE
352 #endif
353 
AGXCORE_EXPORT ReferencedInstance instance()
AGXCORE_EXPORT agx::Vector< agxData::EntityPtr *> & observers()
agxData::EntityData * getData()
agxData::EntityInstance instance()
Definition: EntityPtr.h:269
An entity reference is a safe/referencing handle to an entity instance whose model is descendant from...
Definition: EntityRef.h:34
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
#define agxAssertN(expr, format,...)
Definition: debug.h:145
agxData::EntityData * getData()
agx::String fullPath() const
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
AGXCORE_EXPORT Model * getModel(const Path &path, const Path &_namespace=Path())
Definition: Object.h:363
static agxData::ScalarAttributeT< agx::Vector< agxData::EntityPtr *> > * observersAttribute
Entity instance provides access to a single instance in an EntityStorage.
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:51
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
bool isInstanceOf(agxData::EntityModel *model) const
static agxData::ScalarAttributeT< agx::SpinMutex > * observerMutexAttribute
#define AGX_FORCE_INLINE
Definition: Object.h:59
ReferencedModel ModelType
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
AGXCORE_EXPORT agx::UInt32 & referenceCount()
Templated vector class.
Definition: Vector.h:52
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
EntityPtr & operator=(const EntityPtr &other)=default
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
AGXCORE_EXPORT ReferencedPtr()
static ReferencedModel * instance()
Contains classes for low level data storage for AGX.
Definition: Container.h:23
UInt32 Index
Definition: Integer.h:52
static agxData::ScalarAttributeT< agx::UInt32 > * referenceCountAttribute
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:63
#define CALLABLE
Definition: Object.h:73
Abstract description of the data attributes for the Referenced entity.
bool isInstanceOf(agxData::EntityModel *model) const
Pointer to a entity instance of type Referenced.
AGXCORE_EXPORT ReferencedPtr & operator=(const agxData::EntityPtr &ptr)
ReferencedInstance InstanceType
ReferencedData * getData()
Spin-lock mutex.
Definition: SpinMutex.h:46
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
agxData::EntityRef< ReferencedPtr > ReferencedRef
#define AGXCORE_EXPORT
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
AGXCORE_EXPORT ReferencedSemantics * operator->()
ReferencedData DataType
AGXCORE_EXPORT agx::SpinMutex & observerMutex()