AGX Dynamics  2.35.0.1
EntityInstance.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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_ENTITYINSTANCE_H
18 #define AGXDATA_ENTITYINSTANCE_H
19 
20 #include <agx/agx.h>
21 #include <agx/Integer.h>
22 #include <agx/hash.h>
23 // #include <agxData/EntityData.h>
24 
25 namespace agxData
26 {
27  class EntityStorage;
28  class EntityData;
29  class EntityModel;
30  class EntityPtr;
31  typedef agxData::EntityData* EntityDataPtr;
32 
33 
44  {
45  public:
49  EntityInstance(agxData::EntityData* data, agx::Index index);
51  EntityInstance(const agxData::EntityPtr& other);
52 
54  ~EntityInstance() = default;
55 
61  void init(agxData::EntityData* data, agx::Index index);
62 
66  agx::Index getIndex() const;
67 
71  agx::Index calculateId() const;
72 
76  agxData::EntityData* getData();
77  const agxData::EntityData* getData() const;
78 
84  const agxData::EntityStorage* getStorage() const;
85 
91  const agxData::EntityModel* getModel() const;
92 
96  bool isInstanceOf(agxData::EntityModel* model) const;
97 
101  bool isValid() const;
102 
106  void verifyIndex() const;
107 
108 
109  // Hash function
110  agx::UInt32 hash() const;
111 
113  bool operator!() const;
114  operator bool() const;
115 
116  bool operator<( const EntityInstance& rhs ) const;
117  bool operator>( const EntityInstance& rhs ) const;
118 
119  bool operator==( const EntityInstance& rhs ) const;
120  bool operator!=( const EntityInstance& rhs ) const;
121 
122  static void TransformToAscii(void *targetBuffer, const void *sourceBuffer, size_t numElements);
123 
124  private:
125 
126  EntityDataPtr m_data;
127  agx::Index m_index;
128  };
129 
130 
131  AGXCORE_EXPORT std::ostream& operator << (std::ostream& output, const EntityInstance& entity);
132 
133  /* Implementation */
135  {}
136 
137  AGX_FORCE_INLINE EntityInstance::EntityInstance(agxData::EntityData* data, agx::Index index) : m_data(data), m_index(index)
138  {}
139 
140 
141  AGX_FORCE_INLINE EntityInstance::EntityInstance(const agxData::EntityInstance& other) : m_data(other.m_data), m_index(other.m_index)
142  {}
143 
144 
145  AGX_FORCE_INLINE void EntityInstance::init(agxData::EntityData* data, agx::Index index) { m_data = data; m_index = index; }
146 
148 
149  AGX_FORCE_INLINE agxData::EntityData* EntityInstance::getData() { return m_data; }
150  AGX_FORCE_INLINE const agxData::EntityData* EntityInstance::getData() const { return m_data; }
151 
153  {
154  return agx::hash( agx::hash( m_data ), agx::hash( m_index ) );
155  }
156 
157  AGX_FORCE_INLINE bool EntityInstance::isValid() const { return m_data != nullptr; }
158  AGX_FORCE_INLINE bool EntityInstance::operator!() const { return !this->isValid(); }
159  AGX_FORCE_INLINE EntityInstance::operator bool() const { return this->isValid(); }
160 
162  {
163  return this->getIndex() < rhs.getIndex();
164  }
165 
167  {
168  return this->getIndex() > rhs.getIndex();
169  }
170 
172  {
173  return (this->getStorage() == rhs.getStorage()) && (this->getIndex() == rhs.getIndex());
174  }
175 
177  {
178  return (this->getStorage() != rhs.getStorage()) || (this->getIndex() != rhs.getIndex());
179  }
180 
181 
182 }
183 
184 
185 #endif /* AGXDATA_ENTITYINSTANCE_H */
#define AGXCORE_EXPORT
Entity instance provides access to a single instance in an EntityStorage.
~EntityInstance()=default
Destructor.
bool operator!() const
Boolean operators, implemented using isValid.
bool operator<(const EntityInstance &rhs) const
void init(agxData::EntityData *data, agx::Index index)
Initialize an instance.
bool operator!=(const EntityInstance &rhs) const
agx::UInt32 hash() const
agx::Index getIndex() const
bool operator==(const EntityInstance &rhs) const
bool operator>(const EntityInstance &rhs) const
EntityInstance()
Constructors.
static void TransformToAscii(void *targetBuffer, const void *sourceBuffer, size_t numElements)
agxData::EntityStorage * getStorage()
Alias for getData()->getStorage()
agxData::EntityData * getData()
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
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
#define AGX_FORCE_INLINE
Definition: macros.h:58
Contains classes for low level data storage for AGX.
Definition: Container.h:23
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
agxData::EntityData * EntityDataPtr
Definition: EntityData.h:36
AGXTERRAIN_EXPORT TimingStorage & getStorage()
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:40
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65
bool operator!=(T val, InvalidIndexStruct)
Definition: agx.h:196
bool operator==(T val, InvalidIndexStruct)
Definition: agx.h:190
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
void AGXPHYSICS_EXPORT init()
Initialize agx.
AGXCORE_EXPORT Model * getModel(const Path &path, const Path &_namespace=Path())
Definition: Object.h:364
UInt32 Index
Definition: Integer.h:52