Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:17

0001 // Created on: 1996-12-03
0002 // Created by: Christophe LEYNADIER
0003 // Copyright (c) 1996-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Storage_Schema_HeaderFile
0018 #define _Storage_Schema_HeaderFile
0019 
0020 #include <Storage_BaseDriver.hxx>
0021 #include <Storage_InternalData.hxx>
0022 #include <Storage_MapOfCallBack.hxx>
0023 #include <TCollection_AsciiString.hxx>
0024 #include <TColStd_HSequenceOfAsciiString.hxx>
0025 
0026 class Storage_CallBack;
0027 
0028 
0029 class Storage_Schema;
0030 DEFINE_STANDARD_HANDLE(Storage_Schema, Standard_Transient)
0031 
0032 
0033 //! Root class for basic storage/retrieval algorithms.
0034 //! A Storage_Schema object processes:
0035 //! -   writing of a set of persistent data into a
0036 //! container (store mechanism),
0037 //! -   reading of a container to extract all the
0038 //! contained persistent data (retrieve mechanism).
0039 //! A Storage_Schema object is based on the data
0040 //! schema for the persistent data of the application, i.e.:
0041 //! -   the list of all persistent objects which may be
0042 //! known by the application,
0043 //! -   the organization of their data; a data schema
0044 //! knows how to browse each persistent object it contains.
0045 //! During the store or retrieve operation, only
0046 //! persistent objects known from the data schema
0047 //! can be processed; they are then stored or
0048 //! retrieved according to their description in the schema.
0049 //! A data schema is specific to the object classes to
0050 //! be read or written. Tools dedicated to the
0051 //! environment in use allow a description of the
0052 //! application persistent data structure.
0053 //! Storage_Schema algorithms are called basic
0054 //! because they do not support external references
0055 //! between containers.
0056 class Storage_Schema : public Standard_Transient
0057 {
0058 
0059 public:
0060 
0061   
0062   //! Builds a storage/retrieval algorithm based on a
0063   //! given data schema.
0064   //! Example
0065   //! For example, if ShapeSchema is the class
0066   //! inheriting from Storage_Schema and containing
0067   //! the description of your application data schema,
0068   //! you create a storage/retrieval algorithm as follows:
0069   //! Handle(ShapeSchema) s = new
0070   //! ShapeSchema;
0071   //! -------- --
0072   //! USER API -- --------------------------------------------------------------
0073   //! -------- --
0074   Standard_EXPORT Storage_Schema();
0075   
0076   //! returns version of the schema
0077   Standard_EXPORT void SetVersion (const TCollection_AsciiString& aVersion);
0078   
0079   //! returns the version of the schema
0080   Standard_EXPORT TCollection_AsciiString Version() const;
0081   
0082   //! set the schema's name
0083   Standard_EXPORT void SetName (const TCollection_AsciiString& aSchemaName);
0084   
0085   //! returns the schema's name
0086   Standard_EXPORT TCollection_AsciiString Name() const;
0087   
0088   //! Writes the data aggregated in aData into the
0089   //! container defined by the driver s. The storage
0090   //! operation is performed according to the data
0091   //! schema with which this algorithm is working.
0092   //! Note: aData may aggregate several root objects
0093   //! to be stored together.
0094   Standard_EXPORT void Write (const Handle(Storage_BaseDriver)& s, const Handle(Storage_Data)& aData) const;
0095   
0096   //! return a current date string
0097   Standard_EXPORT static TCollection_AsciiString ICreationDate();
0098   
0099   //! returns True if theType migration is identified
0100   //! the callback support provides a way to read a file
0101   //! with a incomplete schema.
0102   //! ex. : A file contains 3 types a, b, and c.
0103   //! The  application's  schema  contains  only 2
0104   //! type a and b. If you try to read the file in
0105   //! the application, you  will  have an error.To
0106   //! bypass this  problem  you  can  give to your
0107   //! application's schema  a  callback  used when
0108   //! the schema doesn't know  how  to handle this
0109   //! type.
0110   Standard_EXPORT static Standard_Boolean CheckTypeMigration (const TCollection_AsciiString& theTypeName, TCollection_AsciiString& theNewName);
0111   
0112   //! add two functions to the callback list
0113   Standard_EXPORT void AddReadUnknownTypeCallBack (const TCollection_AsciiString& aTypeName, const Handle(Storage_CallBack)& aCallBack);
0114   
0115   //! remove a callback for a type
0116   Standard_EXPORT void RemoveReadUnknownTypeCallBack (const TCollection_AsciiString& aTypeName);
0117   
0118   //! returns  a  list  of   type  name  with  installed
0119   //! callback.
0120   Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) InstalledCallBackList() const;
0121   
0122   //! clear all callback from schema instance.
0123   Standard_EXPORT void ClearCallBackList();
0124   
0125   //! install  a  callback  for  all  unknown  type. the
0126   //! objects with unknown types  will be skipped. (look
0127   //! SkipObject method in BaseDriver)
0128   Standard_EXPORT void UseDefaultCallBack();
0129   
0130   //! tells schema to uninstall the default callback.
0131   Standard_EXPORT void DontUseDefaultCallBack();
0132   
0133   //! ask if the schema is using the default callback.
0134   Standard_EXPORT Standard_Boolean IsUsingDefaultCallBack() const;
0135   
0136   //! overload the  default  function  for build.(use to
0137   //! set an  error  message  or  skip  an  object while
0138   //! reading an unknown type).
0139   Standard_EXPORT void SetDefaultCallBack (const Handle(Storage_CallBack)& f);
0140   
0141   //! reset  the  default  function  defined  by Storage
0142   //! package.
0143   Standard_EXPORT void ResetDefaultCallBack();
0144   
0145   //! returns   the   read   function   used   when  the
0146   //! UseDefaultCallBack() is set.
0147   Standard_EXPORT Handle(Storage_CallBack) DefaultCallBack() const;
0148   
0149   void WritePersistentObjectHeader(const Handle(Standard_Persistent)& sp, const Handle(Storage_BaseDriver)& theDriver)
0150   {
0151     theDriver->WritePersistentObjectHeader(sp->_refnum, sp->_typenum);
0152   }
0153 
0154   void WritePersistentReference(const Handle(Standard_Persistent)& sp, const Handle(Storage_BaseDriver)& theDriver)
0155   {
0156     theDriver->PutReference(sp.IsNull() ? 0 : sp->_refnum);
0157   }
0158   
0159   Standard_EXPORT Standard_Boolean AddPersistent (const Handle(Standard_Persistent)& sp, const Standard_CString tName) const;
0160   
0161   Standard_EXPORT Standard_Boolean PersistentToAdd (const Handle(Standard_Persistent)& sp) const;
0162 
0163   DEFINE_STANDARD_RTTIEXT(Storage_Schema,Standard_Transient)
0164 
0165 protected:
0166   
0167   Standard_Boolean HasTypeBinding(const TCollection_AsciiString& aTypeName) const
0168   {
0169     return Storage_Schema::ICurrentData()->InternalData()->myTypeBinding.IsBound(aTypeName);
0170   }
0171   
0172   Standard_EXPORT void BindType (const TCollection_AsciiString& aTypeName, const Handle(Storage_CallBack)& aCallBack) const;
0173   
0174   Standard_EXPORT Handle(Storage_CallBack) TypeBinding (const TCollection_AsciiString& aTypeName) const;
0175 
0176 
0177 
0178 private:
0179 
0180   Standard_EXPORT void Clear() const;
0181   
0182   Standard_EXPORT static void ISetCurrentData (const Handle(Storage_Data)& dData);
0183   
0184   Standard_EXPORT static Handle(Storage_Data)& ICurrentData();
0185 
0186   Storage_MapOfCallBack myCallBack;
0187   Standard_Boolean myCallBackState;
0188   Handle(Storage_CallBack) myDefaultCallBack;
0189   TCollection_AsciiString myName;
0190   TCollection_AsciiString myVersion;
0191 };
0192 
0193 #endif // _Storage_Schema_HeaderFile