From fe21f7969300692dd8598d06b695cef0f290a418 Mon Sep 17 00:00:00 2001 From: Benjamin Bihler Date: Fri, 18 Aug 2017 10:40:19 +0300 Subject: [PATCH] 0029014: Managing Binary Format Version Is Not Possible for Own TDF_Attributes CDM_Application has been extended to provide application name and version. Application name and version is stored by BinLDrivers_DocumentStorageDriver. BinLDrivers_DocumentStorageDriver propagates application name and version by passing it to BinMDataStd. Made BinObjMgt_RRelocationTable store a handle to the header data of the file begin read in to make it accessible by binary attribute drivers. Undone storing application name and version as static fields in BinMDataStd which is bad style and not thread-safe. Moved method implementations to .cxx files. Clearing a BinObjMgt_RRelocationTable now nullifies the reference to the file header data and BinLDrivers_DocumentRetrievalDriver therefore sets the reference after the relocation table has been cleared before reading in the document subtree. --- .../BinLDrivers_DocumentRetrievalDriver.cxx | 2 +- .../BinLDrivers_DocumentStorageDriver.cxx | 5 ++ src/BinObjMgt/BinObjMgt_RRelocationTable.cxx | 49 +++++++++++++++++++ src/BinObjMgt/BinObjMgt_RRelocationTable.hxx | 30 +++++++++++- src/BinObjMgt/FILES | 1 + src/CDM/CDM_Application.cxx | 22 +++++++++ src/CDM/CDM_Application.hxx | 9 +++- 7 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 src/BinObjMgt/BinObjMgt_RRelocationTable.cxx diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx index 1bd4996494..eede80cf5a 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx @@ -222,6 +222,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& // 2a. Retrieve data from the stream: myRelocTable.Clear(); + myRelocTable.SetHeaderData(aHeaderData); mySections.Clear(); myPAtt.Init(); Handle(TDF_Data) aData = new TDF_Data(); @@ -531,4 +532,3 @@ Standard_Boolean BinLDrivers_DocumentRetrievalDriver::CheckDocumentVersion( } return Standard_True; } - diff --git a/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.cxx index 04baf70745..a8313f614c 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.cxx @@ -429,6 +429,11 @@ void BinLDrivers_DocumentStorageDriver::WriteInfoSection Standard_Integer aObjNb = 1; Standard_Integer aShemaVer = 1; + // Store the name and version of the application that has created the + // document. + theData->SetApplicationVersion(theDoc->Application()->Version()); + theData->SetApplicationName(theDoc->Application()->Name()); + aHeader.einfo += FSD_BinaryFile::WriteInfo (theOStream, aObjNb, BinLDrivers::StorageVersion(), diff --git a/src/BinObjMgt/BinObjMgt_RRelocationTable.cxx b/src/BinObjMgt/BinObjMgt_RRelocationTable.cxx new file mode 100644 index 0000000000..f06f67a73d --- /dev/null +++ b/src/BinObjMgt/BinObjMgt_RRelocationTable.cxx @@ -0,0 +1,49 @@ +// Created on: 2017-08-22 +// Created by: Benjamin BIHLER +// 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 + +//======================================================================= +//function : GetHeaderData +//purpose : getter for the file header data +//======================================================================= + +const Handle(Storage_HeaderData)& BinObjMgt_RRelocationTable::GetHeaderData() const +{ + return myHeaderData; +} + +//======================================================================= +//function : SetHeaderData +//purpose : setter for the file header data +//======================================================================= + +void BinObjMgt_RRelocationTable::SetHeaderData( + const Handle(Storage_HeaderData)& theHeaderData) +{ + myHeaderData = theHeaderData; +} + +//======================================================================= +//function : Clear +//purpose : The relocation table is cleared before/after reading in a document. +// : In this case the reference to the file header data should also be +// : cleared, because it is specific to the document. +//======================================================================= +void BinObjMgt_RRelocationTable::Clear(const Standard_Boolean doReleaseMemory) +{ + myHeaderData.Nullify(); + TColStd_DataMapOfIntegerTransient::Clear(doReleaseMemory); +} diff --git a/src/BinObjMgt/BinObjMgt_RRelocationTable.hxx b/src/BinObjMgt/BinObjMgt_RRelocationTable.hxx index 85199347a7..11de88e551 100644 --- a/src/BinObjMgt/BinObjMgt_RRelocationTable.hxx +++ b/src/BinObjMgt/BinObjMgt_RRelocationTable.hxx @@ -17,8 +17,36 @@ #define _BinObjMgt_RRelocationTable_HeaderFile #include +#include -typedef TColStd_DataMapOfIntegerTransient BinObjMgt_RRelocationTable; +//! Retrieval relocation table is modeled as a child class of +//! TColStd_DataMapOfIntegerTransient that stores a handle to the file +//! header section. With that attribute drivers have access to the file header +//! section. +class BinObjMgt_RRelocationTable : public TColStd_DataMapOfIntegerTransient +{ +public: + //! Returns a handle to the header data of the file that is begin read + Standard_EXPORT const Handle(Storage_HeaderData)& GetHeaderData() const; + + //! Sets the storage header data. + //! + //! @param theHeaderData header data of the file that is begin read + Standard_EXPORT void SetHeaderData( + const Handle(Storage_HeaderData)& theHeaderData); + + Standard_EXPORT void Clear(const Standard_Boolean doReleaseMemory = Standard_True); + + + +protected: + + + +private: + + Handle(Storage_HeaderData) myHeaderData; +}; #endif // _BinObjMgt_RRelocationTable_HeaderFile diff --git a/src/BinObjMgt/FILES b/src/BinObjMgt/FILES index bb324114b2..7954116694 100755 --- a/src/BinObjMgt/FILES +++ b/src/BinObjMgt/FILES @@ -7,5 +7,6 @@ BinObjMgt_PExtChar.hxx BinObjMgt_PInteger.hxx BinObjMgt_PReal.hxx BinObjMgt_PShortReal.hxx +BinObjMgt_RRelocationTable.cxx BinObjMgt_RRelocationTable.hxx BinObjMgt_SRelocationTable.hxx diff --git a/src/CDM/CDM_Application.cxx b/src/CDM/CDM_Application.cxx index 5b3d536fd2..f61332d971 100644 --- a/src/CDM/CDM_Application.cxx +++ b/src/CDM/CDM_Application.cxx @@ -103,3 +103,25 @@ void CDM_Application::EndOfUpdate message+=aDocument->Presentation(); Write(message.ToExtString()); } + +//======================================================================= +//function : Name +//purpose : returns the application name +//======================================================================= + +TCollection_ExtendedString CDM_Application::Name() const +{ + // Default: empty + return TCollection_ExtendedString(); +} + +//======================================================================= +//function : Version +//purpose : returns the application version +//======================================================================= + +TCollection_AsciiString CDM_Application::Version() const +{ + // Default: empty + return TCollection_AsciiString(); +} diff --git a/src/CDM/CDM_Application.hxx b/src/CDM/CDM_Application.hxx index 028a9feca9..3720527b6f 100644 --- a/src/CDM/CDM_Application.hxx +++ b/src/CDM/CDM_Application.hxx @@ -24,12 +24,14 @@ #include #include #include +#include +#include + class CDM_Reference; class CDM_MetaData; class CDM_Document; class Resource_Manager; class CDM_MessageDriver; -class TCollection_ExtendedString; class CDM_Application; @@ -60,6 +62,11 @@ public: //! writes the string in the application MessagerDriver. Standard_EXPORT void Write (const Standard_ExtString aString); + //! Returns the application name. + Standard_EXPORT virtual TCollection_ExtendedString Name() const; + + //! Returns the application version. + Standard_EXPORT virtual TCollection_AsciiString Version() const; friend class CDM_Reference; friend class CDM_MetaData; -- 2.20.1