Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:29:37

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