1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0028564: Support of applications using old persistence (ShapeSchema)

1. Bug fix in reading old persistent data using FSD_File storage driver
2. Persistence compatible with legacy format was restored for shapes
   a. Implemented a storage read / write wrapper for legacy persistence
   b. Added DRAW commands to read / write files in legacy format
   c. Added test cases for reading / writing operations with checking number of sub-shapes and physical properties
   d. Updated related sections of the development guide
This commit is contained in:
snn
2017-03-28 17:13:04 +03:00
committed by bugmaster
parent 632175c3a8
commit ec96437207
124 changed files with 7813 additions and 128 deletions

18
src/StdStorage/FILES Normal file
View File

@@ -0,0 +1,18 @@
StdStorage.cxx
StdStorage.hxx
StdStorage_Data.cxx
StdStorage_Data.hxx
StdStorage_HeaderData.cxx
StdStorage_HeaderData.hxx
StdStorage_Root.cxx
StdStorage_Root.hxx
StdStorage_RootData.cxx
StdStorage_RootData.hxx
StdStorage_HSequenceOfRoots.hxx
StdStorage_SequenceOfRoots.hxx
StdStorage_MapOfRoots.hxx
StdStorage_TypeData.cxx
StdStorage_TypeData.hxx
StdStorage_MapOfTypes.hxx
StdStorage_BacketOfPersistent.cxx
StdStorage_BacketOfPersistent.hxx

View File

@@ -0,0 +1,319 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <NCollection_Handle.hxx>
#include <NCollection_Array1.hxx>
#include <PCDM.hxx>
#include <PCDM_BaseDriverPointer.hxx>
#include <PCDM_ReadWriter.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_NullObject.hxx>
#include <StdObjMgt_Persistent.hxx>
#include <StdObjMgt_ReadData.hxx>
#include <StdObjMgt_WriteData.hxx>
#include <StdStorage.hxx>
#include <StdStorage_Data.hxx>
#include <StdStorage_HeaderData.hxx>
#include <StdStorage_TypeData.hxx>
#include <StdStorage_RootData.hxx>
#include <StdStorage_HSequenceOfRoots.hxx>
#include <StdStorage_BacketOfPersistent.hxx>
#include <Storage.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <Storage_StreamFormatError.hxx>
#include <Storage_StreamWriteError.hxx>
#include <locale.h>
#include <stdio.h>
//=======================================================================
// StdStorage::Version
//=======================================================================
TCollection_AsciiString StdStorage::Version()
{
TCollection_AsciiString v("1.3");
return v;
}
//=======================================================================
// StdStorage::Read
// Reads data from a file
//=======================================================================
Storage_Error StdStorage::Read(const TCollection_AsciiString& theFileName,
Handle(StdStorage_Data)& theData)
{
// Create a driver appropriate for the given file
PCDM_BaseDriverPointer aDriverPtr;
if (PCDM::FileDriverType(theFileName, aDriverPtr) == PCDM_TOFD_Unknown)
return Storage_VSWrongFileDriver;
NCollection_Handle<Storage_BaseDriver> aDriver(aDriverPtr);
// Try to open the file
try
{
OCC_CATCH_SIGNALS
PCDM_ReadWriter::Open(*aDriver, theFileName, Storage_VSRead);
}
catch (Standard_Failure)
{
return Storage_VSOpenError;
}
return Read(*aDriver, theData);
}
//=======================================================================
// StdStorage::Read
// Reads data from a pre-opened for reading driver
//=======================================================================
Storage_Error StdStorage::Read(Storage_BaseDriver& theDriver,
Handle(StdStorage_Data)& theData)
{
if (theData.IsNull())
theData = new StdStorage_Data;
else
theData->Clear();
Handle(StdStorage_HeaderData) aHeaderData = theData->HeaderData();
Handle(StdStorage_TypeData) aTypeData = theData->TypeData();
Handle(StdStorage_RootData) aRootData = theData->RootData();
// Read header section
if (!aHeaderData->Read(theDriver))
return aHeaderData->ErrorStatus();
// Read types section
if (!aTypeData->Read(theDriver))
return aTypeData->ErrorStatus();
// Select instantiators for the used types
NCollection_Array1<StdObjMgt_Persistent::Instantiator>
anInstantiators(1, aTypeData->NumberOfTypes());
for (Standard_Integer i = 1; i <= aTypeData->NumberOfTypes(); i++)
{
StdObjMgt_Persistent::Instantiator anInstantiator =
aTypeData->Instantiator(i);
if (anInstantiator)
anInstantiators(i) = anInstantiator;
else
return Storage_VSUnknownType;
}
// Read root section
if (!aRootData->Read(theDriver))
return aRootData->ErrorStatus();
Storage_Error anError;
// Read and parse reference section
StdObjMgt_ReadData aReadData(theDriver, aHeaderData->NumberOfObjects());
anError = theDriver.BeginReadRefSection();
if (anError != Storage_VSOk)
return anError;
Standard_Integer aNbRefs = theDriver.RefSectionSize();
for (Standard_Integer i = 1; i <= aNbRefs; i++)
{
Standard_Integer aRef = 0, aType = 0;
try
{
OCC_CATCH_SIGNALS
theDriver.ReadReferenceType(aRef, aType);
anError = Storage_VSOk;
}
catch (Storage_StreamTypeMismatchError)
{
anError = Storage_VSTypeMismatch;
}
if (anError != Storage_VSOk)
return anError;
aReadData.CreatePersistentObject(aRef, anInstantiators(aType));
}
anError = theDriver.EndReadRefSection();
if (anError != Storage_VSOk)
return anError;
// Read and parse data section
anError = theDriver.BeginReadDataSection();
if (anError != Storage_VSOk)
return anError;
for (Standard_Integer i = 1; i <= aHeaderData->NumberOfObjects(); i++)
{
try
{
OCC_CATCH_SIGNALS
aReadData.ReadPersistentObject(i);
anError = Storage_VSOk;
}
catch (Storage_StreamTypeMismatchError) { anError = Storage_VSTypeMismatch; }
catch (Storage_StreamFormatError) { anError = Storage_VSFormatError; }
catch (Storage_StreamReadError) { anError = Storage_VSFormatError; }
if (anError != Storage_VSOk)
return anError;
}
anError = theDriver.EndReadDataSection();
if (anError != Storage_VSOk)
return anError;
Handle(StdStorage_HSequenceOfRoots) aRoots = aRootData->Roots();
if (!aRoots.IsNull())
{
for (StdStorage_HSequenceOfRoots::Iterator anIt(*aRoots); anIt.More(); anIt.Next())
{
Handle(StdStorage_Root)& aRoot = anIt.ChangeValue();
aRoot->SetObject(aReadData.PersistentObject(aRoot->Reference()));
}
}
return Storage_VSOk;
}
//=======================================================================
// StdStorage::currentDate
//=======================================================================
static TCollection_AsciiString currentDate()
{
#define SLENGTH 80
char nowstr[SLENGTH];
time_t nowbin;
struct tm *nowstruct;
if (time(&nowbin) != (time_t)-1)
{
nowstruct = localtime(&nowbin);
strftime(nowstr, SLENGTH, "%m/%d/%Y", nowstruct);
}
TCollection_AsciiString t(nowstr);
return t;
#undef SLENGTH
}
//=======================================================================
// StdStorage::Write
//=======================================================================
Storage_Error StdStorage::Write(Storage_BaseDriver& theDriver,
const Handle(StdStorage_Data)& theData)
{
Standard_NullObject_Raise_if(theData.IsNull(), "Null storage data");
Handle(StdStorage_HeaderData) aHeaderData = theData->HeaderData();
Handle(StdStorage_TypeData) aTypeData = theData->TypeData();
Handle(StdStorage_RootData) aRootData = theData->RootData();
aHeaderData->SetCreationDate(currentDate());
Handle(StdStorage_HSequenceOfRoots) aRoots = aRootData->Roots();
StdStorage_BucketOfPersistent aPObjs;
if (!aRoots.IsNull())
{
StdObjMgt_Persistent::SequenceOfPersistent aPQueue;
for (StdStorage_HSequenceOfRoots::Iterator anIt(*aRoots); anIt.More(); anIt.Next())
{
Handle(StdStorage_Root) aRoot = anIt.ChangeValue();
Handle(StdObjMgt_Persistent) aPObj = aRoot->Object();
if (!aPObj.IsNull()) {
aPQueue.Append(aPObj);
}
}
while (!aPQueue.IsEmpty())
{
StdObjMgt_Persistent::SequenceOfPersistent aPQueue1;
for (StdObjMgt_Persistent::SequenceOfPersistent::Iterator anIt(aPQueue); anIt.More(); anIt.Next())
{
Handle(StdObjMgt_Persistent)& aPObj = anIt.ChangeValue();
if (!aPObj.IsNull())
{
if (aPObj->TypeNum() == 0 && aPObj->RefNum() == 0)
{
aPObj->TypeNum(aTypeData->AddType(aPObj));
Standard_Integer anPObjId = aPObjs.Length() + 1;
aPObj->RefNum(anPObjId);
aPObjs.Append(aPObj);
aPObj->PChildren(aPQueue1);
}
}
}
aPQueue.Assign(aPQueue1);
}
}
aHeaderData->SetStorageVersion(StdStorage::Version());
aHeaderData->SetNumberOfObjects(aPObjs.Length());
try {
// Write header section
if (!aHeaderData->Write(theDriver))
return aHeaderData->ErrorStatus();
// Write types section
if (!aTypeData->Write(theDriver))
return aTypeData->ErrorStatus();
// Write root section
if (!aRootData->Write(theDriver))
return aRootData->ErrorStatus();
Storage_Error anError;
// Write reference section
anError = theDriver.BeginWriteRefSection();
if (anError != Storage_VSOk)
return anError;
theDriver.SetRefSectionSize(aPObjs.Length());
for (StdStorage_BucketIterator anIt(&aPObjs); anIt.More(); anIt.Next())
{
Handle(StdObjMgt_Persistent) aPObj = anIt.Value();
if (!aPObj.IsNull())
theDriver.WriteReferenceType(aPObj->RefNum(), aPObj->TypeNum());
}
anError = theDriver.EndWriteRefSection();
if (anError != Storage_VSOk)
return anError;
// Write data section
anError = theDriver.BeginWriteDataSection();
if (anError != Storage_VSOk)
return anError;
StdObjMgt_WriteData aWriteData(theDriver);
for (StdStorage_BucketIterator anIt(&aPObjs); anIt.More(); anIt.Next())
{
Handle(StdObjMgt_Persistent) aPObj = anIt.Value();
if (!aPObj.IsNull())
aWriteData.WritePersistentObject(aPObj);
}
anError = theDriver.EndWriteDataSection();
if (anError != Storage_VSOk)
return anError;
}
catch (Storage_StreamWriteError) {
return Storage_VSWriteError;
}
return Storage_VSOk;
}

