1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0026961: Recover possibility to read files in old persistence format -- preparation

Added basic support for possibility to read filed in old persistent format.
Toolkits TKStd, TKStdL, TKShape added to provide necessary tools (to be done).
Obsolete interfaces are removed from classes in PCDM and Storage.
This commit is contained in:
myn
2015-12-09 20:27:36 +03:00
committed by abv
parent ede9746c21
commit 7ed7467da3
79 changed files with 2010 additions and 1287 deletions

View File

@@ -13,9 +13,11 @@
// commercial license or contractual agreement.
#include <Standard_Type.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Storage_HeaderData.hxx>
#include <Storage_Schema.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <Storage_StreamExtCharParityError.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
@@ -25,6 +27,98 @@ Storage_HeaderData::Storage_HeaderData() : myNBObj(0), myErrorStatus(Storage_VSO
{
}
Standard_Boolean Storage_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;
}
TCollection_AsciiString Storage_HeaderData::CreationDate() const
{
return myDate;

View File

@@ -28,6 +28,7 @@
#include <Storage_Error.hxx>
#include <MMgt_TShared.hxx>
class Storage_Schema;
class Storage_BaseDriver;
class TCollection_AsciiString;
class TCollection_ExtendedString;
@@ -43,6 +44,8 @@ public:
Standard_EXPORT Storage_HeaderData();
Standard_EXPORT Standard_Boolean Read (Storage_BaseDriver& theDriver);
//! return the creation date
Standard_EXPORT TCollection_AsciiString CreationDate() const;

View File

@@ -21,23 +21,27 @@
IMPLEMENT_STANDARD_RTTIEXT(Storage_Root,MMgt_TShared)
Storage_Root::Storage_Root() : myRef(0)
{
}
Storage_Root::Storage_Root()
: myRef (0) {}
Storage_Root::Storage_Root(const TCollection_AsciiString& aName,const Handle(Standard_Persistent)& anObject) : myRef(0)
{
myName = aName;
myObject = anObject;
if (!anObject.IsNull()) {
myType = anObject->DynamicType()->Name();
}
}
Storage_Root::Storage_Root (const TCollection_AsciiString& theName,
const Handle(Standard_Persistent)& theObject)
: myName (theName)
, myObject (theObject)
, myRef (0)
{}
void Storage_Root::SetName(const TCollection_AsciiString& aName)
Storage_Root::Storage_Root (const TCollection_AsciiString& theName,
const Standard_Integer theRef,
const TCollection_AsciiString& theType)
: myName (theName)
, myType (theType)
, myRef (theRef)
{}
void Storage_Root::SetName (const TCollection_AsciiString& theName)
{
myName = aName;
myName = theName;
}
TCollection_AsciiString Storage_Root::Name() const
@@ -48,10 +52,6 @@ TCollection_AsciiString Storage_Root::Name() const
void Storage_Root::SetObject(const Handle(Standard_Persistent)& anObject)
{
myObject = anObject;
if (!anObject.IsNull()) {
myType = anObject->DynamicType()->Name();
}
}
Handle(Standard_Persistent) Storage_Root::Object() const

View File

@@ -53,9 +53,14 @@ public:
Standard_EXPORT Storage_Root();
Standard_EXPORT Storage_Root(const TCollection_AsciiString& aName, const Handle(Standard_Persistent)& anObject);
Standard_EXPORT Storage_Root (const TCollection_AsciiString& theName,
const Handle(Standard_Persistent)& theObject);
Standard_EXPORT Storage_Root (const TCollection_AsciiString& theName,
const Standard_Integer theRef,
const TCollection_AsciiString& theType);
Standard_EXPORT void SetName (const TCollection_AsciiString& aName);
Standard_EXPORT void SetName (const TCollection_AsciiString& theName);
//! Returns the name of this root object.

View File

@@ -13,13 +13,14 @@
// commercial license or contractual agreement.
#include <Standard_NoSuchObject.hxx>
#include <Standard_Persistent.hxx>
#include <Standard_Type.hxx>
#include <Storage_DataMapIteratorOfMapOfPers.hxx>
#include <Storage_Root.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Storage_RootData.hxx>
#include <Storage_Schema.hxx>
#include <Storage_Root.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <Storage_DataMapIteratorOfMapOfPers.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Storage_RootData,MMgt_TShared)
@@ -28,6 +29,57 @@ Storage_RootData::Storage_RootData() : myErrorStatus(Storage_VSOk)
{
}
Standard_Boolean Storage_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(Storage_Root) aRoot = new Storage_Root (aRootName, aRef, aTypeName);
myObjects.Bind (aRootName, aRoot);
}
myErrorStatus = theDriver.EndReadRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndReadRootSection";
return Standard_False;
}
return Standard_True;
}
Standard_Integer Storage_RootData::NumberOfRoots() const
{
return myObjects.Extent();

View File

@@ -29,6 +29,7 @@
#include <Standard_Boolean.hxx>
class Standard_NoSuchObject;
class Storage_Schema;
class Storage_BaseDriver;
class Storage_Root;
class TCollection_AsciiString;
class Standard_Persistent;
@@ -45,6 +46,8 @@ public:
Standard_EXPORT Storage_RootData();
Standard_EXPORT Standard_Boolean Read (Storage_BaseDriver& theDriver);
//! returns the number of roots.
Standard_EXPORT Standard_Integer NumberOfRoots() const;

View File

@@ -287,7 +287,6 @@ Storage_Schema::Storage_Schema()
Clear();
ResetDefaultCallBack();
myCallBackState = Standard_False;
myNestedState = Standard_False;
}
//=======================================================================
@@ -365,11 +364,11 @@ void Storage_Schema::Write
}
for (posto = 1; posto <= plist->Length(); posto++) {
AddTypeSelection(plist->Value(posto)->Object());
// AddTypeSelection(plist->Value(posto)->Object());
}
for (posfrom = plist->Length() + 1; posfrom <= iData->myPtoA.Length(); posfrom++) {
AddTypeSelection(iData->myPtoA.Value(posfrom));
// AddTypeSelection(iData->myPtoA.Value(posfrom));
}
// ...and now we write
@@ -442,7 +441,7 @@ void Storage_Schema::Write
errorContext = "WriteRoot";
for (i = 1; i <= plist->Length(); i++) {
f.WriteRoot(plist->Value(i)->Name(),i,plist->Value(i)->Type());
f.WriteRoot(plist->Value(i)->Name(),i,"PDocStd_Document");
}
errorContext = "EndWriteRootSection";
@@ -499,378 +498,6 @@ void Storage_Schema::Write
Clear();
}
//=======================================================================
//function : Read
//purpose : ...and read a Storage file
//Arguments:
// s: driver to read
//=======================================================================
Handle(Storage_Data) Storage_Schema::Read(Storage_BaseDriver& f) const
{
Handle(Storage_Data) dData = new Storage_Data;
Storage_Error errorCode;
static Standard_Boolean result;
static Standard_Integer len;
static Standard_Integer i;
i = 0 ;
Handle(Standard_Persistent) per;
Handle(Storage_HArrayOfCallBack) theCallBack;
Handle(Storage_InternalData) iData = dData->InternalData();
Handle(Storage_TypeData) tData = dData->TypeData();
Handle(Storage_RootData) rData = dData->RootData();
Handle(Storage_HeaderData) hData = dData->HeaderData();
if ((f.OpenMode() == Storage_VSRead) || (f.OpenMode() == Storage_VSReadWrite)) {
Storage_Schema::ISetCurrentData(dData);
// IReadHeaderSection can set an error status
//
result = IReadHeaderSection(f,hData);
if (result) {
Handle(Storage_CallBack) accallBack;
Standard_Integer p;
TCollection_AsciiString typeName;
iData->myReadArray = new Storage_HPArray(1,dData->NumberOfObjects());
// IReadTypeSection can set an error status
//
result = IReadTypeSection(f,tData);
if (result) {
len = dData->NumberOfTypes();
theCallBack = new Storage_HArrayOfCallBack(1,len);
{
try {
OCC_CATCH_SIGNALS
for (i = 1; i <= len; i++) {
typeName = tData->Type(i);
p = tData->Type(typeName);
theCallBack->SetValue(p,CallBackSelection(typeName));
}
}
catch(Storage_StreamUnknownTypeError) {
result = Standard_False;
dData->SetErrorStatus(Storage_VSUnknownType);
dData->SetErrorStatusExtension(typeName);
}
}
}
else {
dData->SetErrorStatus(tData->ErrorStatus());
dData->SetErrorStatusExtension(tData->ErrorStatusExtension());
}
}
else {
dData->SetErrorStatus(hData->ErrorStatus());
dData->SetErrorStatusExtension(hData->ErrorStatusExtension());
}
if (result) {
result = IReadRootSection(f,rData);
dData->SetErrorStatus(rData->ErrorStatus());
if (!result) dData->SetErrorStatusExtension(rData->ErrorStatusExtension());
}
if (result) {
Standard_Integer otype, oref = 0;
errorCode = f.BeginReadRefSection();
if (errorCode == Storage_VSOk) {
{
try {
OCC_CATCH_SIGNALS
len = f.RefSectionSize();
for (i = 1; i <= len; i++) {
f.ReadReferenceType(oref,otype);
iData->myReadArray->ChangeValue(oref) = theCallBack->Value(otype)->New();
if (!iData->myReadArray->ChangeValue(oref).IsNull()) iData->myReadArray->ChangeValue(oref)->_typenum = otype;
}
}
catch(Storage_StreamTypeMismatchError) {
TCollection_AsciiString aOref = oref;
result = Standard_False;
dData->SetErrorStatus(Storage_VSTypeMismatch);
dData->SetErrorStatusExtension(aOref);
}
}
if (result) {
errorCode = f.EndReadRefSection();
result = (errorCode == Storage_VSOk);
dData->SetErrorStatus(errorCode);
if (!result) dData->SetErrorStatusExtension("EndReadRefSection");
}
}
else {
result = Standard_False;
dData->SetErrorStatus(errorCode);
dData->SetErrorStatusExtension("BeginReadRefSection");
}
}
if (result) {
errorCode = f.BeginReadDataSection();
result = (errorCode == Storage_VSOk);
dData->SetErrorStatus(errorCode);
if (!result) dData->SetErrorStatusExtension("BeginReadDataSection");
}
if (result) {
Handle(Storage_Schema) me = this;
Handle(Storage_CallBack) rcback;
{
try {
OCC_CATCH_SIGNALS
for (i = 1; i <= dData->NumberOfObjects(); i++) {
Handle(Standard_Persistent) pobj = iData->myReadArray->Value(i);
if (!pobj.IsNull()) {
rcback = theCallBack->Value(pobj->_typenum);
rcback->Read(pobj,f,me);
pobj->_typenum = 0;
}
}
}
catch(Storage_StreamTypeMismatchError) {
result = Standard_False;
dData->SetErrorStatus(Storage_VSTypeMismatch);
dData->SetErrorStatusExtension(i-1);
}
catch(Storage_StreamFormatError) {
result = Standard_False;
dData->SetErrorStatus(Storage_VSFormatError);
dData->SetErrorStatusExtension(i-1);
}
catch(Storage_StreamReadError) {
result = Standard_False;
dData->SetErrorStatus(Storage_VSFormatError);
dData->SetErrorStatusExtension(i-1);
}
}
if (result) {
Handle(Storage_HSeqOfRoot) rlist = rData->Roots();
Handle(Storage_Root) rroot;
for(i = 1; i <= dData->NumberOfRoots(); i++) {
rroot = rlist->Value(i);
rData->UpdateRoot(rroot->Name(),iData->myReadArray->Value(rroot->Reference()));
}
errorCode = f.EndReadDataSection();
result = (errorCode == Storage_VSOk);
dData->SetErrorStatus(errorCode);
if (!result) dData->SetErrorStatusExtension("EndReadDataSection");
}
}
}
else {
dData->SetErrorStatus(Storage_VSModeError);
dData->SetErrorStatusExtension("OpenMode");
}
iData->Clear();
Clear();
return dData;
}
//=======================================================================
//function : ReadHeaderSection
//purpose : read the header part of the stream
//Arguments:
// s: driver to read
//=======================================================================
Handle(Storage_HeaderData) Storage_Schema::ReadHeaderSection
(Storage_BaseDriver& s) const
{
Handle(Storage_HeaderData) result = new Storage_HeaderData;
if ((s.OpenMode() == Storage_VSRead) || (s.OpenMode() == Storage_VSReadWrite)) {
IReadHeaderSection(s,result);
}
else {
result->SetErrorStatus(Storage_VSModeError);
result->SetErrorStatusExtension("OpenMode");
}
return result;
}
//=======================================================================
//function : ReadTypeSection
//purpose : fill the TypeData with the names of the type used
// in a stream
//Arguments:
// s: driver to read
//=======================================================================
Handle(Storage_TypeData) Storage_Schema::ReadTypeSection
(Storage_BaseDriver& f) const
{
Handle(Storage_TypeData) result = new Storage_TypeData;
if ((f.OpenMode() == Storage_VSRead) || (f.OpenMode() == Storage_VSReadWrite)) {
IReadTypeSection(f,result);
}
else {
result->SetErrorStatus(Storage_VSModeError);
result->SetErrorStatusExtension("OpenMode");
}
return result;
}
//=======================================================================
//function : ReadRootSection
//purpose : read root part of the file
//Arguments:
// s: driver to read
//=======================================================================
Handle(Storage_RootData) Storage_Schema::ReadRootSection
(Storage_BaseDriver& f) const
{
Handle(Storage_RootData) result = new Storage_RootData;
if ((f.OpenMode() == Storage_VSRead) || (f.OpenMode() == Storage_VSReadWrite)) {
IReadRootSection(f,result);
}
else {
result->SetErrorStatus(Storage_VSModeError);
result->SetErrorStatusExtension("OpenMode");
}
return result;
}
//=======================================================================
//function : SchemaKnownTypes
//purpose : returns the known types of a schema
//=======================================================================
const TColStd_SequenceOfAsciiString& Storage_Schema::SchemaKnownTypes() const
{
static TColStd_SequenceOfAsciiString aSeq;
return aSeq;
}
//=======================================================================
//function : GetAllSchemaKnownTypes
//purpose : returns the all known types of a schema and their
// nested schemes.
//PTV : add get of all known type for inheritance of schemas
//=======================================================================
Handle(TColStd_HSequenceOfAsciiString) Storage_Schema::
GetAllSchemaKnownTypes() const
{
Handle(TColStd_HSequenceOfAsciiString) aSeqOfType = new TColStd_HSequenceOfAsciiString;
const TColStd_SequenceOfAsciiString& alocalTypeList = SchemaKnownTypes();
for (Standard_Integer k = 1; k <= alocalTypeList.Length(); k++)
aSeqOfType->Append(alocalTypeList.Value(k));
// get nested schemas
Handle(Storage_HArrayOfSchema) aNestedSchemas = NestedSchemas();
if (!aNestedSchemas.IsNull())
{
for (Standard_Integer i = aNestedSchemas->Lower(); i <= aNestedSchemas->Upper(); i++)
{
Handle(Storage_Schema) aSchema = aNestedSchemas->Value(i);
if (aSchema.IsNull())
continue;
Handle(TColStd_HSequenceOfAsciiString) typeList = aSchema->GetAllSchemaKnownTypes();
for (Standard_Integer j = 1; j <= typeList->Length(); j++)
aSeqOfType->Append(typeList->Value(j));
}
}
return aSeqOfType;
}
//=======================================================================
//function : HasUnknownType
//purpose : indicates whether the are types in the driver
// which are not known from the schema and for which
// no callbacks have been set. The unknown types can
// be read in <theUnknownTypes>.
//=======================================================================
Standard_Boolean Storage_Schema::HasUnknownType
(Storage_BaseDriver& f,
TColStd_SequenceOfAsciiString& theUnknownTypes) const
{
Standard_Boolean result = Standard_False;
Handle(TColStd_HSequenceOfAsciiString) typeList = GetAllSchemaKnownTypes();
Handle(Storage_TypeData) tData;
tData = ReadTypeSection(f);
result = (tData->ErrorStatus() != Storage_VSOk);
if (!result) {
Standard_Integer i;
TColStd_MapOfAsciiString names;
for (i = 1; i <= typeList->Length(); i++) {
names.Add(typeList->Value(i));
}
Handle(TColStd_HSequenceOfAsciiString) flist = tData->Types();
for (i = 1; i <= flist->Length(); i++) {
if (!names.Contains(flist->Value(i))) {
theUnknownTypes.Append(flist->Value(i));
result = Standard_True;
}
}
}
return result;
}
//=======================================================================
//function : SetNestedSchemas
//purpose :
//=======================================================================
void Storage_Schema::SetNestedSchemas
(const Handle(Storage_HArrayOfSchema)& theSchemas)
{
myArrayOfSchema = theSchemas;
}
//=======================================================================
//function : ClearNestedSchemas
//purpose :
//=======================================================================
void Storage_Schema::ClearNestedSchemas()
{
myArrayOfSchema.Nullify();
}
//=======================================================================
//function : NestedSchemas
//purpose :
//=======================================================================
Handle(Storage_HArrayOfSchema) Storage_Schema::NestedSchemas() const
{
return myArrayOfSchema;
}
//=======================================================================
//function : AddReadUnknownTypeCallBack
//purpose : add two functions to the callback list
@@ -995,92 +622,6 @@ Handle(Storage_CallBack) Storage_Schema::DefaultCallBack() const
return myDefaultCallBack;
}
//=======================================================================
//function : ResolveUnknownType
//purpose :
//=======================================================================
Handle(Storage_CallBack) Storage_Schema::ResolveUnknownType
(const TCollection_AsciiString& aTypeName,
const Handle(Standard_Persistent)& p,
const Storage_SolveMode aMode) const
{
Handle(Storage_CallBack) theCallBack;
if (!myArrayOfSchema.IsNull()) {
Standard_Integer i;
Standard_Boolean IsNotFound = Standard_True;
Standard_Boolean AlreadyMatched;
for(i = myArrayOfSchema->Lower(); i <= myArrayOfSchema->Upper() && IsNotFound; i++) {
Handle(Storage_Schema) aSchema = myArrayOfSchema->Value(i);
if (!aSchema.IsNull()) {
AlreadyMatched = aSchema->SetNested();
if (!AlreadyMatched) {
if (aMode == Storage_WriteSolve || aMode == Storage_ReadSolve) {
theCallBack = aSchema->CallBackSelection(aTypeName);
}
else if (aMode == Storage_AddSolve) {
theCallBack = aSchema->AddTypeSelection(p);
}
aSchema->UnsetNested();
IsNotFound = theCallBack.IsNull();
}
}
}
}
if (!myNestedState && theCallBack.IsNull()) {
if (myCallBack.IsBound(aTypeName)) {
theCallBack = myCallBack.Find(aTypeName)->CallBack();
}
else if (myCallBackState == Standard_True) {
theCallBack = myDefaultCallBack;
}
else {
Clear();
Standard_SStream aMsg;
aMsg << "Unknown type " << aTypeName << " in schema ";
if (!myName.IsEmpty()) {
aMsg << myName;
}
Storage_StreamUnknownTypeError::Raise(aMsg);
}
}
return theCallBack;
}
//=======================================================================
//function : CallBackSelection
//purpose :
//=======================================================================
Handle(Storage_CallBack) Storage_Schema::CallBackSelection
(const TCollection_AsciiString&) const
{
Handle(Storage_CallBack) theCallBack;
return theCallBack;
}
//=======================================================================
//function : AddTypeSelection
//purpose :
//=======================================================================
Handle(Storage_CallBack) Storage_Schema::AddTypeSelection
(const Handle(Standard_Persistent)&) const
{
Handle(Storage_CallBack) theCallBack;
return theCallBack;
}
//=======================================================================
//function : BindType
//purpose :
@@ -1120,29 +661,6 @@ Handle(Storage_CallBack) Storage_Schema::TypeBinding
return result;
}
//=======================================================================
//function : ReadPersistentReference
//purpose :
//=======================================================================
void Storage_Schema::ReadPersistentReference
(Handle(Standard_Persistent)& sp,
Storage_BaseDriver& f)
{
Standard_Integer ref;
f.GetReference(ref);
if (ref != 0) {
Handle(Storage_InternalData) iData = Storage_Schema::ICurrentData()->InternalData();
sp = iData->myReadArray->Value(ref);
}
else {
sp.Nullify();
}
}
//=======================================================================
//function : AddPersistent
//purpose :
@@ -1208,126 +726,6 @@ void Storage_Schema::Clear() const
Storage_Schema::ICurrentData().Nullify();
}
//=======================================================================
//function : IReadHeaderSection
//purpose :
//=======================================================================
Standard_Boolean Storage_Schema::IReadHeaderSection
(Storage_BaseDriver& f,
const Handle(Storage_HeaderData)& iData) const
{
Standard_Boolean result = Standard_False;
Storage_Error errorCode;
TCollection_AsciiString uinfo,mStorageVersion,mDate,mSchemaName,mSchemaVersion,mApplicationVersion;
TCollection_ExtendedString mApplicationName,mDataType;
TColStd_SequenceOfAsciiString mUserInfo;
TColStd_SequenceOfExtendedString mComment;
Standard_Integer mNBObj;
errorCode = f.BeginReadInfoSection();
if (errorCode == Storage_VSOk) {
{
try {
OCC_CATCH_SIGNALS
f.ReadInfo(mNBObj,
mStorageVersion,
mDate,
mSchemaName,
mSchemaVersion,
mApplicationName,
mApplicationVersion,
mDataType,
mUserInfo);
}
catch(Storage_StreamTypeMismatchError) {
iData->SetErrorStatus(Storage_VSTypeMismatch);
iData->SetErrorStatusExtension("ReadInfo");
return Standard_False;
}
catch(Storage_StreamExtCharParityError) {
iData->SetErrorStatus(Storage_VSExtCharParityError);
iData->SetErrorStatusExtension("ReadInfo");
return Standard_False;
}
}
errorCode = f.EndReadInfoSection();
iData->SetErrorStatus(errorCode);
result = (errorCode == Storage_VSOk);
if (result) {
Standard_Integer i;
iData->SetNumberOfObjects(mNBObj);
iData->SetStorageVersion(mStorageVersion);
iData->SetCreationDate(mDate);
iData->SetSchemaName(mSchemaName);
iData->SetSchemaVersion(mSchemaVersion);
iData->SetApplicationName(mApplicationName);
iData->SetApplicationVersion(mApplicationVersion);
iData->SetDataType(mDataType);
for (i = 1; i <= mUserInfo.Length(); i++) {
iData->AddToUserInfo(mUserInfo.Value(i));
}
errorCode = f.BeginReadCommentSection();
if (errorCode == Storage_VSOk) {
{
{
try {
OCC_CATCH_SIGNALS
f.ReadComment(mComment);
}
catch(Storage_StreamTypeMismatchError) {
iData->SetErrorStatus(Storage_VSTypeMismatch);
iData->SetErrorStatusExtension("ReadComment");
return Standard_False;
}
catch(Storage_StreamExtCharParityError) {
iData->SetErrorStatus(Storage_VSExtCharParityError);
iData->SetErrorStatusExtension("ReadComment");
return Standard_False;
}
}
}
errorCode = f.EndReadCommentSection();
iData->SetErrorStatus(errorCode);
iData->SetErrorStatusExtension("EndReadCommentSection");
result = (errorCode == Storage_VSOk);
if (result) {
for (i = 1; i <= mComment.Length(); i++) {
iData->AddToComments(mComment.Value(i));
}
}
}
else {
result = Standard_False;
iData->SetErrorStatus(errorCode);
iData->SetErrorStatusExtension("BeginReadCommentSection");
}
}
else {
iData->SetErrorStatusExtension("EndReadInfoSection");
}
}
else {
iData->SetErrorStatus(errorCode);
iData->SetErrorStatusExtension("BeginReadInfoSection");
}
return result;
}
#ifdef DATATYPE_MIGRATION
//=======================================================================
// environment variable CSF_MIGRATION_TYPES should define full path of a file
@@ -1392,124 +790,6 @@ Standard_Boolean Storage_Schema::CheckTypeMigration(
}
#endif
//=======================================================================
//function : IReadTypeSection
//purpose :
//=======================================================================
Standard_Boolean Storage_Schema::IReadTypeSection
(Storage_BaseDriver& f,
const Handle(Storage_TypeData)& tData) const
{
static Standard_Boolean result;
TCollection_AsciiString typeName;
Standard_Integer typeNum;
Storage_Error errorCode;
Standard_Integer len,i;
result = Standard_False;
errorCode = f.BeginReadTypeSection();
if (errorCode == Storage_VSOk) {
try {
OCC_CATCH_SIGNALS
len = f.TypeSectionSize();
for (i = 1; i <= len; i++) {
f.ReadTypeInformations(typeNum,typeName);
#ifdef DATATYPE_MIGRATION
TCollection_AsciiString newName;
if(CheckTypeMigration(typeName, newName)) {
#ifdef OCCT_DEBUG
cout << "CheckTypeMigration:OldType = " <<typeName << " Len = "<<typeName.Length()<<endl;
cout << "CheckTypeMigration:NewType = " <<newName << " Len = "<< newName.Length()<<endl;
#endif
typeName = newName;
}
#endif
tData->AddType(typeName,typeNum);
}
result = Standard_True;
}
catch(Storage_StreamTypeMismatchError) {
tData->SetErrorStatus(Storage_VSTypeMismatch);
tData->SetErrorStatusExtension("ReadTypeInformations");
return Standard_False;
}
if (result) {
errorCode = f.EndReadTypeSection();
result = (errorCode == Storage_VSOk);
tData->SetErrorStatus(errorCode);
if (!result) tData->SetErrorStatusExtension("EndReadTypeSection");
}
}
else {
tData->SetErrorStatus(errorCode);
tData->SetErrorStatusExtension("BeginReadTypeSection");
}
return result;
}
//=======================================================================
//function : IReadRootSection
//purpose :
//=======================================================================
Standard_Boolean Storage_Schema::IReadRootSection
(Storage_BaseDriver& f,
const Handle(Storage_RootData)& rData) const
{
static Standard_Boolean result;
Standard_Integer len,i,ref;
Storage_Error errorCode;
Handle(Standard_Persistent) p;
Handle(Storage_Root) aRoot;
result = Standard_False;
errorCode = f.BeginReadRootSection();
if (errorCode == Storage_VSOk) {
TCollection_AsciiString rootName,typeName;
try {
OCC_CATCH_SIGNALS
len = f.RootSectionSize();
for (i = 1; i <= len; i++) {
f.ReadRoot(rootName,ref,typeName);
aRoot = new Storage_Root(rootName,p);
aRoot->SetReference(ref);
aRoot->SetType(typeName);
rData->AddRoot(aRoot);
}
result = Standard_True;
}
catch(Storage_StreamTypeMismatchError) {
result = Standard_False;
rData->SetErrorStatus(Storage_VSTypeMismatch);
rData->SetErrorStatusExtension("ReadRoot");
}
if (result) {
errorCode = f.EndReadRootSection();
result = (errorCode == Storage_VSOk);
rData->SetErrorStatus(errorCode);
if (!result) rData->SetErrorStatusExtension("EndReadRootSection");
}
}
else {
rData->SetErrorStatus(errorCode);
rData->SetErrorStatusExtension("BeginReadRootSection");
}
return result;
}
//=======================================================================
//function : ISetCurrentData
//purpose :
@@ -1562,41 +842,3 @@ TCollection_AsciiString Storage_Schema::ICreationDate()
TCollection_AsciiString t(nowstr);
return t;
}
//=======================================================================
//function : SetNested
//purpose :
//=======================================================================
Standard_Boolean Storage_Schema::SetNested()
{
Standard_Boolean result = myNestedState;
myNestedState = Standard_True;
return result;
}
//=======================================================================
//function : IsNested
//purpose :
//=======================================================================
Standard_Boolean Storage_Schema::IsNested() const
{
return myNestedState;
}
//=======================================================================
//function : UnsetNested
//purpose :
//=======================================================================
Standard_Boolean Storage_Schema::UnsetNested()
{
Standard_Boolean result = myNestedState;
myNestedState = Standard_False;
return result;
}

