0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / StdObjMgt / StdObjMgt_WriteData.hxx
1 // Copyright (c) 2017 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 _StdObjMgt_WriteData_HeaderFile
15 #define _StdObjMgt_WriteData_HeaderFile
16
17 #include <Standard.hxx>
18 #include <Storage_BaseDriver.hxx>
19
20 class StdObjMgt_Persistent;
21 class Standard_GUID;
22
23 //! Auxiliary data used to write persistent objects to a file.
24 class StdObjMgt_WriteData
25 {
26 public:
27
28   //! Auxiliary class used to automate begin and end of
29   //! writing object (adding opening and closing parenthesis)
30   //! at constructor and destructor
31   class ObjectSentry
32   {
33   public:
34     explicit ObjectSentry (StdObjMgt_WriteData& theData) : myWriteData(&theData)
35     { myWriteData->myDriver->BeginWriteObjectData(); }
36
37     ~ObjectSentry()
38     { myWriteData->myDriver->EndWriteObjectData(); }
39
40   private:
41     StdObjMgt_WriteData* myWriteData;
42
43     ObjectSentry (const ObjectSentry&);
44     ObjectSentry& operator = (const ObjectSentry&);
45   };
46
47   Standard_EXPORT StdObjMgt_WriteData 
48     (Storage_BaseDriver& theDriver);
49
50   Standard_EXPORT void WritePersistentObject
51     (const Handle(StdObjMgt_Persistent)& thePersistent);
52
53   template <class Persistent>
54   StdObjMgt_WriteData& operator << (const Handle(Persistent)& thePersistent)
55   {
56     myDriver->PutReference(thePersistent ? thePersistent->RefNum() : 0);
57     return *this;
58   }
59
60   Standard_EXPORT StdObjMgt_WriteData& operator << (const Handle(StdObjMgt_Persistent)& thePersistent);
61
62   template <class Type>
63   StdObjMgt_WriteData& WriteValue(const Type& theValue)
64   {
65     *myDriver << theValue;
66     return *this;
67   }
68
69   StdObjMgt_WriteData& operator << (const Standard_Character& theValue)
70     { return WriteValue(theValue); }
71   
72   StdObjMgt_WriteData& operator << (const Standard_ExtCharacter& theValue)
73     { return WriteValue(theValue); }
74   
75   StdObjMgt_WriteData& operator << (const Standard_Integer& theValue)
76    { return WriteValue(theValue); }
77   
78   StdObjMgt_WriteData& operator << (const Standard_Boolean& theValue)
79     { return WriteValue(theValue); }
80   
81   StdObjMgt_WriteData& operator << (const Standard_Real& theValue)
82    { return WriteValue(theValue); }
83   
84   StdObjMgt_WriteData& operator << (const Standard_ShortReal& theValue)
85     { return WriteValue(theValue); }
86
87 private:
88   Storage_BaseDriver* myDriver;
89 };
90
91 Standard_EXPORT StdObjMgt_WriteData& operator <<
92   (StdObjMgt_WriteData& theWriteData, const Standard_GUID& theGUID);
93
94 #endif // _StdObjMgt_WriteData_HeaderFile