/////////////////////////////////////////////////////////////////////////////// // 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_KEY_COLLECTION_H_ #define _DAI_ATTRIBUTE_KEY_COLLECTION_H_ #include "OdaCommon.h" #include "TD_PackPush.h" #include "daiTypeCode.h" #define STL_USING_FUNCTIONAL #define STL_USING_VECTOR #include "OdaSTL.h" #include "daiAttribute/AttributeKey.h" namespace OdDAI { class Attribute; class Entity; class OdSpfFilerBase; //DOM-IGNORE-BEGIN enum KeyCollectionEntityType { entityStaticSchema = 0, entityRuntime, entityComplex, entityComplexForRead, entityTypesCount, }; /** \details This class is a collection of AttributeKey objects. */ class DAI_EXPORT AttributeKeyCollection { public: /** \details Gets an attribute key by the specified attribute. \param attribute [in] Attribute for which to get an attribute key. \returns Pointer to a found key if successful; otherwise the method returns nullptr. */ const AttributeKey* getByAttribute(const Attribute* attribute) const; /** \details Gets an attribute key by the specified inverse attribute. \param attribute [in] Inverse attribute for which to get an attribute key. \returns Pointer to a found key if successful; otherwise the method returns nullptr. */ const AttributeKey* getByAttributeInverse(const Attribute* attribute) const; /** \details Gets an attribute key of an attribute by the specified key name. \param attribute [in] Attribute key name for which to get an attribute key. \returns Pointer to a found key if successful; otherwise the method returns nullptr. */ const AttributeKey* getByName(const char* name) const; /** \details Gets an attribute key of an inverse attribute by the specified key name. \param attribute [in] Attribute key name for which to get an attribute key. \returns Pointer to a found key if successful; otherwise the method returns nullptr. */ const AttributeKey* getByNameInverse(const char* name) const; /** \details Find appropriate dest attribute by src attribute provided when resolving complex entity instances after rearing of partial complexes set. */ const AttributeKey* findByAttribute(const Attribute* srcAttribute) const; /** \details Gets a number of attribute keys stored in this collection. \param withInverse [in] Indicates whether to include into count stored keys of inverse attributes. \returns number of attribute keys stored in this collection. */ size_t getCount(bool withInverse) const; /** \details Gets a data block size stored by this collection. \returns number of bytes that are needed for storing attribute keys. */ unsigned int getDataBlockSize() const; /** \details Runs a specified function for each stored key in the collection, according to their order. \param callBack [in] Callback function to run for each key. */ void forEachKeyInDeclareOrder(std::function callBack) const; /** \details Creates a buffer with data from this attribute key collection. The created buffer has data with attribute keys, then data with attribute keys for inverse attributes. */ void createBuffer(unsigned char** buffer) const; /** \details Cleans the specified buffer and this collection of attribute keys. This operation erases the stored keys and not just removes them from the collection. \param buffer [in] Buffer to clean. */ void cleanBuffer(unsigned char* buffer) const; static std::unique_ptr createByType(KeyCollectionEntityType entityType, const OdDAI::Entity* entity); private: void emplace_key(AttributeKey&& key); void emplace_inverse_key(AttributeKey&& key); void sortKeys(); static std::unique_ptr createFromEntity(const OdDAI::Entity* entityOfInstance); static std::unique_ptr createFromEntityInverseOnly(const OdDAI::Entity* entityOfInstance); static std::unique_ptr createFromEntityComplex(const OdDAI::Entity* entityOfInstance); static std::unique_ptr createFromEntityForComplexRead(const OdDAI::Entity* entityOfInstance); static void collectAttributeKeys(const OdDAI::Entity* parent, OdDAI::AttributeKeyCollection& keyCollection, const OdDAI::Entity* entityOfInstance, unsigned int& orderIndex, bool forComplexRead = false); static void collectParentKeys(const OdDAI::Entity* parent, OdDAI::AttributeKeyCollection& keyCollection, unsigned int& orderIndex, const OdDAI::Entity* entityOfInstance, OdArray& processed); static void collectParentKeysInverseOnly(const OdDAI::Entity* parent, OdDAI::AttributeKeyCollection& keyCollection); static void collectComplexKeys(const OdDAI::Entity* parent, OdDAI::AttributeKeyCollection& keyCollection); private: std::vector m_collection; std::vector m_collectionInverse; std::vector m_collectionDeclareOrder; unsigned int m_dataBlockSize = 0; }; } //DOM-IGNORE-END #include "TD_PackPop.h" #endif // _DAI_ATTRIBUTE_KEY_H_