|
||||
File indexing completed on 2025-01-18 10:05:22
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 <TObj_Container.hxx> 0022 0023 class TDF_Label; 0024 0025 /** This class is intended to be a root of tools (one per class) 0026 * to manage persistence of objects inherited from TObj_Object 0027 * It provides a mechanism to recover correctly typed 0028 * objects (subtypes of TObj_Object) out of their persistent names 0029 * 0030 * This is a special kind of object, it automatically registers itself 0031 * in a global map when created, and the only thing it does is to 0032 * create a new object of the type that it manages, by request 0033 */ 0034 0035 class TObj_Persistence 0036 { 0037 public: 0038 /** 0039 * Public methods, to be called externally 0040 */ 0041 0042 //! Creates and returns a new object of the registered type 0043 //! If the type is not registered, returns Null handle 0044 static Standard_EXPORT Handle(TObj_Object) CreateNewObject 0045 (const Standard_CString theType, 0046 const TDF_Label& theLabel); 0047 0048 //! Dumps names of all the types registered for persistence to the 0049 //! specified stream 0050 static Standard_EXPORT void DumpTypes (Standard_OStream& theOs); 0051 0052 protected: 0053 /** 0054 * Protected methods, to be used or defined by descendants 0055 */ 0056 0057 //! The constructor registers the object 0058 Standard_EXPORT TObj_Persistence (const Standard_CString theType); 0059 0060 //! The destructor unregisters the object 0061 virtual Standard_EXPORT ~TObj_Persistence (); 0062 0063 //! The method must be redefined in the derived class and return 0064 //! new object of the proper type 0065 virtual Standard_EXPORT Handle(TObj_Object) New 0066 (const TDF_Label& theLabel) const = 0; 0067 0068 //! Dictionary storing all the registered types. It is implemented as static 0069 //! variable inside member function in order to ensure initialization 0070 //! at first call 0071 static Standard_EXPORT TObj_DataMapOfStringPointer& getMapOfTypes(); 0072 0073 private: 0074 Standard_CString myType; //!< Name of managed type (recorded for unregistering) 0075 }; 0076 0077 //! Declare subclass and methods of the class inherited from TObj_Object 0078 //! necessary for implementation of persistence 0079 //! This declaration should be put inside class declaration, under 'protected' modifier 0080 #ifdef SOLARIS 0081 //! Workaround on SUN to avoid stupid warnings 0082 #define _TOBJOCAF_PERSISTENCE_ACCESS_ public: 0083 #else 0084 #define _TOBJOCAF_PERSISTENCE_ACCESS_ 0085 #endif 0086 #define DECLARE_TOBJOCAF_PERSISTENCE(name,ancestor) \ 0087 name (const TObj_Persistence *p, \ 0088 const TDF_Label& aLabel) : ancestor(p,aLabel) \ 0089 { initFields(); } /* give the object a chance to initialize its fields */ \ 0090 \ 0091 /* Creates an object of a proper type */ \ 0092 /* First argument is used just to avoid possible conflict with other constructors */ \ 0093 _TOBJOCAF_PERSISTENCE_ACCESS_ \ 0094 class Persistence_ : public TObj_Persistence { \ 0095 /* Friend private class of name, is a tool providing persistence */ \ 0096 public: \ 0097 Persistence_ () : TObj_Persistence(#name) {} /* register the tool */ \ 0098 virtual Handle(TObj_Object) New (const TDF_Label& aLabel) const; \ 0099 /* Creates an object of a proper type */ \ 0100 }; \ 0101 friend class Persistence_; \ 0102 static Persistence_ myPersistence_; /* Static field implementing persistsnce tool */ 0103 0104 //! Implement mechanism for registration the type for persistence 0105 //! This should not be used for abstract classes (while DECLARE should) 0106 #define IMPLEMENT_TOBJOCAF_PERSISTENCE(name) \ 0107 name::Persistence_ name::myPersistence_; \ 0108 Handle(TObj_Object) name::Persistence_::New (const TDF_Label& aLabel) const { \ 0109 return new name((const TObj_Persistence*)0, aLabel); \ 0110 } 0111 0112 #endif 0113 0114 #ifdef _MSC_VER 0115 #pragma once 0116 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |