|
|
|||
File indexing completed on 2026-09-18 09:22:13
0001 // Created on: 2004-11-23 0002 // Created by: Pavel TELKOV 0003 // Copyright (c) 2004-2014 OPEN CASCADE SAS 0004 // 0005 // This file is part of Open CASCADE Technology software library. 0006 // 0007 // This library is free software; you can redistribute it and/or modify it under 0008 // the terms of the GNU Lesser General Public License version 2.1 as published 0009 // by the Free Software Foundation, with special exception defined in the file 0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0011 // distribution for complete text of the license and disclaimer of any warranty. 0012 // 0013 // Alternatively, this file may be used under the terms of Open CASCADE 0014 // commercial license or contractual agreement. 0015 0016 // The original implementation Copyright: (C) RINA S.p.A 0017 0018 #ifndef TObj_Persistence_HeaderFile 0019 #define TObj_Persistence_HeaderFile 0020 0021 #include <NCollection_DataMap.hxx> 0022 #include <TCollection_AsciiString.hxx> 0023 #include <TCollection_HExtendedString.hxx> 0024 #include <TDF_Label.hxx> 0025 #include <NCollection_Sequence.hxx> 0026 #include <NCollection_HSequence.hxx> 0027 class TObj_Object; 0028 0029 class TDF_Label; 0030 0031 /** This class is intended to be a root of tools (one per class) 0032 * to manage persistence of objects inherited from TObj_Object 0033 * It provides a mechanism to recover correctly typed 0034 * objects (subtypes of TObj_Object) out of their persistent names 0035 * 0036 * This is a special kind of object, it automatically registers itself 0037 * in a global map when created, and the only thing it does is to 0038 * create a new object of the type that it manages, by request 0039 */ 0040 0041 class TObj_Persistence 0042 { 0043 public: 0044 /** 0045 * Public methods, to be called externally 0046 */ 0047 0048 //! Creates and returns a new object of the registered type 0049 //! If the type is not registered, returns Null handle 0050 static Standard_EXPORT occ::handle<TObj_Object> CreateNewObject(const char* const theType, 0051 const TDF_Label& theLabel); 0052 0053 //! Dumps names of all the types registered for persistence to the 0054 //! specified stream 0055 static Standard_EXPORT void DumpTypes(Standard_OStream& theOs); 0056 0057 protected: 0058 /** 0059 * Protected methods, to be used or defined by descendants 0060 */ 0061 0062 //! The constructor registers the object 0063 Standard_EXPORT TObj_Persistence(const char* const theType); 0064 0065 //! The destructor unregisters the object 0066 virtual Standard_EXPORT ~TObj_Persistence(); 0067 0068 //! The method must be redefined in the derived class and return 0069 //! new object of the proper type 0070 virtual Standard_EXPORT occ::handle<TObj_Object> New(const TDF_Label& theLabel) const = 0; 0071 0072 //! Dictionary storing all the registered types. It is implemented as static 0073 //! variable inside member function in order to ensure initialization 0074 //! at first call 0075 static Standard_EXPORT NCollection_DataMap<TCollection_AsciiString, void*>& getMapOfTypes(); 0076 0077 private: 0078 const char* myType; //!< Name of managed type (recorded for unregistering) 0079 }; 0080 0081 //! Declare subclass and methods of the class inherited from TObj_Object 0082 //! necessary for implementation of persistence 0083 //! This declaration should be put inside class declaration, under 'protected' modifier 0084 #ifdef SOLARIS 0085 //! Workaround on SUN to avoid stupid warnings 0086 #define _TOBJOCAF_PERSISTENCE_ACCESS_ public: 0087 #else 0088 #define _TOBJOCAF_PERSISTENCE_ACCESS_ 0089 #endif 0090 #define DECLARE_TOBJOCAF_PERSISTENCE(name, ancestor) \ 0091 name(const TObj_Persistence* p, const TDF_Label& aLabel) \ 0092 : ancestor(p, aLabel) \ 0093 { \ 0094 initFields(); \ 0095 } /* give the object a chance to initialize its fields */ \ 0096 \ 0097 /* Creates an object of a proper type */ \ 0098 /* First argument is used just to avoid possible conflict with other constructors */ \ 0099 _TOBJOCAF_PERSISTENCE_ACCESS_ \ 0100 class Persistence_ : public TObj_Persistence \ 0101 { \ 0102 /* Friend private class of name, is a tool providing persistence */ \ 0103 public: \ 0104 Persistence_() \ 0105 : TObj_Persistence(#name) \ 0106 { \ 0107 } /* register the tool */ \ 0108 virtual occ::handle<TObj_Object> New(const TDF_Label& aLabel) const; \ 0109 /* Creates an object of a proper type */ \ 0110 }; \ 0111 friend class Persistence_; \ 0112 static Persistence_ myPersistence_; /* Static field implementing persistsnce tool */ 0113 0114 //! Implement mechanism for registration the type for persistence 0115 //! This should not be used for abstract classes (while DECLARE should) 0116 #define IMPLEMENT_TOBJOCAF_PERSISTENCE(name) \ 0117 name::Persistence_ name::myPersistence_; \ 0118 occ::handle<TObj_Object> name::Persistence_::New(const TDF_Label& aLabel) const \ 0119 { \ 0120 return new name(static_cast<const TObj_Persistence*>(nullptr), aLabel); \ 0121 } 0122 0123 #endif 0124 0125 #ifdef _MSC_VER 0126 #pragma once 0127 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|