View File

@@ -0,0 +1,72 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StdStorage_HeaderFile
#define _StdStorage_HeaderFile
#include <Standard_Macro.hxx>
#include <Storage_Error.hxx>
class StdStorage_Data;
class Storage_BaseDriver;
class TCollection_AsciiString;
//! StdStorage package is used to write and read persistent objects.
//! These objects are read and written by a retrieval or storage
//! algorithm (compatible with legacy Storage_Schema) in a container
//! (disk, memory, network ...). Drivers (FSD_File objects) assign a physical
//! container for data to be stored or retrieved.
//! The standard procedure for an application in reading a container is
//! to call one of the Read functions providing either a file path or a driver
//! opened for reading. Thes function update the instance of the StdStorage_Data
//! class which contains the data being read.
//! The standard procedure for an application in writing a container is the following:
//! - open the driver in writing mode,
//! - create an instance of the StdStorage_Data class, then
//! add the persistent data to write with the function AddRoot,
//! - call the function Write from the storage, setting the driver and the
//! Storage_Data instance as parameters,
//! - close the driver.
class StdStorage
{
public:
//! Returns the version of Storage's read/write routines
Standard_EXPORT static TCollection_AsciiString Version();
//! Returns the data read from a file located at theFileName.
//! The storage format is compartible with legacy persistent one.
//! These data are aggregated in a StdStorage_Data object which may be
//! browsed in order to extract the root objects from the container.
//! Note: - theData object will be created if it is null or cleared otherwise.
Standard_EXPORT static Storage_Error Read(const TCollection_AsciiString& theFileName,
Handle(StdStorage_Data)& theData);
//! Returns the data read from the container defined by theDriver.
//! The storage format is compartible with legacy persistent one.
//! These data are aggregated in a StdStorage_Data object which may be
//! browsed in order to extract the root objects from the container.
//! Note: - theData object will be created if it is null or cleared otherwise.
Standard_EXPORT static Storage_Error Read(Storage_BaseDriver& theDriver,
Handle(StdStorage_Data)& theData);
//! Writes the data aggregated in theData object into the container defined by
//! theDriver. The storage format is compartible with legacy persistent one.
//! Note: - theData may aggregate several root objects to be stored together.
//! - createion date specified in the srorage header will be overwritten.
Standard_EXPORT static Storage_Error Write(Storage_BaseDriver& theDriver,
const Handle(StdStorage_Data)& theData);
};
#endif // _StdStorage_HeaderFile

View File

