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_ReadData_HeaderFile
15 #define _StdObjMgt_ReadData_HeaderFile
17 #include <Standard.hxx>
18 #include <Storage_BaseDriver.hxx>
19 #include <NCollection_Array1.hxx>
21 class StdObjMgt_Persistent;
25 //! Auxiliary data used to read persistent objects from a file.
26 class StdObjMgt_ReadData
29 //! Auxiliary class used to automate begin and end of
30 //! reading object (eating opening and closing parenthesis)
31 //! at constructor and destructor
35 explicit ObjectSentry (StdObjMgt_ReadData& theData) : myReadData (&theData)
36 { myReadData->myDriver->BeginReadObjectData(); }
39 { myReadData->myDriver->EndReadObjectData(); }
42 StdObjMgt_ReadData* myReadData;
44 ObjectSentry (const ObjectSentry&);
45 ObjectSentry& operator = (const ObjectSentry&);
48 Standard_EXPORT StdObjMgt_ReadData
49 (Storage_BaseDriver& theDriver, const Standard_Integer theNumberOfObjects);
51 template <class Instantiator>
52 void CreatePersistentObject
53 (const Standard_Integer theRef, Instantiator theInstantiator)
54 { myPersistentObjects (theRef) = theInstantiator(); }
56 Standard_EXPORT void ReadPersistentObject
57 (const Standard_Integer theRef);
59 Handle(StdObjMgt_Persistent) PersistentObject
60 (const Standard_Integer theRef) const
61 { return myPersistentObjects (theRef); }
63 Standard_EXPORT Handle(StdObjMgt_Persistent) ReadReference();
65 template <class Persistent>
66 StdObjMgt_ReadData& operator >> (Handle(Persistent)& theTarget)
68 theTarget = Handle(Persistent)::DownCast (ReadReference());
72 StdObjMgt_ReadData& operator >> (Handle(StdObjMgt_Persistent)& theTarget)
74 theTarget = ReadReference();
79 StdObjMgt_ReadData& ReadValue (Type& theValue)
81 *myDriver >> theValue;
85 StdObjMgt_ReadData& operator >> (Standard_Character& theValue)
86 { return ReadValue (theValue); }
88 StdObjMgt_ReadData& operator >> (Standard_ExtCharacter& theValue)
89 { return ReadValue (theValue); }
91 StdObjMgt_ReadData& operator >> (Standard_Integer& theValue)
92 { return ReadValue (theValue); }
94 StdObjMgt_ReadData& operator >> (Standard_Boolean& theValue)
95 { return ReadValue (theValue); }
97 StdObjMgt_ReadData& operator >> (Standard_Real& theValue)
98 { return ReadValue (theValue); }
100 StdObjMgt_ReadData& operator >> (Standard_ShortReal& theValue)
101 { return ReadValue (theValue); }
104 Storage_BaseDriver* myDriver;
105 NCollection_Array1<Handle(StdObjMgt_Persistent)> myPersistentObjects;
108 Standard_EXPORT StdObjMgt_ReadData& operator >>
109 (StdObjMgt_ReadData& theReadData, Standard_GUID& theGUID);
111 #endif // _StdObjMgt_ReadData_HeaderFile