0026961: Recover possibility to read files in old persistence format
[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;
7ed7467d 22
23//! Auxiliary data used to read persistent objects from a file.
24class StdObjMgt_ReadData
25{
26public:
ff205346 27 Standard_EXPORT StdObjMgt_ReadData
28 (Storage_BaseDriver& theDriver, const Standard_Integer theNumberOfObjects);
7ed7467d 29
30 Storage_BaseDriver& Driver() const
31 { return *myDriver; }
32
ff205346 33 template <class Instantiator>
34 void CreatePersistentObject
35 (const Standard_Integer theRef, Instantiator theInstantiator)
36 { myPersistentObjects (theRef) = theInstantiator(); }
37
38 Standard_EXPORT void ReadPersistentObject
39 (const Standard_Integer theRef);
40
41 Handle(StdObjMgt_Persistent) PersistentObject
42 (const Standard_Integer theRef) const
43 { return myPersistentObjects (theRef); }
44
45 Standard_EXPORT Handle(StdObjMgt_Persistent) ReadReference();
46
47 template <class Persistent>
48 void ReadReference (Handle(Persistent)& theTarget)
49 {
50 theTarget = Handle(Persistent)::DownCast (ReadReference());
51 }
52
53 template <class Object>
54 void ReadObject (Object& theObject)
55 {
56 myDriver->BeginReadObjectData();
57 theObject.Read (*this);
58 myDriver->EndReadObjectData();
59 }
60
7ed7467d 61 template <class Type>
ff205346 62 void ReadValue (Type& theValue)
7ed7467d 63 {
ff205346 64 *myDriver >> theValue;
7ed7467d 65 }
66
67 template <class Type>
ff205346 68 void ReadEnum (Type& theEnum)
69 {
70 Standard_Integer aValue;
71 *myDriver >> aValue;
72 theEnum = static_cast<Type> (aValue);
73 }
74
75 template <class Base> struct Content : Base {};
76
77 template <class Base>
78 StdObjMgt_ReadData& operator >> (Content<Base>& theContent)
7ed7467d 79 {
ff205346 80 theContent.Read (*this);
7ed7467d 81 return *this;
82 }
83
84private:
85 Storage_BaseDriver* myDriver;
86 NCollection_Array1<Handle(StdObjMgt_Persistent)> myPersistentObjects;
87};
88
89#endif // _StdObjMgt_ReadData_HeaderFile