@@ -0,0 +1,213 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdStorage_BacketOfPersistent.hxx>
#include <StdObjMgt_Persistent.hxx>
StdStorage_Bucket::~StdStorage_Bucket()
{
Standard::Free(mySpace);
mySpace = 0L;
mySpaceSize = 0;
Clear();
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void StdStorage_Bucket::Clear()
{
myCurrentSpace = -1;
}
//=======================================================================
//function : Append
//purpose :
//=======================================================================
void StdStorage_Bucket::Append(StdObjMgt_Persistent *sp)
{
++myCurrentSpace;
mySpace[myCurrentSpace] = sp;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
StdObjMgt_Persistent* StdStorage_Bucket::Value(const Standard_Integer theIndex) const
{
return mySpace[theIndex];
}
//=======================================================================
//function : Storage_BucketOfPersistent
//purpose :
//=======================================================================
StdStorage_BucketOfPersistent::StdStorage_BucketOfPersistent
(const Standard_Integer theBucketSize, const Standard_Integer theBucketNumber)
: myNumberOfBucket(1), myNumberOfBucketAllocated(theBucketNumber)
, myBucketSize(theBucketSize)
{
myBuckets = (StdStorage_Bucket**)Standard::Allocate
(sizeof(StdStorage_Bucket*) * theBucketNumber);
myBuckets[0] = new StdStorage_Bucket(myBucketSize);
myCurrentBucket = myBuckets[0];
myLength = 0;
myCurrentBucketNumber = 0;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void StdStorage_BucketOfPersistent::Clear()
{
if (myBuckets) {
Standard_Integer i;
for (i = 1; i < myNumberOfBucket; i++) delete myBuckets[i];
myNumberOfBucket = 1;
myCurrentBucket = myBuckets[0];
myCurrentBucket->Clear();
myCurrentBucketNumber = 0;
myLength = 0;
}
}
StdStorage_BucketOfPersistent::~StdStorage_BucketOfPersistent()
{
Clear();
delete myBuckets[0];
Standard::Free(myBuckets);
myBuckets = 0L;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
StdObjMgt_Persistent* StdStorage_BucketOfPersistent::Value
(const Standard_Integer theIndex)
{
Standard_Integer theInd, theCurrentBucketNumber, tecurrentind = theIndex - 1;
theCurrentBucketNumber = tecurrentind / myBucketSize;
theInd = tecurrentind - (myBucketSize * theCurrentBucketNumber);
return myBuckets[theCurrentBucketNumber]->mySpace[theInd];
}
//=======================================================================
//function : Append
//purpose :
//=======================================================================
void StdStorage_BucketOfPersistent::Append(const Handle(StdObjMgt_Persistent)& sp)
{
myCurrentBucket->myCurrentSpace++;
if (myCurrentBucket->myCurrentSpace != myBucketSize) {
myLength++;
myCurrentBucket->mySpace[myCurrentBucket->myCurrentSpace] = sp.operator->();
return;
}
myCurrentBucket->myCurrentSpace--;
myNumberOfBucket++;
myCurrentBucketNumber++;
if (myNumberOfBucket > myNumberOfBucketAllocated) {
Standard_Size e = sizeof(StdStorage_Bucket*) * myNumberOfBucketAllocated;
myBuckets = (StdStorage_Bucket**)Standard::Reallocate(myBuckets, e * 2);
myNumberOfBucketAllocated *= 2;
}
myBuckets[myCurrentBucketNumber] = new StdStorage_Bucket(myBucketSize);
myCurrentBucket = myBuckets[myCurrentBucketNumber];
myCurrentBucket->myCurrentSpace++;
myLength++;
myCurrentBucket->mySpace[myCurrentBucket->myCurrentSpace] = sp.operator->();
}
//=======================================================================
//function : Storage_BucketIterator
//purpose :
//=======================================================================
StdStorage_BucketIterator::StdStorage_BucketIterator
(StdStorage_BucketOfPersistent* aBucketManager)
{
if (aBucketManager) {
myBucket = aBucketManager;
myCurrentBucket = myBucket->myBuckets[0];
myBucketNumber = aBucketManager->myNumberOfBucket;
myCurrentBucketIndex = 0;
myCurrentIndex = 0;
myMoreObject = Standard_True;
}
else myMoreObject = Standard_False;
}
//=======================================================================
//function : Reset
//purpose :
//=======================================================================
void StdStorage_BucketIterator::Reset()
{
if (myBucket) {
myCurrentBucket = myBucket->myBuckets[0];
myBucketNumber = myBucket->myNumberOfBucket;
myCurrentIndex = 0;
myCurrentBucketIndex = 0;
myMoreObject = Standard_True;
}
else myMoreObject = Standard_False;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void StdStorage_BucketIterator::Init(StdStorage_BucketOfPersistent* aBucketManager)
{
if (aBucketManager) {
myBucket = aBucketManager;
myCurrentBucket = myBucket->myBuckets[0];
myBucketNumber = aBucketManager->myNumberOfBucket;
myCurrentIndex = 0;
myCurrentBucketIndex = 0;
myMoreObject = Standard_True;
}
else myMoreObject = Standard_False;
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void StdStorage_BucketIterator::Next()
{
if (!myMoreObject) return;
if (myCurrentIndex < myCurrentBucket->myCurrentSpace) {
myCurrentIndex++;
}
else {
myCurrentIndex = 0;
myCurrentBucketIndex++;
if (myCurrentBucketIndex < myBucketNumber) {
myCurrentBucket = myBucket->myBuckets[myCurrentBucketIndex];
}
else {
myMoreObject = Standard_False;
}
}
}

View File

@@ -0,0 +1,114 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StdStorage_BucketOfPersistent_HeaderFile
#define _StdStorage_BucketOfPersistent_HeaderFile
#include <Standard.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Integer.hxx>
class StdStorage_BucketOfPersistent;
class StdStorage_BucketIterator;
class StdObjMgt_Persistent;
class StdStorage_Bucket
{
friend class StdStorage_BucketIterator;
friend class StdStorage_BucketOfPersistent;
StdObjMgt_Persistent** mySpace;
Standard_Integer mySpaceSize;
Standard_Integer myCurrentSpace;
void Append(StdObjMgt_Persistent *);
StdObjMgt_Persistent* Value(const Standard_Integer theIndex) const;
public:
StdStorage_Bucket() : mySpace(0L), mySpaceSize(200000), myCurrentSpace(-1)
{
mySpace = (StdObjMgt_Persistent**)Standard::Allocate(sizeof(StdObjMgt_Persistent*) * mySpaceSize);
}
StdStorage_Bucket(const Standard_Integer theSpaceSize) : mySpace(0L), mySpaceSize(theSpaceSize), myCurrentSpace(-1)
{
mySpace = (StdObjMgt_Persistent**)Standard::Allocate(sizeof(StdObjMgt_Persistent*) * mySpaceSize);
}
void Clear();
~StdStorage_Bucket();
};
class StdStorage_BucketOfPersistent
{
friend class StdStorage_BucketIterator;
StdStorage_Bucket** myBuckets;
Standard_Integer myNumberOfBucket;
Standard_Integer myNumberOfBucketAllocated;
StdStorage_Bucket* myCurrentBucket;
Standard_Integer myCurrentBucketNumber;
Standard_Integer myLength;
Standard_Integer myBucketSize;
public:
StdStorage_BucketOfPersistent(const Standard_Integer theBucketSize = 300000, const Standard_Integer theBucketNumber = 100);
Standard_Integer Length() const
{
return myLength;
}
void Append(const Handle(StdObjMgt_Persistent)& sp);
StdObjMgt_Persistent* Value(const Standard_Integer theIndex);
void Clear();
~StdStorage_BucketOfPersistent();
};
class StdStorage_BucketIterator
{
StdStorage_BucketOfPersistent *myBucket;
StdStorage_Bucket *myCurrentBucket;
Standard_Integer myCurrentBucketIndex;
Standard_Integer myCurrentIndex;
Standard_Integer myBucketNumber;
Standard_Boolean myMoreObject;
public:
StdStorage_BucketIterator(StdStorage_BucketOfPersistent*);
void Init(StdStorage_BucketOfPersistent*);
void Reset();
StdObjMgt_Persistent* Value() const
{
if (myCurrentBucket) {
return myCurrentBucket->mySpace[myCurrentIndex];
}
else return 0L;
}
Standard_Boolean More() const
{
return myMoreObject;
}
void Next();
};
#endif // _StdStorage_BucketOfPersistent_HeaderFile

View File

@@ -0,0 +1,31 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdStorage_Data.hxx>
#include <StdStorage_HeaderData.hxx>
#include <StdStorage_TypeData.hxx>
#include <StdStorage_RootData.hxx>
StdStorage_Data::StdStorage_Data()
: myHeaderData(new StdStorage_HeaderData)
, myTypeData(new StdStorage_TypeData)
, myRootData(new StdStorage_RootData)
{
}
void StdStorage_Data::Clear()
{
myTypeData->Clear();
myRootData->Clear();
}

View File

@@ -0,0 +1,90 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StdStorage_Data_HeaderFile
#define _StdStorage_Data_HeaderFile
#include <MMgt_TShared.hxx>
#include <Standard_Macro.hxx>
class StdStorage_HeaderData;
class StdStorage_TypeData;
class StdStorage_RootData;
//! A picture memorizing the stored in a
//! container (for example, in a file).
//! A StdStorage_Data object represents either:
//! - persistent data to be written into a container,
//! or
//! - persistent data which are read from a container.
//! A StdStorage_Data object is used in both the
//! storage and retrieval operations:
//! - Storage mechanism: create an empty
//! StdStorage_Data object, then add successively
//! persistent objects (roots) to be stored using
//! the StdStorage_RootData's function AddRoot. When the set of
//! data is complete, write it to a container using the
//! function Write in your StdStorage algorithm.
//! - Retrieval mechanism: a StdStorage_Data
//! object is returned by the Read function from
//! your StdStorage algorithm. Use the StdStorage_RootData's
//! functions NumberOfRoots and Roots to find the roots which
//! were stored in the read container.
//! The roots of a StdStorage_Data object may share
//! references on objects. The shared internal
//! references of a StdStorage_Data object are
//! maintained by the storage/retrieval mechanism.
//! Note: References shared by objects which are
//! contained in two distinct StdStorage_Data objects
//! are not maintained by the storage/retrieval
//! mechanism: external references are not
//! supported by Storage_Schema algorithm
class StdStorage_Data
: public MMgt_TShared
{
public:
//! Creates an empty set of data.
//! You explicitly create a StdStorage_Data object
//! when preparing the set of objects to be stored
//! together in a container (for example, in a file).
//! Then use the function StdStorage_RootData's AddRoot
//! to add persistent objects to the set of data.
//! A StdStorage_Data object is also returned by the
//! Read function of a StdStorage algorithm. Use the
//! StdStorage_RootData's functions NumberOfRoots and
//! Roots to find the roots which were stored in the
//! read container.
Standard_EXPORT StdStorage_Data();
//! Makes the container empty
Standard_EXPORT void Clear();
//! Returns the header data section
Handle(StdStorage_HeaderData) HeaderData() { return myHeaderData; }
//! Returns the type data section
Handle(StdStorage_TypeData) TypeData() { return myTypeData; }
//! Returns the root data section
Handle(StdStorage_RootData) RootData() { return myRootData; }
private:
Handle(StdStorage_HeaderData) myHeaderData;
Handle(StdStorage_TypeData) myTypeData;
Handle(StdStorage_RootData) myRootData;
};
#endif // _StdStorage_Data_HeaderFile

View File

@@ -0,0 +1,11 @@
#ifndef StdStorage_HSequenceOfRoots_HeaderFile
#define StdStorage_HSequenceOfRoots_HeaderFile
#include <StdStorage_Root.hxx>
#include <StdStorage_SequenceOfRoots.hxx>
#include <NCollection_DefineHSequence.hxx>
DEFINE_HSEQUENCE(StdStorage_HSequenceOfRoots, StdStorage_SequenceOfRoots)
#endif // StdStorage_HSequenceOfRoots_HeaderFile

View File

@@ -0,0 +1,324 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Standard_ErrorHandler.hxx>
#include <StdStorage_HeaderData.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <Storage_StreamExtCharParityError.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(StdStorage_HeaderData, MMgt_TShared)
StdStorage_HeaderData::StdStorage_HeaderData()
: myNBObj(0), myErrorStatus(Storage_VSOk)
{
}
Standard_Boolean StdStorage_HeaderData::Read(Storage_BaseDriver& theDriver)
{
// Check driver open mode
if (theDriver.OpenMode() != Storage_VSRead
&& theDriver.OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return Standard_False;
}
// Read info section
myErrorStatus = theDriver.BeginReadInfoSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginReadInfoSection";
return Standard_False;
}
try
{
OCC_CATCH_SIGNALS
theDriver.ReadInfo(myNBObj,
myStorageVersion,
myDate,
mySchemaName,
mySchemaVersion,
myApplicationName,
myApplicationVersion,
myDataType,
myUserInfo);
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "ReadInfo";
return Standard_False;
}
catch (Storage_StreamExtCharParityError)
{
myErrorStatus = Storage_VSExtCharParityError;
myErrorStatusExt = "ReadInfo";
return Standard_False;
}
myErrorStatus = theDriver.EndReadInfoSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndReadInfoSection";
return Standard_False;
}
// Read comment section
myErrorStatus = theDriver.BeginReadCommentSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginReadCommentSection";
return Standard_False;
}
try
{
OCC_CATCH_SIGNALS
theDriver.ReadComment(myComments);
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "ReadComment";
return Standard_False;
}
catch (Storage_StreamExtCharParityError)
{
myErrorStatus = Storage_VSExtCharParityError;
myErrorStatusExt = "ReadComment";
return Standard_False;
}
myErrorStatus = theDriver.EndReadCommentSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndReadCommentSection";
return Standard_False;
}
return Standard_True;
}
Standard_Boolean StdStorage_HeaderData::Write(Storage_BaseDriver& theDriver)
{
// Check driver open mode
if (theDriver.OpenMode() != Storage_VSWrite
&& theDriver.OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return Standard_False;
}
// Write info section
myErrorStatus = theDriver.BeginWriteInfoSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginWriteInfoSection";
return Standard_False;
}
try
{
OCC_CATCH_SIGNALS
theDriver.WriteInfo(myNBObj,
myStorageVersion,
myDate,
mySchemaName,
mySchemaVersion,
myApplicationName,
myApplicationVersion,
myDataType,
myUserInfo);
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "WriteInfo";
return Standard_False;
}
catch (Storage_StreamExtCharParityError)
{
myErrorStatus = Storage_VSExtCharParityError;
myErrorStatusExt = "WriteInfo";
return Standard_False;
}
myErrorStatus = theDriver.EndWriteInfoSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndWriteInfoSection";
return Standard_False;
}
// Write comment section
myErrorStatus = theDriver.BeginWriteCommentSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginWriteCommentSection";
return Standard_False;
}
try
{
OCC_CATCH_SIGNALS
theDriver.WriteComment(myComments);
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "WriteComment";
return Standard_False;
}
catch (Storage_StreamExtCharParityError)
{
myErrorStatus = Storage_VSExtCharParityError;
myErrorStatusExt = "WriteComment";
return Standard_False;
}
myErrorStatus = theDriver.EndWriteCommentSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndWriteCommentSection";
return Standard_False;
}
return Standard_True;
}
TCollection_AsciiString StdStorage_HeaderData::CreationDate() const
{
return myDate;
}
void StdStorage_HeaderData::SetSchemaVersion(const TCollection_AsciiString& aVersion)
{
mySchemaVersion = aVersion;
}
TCollection_AsciiString StdStorage_HeaderData::SchemaVersion() const
{
return mySchemaVersion;
}
void StdStorage_HeaderData::SetSchemaName(const TCollection_AsciiString& aSchemaName)
{
mySchemaName = aSchemaName;
}
void StdStorage_HeaderData::SetApplicationVersion(const TCollection_AsciiString& aVersion)
{
myApplicationVersion = aVersion;
}
TCollection_AsciiString StdStorage_HeaderData::ApplicationVersion() const
{
return myApplicationVersion;
}
void StdStorage_HeaderData::SetApplicationName(const TCollection_ExtendedString& aName)
{
myApplicationName = aName;
}
TCollection_ExtendedString StdStorage_HeaderData::ApplicationName() const
{
return myApplicationName;
}
void StdStorage_HeaderData::SetDataType(const TCollection_ExtendedString& aName)
{
myDataType = aName;
}
TCollection_ExtendedString StdStorage_HeaderData::DataType() const
{
return myDataType;
}
void StdStorage_HeaderData::AddToUserInfo(const TCollection_AsciiString& theUserInfo)
{
myUserInfo.Append(theUserInfo);
}
const TColStd_SequenceOfAsciiString& StdStorage_HeaderData::UserInfo() const
{
return myUserInfo;
}
void StdStorage_HeaderData::AddToComments(const TCollection_ExtendedString& aComments)
{
myComments.Append(aComments);
}
const TColStd_SequenceOfExtendedString& StdStorage_HeaderData::Comments() const
{
return myComments;
}
Standard_Integer StdStorage_HeaderData::NumberOfObjects() const
{
return myNBObj;
}
void StdStorage_HeaderData::SetNumberOfObjects(const Standard_Integer anObjectNumber)
{
myNBObj = anObjectNumber;
}
void StdStorage_HeaderData::SetStorageVersion(const TCollection_AsciiString& v)
{
myStorageVersion = v;
}
void StdStorage_HeaderData::SetCreationDate(const TCollection_AsciiString& d)
{
myDate = d;
}
TCollection_AsciiString StdStorage_HeaderData::StorageVersion() const
{
return myStorageVersion;
}
Storage_Error StdStorage_HeaderData::ErrorStatus() const
{
return myErrorStatus;
}
void StdStorage_HeaderData::SetErrorStatus(const Storage_Error anError)
{
myErrorStatus = anError;
}
TCollection_AsciiString StdStorage_HeaderData::ErrorStatusExtension() const
{
return myErrorStatusExt;
}
void StdStorage_HeaderData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
{
myErrorStatusExt = anErrorExt;
}
void StdStorage_HeaderData::ClearErrorStatus()
{
myErrorStatus = Storage_VSOk;
myErrorStatusExt.Clear();
}

