5.5 Generic Attributes
All entities can embed an arbitrary number of generic attributes. They can be accessed from any A3DRootBase instance.
Reading or writing generic attributes involves several steps and a good knowledge on attributes hierarchy:
- An A3DRootBase instance can hold any number of A3DMiscAttribute.
- An A3DMiscAttribute instance can hold any number of A3DMiscSingleAttributeData.
- An A3DMiscSingleAttributeData instance can hold any value of the following types:
- 32-bit integer.
- 32-bit floating-point (IEEE 754).
- time_t.
- UTF-8 C-Style string.
This page is a general presentation on how to read attributes from any A3DRootBase instance.
Reading a single attribute instance
A single attribute is an instance of A3DMiscSingleAttributeData, a data-only structure which is described as:
Any attribute is a Title/Value pair where:
- The Title is either a c-string or an integer.
- The data is any of the above mentioned type.
Reading the title
The title of an attribute is stored in the m_pcTitle attribute and its type depends on m_bTitleIsInt. According to its value the title encodes either a 32-bit unsigned integer or a c-string.
This example code outputs the attribute title according to its type.
32-bit integer data
If m_eType == kA3DModellerAttributeTypeInt
the data is stored as a 32-bit integer data (A3DUns32
):
32-bit floating point
If m_eType == kA3DModellerAttributeTypeReal
the data is stored as a 32-bit floating point data (A3DFloat
):
When the value is a floating-point the field m_usUnit
is used to specify a unit for this value. If no unit is provided, m_usUnit
is set to A3D_DEFAULT_NO_UNIT
.
For more information about generic unit specifiers, see the unit attributes page.
UTF-8 c-string
If m_eType == kA3DModellerAttributeTypeString
the data is stored as a null-terminated UTF-8 string (A3DUTF8Char*
):
Time specifier
If m_eType == kA3DModellerAttributeTypeTime
the data is stored as a time specifier as defined by the time_t
specifications:
Reading an attribute
An attribute is an instance of A3DMiscAttribute. Any attribute has a title and zero or more A3DMiscSingleAttributeData:
Getting the list of attributes
Generic attributes of an A3DRootBase instance are available as an array:
All attributes are instances of A3DMiscAttribute.
A Complete Example
The code below is a complete example which traverses an A3DRootBase instance and print all its attributes in the standard output in the form: