Custom attributes with template types


What would be the recommended architecture to use custom types in one or more custom attributes using a template type? Is there some sort of workflow or example available to start from with best practices? What methods need to be implemented to support the attribute system in a generic way (if possible?).

The example would be a container-based custom attribute that maps a custom typed key to an integer value or vice versa, derived from TDF_Attribute type.

template<typename T, typename I = int> struct MyAttrMap : TDF_Attribute { std::unordered_map<T, I> f; // this is not handled automatically, so what methods need to be present to handle all attribute operations correctly? ... }; struct HalfEdge { ... }; struct Coords { float x, float y; }; struct GeoDesc { std::map<HalfEdge, int> loops; }; struct Poly: GeoDesc { std::vector<Coord> coords; }; struct Circle: GeoDesc { Coord pos; }; MyAttrMap<Circle> circleAttributesInner; MyAttrMap<Circle> circleAttributesOuter; MyAttrMap<Poly> polyAttributesBound; MyAttrMap<Poly> polyAttributesProjection;

There is probably no support for robust handling of such more complex TDF_Attribute derived types, i.e. the alternative is to reconstruct complex attributes based lists of primitive types, based on assumptions of the intended type attribute. Some documentation or an example on how to implement such derived attributes would be helpful.

Best regards, Ignace

Mikhail MPV's picture

  Hello Ignace,

For now there is no possibility to use templates or other approaches to simply create attribute with arbitrary content, to support undo/redo and save/open functionality. It is possible to make a new attribute with the same fields as another one: you may find an example in TDataStd_Name.hxx.

Anyway, using OCAF, it is assumed that a developer does not need creation of complicated attributes, but putting on one or several labels all the needed attributes with standard atomic data: int, double, string, array, etc. I'm sure it is also possible in your case. And normally treating and providing access to this data as application-specific and complicated data-structures is implemented in higher-level classes API. They are usually corresponded to objects (labels), not attributes.

Best Regards, Mikhail.