1 // Copyright (c) 2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _StdObjMgt_Attribute_HeaderFile
15 #define _StdObjMgt_Attribute_HeaderFile
17 #include <StdObjMgt_Persistent.hxx>
18 #include <StdObjMgt_ReadData.hxx>
21 //! Root class for a temporary persistent object corresponding to an attribute.
22 template <class Transient>
23 class StdObjMgt_Attribute : public Standard_Transient,
24 protected StdObjMgt_ContentTypes
26 class base : public StdObjMgt_Persistent
29 //! Create an empty transient attribuite
30 Standard_EXPORT virtual Handle(TDF_Attribute) CreateAttribute()
31 { return myTransient = new Transient; }
33 //! Get transient attribuite for the persistent data
34 Standard_EXPORT virtual Handle(TDF_Attribute) GetAttribute() const
35 { return Handle(TDF_Attribute)(myTransient); }
38 Handle(Transient) myTransient;
42 class Static : public base {};
44 template <class DataType>
45 class Simple : public Static
48 //! Read persistent data from a file.
49 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData)
50 { theReadData >> myData; }
56 struct SingleInt : Simple <Value<Standard_Integer> > {};
57 struct SingleRef : Simple <Reference<> > {};
60 template <class Persistent>
61 class container : public base
64 //! Read persistent data from a file.
65 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData)
67 myPersistent = new Persistent;
68 myPersistent->Read (theReadData);
71 //! Import transient attribuite from the persistent data
72 Standard_EXPORT virtual void ImportAttribute()
74 if (myPersistent && this->myTransient)
76 myPersistent->Import (this->myTransient);
77 myPersistent.Nullify();
82 Handle(Persistent) myPersistent;
86 template <class Persistent>
87 static Handle(StdObjMgt_Persistent) Instantiate()
88 { return new container<Persistent>; }
91 #endif // _StdObjMgt_Attribute_HeaderFile