0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / StdObjMgt / StdObjMgt_ReadData.hxx
CommitLineData
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 21class StdObjMgt_Persistent;
45d8465e 22class Standard_GUID;
23
7ed7467d 24
25//! Auxiliary data used to read persistent objects from a file.
26class StdObjMgt_ReadData
27{
28public:
472433e2 29 //! Auxiliary class used to automate begin and end of
30 //! reading object (eating opening and closing parenthesis)
31 //! at constructor and destructor
32 class ObjectSentry
33 {
34 public:
35 explicit ObjectSentry (StdObjMgt_ReadData& theData) : myReadData (&theData)
36 { myReadData->myDriver->BeginReadObjectData(); }
37
38 ~ObjectSentry ()
39 { myReadData->myDriver->EndReadObjectData(); }
40
41 private:
42 StdObjMgt_ReadData* myReadData;
43
44 ObjectSentry (const ObjectSentry&);
45 ObjectSentry& operator = (const ObjectSentry&);
46 };
45d8465e 47
ff205346 48 Standard_EXPORT StdObjMgt_ReadData
39c8dc70 49 (const Handle(Storage_BaseDriver)& theDriver, const Standard_Integer theNumberOfObjects);
7ed7467d 50
ff205346 51 template <class Instantiator>
52 void CreatePersistentObject
53 (const Standard_Integer theRef, Instantiator theInstantiator)
54 { myPersistentObjects (theRef) = theInstantiator(); }
55
56 Standard_EXPORT void ReadPersistentObject
57 (const Standard_Integer theRef);
58
59 Handle(StdObjMgt_Persistent) PersistentObject
60 (const Standard_Integer theRef) const
61 { return myPersistentObjects (theRef); }
62
63 Standard_EXPORT Handle(StdObjMgt_Persistent) ReadReference();
64
65 template <class Persistent>
45d8465e 66 StdObjMgt_ReadData& operator >> (Handle(Persistent)& theTarget)
ff205346 67 {
68 theTarget = Handle(Persistent)::DownCast (ReadReference());
45d8465e 69 return *this;
ff205346 70 }
71
45d8465e 72 StdObjMgt_ReadData& operator >> (Handle(StdObjMgt_Persistent)& theTarget)
ff205346 73 {
45d8465e 74 theTarget = ReadReference();
75 return *this;
ff205346 76 }
77
7ed7467d 78 template <class Type>
45d8465e 79 StdObjMgt_ReadData& ReadValue (Type& theValue)
7ed7467d 80 {
ff205346 81 *myDriver >> theValue;
7ed7467d 82 return *this;
83 }
84
45d8465e 85 StdObjMgt_ReadData& operator >> (Standard_Character& theValue)
86 { return ReadValue (theValue); }
87
88 StdObjMgt_ReadData& operator >> (Standard_ExtCharacter& theValue)
89 { return ReadValue (theValue); }
90
91 StdObjMgt_ReadData& operator >> (Standard_Integer& theValue)
92 { return ReadValue (theValue); }
93
94 StdObjMgt_ReadData& operator >> (Standard_Boolean& theValue)
95 { return ReadValue (theValue); }
96
97 StdObjMgt_ReadData& operator >> (Standard_Real& theValue)
98 { return ReadValue (theValue); }
99
100 StdObjMgt_ReadData& operator >> (Standard_ShortReal& theValue)
101 { return ReadValue (theValue); }
102
7ed7467d 103private:
39c8dc70 104 Handle(Storage_BaseDriver) myDriver;
7ed7467d 105 NCollection_Array1<Handle(StdObjMgt_Persistent)> myPersistentObjects;
106};
107
45d8465e 108Standard_EXPORT StdObjMgt_ReadData& operator >>
472433e2 109 (StdObjMgt_ReadData& theReadData, Standard_GUID& theGUID);
45d8465e 110
7ed7467d 111#endif // _StdObjMgt_ReadData_HeaderFile