View File

@@ -107,50 +107,6 @@ public:
//! to be stored together.
Standard_EXPORT void Write (Storage_BaseDriver& s, const Handle(Storage_Data)& aData) const;
//! Returns the data read from the container defined
//! by the driver s. The retrieval operation is
//! performed according to the data schema with
//! which this algorithm is working.
//! These data are aggregated in a Storage_Data
//! object which may be browsed in order to extract
//! the root objects from the container.
Standard_EXPORT Handle(Storage_Data) Read (Storage_BaseDriver& s) const;
//! read the header part of the stream
//! Arguments:
//! s: driver to read
Standard_EXPORT Handle(Storage_HeaderData) ReadHeaderSection (Storage_BaseDriver& s) const;
//! fill the TypeData with the names of the type used
//! in a stream
//! Arguments:
//! s: driver to read
Standard_EXPORT Handle(Storage_TypeData) ReadTypeSection (Storage_BaseDriver& s) const;
//! read root part of the file
//! Arguments:
//! s: driver to read
Standard_EXPORT Handle(Storage_RootData) ReadRootSection (Storage_BaseDriver& s) const;
//! returns the known types of a schema
Standard_EXPORT virtual const TColStd_SequenceOfAsciiString& SchemaKnownTypes() const;
//! indicates whether the are types in the driver
//! which are not known from the schema and for which
//! no callbacks have been set. The unknown types can
//! be read in <theUnknownTypes>.
Standard_EXPORT Standard_Boolean HasUnknownType (Storage_BaseDriver& aDriver, TColStd_SequenceOfAsciiString& theUnknownTypes) const;
//! returns the all known types of a schema and their
//! nested schemes.
Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) GetAllSchemaKnownTypes() const;
Standard_EXPORT void SetNestedSchemas (const Handle(Storage_HArrayOfSchema)& theSchemas);
Standard_EXPORT void ClearNestedSchemas();
Standard_EXPORT Handle(Storage_HArrayOfSchema) NestedSchemas() const;
//! return a current date string
Standard_EXPORT static TCollection_AsciiString ICreationDate();
@@ -204,18 +160,10 @@ public:
//! UseDefaultCallBack() is set.
Standard_EXPORT Handle(Storage_CallBack) DefaultCallBack() const;
Standard_EXPORT virtual Handle(Storage_CallBack) CallBackSelection (const TCollection_AsciiString& tName) const;
Standard_EXPORT virtual Handle(Storage_CallBack) AddTypeSelection (const Handle(Standard_Persistent)& sp) const;
void WritePersistentObjectHeader (const Handle(Standard_Persistent)& sp, Storage_BaseDriver& s);
void ReadPersistentObjectHeader (Storage_BaseDriver& s);
void WritePersistentReference (const Handle(Standard_Persistent)& sp, Storage_BaseDriver& s);
Standard_EXPORT void ReadPersistentReference (Handle(Standard_Persistent)& sp, Storage_BaseDriver& s);
Standard_EXPORT Standard_Boolean AddPersistent (const Handle(Standard_Persistent)& sp, const Standard_CString tName) const;
Standard_EXPORT Standard_Boolean PersistentToAdd (const Handle(Standard_Persistent)& sp) const;
@@ -226,11 +174,6 @@ public:
DEFINE_STANDARD_RTTIEXT(Storage_Schema,MMgt_TShared)
protected:
Standard_EXPORT Standard_Boolean IsNested() const;
Standard_EXPORT Handle(Storage_CallBack) ResolveUnknownType (const TCollection_AsciiString& aTypeName, const Handle(Standard_Persistent)& aPers, const Storage_SolveMode aMode) const;
Standard_Boolean HasTypeBinding (const TCollection_AsciiString& aTypeName) const;
@@ -242,19 +185,8 @@ protected:
private:
Standard_EXPORT Standard_Boolean SetNested();
Standard_EXPORT Standard_Boolean UnsetNested();
Standard_EXPORT void Clear() const;
Standard_EXPORT Standard_Boolean IReadHeaderSection (Storage_BaseDriver& s, const Handle(Storage_HeaderData)& iData) const;
Standard_EXPORT Standard_Boolean IReadTypeSection (Storage_BaseDriver& s, const Handle(Storage_TypeData)& tData) const;
Standard_EXPORT Standard_Boolean IReadRootSection (Storage_BaseDriver& s, const Handle(Storage_RootData)& rData) const;
Standard_EXPORT static void ISetCurrentData (const Handle(Storage_Data)& dData);
Standard_EXPORT static Handle(Storage_Data)& ICurrentData();
@@ -264,10 +196,6 @@ private:
Handle(Storage_CallBack) myDefaultCallBack;
TCollection_AsciiString myName;
TCollection_AsciiString myVersion;
Handle(Storage_HArrayOfSchema) myArrayOfSchema;
Standard_Boolean myNestedState;
};

