AGXDynamics  2.35.0.2
Attribute.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_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 ----------------------
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; }
371  AGX_FORCE_INLINE const agxData::Value *Attribute::getNumElements() const { return m_numElements; }
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; }
381 
382 }
383 
384 #ifdef _MSC_VER
385 # pragma warning(pop)
386 #endif
387 #endif /* _AGXDATA_ATTRIBUTE_H_ */
agxData::VectorAttribute::VectorAttribute
VectorAttribute()
Definition: Attribute.h:250
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxData::Attribute::getEntity
EntityModel * getEntity() const
Definition: Attribute.h:374
agxData::Value
Abstract representation of a value.
Definition: Value.h:42
Vector.h
agxData::ContainerAttribute::ContainerAttribute
ContainerAttribute()
Definition: Attribute.h:209
agxData::ScalarAttributeT
Definition: Attribute.h:279
agxData::ArrayAttributeT::Type
Array< T > Type
Definition: Attribute.h:307
agxData::getFormat
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
agxData::HashSetAttribute
A hash set attribute.
Definition: Attribute.h:258
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxData::Attribute::getId
agx::Index getId() const
Definition: Attribute.h:365
agxData::EntityModel
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:63
agxData::PointerAttribute
A pointer attribute.
Definition: Attribute.h:157
agxData::getType
AGXCORE_EXPORT Type * getType(const agx::String &name)
agxData::SharedAttribute::SharedAttribute
SharedAttribute()
Definition: Attribute.h:187
agxData::ArrayAttributeT::ElementType
T ElementType
Definition: Attribute.h:308
agxData::VectorAttributeT::ElementType
T ElementType
Definition: Attribute.h:322
agxData::HashSetAttributeT::Type
agx::HashSet< T > Type
Definition: Attribute.h:335
agxData::Format
A format is an implementation of a agxData::Type.
Definition: Format.h:63
agxData::VectorAttributeT
Definition: Attribute.h:318
agxData::ScalarAttributeT::Type
T Type
Definition: Attribute.h:282
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
agx::Model
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
agxData::Attribute::getType
agxData::Type * getType()
Definition: Attribute.h:366
agxData::Array
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agxData::Attribute::Attribute
Attribute()
Definition: Attribute.h:116
agx::ref_ptr< Type >
agxData::ContainerAttribute::getElementAttribute
ScalarAttribute * getElementAttribute()
Definition: Attribute.h:379
agxData::SharedAttribute
A shared attribute.
Definition: Attribute.h:174
agxData::SharedAttribute::getExpression
const agx::String & getExpression() const
Definition: Attribute.h:184
agxData::HashSetAttributeT
Definition: Attribute.h:332
agxData::HashSetAttributeT::ElementType
T ElementType
Definition: Attribute.h:336
agxData::PointerAttributeT::Type
T Type
Definition: Attribute.h:295
agx::Index
UInt32 Index
Definition: Integer.h:52
agxData::Attribute::getDefaultValue
agxData::Value * getDefaultValue()
Definition: Attribute.h:372
agxData::Type
Abstracted type.
Definition: Type.h:97
agxData::ScalarAttributeT::~ScalarAttributeT
virtual ~ScalarAttributeT()
Definition: Attribute.h:286
agxData::ArrayAttribute
An array attribute.
Definition: Attribute.h:218
agxData::Attribute::getNumElements
agxData::Value * getNumElements()
Definition: Attribute.h:370
agxData::VectorAttribute
A vector attribute.
Definition: Attribute.h:238
agxData::Attribute::getDefaultFormat
agxData::Format * getDefaultFormat()
Definition: Attribute.h:368
agxCore_export.h
agx::Name
Representation of a name string.
Definition: Name.h:32
Object.h
agxData::PointerAttributeT
Definition: Attribute.h:292
agx::Object
agx::Object is a refcounted object with a name.
Definition: Object.h:59
agx::HashSet
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:665
agx.h
agxData::ScalarAttributeT::ScalarAttributeT
ScalarAttributeT(const agx::Name &name)
Definition: Attribute.h:284
agxData::HashSetAttribute::HashSetAttribute
HashSetAttribute()
Definition: Attribute.h:270
agxData::SharedAttributeT::Type
T Type
Definition: Attribute.h:351
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxData::SharedAttributeT
Definition: Attribute.h:348
String.h
agx::AgXString< std::string >
agxData::ArrayAttributeT
Definition: Attribute.h:304
agxData::ContainerAttribute
A container attribute (Array/Vector/HashSet)
Definition: Attribute.h:198
agxData::Attribute
An abstract attribute description, part of an Entity.
Definition: Attribute.h:57
agxData::VectorAttributeT::Type
agx::Vector< T > Type
Definition: Attribute.h:321
agxData::operator<<
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
agxStream::ElementTypes::Type
Type
Definition: Types.h:37
Value.h
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxData::ArrayAttribute::ArrayAttribute
ArrayAttribute()
Definition: Attribute.h:230
agxData::getEntity
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
agxData::ScalarAttribute
A scalar attribute.
Definition: Attribute.h:138