AGX Dynamics  2.37.2.0
Attribute.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 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_ATTRIBUTE_H
18 #define AGXDATA_ATTRIBUTE_H
19 
20 #ifdef _MSC_VER
21 # pragma warning(push)
22 // warning C4505: 'agxData::VectorAttributeT<T>::print' : unreferenced local function has been removed
23 # pragma warning( disable : 4505 )
24 #endif
25 
26 #include <agx/agx.h>
27 #include <agx/agxCore_export.h>
28 #include <agx/String.h>
29 #include <agx/Object.h>
30 #include <agx/Vector.h>
31 #include <agxData/Value.h>
32 #include <iosfwd>
33 
34 
35 namespace agx
36 {
37  class TiXmlElement;
38 }
39 
40 namespace agxData
41 {
42  class EntityModel;
43  class Type;
44 
45  template<typename T>
46  class Array;
47 
52 
53 
58  {
59  public:
60  static agx::Model *ClassModel();
61 
62  public:
63 
69  Attribute(const agx::Name& name, agxData::Type *type, agxData::Format *defaultFormat = nullptr, agxData::Value *defaultValue = nullptr, agxData::Value *numElements = nullptr);
70 
74  agx::Index getId() const;
75 
80  const agxData::Type *getType() const;
81 
85  agx::String fullName() const;
86 
90  agxData::Format *getDefaultFormat();
91  const agxData::Format *getDefaultFormat() const;
92 
96  agxData::Value *getNumElements();
97  const agxData::Value *getNumElements() const;
98 
102  agxData::Value *getDefaultValue();
103  const agxData::Value *getDefaultValue() const;
104 
105 
109  EntityModel *getEntity() const;
110 
111  void setDefaultFormat(agxData::Format *format);
112  void setDefaultValue(agxData::Value *value);
113 
114  protected:
115  virtual ~Attribute();
116  Attribute() : Object(""), m_entity(0) {}
117  friend class EntityModel;
118  friend class EntityStorage;
119  void setId(agx::Index id);
120  void setEntity(EntityModel *entity);
121 
122  private:
123  agx::Index m_id;
124  TypeRef m_type;
125  FormatRef m_defaultFormat;
126  agxData::ValueRef m_defaultValue;
127  agxData::ValueRef m_numElements;
128  EntityModel *m_entity;
129  };
130 
131 
132  std::ostream& operator << (std::ostream& output, const Attribute& attribute);
133 
134 
139  {
140  public:
141  static ScalarAttribute *load(agx::TiXmlElement *eAttribute);
142  static agx::Model *ClassModel();
143 
145  const agx::Name& name, Type* type, Format* defaultFormat = nullptr, agxData::Value* defaultValue = nullptr,
146  agxData::Value* numElementsExpression = nullptr);
147 
148  protected:
149  virtual ~ScalarAttribute();
150 
151  private:
152  };
153 
158  {
159  public:
160  static PointerAttribute *load(agx::TiXmlElement *eAttribute);
161  static agx::Model *ClassModel();
162 
163  PointerAttribute(const agx::Name& name, Type *type, Format *defaultFormat = nullptr, agxData::Value *defaultValue = nullptr);
164 
165  protected:
166  virtual ~PointerAttribute();
167 
168  private:
169  };
170 
175  {
176  public:
177  static SharedAttribute *load(agx::TiXmlElement *eAttribute);
178  static agx::Model *ClassModel();
179 
180  public:
181  SharedAttribute(const agx::Name& name, Format *format, const agx::String& expression);
182 
183  // agxData::Value *getValue() { return m_value; }
184  const agx::String& getExpression() const { return m_expression; }
185 
186  protected:
188  private:
189  // agxData::ValueRef m_value;
190  agx::String m_expression;
191  };
192 
193 
194 
199  {
200  public:
201  static agx::Model *ClassModel();
202 
203  ContainerAttribute(const agx::Name& name, ScalarAttribute *elementAttribute, Type *containerType);
204  ScalarAttribute *getElementAttribute();
205  const ScalarAttribute *getElementAttribute() const;
206  virtual ~ContainerAttribute();
207 
208  protected:
210  private:
211  ScalarAttributeRef m_elementAttribute;
212  };
213 
214 
219  {
220  public:
221  static ArrayAttribute *load(agx::TiXmlElement *eAttribute);
222  static agx::Model *ClassModel();
223 
224 
225  public:
226  ArrayAttribute(const agx::Name& name, ScalarAttribute *elementAttribute, Type *arrayType);
227  virtual ~ArrayAttribute();
228 
229  protected:
231  private:
232  };
233 
234 
239  {
240  public:
241  static VectorAttribute *load(agx::TiXmlElement *eAttribute);
242  static agx::Model *ClassModel();
243 
244 
245  public:
246  VectorAttribute(const agx::Name& name, ScalarAttribute *elementAttribute, Type *vectorType);
247  virtual ~VectorAttribute();
248 
249  protected:
251  private:
252  };
253 
254 
259  {
260  public:
261  static HashSetAttribute *load(agx::TiXmlElement *eAttribute);
262  static agx::Model *ClassModel();
263 
264 
265  public:
266  HashSetAttribute(const agx::Name& name, ScalarAttribute *elementAttribute, Type* hashSetType);
267  virtual ~HashSetAttribute();
268 
269  protected:
271  private:
272  };
273 
274 
275 
276  //--- TEMPLATED ----
277 
278  template <typename T>
280  {
281  public:
282  typedef T Type;
283 
285  //ScalarAttributeT() {}
286  virtual ~ScalarAttributeT() {}
287  private:
288  // T m_defaultValue;
289  };
290 
291  template <typename T>
293  {
294  public:
295  typedef T Type;
296 
297  private:
298  PointerAttributeT() {}
299  virtual ~PointerAttributeT() {}
300  // T m_defaultValue;
301  };
302 
303  template <typename T>
305  {
306  public:
307  typedef Array<T> Type;
308  typedef T ElementType;
309 
310  private:
311  ArrayAttributeT() {}
312  virtual ~ArrayAttributeT() {}
313  // Array<T> m_defaultValue;
314  // ScalarAttributeT<T> m_elementAttribute;
315  };
316 
317  template <typename T>
319  {
320  public:
322  typedef T ElementType;
323 
324  private:
325  VectorAttributeT() {}
326  virtual ~VectorAttributeT() {}
327  // Type m_defaultValue;
328  ScalarAttributeT<T> m_elementAttribute;
329  };
330 
331  template <typename T>
333  {
334  public:
335  typedef agx::HashSet<T> Type; // NOTE agx::HashSet instead of agxData::HashSet due to pointer invalidation (element buffer) in recursive HashSet::rebuild calls
336  typedef T ElementType;
337 
338  private:
339  HashSetAttributeT() {}
340  virtual ~HashSetAttributeT() {}
341  // Type m_defaultValue;
342  ScalarAttributeT<T> m_elementAttribute;
343  };
344 
345 
346 
347  template <typename T>
349  {
350  public:
351  typedef T Type;
352 
353  private:
354  SharedAttributeT() {}
355  virtual ~SharedAttributeT() {}
356  // T m_defaultValue;
357  };
358 
359 
360 
361 
362  /* Implementation */
363 
364  //-- ATTRIBUTE ----------------------
365  AGX_FORCE_INLINE agx::Index Attribute::getId() const { return m_id; }
367  AGX_FORCE_INLINE const Type *Attribute::getType() const { return m_type; }
368  AGX_FORCE_INLINE Format *Attribute::getDefaultFormat() { return m_defaultFormat; }
369  AGX_FORCE_INLINE const Format *Attribute::getDefaultFormat() const { return m_defaultFormat; }
370  AGX_FORCE_INLINE agxData::Value *Attribute::getNumElements() { return m_numElements; }
371  AGX_FORCE_INLINE const agxData::Value *Attribute::getNumElements() const { return m_numElements; }
372  AGX_FORCE_INLINE agxData::Value *Attribute::getDefaultValue() { return m_defaultValue; }
373  AGX_FORCE_INLINE const agxData::Value *Attribute::getDefaultValue() const { return m_defaultValue; }
374  AGX_FORCE_INLINE EntityModel *Attribute::getEntity() const { return m_entity; }
375 
376 
377 
378  //-- CONTAINER ATTRIBUTE --------------------------
379  AGX_FORCE_INLINE const ScalarAttribute *ContainerAttribute::getElementAttribute() const { return m_elementAttribute; }
380  AGX_FORCE_INLINE ScalarAttribute *ContainerAttribute::getElementAttribute() { return m_elementAttribute; }
381 
382 }
383 
384 #ifdef _MSC_VER
385 # pragma warning(pop)
386 #endif
387 #endif /* _AGXDATA_ATTRIBUTE_H_ */
ScalarAttributeT(const agx::Name &name)
Definition: Attribute.h:284
AGXCORE_EXPORT Type * getType(const agx::String &name)
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
Abstract representation of a value.
Definition: Value.h:48
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
A pointer attribute.
Definition: Attribute.h:157
A hash set attribute.
Definition: Attribute.h:258
A format is an implementation of a agxData::Type.
Definition: Format.h:63
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
const agx::String & getExpression() const
Definition: Attribute.h:184
agx::Vector< T > Type
Definition: Attribute.h:321
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
Templated vector class.
Definition: Vector.h:52
A container attribute (Array/Vector/HashSet)
Definition: Attribute.h:198
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Abstracted type.
Definition: Type.h:97
A vector attribute.
Definition: Attribute.h:238
An abstract attribute description, part of an Entity.
Definition: Attribute.h:57
Contains classes for low level data storage for AGX.
Definition: Container.h:23
UInt32 Index
Definition: Integer.h:52
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:63
An array attribute.
Definition: Attribute.h:218
A scalar attribute.
Definition: Attribute.h:138
A shared attribute.
Definition: Attribute.h:174
agx::HashSet< T > Type
Definition: Attribute.h:335
#define AGXCORE_EXPORT
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
agx::Object is a refcounted object with a name.
Definition: Object.h:58