View File

@@ -0,0 +1,142 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StdStorage_HeaderData_HeaderFile
#define _StdStorage_HeaderData_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Standard_Integer.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
#include <Storage_Error.hxx>
#include <MMgt_TShared.hxx>
class Storage_BaseDriver;
class TCollection_AsciiString;
class TCollection_ExtendedString;
class StdStorage_HeaderData;
DEFINE_STANDARD_HANDLE(StdStorage_HeaderData, MMgt_TShared)
//! Storage header data section that contains some
//! auxiliary information (application name, schema version,
//! creation date, comments and so on...)
class StdStorage_HeaderData
: public MMgt_TShared
{
friend class StdStorage_Data;
public:
DEFINE_STANDARD_RTTIEXT(StdStorage_HeaderData, MMgt_TShared)
//! Reads the header data section from the container defined by theDriver.
//! Returns Standard_True in case of success. Otherwise, one need to get
//! an error code and description using ErrorStatus and ErrorStatusExtension
//! functions correspondingly.
Standard_EXPORT Standard_Boolean Read(Storage_BaseDriver& theDriver);
//! Writes the header data section to the container defined by theDriver.
//! Returns Standard_True in case of success. Otherwise, one need to get
//! an error code and description using ErrorStatus and ErrorStatusExtension
//! functions correspondingly.
Standard_EXPORT Standard_Boolean Write(Storage_BaseDriver& theDriver);
//! Return the creation date
Standard_EXPORT TCollection_AsciiString CreationDate() const;
//! Return the Storage package version
Standard_EXPORT TCollection_AsciiString StorageVersion() const;
//! Get the version of the schema
Standard_EXPORT TCollection_AsciiString SchemaVersion() const;
//! Set the version of the application
Standard_EXPORT void SetApplicationVersion(const TCollection_AsciiString& aVersion);
//! Get the version of the application
Standard_EXPORT TCollection_AsciiString ApplicationVersion() const;
//! Set the name of the application
Standard_EXPORT void SetApplicationName(const TCollection_ExtendedString& aName);
//! Get the name of the application
Standard_EXPORT TCollection_ExtendedString ApplicationName() const;
//! Set the data type
Standard_EXPORT void SetDataType(const TCollection_ExtendedString& aType);
//! Returns data type
Standard_EXPORT TCollection_ExtendedString DataType() const;
//! Add <theUserInfo> to the user informations
Standard_EXPORT void AddToUserInfo(const TCollection_AsciiString& theUserInfo);
//! Return the user informations
Standard_EXPORT const TColStd_SequenceOfAsciiString& UserInfo() const;
//! Add <theUserInfo> to the user informations
Standard_EXPORT void AddToComments(const TCollection_ExtendedString& aComment);
//! Return the user informations
Standard_EXPORT const TColStd_SequenceOfExtendedString& Comments() const;
//! Returns the number of persistent objects
Standard_EXPORT Standard_Integer NumberOfObjects() const;
//! Returns a status of the latest call to Read / Write functions
Standard_EXPORT Storage_Error ErrorStatus() const;
//! Returns an error message if any of the latest call to Read / Write functions
Standard_EXPORT TCollection_AsciiString ErrorStatusExtension() const;
//! Clears error status
Standard_EXPORT void ClearErrorStatus();
Standard_EXPORT void SetNumberOfObjects(const Standard_Integer anObjectNumber);
Standard_EXPORT void SetStorageVersion(const TCollection_AsciiString& aVersion);
Standard_EXPORT void SetCreationDate(const TCollection_AsciiString& aDate);
Standard_EXPORT void SetSchemaVersion(const TCollection_AsciiString& aVersion);
Standard_EXPORT void SetSchemaName(const TCollection_AsciiString& aName);
private:
Standard_EXPORT StdStorage_HeaderData();
Standard_EXPORT void SetErrorStatus(const Storage_Error anError);
Standard_EXPORT void SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt);
Standard_Integer myNBObj;
TCollection_AsciiString myStorageVersion;
TCollection_AsciiString mySchemaVersion;
TCollection_AsciiString mySchemaName;
TCollection_AsciiString myApplicationVersion;
TCollection_ExtendedString myApplicationName;
TCollection_ExtendedString myDataType;
TCollection_AsciiString myDate;
TColStd_SequenceOfAsciiString myUserInfo;
TColStd_SequenceOfExtendedString myComments;
Storage_Error myErrorStatus;
TCollection_AsciiString myErrorStatusExt;
};
#endif // _StdStorage_HeaderData_HeaderFile

