From bf86e9f62a5ef7dcd18e0fe599a5f534b67f8e4b Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 13 Mar 2019 14:59:35 +0300 Subject: [PATCH] Fix regression in ModelHighAPI_Dumper --- src/ExchangePlugin/ExchangePlugin_Dump.cpp | 12 +++-- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 54 +++++++++++++--------- src/ModelHighAPI/ModelHighAPI_Dumper.h | 3 +- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_Dump.cpp b/src/ExchangePlugin/ExchangePlugin_Dump.cpp index a6a620357..cf78b9b8c 100644 --- a/src/ExchangePlugin/ExchangePlugin_Dump.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Dump.cpp @@ -123,19 +123,21 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName) ++aNbSelectedTypes; if (boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value()) { - ModelHighAPI_Dumper::DumpStorage aTopoNameStorage; + ModelHighAPI_Dumper::DumpStoragePtr aTopoNameStorage(new ModelHighAPI_Dumper::DumpStorage); aDumper->addCustomStorage(aTopoNameStorage); } if (boolean(GEOMETRIC_DUMP_ID())->value()) { - ModelHighAPI_Dumper::DumpStorageGeom aGeomSelectionStorage; + ModelHighAPI_Dumper::DumpStoragePtr aGeomSelectionStorage( + new ModelHighAPI_Dumper::DumpStorageGeom); if (aNbSelectedTypes > 1) - aGeomSelectionStorage.setFilenameSuffix("_geo"); + aGeomSelectionStorage->setFilenameSuffix("_geo"); aDumper->addCustomStorage(aGeomSelectionStorage); } if (boolean(WEAK_NAMING_DUMP_ID())->value()) { - ModelHighAPI_Dumper::DumpStorageWeak aWeakNamingStorage; + ModelHighAPI_Dumper::DumpStoragePtr aWeakNamingStorage( + new ModelHighAPI_Dumper::DumpStorageWeak); if (aNbSelectedTypes > 1) - aWeakNamingStorage.setFilenameSuffix("_weak"); + aWeakNamingStorage->setFilenameSuffix("_weak"); aDumper->addCustomStorage(aWeakNamingStorage); } diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index ffa551c13..3a2e57d39 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -69,39 +69,39 @@ class ModelHighAPI_Dumper::DumpStorageBuffer : public ModelHighAPI_Dumper::DumpS static const int THE_DUMP_PRECISION = 16; public: - void addStorage(const ModelHighAPI_Dumper::DumpStorage& theStorage) + void addStorage(const ModelHighAPI_Dumper::DumpStoragePtr& theStorage) { myStorageArray.push_back(theStorage); } void clear() { myStorageArray.clear(); } bool isBufferEmpty() { - return myStorageArray.empty() || myStorageArray.front().buffer().str().empty(); + return myStorageArray.empty() || myStorageArray.front()->buffer().str().empty(); } void mergeBuffer() { - std::list::iterator anIt = myStorageArray.begin(); + std::list::iterator anIt = myStorageArray.begin(); for (; anIt != myStorageArray.end(); ++anIt) { // avoid multiple empty lines - std::string aBuf = anIt->buffer().str(); + std::string aBuf = (*anIt)->buffer().str(); size_t anInd = std::string::npos; while ((anInd = aBuf.find("\n\n\n")) != std::string::npos) aBuf.erase(anInd, 1); - anIt->fullDump() << aBuf; - anIt->buffer().str(""); + (*anIt)->fullDump() << aBuf; + (*anIt)->buffer().str(""); } } void write(const std::string& theValue) { if (myStorageArray.empty()) - addStorage(DumpStorage()); + addStorage(DumpStoragePtr(new DumpStorage)); - std::list::iterator anIt = myStorageArray.begin(); + std::list::iterator anIt = myStorageArray.begin(); for (; anIt != myStorageArray.end(); ++anIt) - anIt->buffer() << theValue; + (*anIt)->buffer() << theValue; } DumpStorageBuffer& operator<<(const char theChar) @@ -174,25 +174,25 @@ public: virtual void write(const std::shared_ptr& theAttrSelect) { if (myStorageArray.empty()) - addStorage(DumpStorage()); + addStorage(DumpStoragePtr(new DumpStorage)); - std::list::iterator anIt = myStorageArray.begin(); + std::list::iterator anIt = myStorageArray.begin(); for (; anIt != myStorageArray.end(); ++anIt) - anIt->write(theAttrSelect); + (*anIt)->write(theAttrSelect); } virtual void reserveBuffer() { - std::list::iterator anIt = myStorageArray.begin(); + std::list::iterator anIt = myStorageArray.begin(); for (; anIt != myStorageArray.end(); ++anIt) - anIt->reserveBuffer(); + (*anIt)->reserveBuffer(); } virtual void restoreReservedBuffer() { - std::list::iterator anIt = myStorageArray.begin(); + std::list::iterator anIt = myStorageArray.begin(); for (; anIt != myStorageArray.end(); ++anIt) - anIt->restoreReservedBuffer(); + (*anIt)->restoreReservedBuffer(); } virtual bool exportTo(const std::string& theFilename, const ModulesSet& theUsedModules) @@ -203,17 +203,16 @@ public: aFilenameBase = aFilenameBase.substr(0, aFilenameBase.size() - THE_EXT.size()); bool isOk = true; - std::list::iterator anIt = myStorageArray.begin(); + std::list::iterator anIt = myStorageArray.begin(); for (; anIt != myStorageArray.end(); ++anIt) { - std::string aFilename = aFilenameBase + anIt->myFilenameSuffix + THE_EXT; - isOk = anIt->exportTo(aFilename, theUsedModules) && isOk; + std::string aFilename = aFilenameBase + (*anIt)->myFilenameSuffix + THE_EXT; + isOk = (*anIt)->exportTo(aFilename, theUsedModules) && isOk; } - clear(); return isOk; } private: - std::list myStorageArray; + std::list myStorageArray; }; @@ -478,7 +477,7 @@ ModelHighAPI_Dumper* ModelHighAPI_Dumper::getInstance() return mySelf; } -void ModelHighAPI_Dumper::addCustomStorage(const ModelHighAPI_Dumper::DumpStorage& theStorage) +void ModelHighAPI_Dumper::addCustomStorage(const ModelHighAPI_Dumper::DumpStoragePtr& theStorage) { myDumpStorage->addStorage(theStorage); } @@ -486,6 +485,13 @@ void ModelHighAPI_Dumper::addCustomStorage(const ModelHighAPI_Dumper::DumpStorag void ModelHighAPI_Dumper::clearCustomStorage() { myDumpStorage->clear(); + + myNames.clear(); + myModules.clear(); + myFeatureCount.clear(); + myPostponed.clear(); + while (!myEntitiesStack.empty()) + myEntitiesStack.pop(); clearNotDumped(); } @@ -635,7 +641,9 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD *this << aDocName << " = model.moduleDocument()" << std::endl; // dump subfeatures and store result to file - return process(theDoc) && myDumpStorage->exportTo(theFileName, myModules); + bool isOk = process(theDoc) && myDumpStorage->exportTo(theFileName, myModules); + clearCustomStorage(); + return isOk; } bool ModelHighAPI_Dumper::process(const std::shared_ptr& theDoc) diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 660b98dee..f4d0be3eb 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -112,6 +112,7 @@ public: friend class ModelHighAPI_Dumper; }; + typedef std::shared_ptr DumpStoragePtr; /** \class DumpStorageGeom * \ingroup CPPHighAPI @@ -154,7 +155,7 @@ public: /// Add custom storage to collect corresponding dump MODELHIGHAPI_EXPORT - void addCustomStorage(const DumpStorage& theStorage); + void addCustomStorage(const DumpStoragePtr& theStorage); /// Clear custom storages list MODELHIGHAPI_EXPORT void clearCustomStorage(); -- 2.39.2