/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _DAI_ATTRIBUTE_COLLECTION_H_ #define _DAI_ATTRIBUTE_COLLECTION_H_ #include "daiEntity.h" #include "daiAttribute/AttributeKeyCollection.h" #include "daiAggr/daiSet.h" #include "daiAggr/daiBag.h" #define STL_USING_LIST #include "OdaSTL.h" #include "TD_PackPush.h" namespace OdDAI { /** \details This class represents a container for a collection of attributes. */ class DAI_EXPORT DynamicAttributeHolder { public: using ComplexEntityReadInfo = std::pair; public: /** \details Checks whether this object has no data. \returns true if this object has no data; otherwise the method returns false. */ bool isNull() { return m_data == nullptr; }; /** \details Gets attribute by the specified name. \param attrName [in] Attribute name. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns Typed attribute value. */ template inline TType* getTypedAttr(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Sets a value for an attribute by the specified name attribute name. \param attrName [in] Attribute name. \param newValue [in] Value to set. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns Typed attribute value. */ template inline bool setTypedAttr(const char* attrName, const TType& newValue, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Early-bound version of instances comparison. \param otherAttributes [in] Other application instance. \param ordering [out] Receives the ordering (comparison) status. \param attributeCollection [in/out] Attribute collection. \returns true if comparison was performed, false if method has no implementation, so late-bound version could be applied. \remarks If the method returns true, the ordering parameter can receive one of the following statuses: Name Value Description _kLessThan_ -1 This object < Other Object. _kEqual_ 0 This object = Other Object. _kGreaterThan_ 1 This object > Other Object. _kNotOrderable_ 2 This class is not orderable.
*/ bool comparedToEarlyImpl(const OdDAI::DynamicAttributeHolder& otherAttributes, OdRx::Ordering& ordering, const OdDAI::AttributeKeyCollection& attributeCollection) const; /** \details Copies data from the specified attribute holder. \param from [in] Object to copy from. \param attributeCollection [in/out] Attribute collection. \returns true if copied successfully; otherwise the method returns false. */ bool copy(const OdDAI::DynamicAttributeHolder& from, const OdDAI::AttributeKeyCollection& attributeCollection); /** \details Returns an attribute value by the specified attribute key. \param attrKey [in] Pointer to an attribute key to query. \param attributeCollection [in/out] Attribute collection. \returns OdRxValue object that represents a generic variant type value. */ OdRxValue getAttr(const OdDAI::AttributeKey* attrKey, const OdDAI::AttributeKeyCollection& attributeCollection); /** \details Returns an attribute value by the specified attribute name. \param attrName [in] Attribute name to query. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns OdRxValue object that represents a generic variant type value. */ OdRxValue getAttr(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Returns an attribute value by the specified attribute. \param attr [in] Attribute to query. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns OdRxValue object that represents a generic variant type value. */ OdRxValue getAttr(const Attribute* attr, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Checks whether the specified attribute is set. \param attrName [in] Attribute name of the attribute to test. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns true if the specified attribute is set, false otherwise. */ bool testAttr(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse) const; /** \details Checks whether the specified attribute is set. \param attribute [in] Attribute to test. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns true if the specified attribute is set, false otherwise. */ bool testAttr(const AttributePtr& attribute, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse) const; /** \details Sets the specified attribute with a given value. \param attrName [in] Explicit name of the attribute to set. \param val [in] Value to set. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns true if the value is successfully set for the specified attribute, false otherwise. */ bool putAttr(const char* attrName, const OdRxValue& val, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Sets the specified attribute with a given value. \param attr [in] Attribute to set. \param val [in] Value to set. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. \returns true if the value is successfully set for the specified attribute, false otherwise. */ bool putAttr(const AttributePtr &attr, const OdRxValue& val, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Resets a value for the specified attribute. \param attrName [in] Explicit name of the attribute to reset. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. */ void unsetAttr(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Resets a value for the specified attribute. \param attribute [in] Attribute to unset. \param attributeCollection [in] Attribute collection to search within. \param inverse [in] Indicates whether the attribute is inverse attribute. */ void unsetAttr(const AttributePtr& attribute, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); /** \details Reads object's data from the specified filer. \param rdFiler [in] Pointer to a filer from which to read the data. \param attributeCollection [in] Attribute collection. */ void inFields(OdDAI::OdSpfFilerBase* rdFiler, const OdDAI::AttributeKeyCollection& attributeCollection); /** \details Writes object's data the the specified filer. \param wrFiler [in] Pointer to a filer to which to write the data. \param attributeCollection [in] Attribute collection. */ void outFields(OdDAI::OdSpfFilerBase* wrFiler, const OdDAI::AttributeKeyCollection& attributeCollection); /** \details Writes object's data the the specified filer. \param wrFiler [in] Pointer to a filer to which to write the data. \param attributeCollection [in] Attribute collection. \param complexEntity [in] Complex entity that is written to a filer. */ void outFields(OdDAI::OdSpfFilerBase* wrFiler, const OdDAI::AttributeKeyCollection& attributeCollection, OdDAI::Entity *complexEntity); /** \details Initializes this object for a correct work. \param attributeCollection [out] Attribute collection. \param initFrom [in] Data from which to initialize the attribute collection. */ void init(const OdDAI::AttributeKeyCollection& attributeCollection, const unsigned char* initFrom = nullptr); /** \details Initializes this object for a correct work. \param attributeCollection [out] Attribute collection. \param complexReadDataCollection [in] Data from which to initialize the attribute collection. */ void init(const OdDAI::AttributeKeyCollection& attributeCollection, std::list& complexReadDataCollection); /** \details Cleans an attribute collection. \param attributeCollection [in/out] Attribute collection to clean. */ void clean(const OdDAI::AttributeKeyCollection& attributeCollection); /** \details Gets data of this object. \param attributeCollection [in] Attribute collection. \param copyTo [out] Receives the copied data. \returns true if the data is copied successfully, false otherwise. */ bool getData(const OdDAI::AttributeKeyCollection& attributeCollection, unsigned char* copyTo); private: bool putAttrComplex(const AttributePtr &srcAttr, const OdRxValue& val, const OdDAI::AttributeKeyCollection& attributeCollection); mutable unsigned char* m_data = nullptr; }; template inline TType* DynamicAttributeHolder::getTypedAttr(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse) { if (!attrName) { return nullptr; } const OdDAI::AttributeKey* key = !inverse ? attributeCollection.getByName(attrName) : attributeCollection.getByNameInverse(attrName); if (!key) { return nullptr; } if (m_data == nullptr) { init(attributeCollection); } return reinterpret_cast(m_data + key->typeOffset); } template inline bool DynamicAttributeHolder::setTypedAttr(const char* attrName, const TType& newValue, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse) { if (!attrName) { return false; } const OdDAI::AttributeKey* key = !inverse ? attributeCollection.getByName(attrName) : attributeCollection.getByNameInverse(attrName); if (!key) { return false; } if (m_data == nullptr) { init(attributeCollection); } *reinterpret_cast(m_data + key->typeOffset) = newValue; return true; } #if !defined(SWIG) template OdDAIObjectId* DynamicAttributeHolder::getTypedAttr<>(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse) ; template OdDAI::Set* DynamicAttributeHolder::getTypedAttr<>(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse) ; template OdDAI::Bag* DynamicAttributeHolder::getTypedAttr<>(const char* attrName, const OdDAI::AttributeKeyCollection& attributeCollection, bool inverse); #endif } #include "TD_PackPop.h" #endif // _DAI_TYPECODE_H_