View File

@@ -0,0 +1,13 @@
#ifndef StdStorage_MapOfRoots_HeaderFile
#define StdStorage_MapOfRoots_HeaderFile
#include <TCollection_AsciiString.hxx>
#include <StdStorage_Root.hxx>
#include <TCollection_AsciiString.hxx>
#include <NCollection_DataMap.hxx>
typedef NCollection_DataMap<TCollection_AsciiString, Handle(StdStorage_Root), TCollection_AsciiString> StdStorage_MapOfRoots;
typedef NCollection_DataMap<TCollection_AsciiString, Handle(StdStorage_Root), TCollection_AsciiString>::Iterator StdStorage_DataMapIteratorOfMapOfRoots;
#endif // StdStorage_MapOfRoots_HeaderFile

View File

@@ -0,0 +1,28 @@
// Created on: 1996-04-30
// Created by: cle
// Copyright (c) 1996-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef Storage_PType_HeaderFile
#define Storage_PType_HeaderFile
#include <TCollection_AsciiString.hxx>
#include <Standard_Integer.hxx>
#include <TCollection_AsciiString.hxx>
#include <NCollection_IndexedDataMap.hxx>
typedef NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer, TCollection_AsciiString> StdStorage_MapOfTypes;
#endif

View File

@@ -0,0 +1,82 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdObjMgt_Persistent.hxx>
#include <Standard_Type.hxx>
#include <StdStorage_Root.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(StdStorage_Root, MMgt_TShared)
StdStorage_Root::StdStorage_Root()
: myRef(0)
{
}
StdStorage_Root::StdStorage_Root(const TCollection_AsciiString& theName,
const Handle(StdObjMgt_Persistent)& theObject)
: myName(theName)
, myType(theObject->PName())
, myObject(theObject)
, myRef(0)
{
}
StdStorage_Root::StdStorage_Root(const TCollection_AsciiString& theName,
const Standard_Integer theRef,
const TCollection_AsciiString& theType)
: myName(theName)
, myType(theType)
, myRef(theRef)
{
}
void StdStorage_Root::SetName(const TCollection_AsciiString& theName)
{
myName = theName;
}
TCollection_AsciiString StdStorage_Root::Name() const
{
return myName;
}
void StdStorage_Root::SetObject(const Handle(StdObjMgt_Persistent)& anObject)
{
myObject = anObject;
}
Handle(StdObjMgt_Persistent) StdStorage_Root::Object() const
{
return myObject;
}
TCollection_AsciiString StdStorage_Root::Type() const
{
return myType;
}
void StdStorage_Root::SetReference(const Standard_Integer aRef)
{
myRef = aRef;
}
Standard_Integer StdStorage_Root::Reference() const
{
return myRef;
}
void StdStorage_Root::SetType(const TCollection_AsciiString& aType)
{
myType = aType;
}

View File

@@ -0,0 +1,83 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StdStorage_Root_HeaderFile
#define _StdStorage_Root_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
#include <Standard_Integer.hxx>
#include <MMgt_TShared.hxx>
class StdObjMgt_Persistent;
class Storage_Schema;
class TCollection_AsciiString;
class Storage_Root;
DEFINE_STANDARD_HANDLE(StdStorage_Root, MMgt_TShared)
//! Describes a named persistent root
class StdStorage_Root
: public MMgt_TShared
{
friend class StdStorage_RootData;
public:
DEFINE_STANDARD_RTTIEXT(StdStorage_Root, MMgt_TShared)
//! Creates an empty root
Standard_EXPORT StdStorage_Root();
//! Creates a root for writing
Standard_EXPORT StdStorage_Root(const TCollection_AsciiString& theName,
const Handle(StdObjMgt_Persistent)& theObject);
//! Returns a name of the root
Standard_EXPORT TCollection_AsciiString Name() const;
//! Sets a name to the root object
Standard_EXPORT void SetName(const TCollection_AsciiString& theName);
//! Returns a root's persistent object
Standard_EXPORT Handle(StdObjMgt_Persistent) Object() const;
//! Sets a root's persistent object
Standard_EXPORT void SetObject(const Handle(StdObjMgt_Persistent)& anObject);
//! Returns a root's persistent type
Standard_EXPORT TCollection_AsciiString Type() const;
//! Sets a root's persistent type
Standard_EXPORT void SetType(const TCollection_AsciiString& aType);
//! Returns root's position in the root data section
Standard_EXPORT Standard_Integer Reference() const;
private:
Standard_EXPORT StdStorage_Root(const TCollection_AsciiString& theName,
const Standard_Integer theRef,
const TCollection_AsciiString& theType);
Standard_EXPORT void SetReference(const Standard_Integer aRef);
TCollection_AsciiString myName;
TCollection_AsciiString myType;
Handle(StdObjMgt_Persistent) myObject;
Standard_Integer myRef;
};
#endif // _StdStorage_Root_HeaderFile

View File

@@ -0,0 +1,210 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdObjMgt_Persistent.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_NoSuchObject.hxx>
#include <StdStorage_RootData.hxx>
#include <StdStorage_Root.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <Storage_DataMapIteratorOfMapOfPers.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(StdStorage_RootData, MMgt_TShared)
StdStorage_RootData::StdStorage_RootData()
: myErrorStatus(Storage_VSOk)
{
}
Standard_Boolean StdStorage_RootData::Read(Storage_BaseDriver& theDriver)
{
// Check driver open mode
if (theDriver.OpenMode() != Storage_VSRead
&& theDriver.OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return Standard_False;
}
// Read root section
myErrorStatus = theDriver.BeginReadRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginReadRootSection";
return Standard_False;
}
TCollection_AsciiString aRootName, aTypeName;
Standard_Integer aRef;
Standard_Integer len = theDriver.RootSectionSize();
for (Standard_Integer i = 1; i <= len; i++)
{
try
{
OCC_CATCH_SIGNALS
theDriver.ReadRoot(aRootName, aRef, aTypeName);
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "ReadRoot";
return Standard_False;
}
Handle(StdStorage_Root) aRoot = new StdStorage_Root(aRootName, aRef, aTypeName);
myObjects.Bind(aRootName, aRoot);
}
myErrorStatus = theDriver.EndReadRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndReadRootSection";
return Standard_False;
}
return Standard_True;
}
Standard_Boolean StdStorage_RootData::Write(Storage_BaseDriver& theDriver)
{
// Check driver open mode
if (theDriver.OpenMode() != Storage_VSWrite
&& theDriver.OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return Standard_False;
}
// Write root section
myErrorStatus = theDriver.BeginWriteRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginWriteRootSection";
return Standard_False;
}
theDriver.SetRootSectionSize(NumberOfRoots());
for (StdStorage_MapOfRoots::Iterator anIt(myObjects); anIt.More(); anIt.Next())
{
const Handle(StdStorage_Root)& aRoot = anIt.Value();
try
{
OCC_CATCH_SIGNALS
theDriver.WriteRoot(aRoot->Name(), aRoot->Reference(), aRoot->Type());
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "ReadRoot";
return Standard_False;
}
}
myErrorStatus = theDriver.EndWriteRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndWriteRootSection";
return Standard_False;
}
return Standard_True;
}
Standard_Integer StdStorage_RootData::NumberOfRoots() const
{
return myObjects.Extent();
}
void StdStorage_RootData::AddRoot(const Handle(StdStorage_Root)& aRoot)
{
myObjects.Bind(aRoot->Name(), aRoot);
aRoot->myRef = myObjects.Size();
}
Handle(StdStorage_HSequenceOfRoots) StdStorage_RootData::Roots() const
{
Handle(StdStorage_HSequenceOfRoots) anObjectsSeq = new StdStorage_HSequenceOfRoots;
StdStorage_DataMapIteratorOfMapOfRoots it(myObjects);
for (; it.More(); it.Next()) {
anObjectsSeq->Append(it.Value());
}
return anObjectsSeq;
}
Handle(StdStorage_Root) StdStorage_RootData::Find(const TCollection_AsciiString& aName) const
{
Handle(StdStorage_Root) p;
if (myObjects.IsBound(aName)) {
p = myObjects.Find(aName);
}
return p;
}
Standard_Boolean StdStorage_RootData::IsRoot(const TCollection_AsciiString& aName) const
{
return myObjects.IsBound(aName);
}
void StdStorage_RootData::RemoveRoot(const TCollection_AsciiString& aName)
{
if (myObjects.IsBound(aName)) {
myObjects.ChangeFind(aName)->myRef = 0;
myObjects.UnBind(aName);
Standard_Integer aRef = 1;
for (StdStorage_MapOfRoots::Iterator anIt(myObjects); anIt.More(); anIt.Next(), ++aRef)
anIt.ChangeValue()->myRef = aRef;
}
}
void StdStorage_RootData::Clear()
{
for (StdStorage_MapOfRoots::Iterator anIt(myObjects); anIt.More(); anIt.Next())
anIt.ChangeValue()->myRef = 0;
myObjects.Clear();
}
Storage_Error StdStorage_RootData::ErrorStatus() const
{
return myErrorStatus;
}
void StdStorage_RootData::SetErrorStatus(const Storage_Error anError)
{
myErrorStatus = anError;
}
void StdStorage_RootData::ClearErrorStatus()
{
myErrorStatus = Storage_VSOk;
myErrorStatusExt.Clear();
}
TCollection_AsciiString StdStorage_RootData::ErrorStatusExtension() const
{
return myErrorStatusExt;
}
void StdStorage_RootData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
{
myErrorStatusExt = anErrorExt;
}

View File

@@ -0,0 +1,104 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StdStorage_RootData_HeaderFile
#define _StdStorage_RootData_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Storage_Error.hxx>
#include <TCollection_AsciiString.hxx>
#include <MMgt_TShared.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Integer.hxx>
#include <StdStorage_MapOfRoots.hxx>
#include <StdStorage_HSequenceOfRoots.hxx>
class Standard_NoSuchObject;
class Storage_Schema;
class Storage_BaseDriver;
class StdStorage_Root;
class TCollection_AsciiString;
class StdObjMgt_Persistent;
class StdStorage_RootData;
DEFINE_STANDARD_HANDLE(StdStorage_RootData, MMgt_TShared)
//! Storage root data section contains root persistent objects
class StdStorage_RootData
: public MMgt_TShared
{
friend class StdStorage_Data;
public:
DEFINE_STANDARD_RTTIEXT(StdStorage_RootData, MMgt_TShared)
//! Reads the root data section from the container defined by theDriver.
//! Returns Standard_True in case of success. Otherwise, one need to get
//! an error code and description using ErrorStatus and ErrorStatusExtension
//! functions correspondingly.
Standard_EXPORT Standard_Boolean Read(Storage_BaseDriver& theDriver);
//! Writes the root data section to the container defined by theDriver.
//! Returns Standard_True in case of success. Otherwise, one need to get
//! an error code and description using ErrorStatus and ErrorStatusExtension
//! functions correspondingly.
Standard_EXPORT Standard_Boolean Write(Storage_BaseDriver& theDriver);
//! Returns the number of roots.
Standard_EXPORT Standard_Integer NumberOfRoots() const;
//! Add a root to <me>. If a root with same name is present, it
//! will be replaced by <aRoot>.
Standard_EXPORT void AddRoot(const Handle(StdStorage_Root)& aRoot);
//! Returns a sequence of all roots
Standard_EXPORT Handle(StdStorage_HSequenceOfRoots) Roots() const;
//! Finds a root with name <aName>.
Standard_EXPORT Handle(StdStorage_Root) Find(const TCollection_AsciiString& aName) const;
//! Returns Standard_True if <me> contains a root named <aName>
Standard_EXPORT Standard_Boolean IsRoot(const TCollection_AsciiString& aName) const;
//! Removes the root named <aName>.
Standard_EXPORT void RemoveRoot(const TCollection_AsciiString& aName);
//! Returns a status of the latest call to Read / Write functions
Standard_EXPORT Storage_Error ErrorStatus() const;
//! Returns an error message if any of the latest call to Read / Write functions
Standard_EXPORT TCollection_AsciiString ErrorStatusExtension() const;
//! Clears error status
Standard_EXPORT void ClearErrorStatus();
//! Removes all persistent root objects
Standard_EXPORT void Clear();
private:
Standard_EXPORT StdStorage_RootData();
Standard_EXPORT void SetErrorStatus(const Storage_Error anError);
Standard_EXPORT void SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt);
StdStorage_MapOfRoots myObjects;
Storage_Error myErrorStatus;
TCollection_AsciiString myErrorStatusExt;
};
#endif // _StdStorage_RootData_HeaderFile

View File

@@ -0,0 +1,10 @@
#ifndef StdStorage_SequenceOfRoots_HeaderFile
#define StdStorage_SequenceOfRoots_HeaderFile
#include <StdStorage_Root.hxx>
#include <NCollection_Sequence.hxx>
typedef NCollection_Sequence<Handle(StdStorage_Root)> StdStorage_SequenceOfRoots;
#endif // StdStorage_SequenceOfRoots_HeaderFile

View File

