1 // Created on: 1996-12-03
2 // Created by: Christophe LEYNADIER
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Storage_Schema_HeaderFile
18 #define _Storage_Schema_HeaderFile
20 #include <Storage_BaseDriver.hxx>
21 #include <Storage_InternalData.hxx>
22 #include <Storage_MapOfCallBack.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <TColStd_HSequenceOfAsciiString.hxx>
26 class Storage_CallBack;
30 DEFINE_STANDARD_HANDLE(Storage_Schema, Standard_Transient)
33 //! Root class for basic storage/retrieval algorithms.
34 //! A Storage_Schema object processes:
35 //! - writing of a set of persistent data into a
36 //! container (store mechanism),
37 //! - reading of a container to extract all the
38 //! contained persistent data (retrieve mechanism).
39 //! A Storage_Schema object is based on the data
40 //! schema for the persistent data of the application, i.e.:
41 //! - the list of all persistent objects which may be
42 //! known by the application,
43 //! - the organization of their data; a data schema
44 //! knows how to browse each persistent object it contains.
45 //! During the store or retrieve operation, only
46 //! persistent objects known from the data schema
47 //! can be processed; they are then stored or
48 //! retrieved according to their description in the schema.
49 //! A data schema is specific to the object classes to
50 //! be read or written. Tools dedicated to the
51 //! environment in use allow a description of the
52 //! application persistent data structure.
53 //! Storage_Schema algorithms are called basic
54 //! because they do not support external references
55 //! between containers.
56 class Storage_Schema : public Standard_Transient
62 //! Builds a storage/retrieval algorithm based on a
63 //! given data schema.
65 //! For example, if ShapeSchema is the class
66 //! inheriting from Storage_Schema and containing
67 //! the description of your application data schema,
68 //! you create a storage/retrieval algorithm as follows:
69 //! Handle(ShapeSchema) s = new
72 //! USER API -- --------------------------------------------------------------
74 Standard_EXPORT Storage_Schema();
76 //! returns version of the schema
77 Standard_EXPORT void SetVersion (const TCollection_AsciiString& aVersion);
79 //! returns the version of the schema
80 Standard_EXPORT TCollection_AsciiString Version() const;
82 //! set the schema's name
83 Standard_EXPORT void SetName (const TCollection_AsciiString& aSchemaName);
85 //! returns the schema's name
86 Standard_EXPORT TCollection_AsciiString Name() const;
88 //! Writes the data aggregated in aData into the
89 //! container defined by the driver s. The storage
90 //! operation is performed according to the data
91 //! schema with which this algorithm is working.
92 //! Note: aData may aggregate several root objects
93 //! to be stored together.
94 Standard_EXPORT void Write (const Handle(Storage_BaseDriver)& s, const Handle(Storage_Data)& aData) const;
96 //! return a current date string
97 Standard_EXPORT static TCollection_AsciiString ICreationDate();
99 //! returns True if theType migration is identified
100 //! the callback support provides a way to read a file
101 //! with a incomplete schema.
102 //! ex. : A file contains 3 types a, b, and c.
103 //! The application's schema contains only 2
104 //! type a and b. If you try to read the file in
105 //! the application, you will have an error.To
106 //! bypass this problem you can give to your
107 //! application's schema a callback used when
108 //! the schema doesn't know how to handle this
110 Standard_EXPORT static Standard_Boolean CheckTypeMigration (const TCollection_AsciiString& theTypeName, TCollection_AsciiString& theNewName);
112 //! add two functions to the callback list
113 Standard_EXPORT void AddReadUnknownTypeCallBack (const TCollection_AsciiString& aTypeName, const Handle(Storage_CallBack)& aCallBack);
115 //! remove a callback for a type
116 Standard_EXPORT void RemoveReadUnknownTypeCallBack (const TCollection_AsciiString& aTypeName);
118 //! returns a list of type name with installed
120 Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) InstalledCallBackList() const;
122 //! clear all callback from schema instance.
123 Standard_EXPORT void ClearCallBackList();
125 //! install a callback for all unknown type. the
126 //! objects with unknown types will be skipped. (look
127 //! SkipObject method in BaseDriver)
128 Standard_EXPORT void UseDefaultCallBack();
130 //! tells schema to uninstall the default callback.
131 Standard_EXPORT void DontUseDefaultCallBack();
133 //! ask if the schema is using the default callback.
134 Standard_EXPORT Standard_Boolean IsUsingDefaultCallBack() const;
136 //! overload the default function for build.(use to
137 //! set an error message or skip an object while
138 //! reading an unknown type).
139 Standard_EXPORT void SetDefaultCallBack (const Handle(Storage_CallBack)& f);
141 //! reset the default function defined by Storage
143 Standard_EXPORT void ResetDefaultCallBack();
145 //! returns the read function used when the
146 //! UseDefaultCallBack() is set.
147 Standard_EXPORT Handle(Storage_CallBack) DefaultCallBack() const;
149 void WritePersistentObjectHeader(const Handle(Standard_Persistent)& sp, const Handle(Storage_BaseDriver)& theDriver)
151 theDriver->WritePersistentObjectHeader(sp->_refnum, sp->_typenum);
154 void WritePersistentReference(const Handle(Standard_Persistent)& sp, const Handle(Storage_BaseDriver)& theDriver)
156 theDriver->PutReference(sp.IsNull() ? 0 : sp->_refnum);
159 Standard_EXPORT Standard_Boolean AddPersistent (const Handle(Standard_Persistent)& sp, const Standard_CString tName) const;
161 Standard_EXPORT Standard_Boolean PersistentToAdd (const Handle(Standard_Persistent)& sp) const;
163 DEFINE_STANDARD_RTTIEXT(Storage_Schema,Standard_Transient)
167 Standard_Boolean HasTypeBinding(const TCollection_AsciiString& aTypeName) const
169 return Storage_Schema::ICurrentData()->InternalData()->myTypeBinding.IsBound(aTypeName);
172 Standard_EXPORT void BindType (const TCollection_AsciiString& aTypeName, const Handle(Storage_CallBack)& aCallBack) const;
174 Standard_EXPORT Handle(Storage_CallBack) TypeBinding (const TCollection_AsciiString& aTypeName) const;
180 Standard_EXPORT void Clear() const;
182 Standard_EXPORT static void ISetCurrentData (const Handle(Storage_Data)& dData);
184 Standard_EXPORT static Handle(Storage_Data)& ICurrentData();
186 Storage_MapOfCallBack myCallBack;
187 Standard_Boolean myCallBackState;
188 Handle(Storage_CallBack) myDefaultCallBack;
189 TCollection_AsciiString myName;
190 TCollection_AsciiString myVersion;
193 #endif // _Storage_Schema_HeaderFile