return;
}
- theDevice->Open( Storage_VSWrite );
+ theDevice->Open( Storage_VSAppend );
+ Standard_Size aP = theDevice->Tell();
- /*
-#if defined(_WIN32)
- ofstream anOS ((const wchar_t*) theFileName.ToExtString(), ios::in | ios::binary | ios::ate);
-#elif !defined(IRIX) // 10.10.2005
- ofstream anOS (aFileName.ToCString(), ios::in | ios::binary | ios::ate);
-#else
- ofstream anOS (aFileName.ToCString(), ios::ate);
- //ofstream anOS (aFileName.ToCString(), ios::out| ios::binary | ios::ate);
-#endif
-#ifdef DEB
- const Standard_Integer aP = (Standard_Integer) anOS.tellp();
- cout << "POS = " << aP <<endl;
-#endif
-//#endif
-*/
if (theDevice->CanWrite()) {
// 2. Write the Table of Contents of Sections
- BinLDrivers_VectorOfDocumentSection::Iterator anIterS (mySections);
- for (; anIterS.More(); anIterS.Next())
- anIterS.ChangeValue().WriteTOC (theDevice);
+ BinLDrivers_VectorOfDocumentSection::Iterator anIterS (mySections);
+ for (; anIterS.More(); anIterS.Next())
+ anIterS.ChangeValue().WriteTOC (theDevice);
// Shapes Section is the last one, it indicates the end of the table.
BinLDrivers_DocumentSection aShapesSection (SHAPESECTION_POS,
WriteMessage (anErrorStr + "BinLDrivers_DocumentStorageDriver, Problem with the file stream.";
#else
TCollection_ExtendedString aStr =
- anErrorStr + aMethStr + "Problem writing the file ";
- WriteMessage (aStr + theFileName);
+ anErrorStr + aMethStr + "Problem writing the file.";
+ WriteMessage (aStr);
#endif
SetIsError(Standard_True);
SetStoreStatus(PCDM_SS_WriteFailure);
}
+
+ theDevice->Close();
}
}
if (aFileDriver.Open( theDevice, Storage_VSWrite ) != Storage_VSOk) {
WriteMessage (TCollection_ExtendedString("Error: Cannot open the device ") +
theDevice->Name());
-#endif
SetIsError(Standard_True);
return;
}
void BinObjMgt_Persistent::Write (const Handle(Storage_IODevice)& theDevice)
{
- if (!theDevice->CanWrite())
- {
- return;
- }
-
- Handle(Storage_OStream) aStream = Handle(Storage_OStream)::DownCast(theDevice);
- if (!aStream.IsNull())
+ Standard_Integer nbWritten = 0;
+ Standard_Integer *aData = (Standard_Integer*) myData(1);
+ // update data length
+ aData[2] = mySize - BP_HEADSIZE;
+#if DO_INVERSE
+ aData[0] = InverseInt (aData[0]);
+ aData[1] = InverseInt (aData[1]);
+ aData[2] = InverseInt (aData[2]);
+#endif
+ for (Standard_Integer i=1; theDevice->CanWrite() && nbWritten < mySize && i <= myData.Length(); i++)
{
- Write (*aStream->Stream());
+ Standard_Integer nbToWrite = Min(mySize - nbWritten, BP_PIECESIZE);
+ theDevice->Write( (char*)myData(i), nbToWrite );
+ nbWritten += nbToWrite;
}
+ myIndex = 1;
+ myOffset = BP_HEADSIZE;
+ mySize = BP_HEADSIZE;
+ myIsError = Standard_False;
}
//=======================================================================
}
Standard_Boolean CDF_Store::SetDevice(const Handle(Storage_IODevice)& aDevice) {
- /*
- TCollection_ExtendedString theFolder(aFolder);
- Standard_Integer l = theFolder.Length();
-
- // if the last character is the folder separator (which is always the first character)
- // it is removed.
- // This is correct for Unix systems but not for Windows! VMS and MAC? Thomas Haller, 23.11.01
- if(l > 1) {
-#ifndef WNT
- if(theFolder.Value(l) == theFolder.Value(1)) theFolder.Trunc(l-1);
-#else
- if (theFolder.Value(l) == '/' || theFolder.Value(l) == '\\')
- theFolder.Trunc(l-1);
-#endif
- }
-
- if(theMetaDataDriver->FindFolder(theFolder)) {
- */
- myCurrentDocument->SetRequestedDevice(aDevice);
- return Standard_True;
- /*
- }
- return Standard_False;
- */
+ myCurrentDocument->SetRequestedDevice(aDevice);
+ return Standard_True;
}
CDF_StoreSetNameStatus CDF_Store::RecheckName () {
// return SetName(myCurrentDocument->RequestedName());
return CDF_SSNS_OK;
}
-/*
-CDF_StoreSetNameStatus CDF_Store::SetName(const TCollection_ExtendedString& aName)
-{
- TCollection_ExtendedString theName=theMetaDataDriver->SetName(myCurrentDocument,aName);
-
- if(myCurrentDocument->IsStored ()) {
- Handle(CDM_MetaData) E = myCurrentDocument->MetaData();
- if( E->Folder() == myCurrentDocument->RequestedFolder()
- && E->Name() == theName) return CDF_SSNS_OK;
- }
-
- if(myCurrentDocument->HasRequestedFolder()) {
- if (theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),theName)) {
- if(theMetaDataDriver->MetaData(myCurrentDocument->RequestedFolder(),theName)->IsRetrieved())
- return CDF_SSNS_OpenDocument;
- else {
- myCurrentDocument->SetRequestedName(theName);
- return CDF_SSNS_ReplacingAnExistentDocument;
- }
- }
- }
- myCurrentDocument->SetRequestedName(theName);
- return CDF_SSNS_OK;
-}
-
-CDF_StoreSetNameStatus CDF_Store::SetName(const Standard_ExtString aName)
-{
- TCollection_ExtendedString theName(aName);
- return SetName(theName);
-}
-*/
void CDF_Store::Realize() {
Standard_ProgramError_Raise_if(!myList->IsConsistent(),"information are missing");
Handle(CDM_MetaData) m;
myText = "";
- myCurrentDocument->RequestedDevice()->Open (Storage_VSWrite);
myStatus = myList->Store(m,myText);
- myCurrentDocument->RequestedDevice()->Close();
-}
-/*
-Standard_ExtString CDF_Store::Path() const {
- return myPath.ToExtString();
}
-*/
Handle(Storage_IODevice) CDF_Store::MetaDataDevice() const {
- /*
- static TCollection_ExtendedString retv;
- retv="";
- if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
- return retv.ToExtString();
- */
return myCurrentDocument->MetaData()->Device();
}
-- - Storage_VSInternalError : an internal error has been detected
-- - Storage_VSExtCharParityError : an error
-- has occurred while reading 16 bit characte
-
+
+ enumeration SeekMode
+ is
+ SMBegin,
+ SMCur,
+ SMEnd
+ end;
+
enumeration OpenMode
is
VSNone,
VSRead,
VSWrite,
+ VSAppend,
VSReadWrite
end;
---Purpose:
uses Position from Storage,
AsciiString from TCollection,
OpenMode from Storage,
+ SeekMode from Storage,
Error from Storage,
FStream from Standard,
ExtendedString from TCollection
Tell (me: mutable) returns Position from Storage is redefined;
---Purpose: returns a position in the device. Return -1 upon error.
- Seek (me: mutable; thePos: Position from Storage) returns Boolean from Standard is redefined;
+ Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+ returns Boolean from Standard is redefined;
Close (me: mutable) returns Boolean from Standard;
{
if (theMode == Storage_VSRead)
{
- myStream.open(aFilePath, ios::in | ios::binary );
+ myStream.open( aFilePath, ios::in | ios::binary );
}
else if (theMode == Storage_VSWrite)
{
- myStream.open(aFilePath, ios::out | ios::binary );
+ myStream.open( aFilePath, ios::out | ios::binary );
+ }
+ else if (theMode == Storage_VSAppend)
+ {
+ myStream.open( aFilePath, ios::in | ios::out | ios::binary | ios::ate );
}
else if (theMode == Storage_VSReadWrite)
{
- myStream.open(aFilePath, ios::in | ios::out);
+ myStream.open( aFilePath, ios::in | ios::out | ios::binary );
}
if (!myStream.rdbuf()->is_open()) {
//function : Seek
//purpose :
//=======================================================================
-Standard_Boolean Storage_File::Seek (const Storage_Position& thePos)
+Standard_Boolean Storage_File::Seek (const Storage_Position& thePos, const Storage_SeekMode aMode)
{
+ ios::seekdir dir = ios::beg;
+ switch ( aMode )
+ {
+ case Storage_SMEnd:
+ dir = ios::end;
+ break;
+ case Storage_SMCur:
+ dir = ios::cur;
+ break;
+ case Storage_SMBegin:
+ default:
+ dir = ios::beg;
+ break;
+ }
+
if ( OpenMode() == Storage_VSRead )
- myStream.seekg( thePos );
+ myStream.seekg( thePos, dir );
else
- myStream.seekp( thePos );
+ myStream.seekp( thePos, dir );
return !myStream.fail();
}
//=======================================================================
Standard_Boolean Storage_File::CanWrite() const
{
- return myStream.good() && ( OpenMode() == Storage_VSWrite || OpenMode() == Storage_VSReadWrite );
+ return myStream.good() && ( OpenMode() == Storage_VSWrite || OpenMode() == Storage_VSAppend || OpenMode() == Storage_VSReadWrite );
}
//=======================================================================
AsciiString from TCollection,
OpenMode from Storage,
Error from Storage,
+ SeekMode from Storage,
ExtendedString from TCollection,
SequenceOfAsciiString from TColStd,
SequenceOfExtendedString from TColStd
Tell( me : mutable ) returns Position from Storage is deferred;
---Purpose: return position in the device. Return -1 upon error.
- Seek( me: mutable; aPos : Position from Storage ) returns Boolean from Standard is deferred;
+ Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+ returns Boolean from Standard is deferred;
---Purpose: Set new absolute position within the stream
Close(me : mutable) returns Boolean from Standard is deferred;
{
Standard_Character c;
Read( &c, sizeof( Standard_Character ) );
- if ( aFin = ( c == anEndSymbol ) )
+ aFin = ( c == anEndSymbol );
+ if ( aFin )
aBuf[i++] = '\0';
else
aBuf[i++] = c;
uses Position from Storage,
AsciiString from TCollection,
OpenMode from Storage,
+ SeekMode from Storage,
Error from Storage,
IStream from Standard,
IStreamPtr from Standard,
Tell (me: mutable) returns Position from Storage is redefined;
---Purpose: returns a position in the device. Return -1 upon error.
- Seek (me: mutable; thePos: Position from Storage) returns Boolean from Standard is redefined;
+ Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+ returns Boolean from Standard is redefined;
Close (me: mutable) returns Boolean from Standard;
//function : Seek
//purpose :
//=======================================================================
-Standard_Boolean Storage_IStream::Seek (const Storage_Position& thePos)
+Standard_Boolean Storage_IStream::Seek (const Storage_Position& thePos, const Storage_SeekMode aMode )
{
- myStream->seekg (thePos);
+ switch ( aMode )
+ {
+ case Storage_SMEnd:
+ myStream->seekg(thePos, ios::end);
+ break;
+ case Storage_SMCur:
+ myStream->seekg(thePos, ios::cur);
+ break;
+ case Storage_SMBegin:
+ default:
+ myStream->seekg(thePos, ios::beg);
+ break;
+ }
return !myStream->fail();
}
uses Position from Storage,
AsciiString from TCollection,
OpenMode from Storage,
+ SeekMode from Storage,
Error from Storage,
OStream from Standard,
OStreamPtr from Standard,
Tell (me: mutable) returns Position from Storage is redefined;
---Purpose: returns a position in the device. Return -1 upon error.
- Seek (me: mutable; thePos: Position from Storage) returns Boolean from Standard is redefined;
+ Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+ returns Boolean from Standard is redefined;
Close (me: mutable) returns Boolean from Standard;
//=======================================================================
Storage_Error Storage_OStream::Open (const Storage_OpenMode theMode)
{
- if (theMode != Storage_VSWrite)
+ if (theMode != Storage_VSWrite || theMode != Storage_VSAppend)
{
return Storage_VSOpenError;
}
// clear flags and set the position where the next character is to be inserted
myStream->clear();
- myStream->seekp(0, ios::beg);
+ if ( theMode == Storage_VSWrite )
+ myStream->seekp(0, ios::beg);
+ else
+ myStream->seekp(0, ios::end);
}
}
else
//function : Seek
//purpose :
//=======================================================================
-Standard_Boolean Storage_OStream::Seek (const Storage_Position& thePos)
+Standard_Boolean Storage_OStream::Seek (const Storage_Position& thePos, const Storage_SeekMode aMode )
{
- myStream->seekp (thePos);
+ switch ( aMode )
+ {
+ case Storage_SMEnd:
+ myStream->seekp(thePos, ios::end);
+ break;
+ case Storage_SMCur:
+ myStream->seekp(thePos, ios::cur);
+ break;
+ case Storage_SMBegin:
+ default:
+ myStream->seekp(thePos, ios::beg);
+ break;
+ }
return !myStream->fail();
}
if (WriteToDomDocument (theDocument, anElement, theDevice) == Standard_False) {
// Write DOM_Document into XML file,
- //FILE * aFile = OSD_OpenFile(theFileName, "wt");
+ theDevice->Open( Storage_VSWrite );
if (theDevice->CanWrite()) {
LDOM_XmlWriter aWriter (theDevice);
aWriter.SetIndentation(1);
aWriter << aDOMDoc;
- //fclose(aFile);
+ theDevice->Close();
::take_time (0, " +++++ Fin formatting to XML : ", aMessageDriver);
-
- }else{
+ }
+ else
+ {
SetIsError (Standard_True);
TCollection_ExtendedString aMsg =
TCollection_ExtendedString("Error: the device ") + theDevice->Name() +