1 // Copyright (c) 2020 OPEN CASCADE SAS 2 // 3 // This file is part of Open CASCADE Technology software library. 4 // 5 // This library is free software; you can redistribute it and/or modify it under 6 // the terms of the GNU Lesser General Public License version 2.1 as published 7 // by the Free Software Foundation, with special exception defined in the file 8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 9 // distribution for complete text of the license and disclaimer of any warranty. 10 // 11 // Alternatively, this file may be used under the terms of Open CASCADE 12 // commercial license or contractual agreement. 13 14 #ifndef _TDF_DerivedAttribute_HeaderFile 15 #define _TDF_DerivedAttribute_HeaderFile 16 17 #include <NCollection_List.hxx> 18 #include <TDF_Attribute.hxx> 19 20 class TCollection_AsciiString; 21 22 //! @def DEFINE_DERIVED_ATTRIBUTE 23 //! Defines declaration of Handle method and declares methods for serialization 24 //! of derived attribute 25 #define DEFINE_DERIVED_ATTRIBUTE(Class, Base) \ 26 DEFINE_STANDARD_RTTIEXT(Class, Base); \ 27 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; 28 29 //! @def IMPLEMENT_DERIVED_ATTRIBUTE 30 //! Defines implementation of Handle method, serialization methods and registers the derived attribute 31 #define IMPLEMENT_DERIVED_ATTRIBUTE(Class, Base) \ 32 IMPLEMENT_STANDARD_RTTIEXT(Class, Base) \ 33 static Handle(TDF_Attribute) TDF_DERIVED_New##Class() { return new Class(); } \ 34 static TDF_DerivedAttribute::NewDerived TDF_DERIVED_##Class( \ 35 TDF_DerivedAttribute::Register(TDF_DERIVED_New##Class)); \ 36 Handle(TDF_Attribute) Class::NewEmpty() const { return TDF_DERIVED_##Class(); } \ 37 38 39 //! @def IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE 40 //! Defines implementation of Handle method and registers the derived attribute 41 #define IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE(Class, Base, NameSpace, TypeName) \ 42 IMPLEMENT_STANDARD_RTTIEXT(Class, Base) \ 43 static Handle(TDF_Attribute) TDF_DERIVED_New##Class() { return new Class(); } \ 44 static TDF_DerivedAttribute::NewDerived TDF_DERIVED_##Class( \ 45 TDF_DerivedAttribute::Register(TDF_DERIVED_New##Class, NameSpace, TypeName)); \ 46 Handle(TDF_Attribute) Class::NewEmpty() const { return TDF_DERIVED_##Class(); } \ 47 48 //! Class provides global access (through static methods) to all derived attributres information. 49 //! It is used internally by macros for registration of derived attributes and driver-tables 50 //! for getting this data. 51 class TDF_DerivedAttribute 52 { 53 public: 54 /// A function of derived attribute that returns a new attribute instance 55 typedef Handle(TDF_Attribute) (*NewDerived) (); 56 57 //! Registers a derived by the pointer to a method that creates a new derived attribute instance 58 Standard_EXPORT static NewDerived Register (NewDerived theNewAttributeFunction, 59 Standard_CString theNameSpace = NULL, 60 Standard_CString theTypeName = NULL); 61 62 //! Returns the derived registered attribute by its type. 63 Standard_EXPORT static Handle(TDF_Attribute) Attribute (Standard_CString theType); 64 65 //! Returns the type name of the registered attribute by its type. 66 Standard_EXPORT static const TCollection_AsciiString& TypeName (Standard_CString theType); 67 68 //! Returns all the derived registered attributes list. 69 Standard_EXPORT static void Attributes (NCollection_List<Handle(TDF_Attribute)>& theList); 70 71 }; 72 73 #endif // _TDF_DerivedAttribute_HeaderFile 74