AGXDynamics  2.35.0.3
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 */
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxData::EntityInstance::operator<
bool operator<(const EntityInstance &rhs) const
Definition: EntityInstance.h:161
agxData::EntityModel
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:63
agxData::EntityInstance::operator>
bool operator>(const EntityInstance &rhs) const
Definition: EntityInstance.h:166
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agxData
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agxData::EntityInstance::operator!
bool operator!() const
Boolean operators, implemented using isValid.
Definition: EntityInstance.h:158
agxData::EntityInstance::operator!=
bool operator!=(const EntityInstance &rhs) const
Definition: EntityInstance.h:176
agxData::EntityInstance::getIndex
agx::Index getIndex() const
Definition: EntityInstance.h:147
agxData::EntityInstance::init
void init(agxData::EntityData *data, agx::Index index)
Initialize an instance.
Definition: EntityInstance.h:145
agxTerrain::Profiler::getStorage
AGXTERRAIN_EXPORT TimingStorage & getStorage()
Integer.h
agx::Index
UInt32 Index
Definition: Integer.h:52
agxData::EntityInstance
Entity instance provides access to a single instance in an EntityStorage.
Definition: EntityInstance.h:43
agx::operator!=
bool operator!=(T val, InvalidIndexStruct)
Definition: agx.h:196
agx::hash
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65
agxData::EntityInstance::getStorage
agxData::EntityStorage * getStorage()
Alias for getData()->getStorage()
Definition: EntityStorage.h:822
agx.h
agxData::EntityInstance::getData
agxData::EntityData * getData()
Definition: EntityInstance.h:149
agxData::EntityInstance::isValid
bool isValid() const
Definition: EntityInstance.h:157
agx::operator==
bool operator==(T val, InvalidIndexStruct)
Definition: agx.h:190
hash.h
agx::init
void AGXPHYSICS_EXPORT init()
Initialize agx.
agx::InvalidIndex
const AGXCORE_EXPORT InvalidIndexStruct InvalidIndex
agxData::EntityInstance::EntityInstance
EntityInstance()
Constructors.
Definition: EntityInstance.h:134
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxData::EntityPtr
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:51
agxData::operator<<
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxData::EntityInstance::hash
agx::UInt32 hash() const
Definition: EntityInstance.h:152
agxData::EntityDataPtr
agxData::EntityData * EntityDataPtr
Definition: EntityData.h:36
agx::getModel
AGXCORE_EXPORT Model * getModel(const Path &path, const Path &_namespace=Path())
Definition: Object.h:364
agxData::EntityInstance::operator==
bool operator==(const EntityInstance &rhs) const
Definition: EntityInstance.h:171