7ed7467d |
1 | // Copyright (c) 2015 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_ReadData_HeaderFile |
15 | #define _StdObjMgt_ReadData_HeaderFile |
16 | |
17 | #include <Standard.hxx> |
7ed7467d |
18 | #include <Storage_BaseDriver.hxx> |
ff205346 |
19 | #include <NCollection_Array1.hxx> |
7ed7467d |
20 | |
ff205346 |
21 | class StdObjMgt_Persistent; |
45d8465e |
22 | class Standard_GUID; |
23 | |
7ed7467d |
24 | |
25 | //! Auxiliary data used to read persistent objects from a file. |
26 | class StdObjMgt_ReadData |
27 | { |
28 | public: |
45d8465e |
29 | class Object; |
30 | |
ff205346 |
31 | Standard_EXPORT StdObjMgt_ReadData |
32 | (Storage_BaseDriver& theDriver, const Standard_Integer theNumberOfObjects); |
7ed7467d |
33 | |
ff205346 |
34 | template <class Instantiator> |
35 | void CreatePersistentObject |
36 | (const Standard_Integer theRef, Instantiator theInstantiator) |
37 | { myPersistentObjects (theRef) = theInstantiator(); } |
38 | |
39 | Standard_EXPORT void ReadPersistentObject |
40 | (const Standard_Integer theRef); |
41 | |
42 | Handle(StdObjMgt_Persistent) PersistentObject |
43 | (const Standard_Integer theRef) const |
44 | { return myPersistentObjects (theRef); } |
45 | |
46 | Standard_EXPORT Handle(StdObjMgt_Persistent) ReadReference(); |
47 | |
48 | template <class Persistent> |
45d8465e |
49 | StdObjMgt_ReadData& operator >> (Handle(Persistent)& theTarget) |
ff205346 |
50 | { |
51 | theTarget = Handle(Persistent)::DownCast (ReadReference()); |
45d8465e |
52 | return *this; |
ff205346 |
53 | } |
54 | |
45d8465e |
55 | StdObjMgt_ReadData& operator >> (Handle(StdObjMgt_Persistent)& theTarget) |
ff205346 |
56 | { |
45d8465e |
57 | theTarget = ReadReference(); |
58 | return *this; |
ff205346 |
59 | } |
60 | |
7ed7467d |
61 | template <class Type> |
45d8465e |
62 | StdObjMgt_ReadData& ReadValue (Type& theValue) |
7ed7467d |
63 | { |
ff205346 |
64 | *myDriver >> theValue; |
7ed7467d |
65 | return *this; |
66 | } |
67 | |
45d8465e |
68 | StdObjMgt_ReadData& operator >> (Standard_Character& theValue) |
69 | { return ReadValue (theValue); } |
70 | |
71 | StdObjMgt_ReadData& operator >> (Standard_ExtCharacter& theValue) |
72 | { return ReadValue (theValue); } |
73 | |
74 | StdObjMgt_ReadData& operator >> (Standard_Integer& theValue) |
75 | { return ReadValue (theValue); } |
76 | |
77 | StdObjMgt_ReadData& operator >> (Standard_Boolean& theValue) |
78 | { return ReadValue (theValue); } |
79 | |
80 | StdObjMgt_ReadData& operator >> (Standard_Real& theValue) |
81 | { return ReadValue (theValue); } |
82 | |
83 | StdObjMgt_ReadData& operator >> (Standard_ShortReal& theValue) |
84 | { return ReadValue (theValue); } |
85 | |
7ed7467d |
86 | private: |
87 | Storage_BaseDriver* myDriver; |
88 | NCollection_Array1<Handle(StdObjMgt_Persistent)> myPersistentObjects; |
89 | }; |
90 | |
45d8465e |
91 | class StdObjMgt_ReadData::Object |
92 | { |
93 | public: |
94 | Object (StdObjMgt_ReadData& theData) : myReadData (&theData) |
95 | { myReadData->myDriver->BeginReadObjectData(); } |
ec964372 |
96 | Object(const StdObjMgt_ReadData::Object& theOther) : myReadData(theOther.myReadData) |
97 | { myReadData->myDriver->BeginReadObjectData(); } |
45d8465e |
98 | |
99 | ~Object() |
100 | { myReadData->myDriver->EndReadObjectData(); } |
101 | |
102 | operator StdObjMgt_ReadData&() |
103 | { return *myReadData; } |
104 | |
105 | template <class Data> |
106 | StdObjMgt_ReadData& operator >> (Data& theData) |
107 | { return *myReadData >> theData; } |
108 | |
109 | private: |
110 | StdObjMgt_ReadData* myReadData; |
ec964372 |
111 | |
112 | StdObjMgt_ReadData::Object& operator = (const StdObjMgt_ReadData::Object&); |
45d8465e |
113 | }; |
114 | |
115 | Standard_EXPORT StdObjMgt_ReadData& operator >> |
116 | (StdObjMgt_ReadData::Object theReadData, Standard_GUID& theGUID); |
117 | |
7ed7467d |
118 | #endif // _StdObjMgt_ReadData_HeaderFile |