Close

Relief for ODA Team in Ukraine

Learn more
ODA BimRv SDK
Work with TfClass

OdTfClass is a meta-data container associated with an object derived from OdTfObject.

To get the base class of the current class, use the tfParent() method, which requires no parameters and returns the base class as a pointer to the OdTfClass object. For example:


OdTfClassPtr pBaseClass = pClass->tfParent(); // pClass is a pointer to an OdTfClass object
    

You can easily list all base classes:


while (pClass)
{
  /* 
    do stuff 
  */
  pClass = pClass->tfParent();
}
    

To get the name of the class, use the name() method, which requires no parameters and returns the class name as an OdString value. For example:


message.format(L"\nClass name is %s", pClass->name().c_str());
pIO->putString(message);
    

To get the list of the class properties, use the properties() method, which requires no parameters and returns the list of object properties as a pointer to the OdTfPropertiesContainer object. For example:


OdTfPropertiesContainerPtr pProps = pClass->properties();
    

You can list all properties of classes in the hierarchy using this method:


OdArray<const OdTfProperty*> getAllHierarchyProperties_1(OdTfClass* pClass)
{
  OdArray<const OdTfProperty*> properties;
  while (pClass)
  {
    // Get container, lists all properties of 'pClass'
    OdTfPropertiesContainerPtr pProperties = pClass->properties();
    for (OdRxIteratorPtr pIt = pClass->properties()->iterator(); !pIt->done(); pIt->next())
    {
      OdTfPropertyPtr pProperty = pIt->object();
      properties.push_back(pProperty.get());
    }
    pClass = pClass->tfParent();
  }
  return properties;
}
    

This code will return the properties of the full class hierarchy, but as a result, properties will be in an inconvenient order. Properties of the derived classes in the lists will appear before the properties of the base class.

To get the property list of the full class hierarchy, use the allProperties() method, which requires no parameters and returns the list of properties of all classes in the hierarchy as a pointer to an OdTfPropertiesContainer object. For example:


OdTfPropertiesContainerPtr pAllProps = pClass->allProperties();
    

You can use this method to fix the previous example:


OdArray < const OdTfProperty* > getAllHierarchyProperties_2(OdTfClass* pClass)
{
  // Get container, lists all properties of hierarchy from first of the base class, till last of derived.
  OdTfPropertiesContainerPtr pAllProperties = pClass->allProperties();
  OdArray< const OdTfProperty* > properties;
  properties.reserve(pAllProperties->size());
  for (OdRxIteratorPtr pIt = pClass->allProperties()->iterator(); !pIt->done(); pIt->next())
  {
    OdTfPropertyPtr pProperty = pIt->object();
    properties.push_back(pProperty.get());
  }
  return properties;
}
    

See Also

Work with Tf Interface

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.