@@ -0,0 +1,242 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Standard_ErrorHandler.hxx>
#include <Standard_NoSuchObject.hxx>
#include <StdDrivers.hxx>
#include <StdStorage_TypeData.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(StdStorage_TypeData, MMgt_TShared)
StdStorage_TypeData::StdStorage_TypeData()
: myTypeId(0),
myErrorStatus(Storage_VSOk)
{
StdDrivers::BindTypes(myMapOfPInst);
}
Standard_Boolean StdStorage_TypeData::Read(Storage_BaseDriver& theDriver)
{
// Check driver open mode
if (theDriver.OpenMode() != Storage_VSRead
&& theDriver.OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return Standard_False;
}
// Read type section
myErrorStatus = theDriver.BeginReadTypeSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginReadTypeSection";
return Standard_False;
}
Standard_Integer aTypeNum;
TCollection_AsciiString aTypeName;
Standard_Integer len = theDriver.TypeSectionSize();
for (Standard_Integer i = 1; i <= len; i++)
{
try
{
OCC_CATCH_SIGNALS
theDriver.ReadTypeInformations (aTypeNum, aTypeName);
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "ReadTypeInformations";
return Standard_False;
}
myPt.Add (aTypeName, aTypeNum);
}
myErrorStatus = theDriver.EndReadTypeSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndReadTypeSection";
return Standard_False;
}
return Standard_True;
}
Standard_Boolean StdStorage_TypeData::Write(Storage_BaseDriver& theDriver)
{
// Check driver open mode
if (theDriver.OpenMode() != Storage_VSWrite
&& theDriver.OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return Standard_False;
}
// Write type section
myErrorStatus = theDriver.BeginWriteTypeSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginWriteTypeSection";
return Standard_False;
}
Standard_Integer len = NumberOfTypes();
theDriver.SetTypeSectionSize(len);
for (Standard_Integer i = 1; i <= len; i++)
{
try
{
OCC_CATCH_SIGNALS
theDriver.WriteTypeInformations(i, Type(i));
}
catch (Storage_StreamTypeMismatchError)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "WriteTypeInformations";
return Standard_False;
}
}
myErrorStatus = theDriver.EndWriteTypeSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndWriteTypeSection";
return Standard_False;
}
return Standard_True;
}
Standard_Integer StdStorage_TypeData::NumberOfTypes() const
{
return myPt.Extent();
}
Standard_Boolean StdStorage_TypeData::IsType(const TCollection_AsciiString& aName) const
{
return myPt.Contains(aName);
}
Handle(TColStd_HSequenceOfAsciiString) StdStorage_TypeData::Types() const
{
Handle(TColStd_HSequenceOfAsciiString) r = new TColStd_HSequenceOfAsciiString;
Standard_Integer i;
for (i = 1; i <= myPt.Extent(); i++) {
r->Append(myPt.FindKey(i));
}
return r;
}
void StdStorage_TypeData::AddType(const TCollection_AsciiString& aTypeName, const Standard_Integer aTypeNum)
{
myPt.Add(aTypeName, aTypeNum);
myTypeId = Max(aTypeNum, myTypeId);
}
Standard_Integer StdStorage_TypeData::AddType(const Handle(StdObjMgt_Persistent)& aPObj)
{
TCollection_AsciiString aTypeName = aPObj->PName();
if (IsType(aTypeName))
return Type(aTypeName);
if (!myMapOfPInst.IsBound(aTypeName)) {
Standard_SStream aSS;
aSS << "StdStorage_TypeData::Type " << aTypeName << " isn't registered";
throw Standard_NoSuchObject(aSS.str().c_str());
}
Standard_Integer aTypeId = ++myTypeId;
AddType(aTypeName, aTypeId);
return aTypeId;
}
TCollection_AsciiString StdStorage_TypeData::Type(const Standard_Integer aTypeNum) const
{
TCollection_AsciiString r;
if (aTypeNum <= myPt.Extent() && aTypeNum > 0)
r = myPt.FindKey(aTypeNum);
else {
Standard_SStream aSS;
aSS << "StdStorage_TypeData::Type " << aTypeNum << " not in range";
throw Standard_NoSuchObject(aSS.str().c_str());
}
return r;
}
Standard_Integer StdStorage_TypeData::Type(const TCollection_AsciiString& aTypeName) const
{
Standard_Integer r = 0;
if (myPt.Contains(aTypeName))
r = myPt.FindFromKey(aTypeName);
else {
Standard_SStream aSS;
aSS << "StdStorage_TypeData::Type " << aTypeName << " not found";
throw Standard_NoSuchObject(aSS.str().c_str());
}
return r;
}
StdObjMgt_Persistent::Instantiator
StdStorage_TypeData::Instantiator(const Standard_Integer aTypeNum) const
{
TCollection_AsciiString aTypeName = Type(aTypeNum);
StdObjMgt_Persistent::Instantiator anInstantiator = 0;
if (!myMapOfPInst.Find(aTypeName, anInstantiator))
return 0;
return anInstantiator;
}
void StdStorage_TypeData::Clear()
{
myPt.Clear();
}
Storage_Error StdStorage_TypeData::ErrorStatus() const
{
return myErrorStatus;
}
void StdStorage_TypeData::SetErrorStatus(const Storage_Error anError)
{
myErrorStatus = anError;
}
void StdStorage_TypeData::ClearErrorStatus()
{
myErrorStatus = Storage_VSOk;
myErrorStatusExt.Clear();
}
TCollection_AsciiString StdStorage_TypeData::ErrorStatusExtension() const
{
return myErrorStatusExt;
}
void StdStorage_TypeData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
{
myErrorStatusExt = anErrorExt;
}

View File

@@ -0,0 +1,110 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StdStorage_TypeData_HeaderFile
#define _StdStorage_TypeData_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <StdStorage_MapOfTypes.hxx>
#include <Storage_Error.hxx>
#include <TCollection_AsciiString.hxx>
#include <MMgt_TShared.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Boolean.hxx>
#include <StdObjMgt_MapOfInstantiators.hxx>
#include <TColStd_HSequenceOfAsciiString.hxx>
class Standard_NoSuchObject;
class Storage_BaseDriver;
class TCollection_AsciiString;
class StdStorage_TypeData;
DEFINE_STANDARD_HANDLE(StdStorage_TypeData, MMgt_TShared)
//! Storage type data section keeps association between
//! persistent textual types and their numbers
class StdStorage_TypeData
: public MMgt_TShared
{
friend class StdStorage_Data;
public:
DEFINE_STANDARD_RTTIEXT(StdStorage_TypeData, MMgt_TShared)
//! Reads the type data section from the container defined by theDriver.
//! Returns Standard_True in case of success. Otherwise, one need to get
//! an error code and description using ErrorStatus and ErrorStatusExtension
//! functions correspondingly.
Standard_EXPORT Standard_Boolean Read(Storage_BaseDriver& theDriver);
//! Writes the type data section to the container defined by theDriver.
//! Returns Standard_True in case of success. Otherwise, one need to get
//! an error code and description using ErrorStatus and ErrorStatusExtension
//! functions correspondingly.
Standard_EXPORT Standard_Boolean Write(Storage_BaseDriver& theDriver);
//! Returns the number of registered types
Standard_EXPORT Standard_Integer NumberOfTypes() const;
//! Add a type to the list in case of reading data
Standard_EXPORT void AddType (const TCollection_AsciiString& aTypeName, const Standard_Integer aTypeNum);
//! Add a type of the persistent object in case of writing data
Standard_EXPORT Standard_Integer AddType (const Handle(StdObjMgt_Persistent)& aPObj);
//! Returns the name of the type with number <aTypeNum>
Standard_EXPORT TCollection_AsciiString Type (const Standard_Integer aTypeNum) const;
//! Returns the name of the type with number <aTypeNum>
Standard_EXPORT Standard_Integer Type (const TCollection_AsciiString& aTypeName) const;
//! Returns a persistent object instantiator of <aTypeName>
Standard_EXPORT StdObjMgt_Persistent::Instantiator Instantiator(const Standard_Integer aTypeNum) const;
//! Checks if <aName> is a registered type
Standard_EXPORT Standard_Boolean IsType (const TCollection_AsciiString& aName) const;
//! Returns a sequence of all registered types
Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) Types() const;
//! Returns a status of the latest call to Read / Write functions
Standard_EXPORT Storage_Error ErrorStatus() const;
//! Returns an error message if any of the latest call to Read / Write functions
Standard_EXPORT TCollection_AsciiString ErrorStatusExtension() const;
//! Clears error status
Standard_EXPORT void ClearErrorStatus();
//! Unregisters all types
Standard_EXPORT void Clear();
private:
Standard_EXPORT StdStorage_TypeData();
Standard_EXPORT void SetErrorStatus (const Storage_Error anError);
Standard_EXPORT void SetErrorStatusExtension (const TCollection_AsciiString& anErrorExt);
Standard_Integer myTypeId;
StdObjMgt_MapOfInstantiators myMapOfPInst;
StdStorage_MapOfTypes myPt;
Storage_Error myErrorStatus;
TCollection_AsciiString myErrorStatusExt;
};
#endif // _StdStorage_TypeData_HeaderFile