View File

@@ -22,13 +22,6 @@ inline void Storage_Schema::WritePersistentObjectHeader(const Handle(Standard_Pe
f.WritePersistentObjectHeader(sp->_refnum,sp->_typenum);
}
inline void Storage_Schema::ReadPersistentObjectHeader(Storage_BaseDriver& f)
{
Standard_Integer i,j;
f.ReadPersistentObjectHeader(i,j);
}
inline Standard_Boolean Storage_Schema::HasTypeBinding(const TCollection_AsciiString& aTypeName) const
{
return Storage_Schema::ICurrentData()->InternalData()->myTypeBinding.IsBound(aTypeName);

View File

@@ -13,10 +13,11 @@
// commercial license or contractual agreement.
#include <Standard_ErrorHandler.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_Type.hxx>
#include <Storage_Schema.hxx>
#include <Storage_TypeData.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Storage_TypeData,MMgt_TShared)
@@ -25,6 +26,56 @@ Storage_TypeData::Storage_TypeData() : myErrorStatus(Storage_VSOk)
{
}
Standard_Boolean Storage_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_Integer Storage_TypeData::NumberOfTypes() const
{
return myPt.Extent();

View File

@@ -29,6 +29,7 @@
#include <TColStd_HSequenceOfAsciiString.hxx>
class Standard_NoSuchObject;
class Storage_Schema;
class Storage_BaseDriver;
class TCollection_AsciiString;
@@ -43,8 +44,19 @@ public:
Standard_EXPORT Storage_TypeData();
Standard_EXPORT Standard_Boolean Read (Storage_BaseDriver& theDriver);
Standard_EXPORT Standard_Integer NumberOfTypes() const;
//! add a type to the list
Standard_EXPORT void AddType (const TCollection_AsciiString& aName, const Standard_Integer aTypeNum);
//! 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;
Standard_EXPORT Standard_Boolean IsType (const TCollection_AsciiString& aName) const;
@@ -58,15 +70,6 @@ public:
Standard_EXPORT void Clear();
//! add a type to the list
Standard_EXPORT void AddType (const TCollection_AsciiString& aName, const Standard_Integer aTypeNum);
//! 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;
friend class Storage_Schema;