/////////////////////////////////////////////////////////////////////////////// // 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_BASE_SIMPLE_SECTION_H #define _DAI_BASE_SIMPLE_SECTION_H #include "OdaCommon.h" #include "daiBuildOptions.h" #include #include #include #define STL_USING_MAP #define STL_USING_FUNCTIONAL #include "OdaSTL.h" #include "TD_PackPush.h" /** \details Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format. */ namespace OdDAI { class Repository; class OdSpfFilerBase; /** \details A smart pointer to an OdSpfFilerBase object or an object of a class derived from the OdSpfFilerBase class. */ using OdSpfFilerBasePtr = OdSmartPtr; /** \details The class implements storing and handling data (provides simple operations) of all section items (like or ) for a object. */ template class DAI_EXPORT SimpleSectionBase { friend class Repository; public: /** \details Creates a new item with specified name and value in the section. \param name [in] An ANSI string that contains the name of an item to be created. \param value [in] An ANSI string that contains the value of the created item. \returns A shared pointer to the created item; if the item with the specified name exists within the section, the method returns a NULL (nullptr) smart pointer. */ OdSharedPtr createNew(const OdAnsiString& name, const OdAnsiString& value); /** \details Retrieves a section item by its name. \param name [in] An ANSI string that contains the name of the item. \returns A shared pointer to the item if it was found in the section by its name; otherwise, the method returns an empty pointer (nullptr). */ OdSharedPtr getByName(const OdAnsiString& name); /** \details Removes a section item with a specified name. \param name [in] An ANSI string that contains the name of the item. \returns true if the item were deleted successfuly; otherwise, the method returns false. */ bool removeByName(const OdAnsiString& name); /** \details Executed a specified STL function for all items the section contains. \param anchorEnumerator [in] An STL functor to execute for each item. */ void forEach(std::function&)> anchorEnumerator) const; /** \details Retrieves the items count. \returns A signed integer value that contains the number of items the section contains. */ int itemsCount() const; private: SimpleSectionBase(Repository* Repository); private: std::map> m_itemsDictionary; Repository* m_repository; }; } /** \details Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format. */ namespace OdDAI { //DOM-IGNORE-BEGIN template inline SimpleSectionBase::SimpleSectionBase(Repository* repository) : m_repository(repository) { } template inline OdSharedPtr SimpleSectionBase::createNew(const OdAnsiString& name, const OdAnsiString& value) { auto foundItem = m_itemsDictionary.find(name); if (foundItem != m_itemsDictionary.end()) { return nullptr; } OdSharedPtr result = new TItem(name, value, this); m_itemsDictionary[name] = result; return result; } template inline OdSharedPtr SimpleSectionBase::getByName(const OdAnsiString& name) { auto foundAnchor = m_itemsDictionary.find(name); if (foundAnchor == m_itemsDictionary.end()) { return {}; } return foundAnchor->second; } template inline bool SimpleSectionBase::removeByName(const OdAnsiString& name) { auto foundAnchor = m_itemsDictionary.find(name); if (foundAnchor == m_itemsDictionary.end()) { return false; } foundAnchor->second.detach(); m_itemsDictionary.erase(foundAnchor); return true; } template inline void SimpleSectionBase::forEach(std::function&)> anchorEnumerator) const { for (auto& anchor : m_itemsDictionary) { anchorEnumerator(anchor.second); } } template inline int SimpleSectionBase::itemsCount() const { return static_cast(m_itemsDictionary.size()); } //DOM-IGNORE-END } #include "TD_PackPop.h" #endif // _DAI_BASE_SIMPLE_SECTION_H