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>
19 #include <StdObjMgt_WriteData.hxx>
22 //! Root class for a temporary persistent object corresponding to an attribute.
23 template <class Transient>
24 class StdObjMgt_Attribute : public Standard_Transient
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; }
51 //! Write persistent data to a file.
52 Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const
53 { theWriteData << myData; }
54 Standard_EXPORT virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
55 Standard_EXPORT virtual Standard_CString PName() const { return "StdObjMgt_Attribute::undefined"; }
61 struct SingleInt : Simple<Standard_Integer> {};
62 struct SingleRef : Simple<Handle(StdObjMgt_Persistent)> {};
65 template <class Persistent>
66 class container : public base
69 //! Read persistent data from a file.
70 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData)
72 myPersistent = new Persistent;
73 myPersistent->Read (theReadData);
75 //! Write persistent data to a file.
76 Standard_EXPORT virtual void Write(StdObjMgt_WriteData& theWriteData) const
77 { myPersistent->Write(theWriteData); }
78 Standard_EXPORT virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
79 Standard_EXPORT virtual Standard_CString PName() const
80 { return myPersistent->PName(); }
82 //! Import transient attribuite from the persistent data
83 Standard_EXPORT virtual void ImportAttribute()
85 if (myPersistent && this->myTransient)
87 myPersistent->Import (this->myTransient);
88 myPersistent.Nullify();
93 Handle(Persistent) myPersistent;
97 template <class Persistent>
98 static Handle(StdObjMgt_Persistent) Instantiate()
99 { return new container<Persistent>; }
102 #endif // _StdObjMgt_Attribute_HeaderFile