AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
EntityInstance.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_ENTITYINSTANCE_H
18#define AGXDATA_ENTITYINSTANCE_H
19
20#include <agx/agx.h>
21#include <agx/hash.h>
22// #include <agxData/EntityData.h>
23
24namespace agxData
25{
26 class EntityStorage;
27 class EntityData;
28 class EntityModel;
29 class EntityPtr;
30 typedef agxData::EntityData* EntityDataPtr;
31
32
43 {
44 public:
48 EntityInstance(agxData::EntityData* data, agx::Index index);
51
53 ~EntityInstance() = default;
54
60 void init(agxData::EntityData* data, agx::Index index);
61
65 agx::Index getIndex() const;
66
70 agx::Index calculateId() const;
71
75 agxData::EntityData* getData();
76 const agxData::EntityData* getData() const;
77
82 agxData::EntityStorage* getStorage();
83 const agxData::EntityStorage* getStorage() const;
84
89 agxData::EntityModel* getModel();
90 const agxData::EntityModel* getModel() const;
91
95 bool isInstanceOf(agxData::EntityModel* model) const;
96
100 bool isValid() const;
101
105 void verifyIndex() const;
106
107
108 // Hash function
109 agx::UInt32 hash() const;
110
112 bool operator!() const;
113 operator bool() const;
114
115 bool operator<( const EntityInstance& rhs ) const;
116 bool operator>( const EntityInstance& rhs ) const;
117
118 bool operator==( const EntityInstance& rhs ) const;
119 bool operator!=( const EntityInstance& rhs ) const;
120
121 static void TransformToAscii(void *targetBuffer, const void *sourceBuffer, size_t numElements);
122
123 private:
124
125 EntityDataPtr m_data;
126 agx::Index m_index;
127 };
128
129
130 AGXCORE_EXPORT std::ostream& operator << (std::ostream& output, const EntityInstance& entity);
131
132 /* Implementation */
133 AGX_FORCE_INLINE EntityInstance::EntityInstance() : m_data(nullptr), m_index(agx::InvalidIndex)
134 {}
135
136 AGX_FORCE_INLINE EntityInstance::EntityInstance(agxData::EntityData* data, agx::Index index) : m_data(data), m_index(index)
137 {}
138
139
140 AGX_FORCE_INLINE EntityInstance::EntityInstance(const agxData::EntityInstance& other) : m_data(other.m_data), m_index(other.m_index)
141 {}
142
143
144 AGX_FORCE_INLINE void EntityInstance::init(agxData::EntityData* data, agx::Index index) { m_data = data; m_index = index; }
145
147
148 AGX_FORCE_INLINE agxData::EntityData* EntityInstance::getData() { return m_data; }
149 AGX_FORCE_INLINE const agxData::EntityData* EntityInstance::getData() const { return m_data; }
150
152 {
153 return agx::hash( agx::hash( m_data ), agx::hash( m_index ) );
154 }
155
156 AGX_FORCE_INLINE bool EntityInstance::isValid() const { return m_data != nullptr; }
157 AGX_FORCE_INLINE bool EntityInstance::operator!() const { return !this->isValid(); }
158 AGX_FORCE_INLINE EntityInstance::operator bool() const { return this->isValid(); }
159
161 {
162 return this->getIndex() < rhs.getIndex();
163 }
164
166 {
167 return this->getIndex() > rhs.getIndex();
168 }
169
171 {
172 return (this->getStorage() == rhs.getStorage()) && (this->getIndex() == rhs.getIndex());
173 }
174
176 {
177 return (this->getStorage() != rhs.getStorage()) || (this->getIndex() != rhs.getIndex());
178 }
179
180
181}
182
183
184#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:152
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
UInt32 Index
Definition: Integer.h:44