diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f5bc9db..2fa7344 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -5,11 +5,10 @@ find_path(COMPOUNDFILEREADER_INCLUDE_DIRS "compoundfilereader.h") find_package(tinyxml2 CONFIG REQUIRED) set(SOURCES - ${LIB_SRC_DIR}/CommonBase.cpp ${LIB_SRC_DIR}/Container.cpp ${LIB_SRC_DIR}/ContainerExtractor.cpp ${LIB_SRC_DIR}/DataStream.cpp - # ${LIB_SRC_DIR}/Misc.cpp + ${LIB_SRC_DIR}/GenericParser.cpp ${LIB_SRC_DIR}/PageSettings.cpp ${LIB_SRC_DIR}/Primitives/Point.cpp ${LIB_SRC_DIR}/Primitives/PrimArc.cpp @@ -22,6 +21,7 @@ set(SOURCES ${LIB_SRC_DIR}/Primitives/PrimPolyline.cpp ${LIB_SRC_DIR}/Primitives/PrimRect.cpp ${LIB_SRC_DIR}/Primitives/PrimSymbolVector.cpp + ${LIB_SRC_DIR}/RecordFactory.cpp ${LIB_SRC_DIR}/StreamFactory.cpp ${LIB_SRC_DIR}/Streams/StreamAdminData.cpp ${LIB_SRC_DIR}/Streams/StreamCache.cpp @@ -100,6 +100,7 @@ set(SOURCES set(HEADERS ${LIB_INCLUDE_DIR}/Container.hpp + ${LIB_INCLUDE_DIR}/ContainerContext.hpp ${LIB_INCLUDE_DIR}/ContainerExtractor.hpp ${LIB_INCLUDE_DIR}/DataStream.hpp ${LIB_INCLUDE_DIR}/Enums/Color.hpp @@ -113,8 +114,8 @@ set(HEADERS ${LIB_INCLUDE_DIR}/Enums/Structure.hpp ${LIB_INCLUDE_DIR}/FutureData.hpp ${LIB_INCLUDE_DIR}/General.hpp + ${LIB_INCLUDE_DIR}/GenericParser.hpp ${LIB_INCLUDE_DIR}/PageSettings.hpp - ${LIB_INCLUDE_DIR}/ParserContext.hpp ${LIB_INCLUDE_DIR}/Primitives/Point.hpp ${LIB_INCLUDE_DIR}/Primitives/PrimArc.hpp ${LIB_INCLUDE_DIR}/Primitives/PrimBezier.hpp @@ -125,6 +126,10 @@ set(HEADERS ${LIB_INCLUDE_DIR}/Primitives/PrimPolygon.hpp ${LIB_INCLUDE_DIR}/Primitives/PrimPolyline.hpp ${LIB_INCLUDE_DIR}/Primitives/PrimRect.hpp + ${LIB_INCLUDE_DIR}/Record.hpp + ${LIB_INCLUDE_DIR}/RecordFactory.hpp + ${LIB_INCLUDE_DIR}/Stream.hpp + ${LIB_INCLUDE_DIR}/StreamContext.hpp ${LIB_INCLUDE_DIR}/StreamFactory.hpp ${LIB_INCLUDE_DIR}/Streams/StreamAdminData.hpp ${LIB_INCLUDE_DIR}/Streams/StreamCache.hpp diff --git a/src/CommonBase.cpp b/src/CommonBase.cpp deleted file mode 100644 index 0ac891b..0000000 --- a/src/CommonBase.cpp +++ /dev/null @@ -1,786 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "CommonBase.hpp" -#include "Enums/Primitive.hpp" -#include "Enums/Structure.hpp" -#include "Library.hpp" -#include "Primitives/Point.hpp" -#include "Primitives/PrimArc.hpp" -#include "Primitives/PrimBezier.hpp" -#include "Primitives/PrimBitmap.hpp" -#include "Primitives/PrimCommentText.hpp" -#include "Primitives/PrimEllipse.hpp" -#include "Primitives/PrimLine.hpp" -#include "Primitives/PrimPolygon.hpp" -#include "Primitives/PrimPolyline.hpp" -#include "Primitives/PrimRect.hpp" -#include "Primitives/PrimSymbolVector.hpp" -#include "Structures/StructAlias.hpp" -#include "Structures/StructBookMarkSymbolInst.hpp" -#include "Structures/StructBusEntry.hpp" -#include "Structures/StructERCSymbol.hpp" -#include "Structures/StructERCSymbolInst.hpp" -#include "Structures/StructGeneralProperties.hpp" -#include "Structures/StructGlobal.hpp" -#include "Structures/StructGlobalSymbol.hpp" -#include "Structures/StructGraphicArcInst.hpp" -#include "Structures/StructGraphicBezierInst.hpp" -#include "Structures/StructGraphicBitMapInst.hpp" -#include "Structures/StructGraphicBoxInst.hpp" -#include "Structures/StructGraphicCommentTextInst.hpp" -#include "Structures/StructGraphicEllipseInst.hpp" -#include "Structures/StructGraphicLineInst.hpp" -#include "Structures/StructGraphicOleEmbedInst.hpp" -#include "Structures/StructGraphicPolygonInst.hpp" -#include "Structures/StructGraphicPolylineInst.hpp" -#include "Structures/StructHierarchicSymbol.hpp" -#include "Structures/StructNetDbIdMapping.hpp" -#include "Structures/StructOffPageConnector.hpp" -#include "Structures/StructOffPageSymbol.hpp" -#include "Structures/StructPartInst.hpp" -#include "Structures/StructPinIdxMapping.hpp" -#include "Structures/StructPinShapeSymbol.hpp" -#include "Structures/StructPort.hpp" -#include "Structures/StructPrimitives.hpp" -#include "Structures/StructProperties.hpp" -#include "Structures/StructSthInHierarchy1.hpp" -#include "Structures/StructSthInHierarchy2.hpp" -#include "Structures/StructSthInHierarchy3.hpp" -#include "Structures/StructSthInPages0.hpp" -#include "Structures/StructSymbolBBox.hpp" -#include "Structures/StructSymbolDisplayProp.hpp" -#include "Structures/StructSymbolPinBus.hpp" -#include "Structures/StructSymbolPinScalar.hpp" -#include "Structures/StructT0x10.hpp" -#include "Structures/StructT0x1f.hpp" -#include "Structures/StructT0x34.hpp" -#include "Structures/StructT0x35.hpp" -#include "Structures/StructT0x45.hpp" -#include "Structures/StructT0x5b.hpp" -#include "Structures/StructTitleBlock.hpp" -#include "Structures/StructTitleBlockSymbol.hpp" -#include "Structures/StructWireBus.hpp" -#include "Structures/StructWireScalar.hpp" - - -void CommonBase::discard_until_preamble() -{ - const int patternSize = 4; - std::array buffer = {0}; - - const size_t startOffset = mCtx.get().mDs.get().getCurrentOffset(); - - // Magic number specifying the beginning of a struct - const std::array preamble = {0xff, 0xe4, 0x5c, 0x39}; - - auto shift_left = [](std::array& buffer) - { - for(size_t i = 0u; i < buffer.size() - 1; ++i) - { - buffer[i] = buffer[i + 1]; - } - }; - - while(buffer != preamble) - { - shift_left(buffer); - mCtx.get().mDs.get().read(reinterpret_cast(buffer.data()) + buffer.size() - 1, 1); - - if(mCtx.get().mDs.get().isEoF()) - { - const std::string msg = fmt::format("{}: Unexpectedly reached end-of-file!", - getMethodName(this, __func__)); - - spdlog::debug(msg); - throw std::runtime_error(msg); - } - } - - // Put back the preamble such that it can be parsed in the next step - for(size_t i = 0u; i < preamble.size(); ++i) - { - mCtx.get().mDs.get().putback(preamble[preamble.size() - 1 - i]); - } - - const size_t endOffset = mCtx.get().mDs.get().getCurrentOffset(); - - spdlog::debug("{}: Discarded {} Byte until next preamble", - getMethodName(this, __func__), endOffset - startOffset); -} - - -Structure CommonBase::auto_read_prefixes(FutureDataLst& aFutureDataLst) -{ - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - const size_t startOffset = mCtx.get().mDs.get().getCurrentOffset(); - - const auto logLevel = spdlog::get_level(); - spdlog::set_level(spdlog::level::off); - - bool failed = true; - size_t prefixCtr = 0U; - - // Count from back to make it easier catching long preambles - // that could succeed by mistake if the the algorithm detects - // no errors in a shorter version. - const size_t maxPrefixes = 10U; - for(prefixCtr = maxPrefixes; prefixCtr >= 1U; --prefixCtr) - { - // Reading the prefixes might read beyond EoF in some cases, - // because its just a prediction, we do not care. Therefore - // reset the EoF flag. - mCtx.get().mDs.get().clear(); - - failed = false; - - try - { - FutureDataLst tmpLst{mCtx}; - read_prefixes(prefixCtr, tmpLst); - } - catch(const std::exception& e) - { - failed = true; - } - - mCtx.get().mDs.get().setCurrentOffset(startOffset); - - // Reading the prefixes might read beyond EoF in some cases, - // because its just a prediction, we do not care. Therefore - // reset the EoF flag. - mCtx.get().mDs.get().clear(); - - if(!failed) - { - break; - } - } - - // Reading the prefixes might read beyond EoF in some cases, - // because its just a prediction, we do not care. Therefore - // reset the EoF flag. - mCtx.get().mDs.get().clear(); - - spdlog::set_level(logLevel); - - if(failed) - { - const std::string msg = fmt::format("{}: Could not find valid number of prefixes!" - " (maximum is set to {} but could be higher)", - getMethodName(this, __func__), maxPrefixes); - - spdlog::debug(msg); - throw std::runtime_error(msg); - } - - const Structure structure = read_prefixes(prefixCtr, aFutureDataLst); - - // @todo Looks like each structure type has a fixed number of prefixes - // I.e. figure out the numbers for each structure and move the - // parsing code into the structure specific parser. This should - // get rid of auto_read_prefixes. - spdlog::debug("{}: Found {} prefixes for {}\n", - getMethodName(this, __func__), prefixCtr, ::to_string(structure)); - spdlog::debug(" {}", aFutureDataLst.string()); - - mCtx.get().mDs.get().sanitizeNoEoF(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - return structure; -} - - -Structure CommonBase::auto_read_prefixes(Structure aExpectedStruct, FutureDataLst& aFutureDataLst) -{ - const Structure actualStruct = auto_read_prefixes(aFutureDataLst); - - if(actualStruct != aExpectedStruct) - { - const std::string err = fmt::format("{}: Expected {} but got {}", - getMethodName(this, __func__), ::to_string(aExpectedStruct), ::to_string(actualStruct)); - - spdlog::debug(err); - throw std::runtime_error(err); - } - - return actualStruct; -} - - -Structure CommonBase::auto_read_prefixes(const std::vector& aExpectedOneOfStruct, FutureDataLst& aFutureDataLst) -{ - const Structure actualStruct = auto_read_prefixes(aFutureDataLst); - - const bool foundStructure = std::find(aExpectedOneOfStruct.cbegin(), - aExpectedOneOfStruct.cend(), actualStruct) != aExpectedOneOfStruct.cend(); - - if(!foundStructure) - { - std::vector expectedStrStructs{}; - std::transform(aExpectedOneOfStruct.cbegin(), aExpectedOneOfStruct.cend(), - expectedStrStructs.begin(), [](Structure a){ return ::to_string(a); }); - - const std::string err = fmt::format("{}: Expected one of [{}] but got {}", getMethodName(this, __func__), - std::accumulate(expectedStrStructs.cbegin(), expectedStrStructs.cend(), std::string{", "}), - ::to_string(actualStruct)); - - spdlog::debug(err); - throw std::runtime_error(err); - } - - return actualStruct; -} - - -// Read number of prefixes, where the last one is a short prefix -Structure CommonBase::read_prefixes(size_t aNumber, FutureDataLst& aFutureDataLst) -{ - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - if(aNumber == 0U) - { - throw std::invalid_argument(fmt::format("{}: aNumber = {} but must be > 0!", - getMethodName(this, __func__), aNumber)); - } - - Structure firstStruct; - - for(size_t i = 0U; i < aNumber; ++i) - { - Structure currStruct; - - const size_t preambleOffset = mCtx.get().mDs.get().getCurrentOffset(); - - if(i == aNumber - 1) - { - const auto currPrefix = read_single_prefix_short(); - currStruct = currPrefix.first; - } - else - { - const auto currPrefix = read_single_prefix(); - currStruct = currPrefix.first; - const size_t currStructSize = static_cast(currPrefix.second); - - const FutureData futureData{preambleOffset, currStructSize}; - - aFutureDataLst.push_back(futureData); - } - - if(i == 0U) - { - firstStruct = currStruct; - } - - if(currStruct != firstStruct) - { - const std::string msg = fmt::format("{}: {} != {}", - getMethodName(this, __func__), ::to_string(currStruct), - ::to_string(firstStruct)); - - spdlog::debug(msg); - throw std::runtime_error(msg); - } - } - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - return firstStruct; -} - -std::pair CommonBase::read_single_prefix() -{ - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - const Structure typeId = ToStructure(mCtx.get().mDs.get().readUint8()); - - const uint32_t byteOffset = mCtx.get().mDs.get().readUint32(); - - spdlog::debug("{:>2} = {}: Offset = {}\n", static_cast(typeId), ::to_string(typeId), byteOffset); - - mCtx.get().mDs.get().printUnknownData(4, getMethodName(this, __func__) + ": 0"); - // mCtx.get().mDs.get().assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - return std::pair{typeId, byteOffset}; -} - - -std::pair CommonBase::read_single_prefix_short() -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const Structure typeId = ToStructure(ds.readUint8()); - - const int16_t size = ds.readInt16(); - - spdlog::debug("{:>2} = {}: Size = {}\n", static_cast(typeId), ::to_string(typeId), size); - - if(size >= 0) - { - // @todo This vector needs to be stored in the package, therefore return it to caller - std::vector > nameValueMapping; //!< .first = Name Index, .second = Value Index - - for(int i = 0; i < size; ++i) - { - uint32_t strLstIdxName = ds.readUint32(); - uint32_t strLstIdxValue = ds.readUint32(); - - nameValueMapping.push_back(std::make_pair(strLstIdxName, strLstIdxValue)); - } - - for(size_t i = 0u; i < nameValueMapping.size(); ++i) - { - try - { - const auto getStr = [&, this](uint32_t idx) -> std::string - { - int64_t newIdx = static_cast(idx); - if(gLibrary != nullptr) - { - if(gLibrary->library) - { - return newIdx >= 0 ? gLibrary->library->strLst.at(newIdx) : ""; - } - } - - return ""; - }; - - spdlog::debug(" {}: {} <- {}", i, getStr(nameValueMapping.at(i).first), getStr(nameValueMapping.at(i).second)); - } - catch(const std::exception& e) - { - const std::string msg = fmt::format("{}: Tried to access strLst out of range!\n{}", - getMethodName(this, __func__), e.what()); - - spdlog::debug(msg); - throw std::out_of_range(msg); - } - } - } - else // size < 0 - { - // @todo Why is -1 used? The value 0 would also suffice... - // Until now I only saw it for PinIdxMapping, Properties and SymbolDisplayProp - spdlog::debug("{}: What does {} mean?", ::to_string(typeId), size); // @todo Figure out - } - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - return std::pair{typeId, size}; -} - - -void CommonBase::readPreamble() -{ - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - const std::size_t startOffset = mCtx.get().mDs.get().getCurrentOffset(); - - // Try to find prefix and read trailing data. If - // the prefix is not there, just skip it. - try - { - // Magic number indicating some data - mCtx.get().mDs.get().assumeData({0xff, 0xe4, 0x5c, 0x39}, getMethodName(this, __func__) + " Preamble Check Failed"); - - const uint32_t dataLen = mCtx.get().mDs.get().readUint32(); - mCtx.get().mDs.get().printUnknownData(dataLen, fmt::format("{}: Trailing preamble data", - getMethodName(this, __func__))); - - // spdlog::debug("{}: Found preamble", getMethodName(this, __func__)); - } - catch(const std::runtime_error& err) - { - mCtx.get().mDs.get().setCurrentOffset(startOffset); - - spdlog::debug("{}: Skipping preamble", getMethodName(this, __func__)); - } - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); -} - - -Primitive CommonBase::readPrefixPrimitive() -{ - Primitive primitive1 = ToPrimitive(mCtx.get().mDs.get().readUint8()); - Primitive primitive2 = ToPrimitive(mCtx.get().mDs.get().readUint8()); - - if(primitive1 != primitive2) - { - const std::string msg = fmt::format("{}: Primitives {} != {}", - getMethodName(this, __func__), ::to_string(primitive1), - ::to_string(primitive2)); - - spdlog::debug(msg); - throw std::runtime_error(msg); - } - - return primitive1; -} - - -std::unique_ptr CommonBase::readPrimitive() -{ - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - Primitive typeId = ToPrimitive(mCtx.get().mDs.get().peek(1)[0]); - - std::unique_ptr obj = readPrimitive(typeId); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - return obj; -} - - -std::unique_ptr CommonBase::readPrimitive(Primitive aPrimitive) -{ - auto& ctx = mCtx.get(); - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const size_t startOffset = ds.getCurrentOffset(); - - std::unique_ptr obj{}; - - switch(aPrimitive) - { - case Primitive::Rect: obj = std::make_unique(mCtx); break; - case Primitive::Line: obj = std::make_unique(mCtx); break; - case Primitive::Arc: obj = std::make_unique(mCtx); break; - case Primitive::Ellipse: obj = std::make_unique(mCtx); break; - case Primitive::Polygon: obj = std::make_unique(mCtx); break; - case Primitive::Polyline: obj = std::make_unique(mCtx); break; - case Primitive::CommentText: obj = std::make_unique(mCtx); break; - case Primitive::Bitmap: obj = std::make_unique(mCtx); break; - case Primitive::SymbolVector: obj = std::make_unique(mCtx); break; - case Primitive::Bezier: obj = std::make_unique(mCtx); break; - default: - { - const std::string msg = fmt::format("{}: Primitive {} is not implemented!", - getMethodName(this, __func__), ::to_string(aPrimitive)); - - spdlog::debug(msg); - - if(!mCtx.get().mCfg.mSkipUnknownPrim) - { - throw std::runtime_error(msg); - } - - spdlog::debug("{}: Skipping unimplemented Primitive {}", - getMethodName(this, __func__), ::to_string(aPrimitive)); - - const uint32_t byteLength = ds.readUint32(); - - ds.printUnknownData(byteLength - sizeof(byteLength), - fmt::format("{} data", ::to_string(aPrimitive))); - - readPreamble(); - - break; - } - } - - if(obj.get() != nullptr) - { - try - { - obj->read(); - } - catch(...) - { - if(ctx.mCfg.mSkipInvalidPrim) - { - spdlog::debug("{}: Skipping invalid Primitive {}", - getMethodName(this, __func__), ::to_string(aPrimitive)); - - // Reset file position to the state before - // the structure was parsed and failed - ds.setCurrentOffset(startOffset); - - // Previous read operations might have read beyond EoF, - // therefore reset the EoF flag. - ds.clear(); - - const uint32_t byteLength = ds.readUint32(); - - ds.printUnknownData(byteLength - sizeof(byteLength), - fmt::format("{} data", ::to_string(aPrimitive))); - - readPreamble(); - } - else - { - throw; - } - } - } - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - return obj; -} - - -std::unique_ptr CommonBase::readStructure() -{ - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - Structure typeId = ToStructure(mCtx.get().mDs.get().peek(1)[0]); - - std::unique_ptr obj = readStructure(typeId); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.get().mDs.get().getCurrentOffset())); - - return obj; -} - - -std::unique_ptr CommonBase::readStructure(Structure aStructure) -{ - auto& ctx = mCtx.get(); - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const size_t startOffset = ds.getCurrentOffset(); - - std::unique_ptr obj{}; - - switch(aStructure) - { - case Structure::Alias: obj = std::make_unique(mCtx); break; - case Structure::BookMarkSymbolInst: obj = std::make_unique(mCtx); break; - case Structure::BusEntry: obj = std::make_unique(mCtx); break; - case Structure::ERCSymbol: obj = std::make_unique(mCtx); break; - case Structure::ERCSymbolInst: obj = std::make_unique(mCtx); break; - case Structure::Global: obj = std::make_unique(mCtx); break; - case Structure::GlobalSymbol: obj = std::make_unique(mCtx); break; - case Structure::GraphicArcInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicBezierInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicBitMapInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicBoxInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicCommentTextInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicEllipseInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicLineInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicOleEmbedInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicPolygonInst: obj = std::make_unique(mCtx); break; - case Structure::GraphicPolylineInst: obj = std::make_unique(mCtx); break; - case Structure::NetDbIdMapping: obj = std::make_unique(mCtx); break; - case Structure::OffPageConnector: obj = std::make_unique(mCtx); break; - case Structure::OffPageSymbol: obj = std::make_unique(mCtx); break; - case Structure::PartInst: obj = std::make_unique(mCtx); break; - case Structure::PinIdxMapping: obj = std::make_unique(mCtx); break; - case Structure::PinShapeSymbol: obj = std::make_unique(mCtx); break; - case Structure::Port: obj = std::make_unique(mCtx); break; - case Structure::PortSymbol: obj = std::make_unique(mCtx); break; - case Structure::Primitives: obj = std::make_unique(mCtx); break; - case Structure::Properties: obj = std::make_unique(mCtx); break; - case Structure::SthInHierarchy1: obj = std::make_unique(mCtx); break; - case Structure::SthInHierarchy2: obj = std::make_unique(mCtx); break; - case Structure::SthInHierarchy3: obj = std::make_unique(mCtx); break; - case Structure::SthInPages0: obj = std::make_unique(mCtx); break; - case Structure::SymbolDisplayProp: obj = std::make_unique(mCtx); break; - case Structure::SymbolPinBus: obj = std::make_unique(mCtx); break; - case Structure::SymbolPinScalar: obj = std::make_unique(mCtx); break; - case Structure::T0x10: obj = std::make_unique(mCtx); break; - case Structure::T0x1f: obj = std::make_unique(mCtx); break; - case Structure::T0x34: obj = std::make_unique(mCtx); break; - case Structure::T0x35: obj = std::make_unique(mCtx); break; - case Structure::T0x45: obj = std::make_unique(mCtx); break; - case Structure::T0x5b: obj = std::make_unique(mCtx); break; - case Structure::TitleBlock: obj = std::make_unique(mCtx); break; - case Structure::TitleBlockSymbol: obj = std::make_unique(mCtx); break; - case Structure::WireBus: obj = std::make_unique(mCtx); break; - case Structure::WireScalar: obj = std::make_unique(mCtx); break; - default: - { - const std::string msg = fmt::format("{}: Structure {} is unimplemented!", - getMethodName(this, __func__), ::to_string(aStructure)); - - spdlog::debug(msg); - - if(!ctx.mCfg.mSkipUnknownStruct) - { - throw std::runtime_error(msg); - } - - spdlog::debug("{}: Skipping unimplemented Structure {}", - getMethodName(this, __func__), ::to_string(aStructure)); - - FutureDataLst localFutureDataLst{mCtx}; - - auto_read_prefixes(localFutureDataLst); - - localFutureDataLst.readRestOfStructure(); - - break; - } - } - - if(obj) - { - try - { - obj->read(); - } - catch(...) - { - if(ctx.mCfg.mSkipInvalidStruct) - { - spdlog::debug("{}: Skipping invalid Structure {}", - getMethodName(this, __func__), ::to_string(aStructure)); - - // Reset file position to the state before - // the structure was parsed and failed - ds.setCurrentOffset(startOffset); - - // Previous read operations might have read beyond EoF, - // therefore reset the EoF flag. - ds.clear(); - - FutureDataLst localFutureDataLst{mCtx}; - - auto_read_prefixes(localFutureDataLst); - - localFutureDataLst.readRestOfStructure(); - } - else - { - throw; - } - } - } - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - return obj; -} - - -bool CommonBase::tryRead(std::function aFunction) -{ - auto& ds = mCtx.get().mDs.get(); - - const auto offsetBeforeTest = ds.getCurrentOffset(); - bool checkFailed = false; - - try - { - aFunction(); - } - catch(...) - { - checkFailed = true; - } - - ds.setCurrentOffset(offsetBeforeTest); - - return !checkFailed; -} - - -void CommonBase::checkInterpretedDataLen(const std::string& aFuncName, size_t aStartOffset, size_t aEndOffset, size_t aExpectedLen) -{ - if(aStartOffset > aEndOffset) - { - throw std::invalid_argument("Start offset must be smaller or equal to end offset!"); - } - - const size_t actuallLen = aEndOffset - aStartOffset; - - if(actuallLen != aExpectedLen) - { - throw MisinterpretedData(aFuncName.c_str(), aStartOffset, aExpectedLen, aEndOffset); - } -} - - -FileFormatVersion CommonBase::predictVersion() -{ - FileFormatVersion prediction = FileFormatVersion::Unknown; - - const std::vector versions{ - FileFormatVersion::A, - FileFormatVersion::B, - FileFormatVersion::C, - FileFormatVersion::D, - FileFormatVersion::E, - FileFormatVersion::F, - FileFormatVersion::G, - FileFormatVersion::H, - FileFormatVersion::I, - FileFormatVersion::J, - FileFormatVersion::K, - FileFormatVersion::L, - FileFormatVersion::M, - FileFormatVersion::N, - FileFormatVersion::O, - FileFormatVersion::P - }; - - const size_t initial_offset = mCtx.get().mDs.get().getCurrentOffset(); - - // Testing different versions on a try and error basis - // should not write into log files - const auto logLevel = spdlog::get_level(); - spdlog::set_level(spdlog::level::off); - - for(const auto& version : versions) - { - bool found = true; - - try - { - read(version); - } - catch(...) - { - found = false; - } - - mCtx.get().mDs.get().setCurrentOffset(initial_offset); - - if(found) - { - prediction = version; - break; - } - } - - // Restore user log level - spdlog::set_level(logLevel); - - spdlog::debug("{}: Predicted version to be {}", - getMethodName(this, __func__), magic_enum::enum_name(prediction)); - - if(prediction == FileFormatVersion::Unknown) - { - // @todo Fix this hack - // Set to previous default value - // s.t. tests not fail - prediction = FileFormatVersion::C; - spdlog::debug("{}: Setting version to {} anyway", - getMethodName(this, __func__), magic_enum::enum_name(prediction)); - } - - return prediction; -} \ No newline at end of file diff --git a/src/Container.cpp b/src/Container.cpp index e9728aa..21cbabe 100644 --- a/src/Container.cpp +++ b/src/Container.cpp @@ -12,13 +12,13 @@ #include #include #include +#include #include #include #include #include -#include "CommonBase.hpp" #include "Container.hpp" #include "ContainerExtractor.hpp" #include "DataStream.hpp" @@ -34,6 +34,7 @@ #include "General.hpp" #include "Library.hpp" #include "PinShape.hpp" +#include "Stream.hpp" #include "StreamFactory.hpp" @@ -42,15 +43,12 @@ namespace fs = std::filesystem; // @todo Add ContainerContext and ParserContext where ContainerContext is shared by all ParserContexts, maybe even derived from it? Library* gLibrary = new Library{}; -FileType gFileType = FileType::Library; // @todo move to parser context -FileFormatVersion gFileFormatVersion = FileFormatVersion::C; // @todo move to parser context Container::Container(const fs::path& aCfbfContainer, ParserConfig aCfg) : - mFileCtr{0U}, mFileErrCtr{0U}, tmpCtx{"", "", "", aCfg}, mCtx{tmpCtx}, mCfg{aCfg} + mFileCtr{0U}, mFileErrCtr{0U}, mCtx{aCfbfContainer, "", aCfg, *this}, mCfg{aCfg}, mStreams{} { - gFileType = getFileTypeByExtension(aCfbfContainer); - mInputCfbfFile = aCfbfContainer; + mCtx.mFileType = getFileTypeByExtension(aCfbfContainer); // Extract to a unique folder in case two similar named files // are extracted at the same time. E.g. in parallel execution. @@ -60,7 +58,7 @@ Container::Container(const fs::path& aCfbfContainer, ParserConfig aCfg) : const std::string uuid = fmt::format("{:08x}{:08x}{:08x}{:08x}", gen(), gen(), gen(), gen()); const fs::path extractTo = fs::temp_directory_path() / "OpenOrCadParser" / uuid; - mExtractedCfbfPath = extractContainer(aCfbfContainer, extractTo); + mCtx.mExtractedCfbfPath = extractContainer(aCfbfContainer, extractTo); spdlog::debug("Using parser configuration:"); spdlog::debug(to_string(mCfg)); @@ -72,21 +70,69 @@ Container::~Container() if(!mCfg.mKeepTmpFiles) { // Remove temporary extracted files - fs::remove_all(mExtractedCfbfPath.parent_path()); + fs::remove_all(mCtx.mExtractedCfbfPath.parent_path()); - spdlog::debug("Deleted CFBF container at `{}`", mExtractedCfbfPath.string()); + spdlog::debug("Deleted CFBF container at `{}`", mCtx.mExtractedCfbfPath.string()); } } + +void Container::parseLibraryThread(std::vector*> aStreamList) +{ + for(auto& stream : aStreamList) + { + bool parsedSuccessfully = true; + try + { + (*stream)->mCtx.mAttemptedParsing = true; + (*stream)->openFile(); + (*stream)->read(); + (*stream)->closeFile(); + } + catch(...) + { + parsedSuccessfully = false; + exceptionHandling(); + } + + (*stream)->mCtx.mParsedSuccessfully = parsedSuccessfully; + } +} + + +// Equally distribute elements into new lists of pointers to the original elements +template +std::vector> equallyDistributeElementsIntoLists( + std::size_t aListCount, std::vector& aElements) +{ + std::vector> lists{}; + + lists.resize(aListCount); + + std::size_t listIdx{0U}; + + for(auto& element : aElements) + { + lists.at(listIdx).push_back(&element); + listIdx = (listIdx + 1U) % aListCount; + } + + return lists; +} + /** * @brief Parse the whole library. */ void Container::parseLibrary() { - spdlog::info("Start parsing library located at {}", mExtractedCfbfPath.string()); + const std::size_t threadCount{1U}; + + spdlog::info("Using {} threads", threadCount); + + spdlog::info("Start parsing library located at {}", mCtx.mExtractedCfbfPath.string()); // Parse all streams in the container i.e. files in the file system - for(const auto& dir_entry : fs::recursive_directory_iterator(mExtractedCfbfPath)) + for(const auto& dir_entry : fs::recursive_directory_iterator(mCtx.mExtractedCfbfPath)) { if(!dir_entry.is_regular_file()) { @@ -97,29 +143,48 @@ void Container::parseLibrary() ++mFileCtr; - std::unique_ptr stream; - - ParserContext ctx{mInputCfbfFile, remainingFile, mExtractedCfbfPath, mCfg}; - mCtx = ctx; + auto stream = StreamFactory::build(mCtx, remainingFile); - const auto streamLoc = getCfbfStreamLocationFromFileSytemLayout(remainingFile, mExtractedCfbfPath); - stream = StreamFactory::build(ctx, streamLoc); - - if(nullptr == stream) + if(!stream) { continue; } - try + mStreams.push_back(std::move(stream)); + } + + auto threadJobList = equallyDistributeElementsIntoLists>(threadCount, mStreams); + + for(std::size_t i{0U}; i < threadJobList.size(); ++i) + { + spdlog::info("Assigning thread {} with the following {}/{} jobs:", + i, threadJobList.at(i).size(), mFileCtr); + + const auto& threadJobs = threadJobList.at(i); + + for(const auto& job : threadJobs) { - openFile(remainingFile); - stream->read(); - closeFile(); + spdlog::debug(" {}", (*job)->mCtx.mInputStream.string()); } - catch(...) + } + + std::vector threadList; + + for(auto& threadJobs : threadJobList) + { + threadList.push_back(std::thread{&Container::parseLibraryThread, this, threadJobs}); + } + + for(auto& thread : threadList) + { + thread.join(); + } + + for(const auto& stream : mStreams) + { + if(!stream->mCtx.mParsedSuccessfully.value_or(false)) { - mCtx.get().mFinishedParsing = true; - exceptionHandling(); + mFileErrCtr++; } } @@ -142,12 +207,11 @@ void Container::exceptionHandling() } catch(const std::exception& e) { - ++mFileErrCtr; - spdlog::error(fmt::format(fg(fmt::color::crimson), "--------ERROR REPORT--------")); - spdlog::error(fmt::format(fg(fmt::color::crimson), "Input Container: {}", mCtx.get().mInputCfbfFile.string())); - spdlog::error(fmt::format(fg(fmt::color::crimson), "Current File: {}", mCtx.get().mInputStream.string())); - spdlog::error(fmt::format(fg(fmt::color::crimson), mCtx.get().mDs.get().getCurrentOffsetStrMsg())); + spdlog::error(fmt::format(fg(fmt::color::crimson), "Input Container: {}", mCtx.mInputCfbfFile.string())); + // @todo + // spdlog::error(fmt::format(fg(fmt::color::crimson), "Current File: {}", mCtx.mInputStream.string())); + // spdlog::error(fmt::format(fg(fmt::color::crimson), mCtx.mDs.getCurrentOffsetStrMsg())); spdlog::error(fmt::format(fg(fmt::color::crimson), "\nError Message: {}\n\n", e.what())); } catch(...) @@ -170,13 +234,13 @@ fs::path Container::extractContainer(const fs::path& aFile, const fs::path& aOut fs::path Container::extractContainer(const fs::path& aOutDir) const { - return extractContainer(mInputCfbfFile, aOutDir); + return extractContainer(mCtx.mInputCfbfFile, aOutDir); } void Container::printContainerTree() const { - ContainerExtractor extractor{mInputCfbfFile}; + ContainerExtractor extractor{mCtx.mInputCfbfFile}; extractor.printContainerTree(); } @@ -209,22 +273,4 @@ FileType Container::getFileTypeByExtension(const fs::path& aFile) const } return fileType; -} - - -void Container::openFile(const fs::path& aInputStream) -{ - spdlog::info("Opening file: {}", aInputStream.string()); - - spdlog::info("File contains {} byte.", fs::file_size(aInputStream)); -} - - -void Container::closeFile() -{ - spdlog::info("Closing file: {}", mCtx.get().mInputStream.string()); - - mCtx.get().mDs.get().close(); - - mCtx.get().mFinishedParsing = true; } \ No newline at end of file diff --git a/src/Container.hpp b/src/Container.hpp index 414a569..42888db 100644 --- a/src/Container.hpp +++ b/src/Container.hpp @@ -7,19 +7,25 @@ #include #include #include +#include +#include #include #include #include +#include "ContainerContext.hpp" #include "DataStream.hpp" #include "Enums/Primitive.hpp" #include "Enums/Structure.hpp" #include "FutureData.hpp" #include "General.hpp" #include "Library.hpp" -#include "ParserContext.hpp" #include "Primitives/PrimBase.hpp" +#include "Stream.hpp" + + +class StreamLibrary; namespace fs = std::filesystem; @@ -38,9 +44,9 @@ class Container return mFileErrCtr; } - ParserContext& getContext() + ContainerContext& getContext() { - return mCtx.get(); + return mCtx; } /** @@ -77,6 +83,7 @@ class Container // -------------- Read Container --------------- // --------------------------------------------- + void parseLibraryThread(std::vector*> aStreamList); void parseLibrary(); Library& getLibrary() const @@ -84,21 +91,37 @@ class Container return *gLibrary; } + std::optional getStreamLibrary() const + { + for(auto& stream : mStreams) + { + if(!stream) + { + continue; + } + + const std::vector> pattern = {"Library"}; + if(stream->mCtx.mCfbfStreamLocation.matches_pattern(pattern)) + { + return dynamic_cast(stream.get()); + } + } + + return std::nullopt; + } + private: - void openFile(const fs::path& aFile); - void closeFile(); void exceptionHandling(); size_t mFileCtr; //!< Counts all files that were opened for parsing size_t mFileErrCtr; //!< Counts all files that failed somewhere - fs::path mInputCfbfFile; - fs::path mExtractedCfbfPath; - - ParserContext tmpCtx; - std::reference_wrapper mCtx; + ContainerContext mCtx; ParserConfig mCfg; + + // List of streams in the CFBF container + std::vector> mStreams; }; diff --git a/src/ContainerContext.hpp b/src/ContainerContext.hpp new file mode 100644 index 0000000..bf60589 --- /dev/null +++ b/src/ContainerContext.hpp @@ -0,0 +1,185 @@ +#ifndef CONTAINERCONTEXT_HPP +#define CONTAINERCONTEXT_HPP + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" + + +class Container; + + +namespace fs = std::filesystem; + +class CfbfStreamLocation +{ +public: + CfbfStreamLocation( + const fs::path& aStreamPath, const fs::path& aExtractedCfbfPath) + { + std::vector streamLocation{}; + + // The layout in the filesystem is equal + // to the one inside the CFBF container + fs::path relPathStreamLoc = fs::relative(aStreamPath, aExtractedCfbfPath); + + for(const auto& pathPart : relPathStreamLoc) + { + streamLocation.push_back(pathPart); + } + + if(!streamLocation.empty()) + { + // Remove file extension (`.bin`) + streamLocation.back() = fs::path{streamLocation.back()}.replace_extension(); + } + + mStreamLocation = std::move(streamLocation); + } + + const std::vector& get_vector() const + { + return mStreamLocation; + } + + /** + * Check if the CfbfStreamLocation matches the given pattern. Note + * that the vector size needs to be equal and all given string parts + * need to match. As a wildcard part, you can use std::nullopt + */ + bool matches_pattern(const std::vector>& aPattern) + { + if(get_vector().size() != aPattern.size()) + { + return false; + } + + // Both vectors have the same length + for(std::size_t i{0U}; i < get_vector().size(); ++i) + { + // Check for wildcard and skip if found + if(!aPattern.at(i).has_value()) + { + continue; + } + + // Check that the location part is equal + if(get_vector().at(i) != aPattern.at(i).value()) + { + return false; + } + } + + return true; + } + +private: + + std::vector mStreamLocation{}; +}; + + +[[maybe_unused]] +std::string to_string(const CfbfStreamLocation& aLocation) +{ + std::string locStr{}; + for(const auto& locPart : aLocation.get_vector()) + { + locStr += "/" + locPart; + } + + return locStr; +} + +[[maybe_unused]] +bool operator==(const CfbfStreamLocation& aLhs, const std::vector& aRhs) +{ + return aLhs.get_vector() == aRhs; +} + +[[maybe_unused]] +bool operator==(const std::vector& aLhs, const CfbfStreamLocation& aRhs) +{ + return aRhs == aLhs; +} + +[[maybe_unused]] +bool operator==(const CfbfStreamLocation& aLhs, const CfbfStreamLocation& aRhs) +{ + return aLhs.get_vector() == aRhs.get_vector(); +} + + + +struct ParserConfig +{ + bool mSkipUnknownPrim{true}; //!< Unknown primitives should be skipped during parsing + bool mSkipInvalidPrim{true}; //!< Invalid primitives should be skipped during parsing + + bool mSkipUnknownStruct{true}; //!< Unknown structures should be skipped during parsing + bool mSkipInvalidStruct{true}; //!< Invalid structures should be skipped during parsing + + bool mKeepTmpFiles{false}; //!< Do not delete temporary files after parser completed +}; + + +[[maybe_unused]] +static std::string to_string(const ParserConfig& aCfg) +{ + std::string str; + str += fmt::format("mSkipUnknownPrim = {}\n", aCfg.mSkipUnknownPrim); + str += fmt::format("mSkipInvalidPrim = {}\n", aCfg.mSkipInvalidPrim); + str += fmt::format("mSkipUnknownStruct = {}\n", aCfg.mSkipUnknownStruct); + str += fmt::format("mSkipInvalidStruct = {}\n", aCfg.mSkipInvalidStruct); + str += fmt::format("mKeepTmpFiles = {}\n", aCfg.mKeepTmpFiles); + + return str; +} + + +class ContainerContext +{ +public: + + ContainerContext(const fs::path& aInputCfbfFile, + const fs::path& aExtractedCfbfPath, ParserConfig aCfg, Container& aContainer) : mContainer{aContainer} + { + mInputCfbfFile = aInputCfbfFile; + mExtractedCfbfPath = aExtractedCfbfPath; + mCfg = aCfg; + mFileFormatVersion = FileFormatVersion::C; + mFileType = FileType::Library; + } + + ContainerContext(const ContainerContext& aCtx) : mContainer{aCtx.mContainer} + { + mInputCfbfFile = aCtx.mInputCfbfFile; + mExtractedCfbfPath = aCtx.mExtractedCfbfPath; + mCfg = aCtx.mCfg; + mFileFormatVersion = aCtx.mFileFormatVersion; + mFileType = aCtx.mFileType; + } + + Container& mContainer; + + fs::path mInputCfbfFile; //!< Input CFBF container + fs::path mExtractedCfbfPath; + + ParserConfig mCfg; + + FileFormatVersion mFileFormatVersion; + FileType mFileType; +}; + + +#endif // CONTAINERCONTEXT_HPP \ No newline at end of file diff --git a/src/DataStream.hpp b/src/DataStream.hpp index e87923a..ce2596e 100644 --- a/src/DataStream.hpp +++ b/src/DataStream.hpp @@ -4,11 +4,24 @@ #include #include +#include #include +#include +#include #include #include +#include #include +#include "Enums/Primitive.hpp" +#include "Enums/Structure.hpp" +#include "General.hpp" +// #include "Record.hpp" + + +class FutureDataLst; +class Record; + namespace fs = std::filesystem; diff --git a/src/FutureData.hpp b/src/FutureData.hpp index 37ea3f6..6f07049 100644 --- a/src/FutureData.hpp +++ b/src/FutureData.hpp @@ -12,7 +12,7 @@ #include #include "General.hpp" -#include "ParserContext.hpp" +#include "StreamContext.hpp" class FutureData @@ -72,7 +72,7 @@ class FutureDataLst : public std::vector { public: - FutureDataLst(ParserContext& aCtx) : std::vector{}, mCtx{aCtx} + FutureDataLst(StreamContext& aCtx) : std::vector{}, mCtx{aCtx} { } std::optional getByStartOffset(std::size_t aAbsStartOffset) const @@ -143,7 +143,7 @@ class FutureDataLst : public std::vector void checkpoint() { - const size_t currOffset = mCtx.get().mDs.get().getCurrentOffset(); + const size_t currOffset = mCtx.get().mDs.getCurrentOffset(); const auto cmp = [&currOffset] (FutureData aFutureData) -> bool { return aFutureData.getStopOffset() == currOffset; }; @@ -227,7 +227,7 @@ class FutureDataLst : public std::vector std::optional getNextCheckpointPos() const { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.get().mDs; const size_t curPos = ds.getCurrentOffset(); @@ -247,7 +247,7 @@ class FutureDataLst : public std::vector void readUntilNextFutureData(const std::string& aComment = "") { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.get().mDs; const size_t curPos = ds.getCurrentOffset(); @@ -289,7 +289,7 @@ class FutureDataLst : public std::vector endPos = std::max(static_cast(data.getStopOffset()), endPos); } - const int64_t curPos = static_cast(mCtx.get().mDs.get().getCurrentOffset()); + const int64_t curPos = static_cast(mCtx.get().mDs.getCurrentOffset()); const int64_t byteDiff = endPos - curPos; @@ -299,7 +299,7 @@ class FutureDataLst : public std::vector " Expected it to end at 0x{:08x} but ended at 0x{:08x}. Too small by {} Byte.", getMethodName(this, __func__), endPos, curPos, std::abs(byteDiff)); - mCtx.get().mDs.get().printUnknownData(byteDiff, msg); + mCtx.get().mDs.printUnknownData(byteDiff, msg); } else if(byteDiff < 0) { @@ -321,7 +321,7 @@ class FutureDataLst : public std::vector private: - std::reference_wrapper mCtx; + std::reference_wrapper mCtx; }; diff --git a/src/General.hpp b/src/General.hpp index 8600597..cb02ae5 100644 --- a/src/General.hpp +++ b/src/General.hpp @@ -24,9 +24,6 @@ namespace fs = std::filesystem; enum class FileType; enum class FileFormatVersion; -extern FileType gFileType; -extern FileFormatVersion gFileFormatVersion; - /** * @brief Version of the file format. diff --git a/src/GenericParser.cpp b/src/GenericParser.cpp new file mode 100644 index 0000000..6a2ae23 --- /dev/null +++ b/src/GenericParser.cpp @@ -0,0 +1,657 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "Enums/Primitive.hpp" +#include "Enums/Structure.hpp" +#include "FutureData.hpp" +#include "GenericParser.hpp" +#include "Library.hpp" +#include "Record.hpp" +#include "RecordFactory.hpp" +#include "Stream.hpp" + + +void GenericParser::discard_until_preamble() +{ + const int patternSize = 4; + std::array buffer = {0}; + + const size_t startOffset = mCtx.mDs.getCurrentOffset(); + + // Magic number specifying the beginning of a struct + const std::array preamble = {0xff, 0xe4, 0x5c, 0x39}; + + auto shift_left = [](std::array& buffer) + { + for(size_t i = 0u; i < buffer.size() - 1; ++i) + { + buffer[i] = buffer[i + 1]; + } + }; + + while(buffer != preamble) + { + shift_left(buffer); + mCtx.mDs.read(reinterpret_cast(buffer.data()) + buffer.size() - 1, 1); + + if(mCtx.mDs.isEoF()) + { + const std::string msg = fmt::format("{}: Unexpectedly reached end-of-file!", + getMethodName(this, __func__)); + + spdlog::debug(msg); + throw std::runtime_error(msg); + } + } + + // Put back the preamble such that it can be parsed in the next step + for(size_t i = 0u; i < preamble.size(); ++i) + { + mCtx.mDs.putback(preamble[preamble.size() - 1 - i]); + } + + const size_t endOffset = mCtx.mDs.getCurrentOffset(); + + spdlog::debug("{}: Discarded {} Byte until next preamble", + getMethodName(this, __func__), endOffset - startOffset); +} + + +Structure GenericParser::auto_read_prefixes(FutureDataLst& aFutureDataLst) +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + const size_t startOffset = mCtx.mDs.getCurrentOffset(); + + const auto logLevel = spdlog::get_level(); + spdlog::set_level(spdlog::level::off); + + bool failed = true; + size_t prefixCtr = 0U; + + // Count from back to make it easier catching long preambles + // that could succeed by mistake if the the algorithm detects + // no errors in a shorter version. + const size_t maxPrefixes = 10U; + for(prefixCtr = maxPrefixes; prefixCtr >= 1U; --prefixCtr) + { + // Reading the prefixes might read beyond EoF in some cases, + // because its just a prediction, we do not care. Therefore + // reset the EoF flag. + mCtx.mDs.clear(); + + failed = false; + + try + { + FutureDataLst tmpLst{mCtx}; + read_prefixes(prefixCtr, tmpLst); + } + catch(const std::exception& e) + { + failed = true; + } + + mCtx.mDs.setCurrentOffset(startOffset); + + // Reading the prefixes might read beyond EoF in some cases, + // because its just a prediction, we do not care. Therefore + // reset the EoF flag. + mCtx.mDs.clear(); + + if(!failed) + { + break; + } + } + + // Reading the prefixes might read beyond EoF in some cases, + // because its just a prediction, we do not care. Therefore + // reset the EoF flag. + mCtx.mDs.clear(); + + spdlog::set_level(logLevel); + + if(failed) + { + const std::string msg = fmt::format("{}: Could not find valid number of prefixes!" + " (maximum is set to {} but could be higher)", + getMethodName(this, __func__), maxPrefixes); + + spdlog::debug(msg); + throw std::runtime_error(msg); + } + + const Structure structure = read_prefixes(prefixCtr, aFutureDataLst); + + // @todo Looks like each structure type has a fixed number of prefixes + // I.e. figure out the numbers for each structure and move the + // parsing code into the structure specific parser. This should + // get rid of auto_read_prefixes. + spdlog::debug("{}: Found {} prefixes for {}\n", + getMethodName(this, __func__), prefixCtr, ::to_string(structure)); + spdlog::debug(" {}", aFutureDataLst.string()); + + mCtx.mDs.sanitizeNoEoF(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return structure; +} + + +Structure GenericParser::auto_read_prefixes(Structure aExpectedStruct, FutureDataLst& aFutureDataLst) +{ + const Structure actualStruct = auto_read_prefixes(aFutureDataLst); + + if(actualStruct != aExpectedStruct) + { + const std::string err = fmt::format("{}: Expected {} but got {}", + getMethodName(this, __func__), ::to_string(aExpectedStruct), ::to_string(actualStruct)); + + spdlog::debug(err); + throw std::runtime_error(err); + } + + return actualStruct; +} + + +Structure GenericParser::auto_read_prefixes(const std::vector& aExpectedOneOfStruct, FutureDataLst& aFutureDataLst) +{ + const Structure actualStruct = auto_read_prefixes(aFutureDataLst); + + const bool foundStructure = std::find(aExpectedOneOfStruct.cbegin(), + aExpectedOneOfStruct.cend(), actualStruct) != aExpectedOneOfStruct.cend(); + + if(!foundStructure) + { + std::vector expectedStrStructs{}; + std::transform(aExpectedOneOfStruct.cbegin(), aExpectedOneOfStruct.cend(), + expectedStrStructs.begin(), [](Structure a){ return ::to_string(a); }); + + const std::string err = fmt::format("{}: Expected one of [{}] but got {}", getMethodName(this, __func__), + std::accumulate(expectedStrStructs.cbegin(), expectedStrStructs.cend(), std::string{", "}), + ::to_string(actualStruct)); + + spdlog::debug(err); + throw std::runtime_error(err); + } + + return actualStruct; +} + + +// Read number of prefixes, where the last one is a short prefix +Structure GenericParser::read_prefixes(size_t aNumber, FutureDataLst& aFutureDataLst) +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + if(aNumber == 0U) + { + throw std::invalid_argument(fmt::format("{}: aNumber = {} but must be > 0!", + getMethodName(this, __func__), aNumber)); + } + + Structure firstStruct; + + for(size_t i = 0U; i < aNumber; ++i) + { + Structure currStruct; + + const size_t preambleOffset = mCtx.mDs.getCurrentOffset(); + + if(i == aNumber - 1) + { + const auto currPrefix = read_single_prefix_short(); + currStruct = currPrefix.first; + } + else + { + const auto currPrefix = read_single_prefix(); + currStruct = currPrefix.first; + const size_t currStructSize = static_cast(currPrefix.second); + + const FutureData futureData{preambleOffset, currStructSize}; + + aFutureDataLst.push_back(futureData); + } + + if(i == 0U) + { + firstStruct = currStruct; + } + + if(currStruct != firstStruct) + { + const std::string msg = fmt::format("{}: {} != {}", + getMethodName(this, __func__), ::to_string(currStruct), + ::to_string(firstStruct)); + + spdlog::debug(msg); + throw std::runtime_error(msg); + } + } + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return firstStruct; +} + +std::pair GenericParser::read_single_prefix() +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + const Structure typeId = ToStructure(mCtx.mDs.readUint8()); + + const uint32_t byteOffset = mCtx.mDs.readUint32(); + + spdlog::debug("{:>2} = {}: Offset = {}\n", static_cast(typeId), ::to_string(typeId), byteOffset); + + mCtx.mDs.printUnknownData(4, getMethodName(this, __func__) + ": 0"); + // assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return std::pair{typeId, byteOffset}; +} + + +std::pair GenericParser::read_single_prefix_short() +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + const Structure typeId = ToStructure(mCtx.mDs.readUint8()); + + const int16_t size = mCtx.mDs.readInt16(); + + spdlog::debug("{:>2} = {}: Size = {}\n", static_cast(typeId), ::to_string(typeId), size); + + if(size >= 0) + { + // @todo This vector needs to be stored in the package, therefore return it to caller + std::vector > nameValueMapping; //!< .first = Name Index, .second = Value Index + + for(int i = 0; i < size; ++i) + { + uint32_t strLstIdxName = mCtx.mDs.readUint32(); + uint32_t strLstIdxValue = mCtx.mDs.readUint32(); + + nameValueMapping.push_back(std::make_pair(strLstIdxName, strLstIdxValue)); + } + + for(size_t i = 0u; i < nameValueMapping.size(); ++i) + { + try + { + const auto getStr = [&, this](uint32_t idx) -> std::string + { + int64_t newIdx = static_cast(idx); + if(gLibrary != nullptr) + { + if(gLibrary->library) + { + return newIdx >= 0 ? gLibrary->library->strLst.at(newIdx) : ""; + } + } + + return ""; + }; + + spdlog::debug(" {}: {} <- {}", i, getStr(nameValueMapping.at(i).first), getStr(nameValueMapping.at(i).second)); + } + catch(const std::exception& e) + { + const std::string msg = fmt::format("{}: Tried to access strLst out of range!\n{}", + getMethodName(this, __func__), e.what()); + + spdlog::debug(msg); + throw std::out_of_range(msg); + } + } + } + else // size < 0 + { + // @todo Why is -1 used? The value 0 would also suffice... + // Until now I only saw it for PinIdxMapping, Properties and SymbolDisplayProp + spdlog::debug("{}: What does {} mean?", ::to_string(typeId), size); // @todo Figure out + } + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return std::pair{typeId, size}; +} + + +void GenericParser::readPreamble() +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + const std::size_t startOffset = mCtx.mDs.getCurrentOffset(); + + // Try to find prefix and read trailing data. If + // the prefix is not there, just skip it. + try + { + // Magic number indicating some data + mCtx.mDs.assumeData({0xff, 0xe4, 0x5c, 0x39}, getMethodName(this, __func__) + " Preamble Check Failed"); + + const uint32_t dataLen = mCtx.mDs.readUint32(); + mCtx.mDs.printUnknownData(dataLen, fmt::format("{}: Trailing preamble data", + getMethodName(this, __func__))); + + // spdlog::debug("{}: Found preamble", getMethodName(this, __func__)); + } + catch(const std::runtime_error& err) + { + mCtx.mDs.setCurrentOffset(startOffset); + + spdlog::debug("{}: Skipping preamble", getMethodName(this, __func__)); + } + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); +} + + +Primitive GenericParser::readPrefixPrimitive() +{ + Primitive primitive1 = ToPrimitive(mCtx.mDs.readUint8()); + Primitive primitive2 = ToPrimitive(mCtx.mDs.readUint8()); + + if(primitive1 != primitive2) + { + const std::string msg = fmt::format("{}: Primitives {} != {}", + getMethodName(this, __func__), ::to_string(primitive1), + ::to_string(primitive2)); + + spdlog::debug(msg); + throw std::runtime_error(msg); + } + + return primitive1; +} + + +std::unique_ptr GenericParser::readPrimitive() +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + Primitive typeId = ToPrimitive(mCtx.mDs.peek(1)[0]); + + std::unique_ptr obj = readPrimitive(typeId); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return obj; +} + + +std::unique_ptr GenericParser::readPrimitive(Primitive aPrimitive) +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + const size_t startOffset = mCtx.mDs.getCurrentOffset(); + + std::unique_ptr obj = RecordFactory::build(mCtx, aPrimitive); + + if(obj) + { + try + { + obj->read(); + } + catch(...) + { + if(mCtx.mCfg.mSkipInvalidPrim) + { + spdlog::debug("{}: Skipping invalid Primitive {}", + getMethodName(this, __func__), ::to_string(aPrimitive)); + + // Reset file position to the state before + // the structure was parsed and failed + mCtx.mDs.setCurrentOffset(startOffset); + + // Previous read operations might have read beyond EoF, + // therefore reset the EoF flag. + mCtx.mDs.clear(); + + const uint32_t byteLength = mCtx.mDs.readUint32(); + + mCtx.mDs.printUnknownData(byteLength - sizeof(byteLength), + fmt::format("{} data", ::to_string(aPrimitive))); + + readPreamble(); + } + else + { + throw; + } + } + } + else + { + const std::string msg = fmt::format("{}: Primitive {} is not implemented!", + getMethodName(this, __func__), ::to_string(aPrimitive)); + + spdlog::debug(msg); + + if(!mCtx.mCfg.mSkipUnknownPrim) + { + throw std::runtime_error(msg); + } + + spdlog::debug("{}: Skipping unimplemented Primitive {}", + getMethodName(this, __func__), ::to_string(aPrimitive)); + + const uint32_t byteLength = mCtx.mDs.readUint32(); + + mCtx.mDs.printUnknownData(byteLength - sizeof(byteLength), + fmt::format("{} data", ::to_string(aPrimitive))); + + readPreamble(); + } + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return obj; +} + + +std::unique_ptr GenericParser::readStructure() +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + Structure typeId = ToStructure(mCtx.mDs.peek(1)[0]); + + std::unique_ptr obj = readStructure(typeId); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return obj; +} + + +std::unique_ptr GenericParser::readStructure(Structure aStructure) +{ + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + const size_t startOffset = mCtx.mDs.getCurrentOffset(); + + std::unique_ptr obj = RecordFactory::build(mCtx, aStructure); + + if(obj) + { + try + { + obj->read(); + } + catch(...) + { + if(mCtx.mCfg.mSkipInvalidStruct) + { + spdlog::debug("{}: Skipping invalid Structure {}", + getMethodName(this, __func__), ::to_string(aStructure)); + + // Reset file position to the state before + // the structure was parsed and failed + mCtx.mDs.setCurrentOffset(startOffset); + + // Previous read operations might have read beyond EoF, + // therefore reset the EoF flag. + mCtx.mDs.clear(); + + FutureDataLst localFutureDataLst{mCtx}; + + auto_read_prefixes(localFutureDataLst); + + localFutureDataLst.readRestOfStructure(); + } + else + { + throw; + } + } + } + else + { + const std::string msg = fmt::format("{}: Structure {} is unimplemented!", + getMethodName(this, __func__), ::to_string(aStructure)); + + spdlog::debug(msg); + + if(!mCtx.mCfg.mSkipUnknownStruct) + { + throw std::runtime_error(msg); + } + + spdlog::debug("{}: Skipping unimplemented Structure {}", + getMethodName(this, __func__), ::to_string(aStructure)); + + FutureDataLst localFutureDataLst{mCtx}; + + auto_read_prefixes(localFutureDataLst); + + localFutureDataLst.readRestOfStructure(); + } + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), mCtx.mDs.getCurrentOffset())); + + return obj; +} + + +bool GenericParser::tryRead(std::function aFunction) +{ + const auto offsetBeforeTest = mCtx.mDs.getCurrentOffset(); + bool checkFailed = false; + + try + { + aFunction(); + } + catch(...) + { + checkFailed = true; + } + + mCtx.mDs.setCurrentOffset(offsetBeforeTest); + + return !checkFailed; +} + + +void GenericParser::checkInterpretedDataLen(const std::string& aFuncName, size_t aStartOffset, size_t aEndOffset, size_t aExpectedLen) +{ + if(aStartOffset > aEndOffset) + { + throw std::invalid_argument("Start offset must be smaller or equal to end offset!"); + } + + const size_t actuallLen = aEndOffset - aStartOffset; + + if(actuallLen != aExpectedLen) + { + throw MisinterpretedData(aFuncName.c_str(), aStartOffset, aExpectedLen, aEndOffset); + } +} + + +FileFormatVersion GenericParser::predictVersion(std::function aFunc) +{ + FileFormatVersion prediction = FileFormatVersion::Unknown; + + const std::vector versions{ + FileFormatVersion::A, + FileFormatVersion::B, + FileFormatVersion::C, + FileFormatVersion::D, + FileFormatVersion::E, + FileFormatVersion::F, + FileFormatVersion::G, + FileFormatVersion::H, + FileFormatVersion::I, + FileFormatVersion::J, + FileFormatVersion::K, + FileFormatVersion::L, + FileFormatVersion::M, + FileFormatVersion::N, + FileFormatVersion::O, + FileFormatVersion::P + }; + + const size_t initial_offset = mCtx.mDs.getCurrentOffset(); + + // Testing different versions on a try and error basis + // should not write into log files + const auto logLevel = spdlog::get_level(); + spdlog::set_level(spdlog::level::off); + + for(const auto& version : versions) + { + bool found = true; + + try + { + aFunc(version); + } + catch(...) + { + found = false; + } + + mCtx.mDs.setCurrentOffset(initial_offset); + + if(found) + { + prediction = version; + break; + } + } + + // Restore user log level + spdlog::set_level(logLevel); + + spdlog::debug("{}: Predicted version to be {}", + getMethodName(this, __func__), magic_enum::enum_name(prediction)); + + if(prediction == FileFormatVersion::Unknown) + { + // @todo Fix this hack + // Set to previous default value + // s.t. tests not fail + prediction = FileFormatVersion::C; + spdlog::debug("{}: Setting version to {} anyway", + getMethodName(this, __func__), magic_enum::enum_name(prediction)); + } + + return prediction; +} \ No newline at end of file diff --git a/src/CommonBase.hpp b/src/GenericParser.hpp similarity index 55% rename from src/CommonBase.hpp rename to src/GenericParser.hpp index faa34ed..f56810d 100644 --- a/src/CommonBase.hpp +++ b/src/GenericParser.hpp @@ -1,32 +1,35 @@ -#ifndef COMMONBASE_HPP -#define COMMONBASE_HPP +#ifndef GENERICPARSER_HPP +#define GENERICPARSER_HPP +#include +#include #include +#include #include #include +#include +#include #include +#include #include "Enums/Primitive.hpp" #include "Enums/Structure.hpp" -#include "FutureData.hpp" #include "General.hpp" -#include "ParserContext.hpp" -#include "VisitorPattern.hpp" +#include "StreamContext.hpp" +// #include "Record.hpp" -class PrimBase; +class FutureDataLst; +class Record; -class CommonBase : public Component +class GenericParser { public: - CommonBase(ParserContext& aCtx) : mCtx{aCtx}, mFileFormatVersion{FileFormatVersion::C} - { } - - virtual std::string to_string() const = 0; - virtual void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) = 0; + GenericParser(StreamContext& aCtx) : mCtx{aCtx} + { } void discard_until_preamble(); @@ -47,25 +50,21 @@ class CommonBase : public Component void checkInterpretedDataLen(const std::string &aFuncName, size_t aStartOffset, size_t aEndOffset, size_t aExpectedLen); - FileFormatVersion predictVersion(); + FileFormatVersion predictVersion(std::function aFunc); - std::unique_ptr readPrimitive(); - std::unique_ptr readPrimitive(Primitive aPrimitive); + std::unique_ptr readPrimitive(); + std::unique_ptr readPrimitive(Primitive aPrimitive); - std::unique_ptr readStructure(); - std::unique_ptr readStructure(Structure aStructure); + std::unique_ptr readStructure(); + std::unique_ptr readStructure(Structure aStructure); // Return true if function call was successful, i.e. without throwing exceptions bool tryRead(std::function aFunction); -protected: - std::reference_wrapper mCtx; +private: - FileFormatVersion mFileFormatVersion; + StreamContext& mCtx; }; -#include "Primitives/PrimBase.hpp" - - -#endif // COMMONBASE_HPP \ No newline at end of file +#endif // GENERICPARSER_HPP \ No newline at end of file diff --git a/src/Library.hpp b/src/Library.hpp index f4aa921..343b3a4 100644 --- a/src/Library.hpp +++ b/src/Library.hpp @@ -1,198 +1,198 @@ -#ifndef LIBRARY_HPP -#define LIBRARY_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "Streams/StreamAdminData.hpp" -#include "Streams/StreamDirectoryStruct.hpp" -#include "Streams/StreamDsnStream.hpp" -#include "Streams/StreamHSObjects.hpp" -#include "Streams/StreamLibrary.hpp" -#include "Streams/StreamNetBundleMapData.hpp" -#include "Streams/StreamPackage.hpp" -#include "Streams/StreamSymbol.hpp" -#include "Streams/StreamType.hpp" -#include "VisitorPattern.hpp" - - -class Library : public Component -{ -public: - - Library() : Component{}, adminData{}, dsnStream{}, netBundleMapData{}, hsObjects{}, - cellsDir{}, exportBlocksDir{}, graphicsDir{}, packagesDir{}, partsDir{}, symbolsDir{}, - viewsDir{}, library{}, graphicsTypes{}, symbolsTypes{}, packages{}, symbols{} - { } - - ~Library() override - { } - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::unique_ptr adminData; - std::unique_ptr dsnStream; - std::unique_ptr netBundleMapData; - std::unique_ptr hsObjects; - - std::unique_ptr cellsDir; - std::unique_ptr exportBlocksDir; - std::unique_ptr graphicsDir; - std::unique_ptr packagesDir; - std::unique_ptr partsDir; - std::unique_ptr symbolsDir; - std::unique_ptr viewsDir; - - std::unique_ptr library; - - std::unique_ptr graphicsTypes; - std::unique_ptr symbolsTypes; - - std::vector> packages; - std::vector> symbols; - // std::vector> cells; -}; - - -extern Library* gLibrary; //!< This stores the content of the parsed library file - - -[[maybe_unused]] -static std::string to_string(const Library& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += fmt::format("{}adminData:\n", indent(1)); - if(aObj.adminData) - { - str += indent(aObj.adminData->to_string(), 2); - } - - str += fmt::format("{}dsnStream:\n", indent(1)); - if(aObj.dsnStream) - { - str += indent(aObj.dsnStream->to_string(), 2); - } - - str += fmt::format("{}netBundleMapData:\n", indent(1)); - if(aObj.netBundleMapData) - { - str += indent(aObj.netBundleMapData->to_string(), 2); - } - - str += fmt::format("{}hsObjects:\n", indent(1)); - if(aObj.hsObjects) - { - str += indent(aObj.hsObjects->to_string(), 2); - } - - str += fmt::format("{}cellsDir:\n", indent(1)); - if(aObj.cellsDir) - { - str += indent(aObj.cellsDir->to_string(), 2); - } - - str += fmt::format("{}exportBlocksDir:\n", indent(1)); - if(aObj.exportBlocksDir) - { - str += indent(aObj.exportBlocksDir->to_string(), 2); - } - - str += fmt::format("{}graphicsDir:\n", indent(1)); - if(aObj.graphicsDir) - { - str += indent(aObj.graphicsDir->to_string(), 2); - } - - str += fmt::format("{}packagesDir:\n", indent(1)); - if(aObj.packagesDir) - { - str += indent(aObj.packagesDir->to_string(), 2); - } - - str += fmt::format("{}partsDir:\n", indent(1)); - if(aObj.partsDir) - { - str += indent(aObj.partsDir->to_string(), 2); - } - - str += fmt::format("{}symbolsDir:\n", indent(1)); - if(aObj.symbolsDir) - { - str += indent(aObj.symbolsDir->to_string(), 2); - } - - str += fmt::format("{}viewsDir:\n", indent(1)); - if(aObj.viewsDir) - { - str += indent(aObj.viewsDir->to_string(), 2); - } - - str += fmt::format("{}library:\n", indent(1)); - if(aObj.library) - { - str += indent(aObj.library->to_string(), 2); - } - - str += fmt::format("{}graphicsTypes:\n", indent(1)); - if(aObj.graphicsTypes) - { - for(size_t i = 0u; i < aObj.graphicsTypes->types.size(); ++i) - { - str += indent(fmt::format("[{}]: {}", i, aObj.graphicsTypes->types[i].to_string()), 2); - } - } - - str += fmt::format("{}symbolsTypes:\n", indent(1)); - if(aObj.symbolsTypes) - { - for(size_t i = 0u; i < aObj.symbolsTypes->types.size(); ++i) - { - str += indent(fmt::format("[{}]: {}", i, aObj.symbolsTypes->types[i].to_string()), 2); - } - } - - str += fmt::format("{}packages:\n", indent(1)); - for(size_t i = 0u; i < aObj.packages.size(); ++i) - { - if(aObj.packages[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.packages[i]->to_string()), 2); - } - } - - str += fmt::format("{}symbols:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbols.size(); ++i) - { - if(aObj.symbols[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.symbols[i]->to_string()), 2); - } - } - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const Library& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef LIBRARY_HPP +#define LIBRARY_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "Streams/StreamAdminData.hpp" +#include "Streams/StreamDirectoryStruct.hpp" +#include "Streams/StreamDsnStream.hpp" +#include "Streams/StreamHSObjects.hpp" +#include "Streams/StreamLibrary.hpp" +#include "Streams/StreamNetBundleMapData.hpp" +#include "Streams/StreamPackage.hpp" +#include "Streams/StreamSymbol.hpp" +#include "Streams/StreamType.hpp" +#include "VisitorPattern.hpp" + + +class Library : public Component +{ +public: + + Library() : Component{}, adminData{}, dsnStream{}, netBundleMapData{}, hsObjects{}, + cellsDir{}, exportBlocksDir{}, graphicsDir{}, packagesDir{}, partsDir{}, symbolsDir{}, + viewsDir{}, library{}, graphicsTypes{}, symbolsTypes{}, packages{}, symbols{} + { } + + ~Library() override + { } + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::unique_ptr adminData; + std::unique_ptr dsnStream; + std::unique_ptr netBundleMapData; + std::unique_ptr hsObjects; + + std::unique_ptr cellsDir; + std::unique_ptr exportBlocksDir; + std::unique_ptr graphicsDir; + std::unique_ptr packagesDir; + std::unique_ptr partsDir; + std::unique_ptr symbolsDir; + std::unique_ptr viewsDir; + + std::unique_ptr library; + + std::unique_ptr graphicsTypes; + std::unique_ptr symbolsTypes; + + std::vector> packages; + std::vector> symbols; + // std::vector> cells; +}; + + +extern Library* gLibrary; //!< This stores the content of the parsed library file + + +[[maybe_unused]] +static std::string to_string(const Library& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += fmt::format("{}adminData:\n", indent(1)); + if(aObj.adminData) + { + str += indent(aObj.adminData->to_string(), 2); + } + + str += fmt::format("{}dsnStream:\n", indent(1)); + if(aObj.dsnStream) + { + str += indent(aObj.dsnStream->to_string(), 2); + } + + str += fmt::format("{}netBundleMapData:\n", indent(1)); + if(aObj.netBundleMapData) + { + str += indent(aObj.netBundleMapData->to_string(), 2); + } + + str += fmt::format("{}hsObjects:\n", indent(1)); + if(aObj.hsObjects) + { + str += indent(aObj.hsObjects->to_string(), 2); + } + + str += fmt::format("{}cellsDir:\n", indent(1)); + if(aObj.cellsDir) + { + str += indent(aObj.cellsDir->to_string(), 2); + } + + str += fmt::format("{}exportBlocksDir:\n", indent(1)); + if(aObj.exportBlocksDir) + { + str += indent(aObj.exportBlocksDir->to_string(), 2); + } + + str += fmt::format("{}graphicsDir:\n", indent(1)); + if(aObj.graphicsDir) + { + str += indent(aObj.graphicsDir->to_string(), 2); + } + + str += fmt::format("{}packagesDir:\n", indent(1)); + if(aObj.packagesDir) + { + str += indent(aObj.packagesDir->to_string(), 2); + } + + str += fmt::format("{}partsDir:\n", indent(1)); + if(aObj.partsDir) + { + str += indent(aObj.partsDir->to_string(), 2); + } + + str += fmt::format("{}symbolsDir:\n", indent(1)); + if(aObj.symbolsDir) + { + str += indent(aObj.symbolsDir->to_string(), 2); + } + + str += fmt::format("{}viewsDir:\n", indent(1)); + if(aObj.viewsDir) + { + str += indent(aObj.viewsDir->to_string(), 2); + } + + str += fmt::format("{}library:\n", indent(1)); + if(aObj.library) + { + str += indent(aObj.library->to_string(), 2); + } + + str += fmt::format("{}graphicsTypes:\n", indent(1)); + if(aObj.graphicsTypes) + { + for(size_t i = 0u; i < aObj.graphicsTypes->types.size(); ++i) + { + str += indent(fmt::format("[{}]: {}", i, aObj.graphicsTypes->types[i].to_string()), 2); + } + } + + str += fmt::format("{}symbolsTypes:\n", indent(1)); + if(aObj.symbolsTypes) + { + for(size_t i = 0u; i < aObj.symbolsTypes->types.size(); ++i) + { + str += indent(fmt::format("[{}]: {}", i, aObj.symbolsTypes->types[i].to_string()), 2); + } + } + + str += fmt::format("{}packages:\n", indent(1)); + for(size_t i = 0u; i < aObj.packages.size(); ++i) + { + if(aObj.packages[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.packages[i]->to_string()), 2); + } + } + + str += fmt::format("{}symbols:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbols.size(); ++i) + { + if(aObj.symbols[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.symbols[i]->to_string()), 2); + } + } + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const Library& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // LIBRARY_HPP \ No newline at end of file diff --git a/src/Misc.cpp b/src/Misc.cpp index 6bc5621..1b1a00c 100644 --- a/src/Misc.cpp +++ b/src/Misc.cpp @@ -87,7 +87,7 @@ std::string SymbolUserProp::getVal() const // @todo this is a whole file parser. Split it up into the title block structure and move the rest to the symbol parser? void Container::readTitleBlockSymbol() { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); @@ -116,7 +116,7 @@ void Container::readTitleBlockSymbol() } // The following should be its own structure - readPreamble(); + ds.readPreamble(); std::string str0 = ds.readStringLenZeroTerm(); ds.printUnknownData(7, getMethodName(this, __func__) + ": 1"); @@ -128,7 +128,7 @@ void Container::readTitleBlockSymbol() for(size_t i = 0u; i < someLen; ++i) { const Primitive primitive = readPrefixPrimitive(); - readPrimitive(primitive); + ds.readPrimitive(primitive); } ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 2"); @@ -141,7 +141,7 @@ void Container::readTitleBlockSymbol() for(size_t i = 0u; i < followingLen; ++i) { // @todo push structure - const auto s = readStructure(); + const auto s = ds.readStructure(); if(s) { spdlog::debug("VERIFYING Misc Structure0 is {}", NAMEOF_TYPE_RTTI(*s)); diff --git a/src/PageSettings.cpp b/src/PageSettings.cpp index 3a47268..059c3dd 100644 --- a/src/PageSettings.cpp +++ b/src/PageSettings.cpp @@ -10,7 +10,7 @@ void PageSettings::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/PageSettings.hpp b/src/PageSettings.hpp index fb460aa..bb5daa6 100644 --- a/src/PageSettings.hpp +++ b/src/PageSettings.hpp @@ -9,15 +9,15 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" -class PageSettings : public CommonBase +class PageSettings : public Record { public: - PageSettings(ParserContext& aCtx) : CommonBase{aCtx}, + PageSettings(StreamContext& aCtx) : Record{aCtx}, createDateTime{0}, modifyDateTime{0}, width{0}, height{0}, pinToPin{0}, @@ -36,7 +36,7 @@ class PageSettings : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/ParserContext.hpp b/src/ParserContext.hpp deleted file mode 100644 index 3d69ea5..0000000 --- a/src/ParserContext.hpp +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef PARSERCONTEXT_HPP -#define PARSERCONTEXT_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "DataStream.hpp" -#include "General.hpp" - - -namespace fs = std::filesystem; - - -[[maybe_unused]] static std::vector getCfbfStreamLocationFromFileSytemLayout( - fs::path aStreamPath, fs::path aExtractedCfbfPath) -{ - std::vector streamLocation{}; - - // The layout in the filesystem is equal - // to the one inside the CFBF container - fs::path relPathStreamLoc = fs::relative(aStreamPath, aExtractedCfbfPath); - - for(const auto& pathPart : relPathStreamLoc) - { - streamLocation.push_back(pathPart); - } - - if(!streamLocation.empty()) - { - // Remove file extension (`.bin`) - streamLocation.back() = fs::path{streamLocation.back()}.replace_extension(); - } - - return streamLocation; -} - - -static std::unique_ptr globalStream{}; - -struct ParserConfig -{ - bool mSkipUnknownPrim{true}; //!< Unknown primitives should be skipped during parsing - bool mSkipInvalidPrim{true}; //!< Invalid primitives should be skipped during parsing - - bool mSkipUnknownStruct{true}; //!< Unknown structures should be skipped during parsing - bool mSkipInvalidStruct{true}; //!< Invalid structures should be skipped during parsing - - bool mKeepTmpFiles{false}; //!< Do not delete temporary files after parser completed -}; - -[[maybe_unused]] -static std::string to_string(const ParserConfig& aCfg) -{ - std::string str; - str += fmt::format("mSkipUnknownPrim = {}\n", aCfg.mSkipUnknownPrim); - str += fmt::format("mSkipInvalidPrim = {}\n", aCfg.mSkipInvalidPrim); - str += fmt::format("mSkipUnknownStruct = {}\n", aCfg.mSkipUnknownStruct); - str += fmt::format("mSkipInvalidStruct = {}\n", aCfg.mSkipInvalidStruct); - str += fmt::format("mKeepTmpFiles = {}\n", aCfg.mKeepTmpFiles); - - return str; -} - - -class ParserContext -{ -public: - - ParserContext() = default; - - ParserContext(const fs::path& aInputCfbfFile, - const fs::path& aInputStream, const fs::path& aExtractedCfbfPath, ParserConfig aCfg) : mDs{*globalStream} - { - mInputCfbfFile = aInputCfbfFile; - mInputStream = aInputStream; - mExtractedCfbfPath = aExtractedCfbfPath; - - mCfbfStreamLocation = getCfbfStreamLocationFromFileSytemLayout(mInputStream, mExtractedCfbfPath); - - globalStream = std::make_unique(mInputStream); - mDs = *globalStream; - - mImgCtr = 0U; - - mFinishedParsing = false; - - mCfg = aCfg; - } - - fs::path mInputCfbfFile; //!< Input CFBF container - fs::path mInputStream; //!< Input CFBF stream as file in the file system - fs::path mExtractedCfbfPath; - - std::vector mCfbfStreamLocation; //!< Location of the stream inside the CFBF container - - std::reference_wrapper mDs; - - size_t mImgCtr; //!< Counts images per stream - - bool mFinishedParsing; - - ParserConfig mCfg; -}; - - -#endif // PARSERCONTEXT_HPP \ No newline at end of file diff --git a/src/Primitives/Point.cpp b/src/Primitives/Point.cpp index 9f837db..381e394 100644 --- a/src/Primitives/Point.cpp +++ b/src/Primitives/Point.cpp @@ -10,7 +10,7 @@ void Point::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Primitives/Point.hpp b/src/Primitives/Point.hpp index b2ab878..e61b5b5 100644 --- a/src/Primitives/Point.hpp +++ b/src/Primitives/Point.hpp @@ -9,24 +9,24 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "PrimBase.hpp" /// @note Represents 'BezierPoint', 'PolygonPoint' and 'PolylinePoint' because /// all of them use the same point structure. -class Point : public CommonBase +class Point : public PrimBase { public: - Point(ParserContext& aCtx) : CommonBase{aCtx}, x{0}, y{0} + Point(StreamContext& aCtx) : PrimBase{aCtx}, x{0}, y{0} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Primitives/PrimArc.cpp b/src/Primitives/PrimArc.cpp index 4a260bc..f9e105c 100644 --- a/src/Primitives/PrimArc.cpp +++ b/src/Primitives/PrimArc.cpp @@ -1,80 +1,82 @@ -#include -#include -#include - -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimArc.hpp" - - -size_t PrimArc::getExpectedStructSize(FileFormatVersion aVersion) -{ - size_t expectedByteLength; - - if(aVersion <= FileFormatVersion::A) - { - expectedByteLength = 40u; - } - else - { - expectedByteLength = 48u; - } - - return expectedByteLength; -} - - -void PrimArc::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const size_t startOffset = ds.getCurrentOffset(); - - const uint32_t byteLength = ds.readUint32(); - - // Predict version - switch(byteLength) - { - case 40: aVersion = FileFormatVersion::A; break; - case 48: aVersion = FileFormatVersion::B; break; - default: break; - } - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - x1 = ds.readInt32(); - y1 = ds.readInt32(); - x2 = ds.readInt32(); - y2 = ds.readInt32(); - - startX = ds.readInt32(); - startY = ds.readInt32(); - endX = ds.readInt32(); - endY = ds.readInt32(); - - if(aVersion >= FileFormatVersion::B) - { - setLineStyle(ToLineStyle(ds.readUint32())); - setLineWidth(ToLineWidth(ds.readUint32())); - } - - if(ds.getCurrentOffset() != startOffset + byteLength) - { - throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); - } - - if(byteLength != getExpectedStructSize(aVersion)) - { - throw FileFormatChanged(std::string(nameof::nameof_type())); - } - - readPreamble(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimArc.hpp" + + +size_t PrimArc::getExpectedStructSize(FileFormatVersion aVersion) +{ + size_t expectedByteLength; + + if(aVersion <= FileFormatVersion::A) + { + expectedByteLength = 40u; + } + else + { + expectedByteLength = 48u; + } + + return expectedByteLength; +} + + +void PrimArc::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + const size_t startOffset = ds.getCurrentOffset(); + + const uint32_t byteLength = ds.readUint32(); + + // Predict version + switch(byteLength) + { + case 40: aVersion = FileFormatVersion::A; break; + case 48: aVersion = FileFormatVersion::B; break; + default: break; + } + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + x1 = ds.readInt32(); + y1 = ds.readInt32(); + x2 = ds.readInt32(); + y2 = ds.readInt32(); + + startX = ds.readInt32(); + startY = ds.readInt32(); + endX = ds.readInt32(); + endY = ds.readInt32(); + + if(aVersion >= FileFormatVersion::B) + { + setLineStyle(ToLineStyle(ds.readUint32())); + setLineWidth(ToLineWidth(ds.readUint32())); + } + + if(ds.getCurrentOffset() != startOffset + byteLength) + { + throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); + } + + if(byteLength != getExpectedStructSize(aVersion)) + { + throw FileFormatChanged(std::string(nameof::nameof_type())); + } + + parser.readPreamble(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimArc.hpp b/src/Primitives/PrimArc.hpp index a81a74f..ce4925d 100644 --- a/src/Primitives/PrimArc.hpp +++ b/src/Primitives/PrimArc.hpp @@ -21,7 +21,7 @@ class PrimArc : public PrimBase { public: - PrimArc(ParserContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, + PrimArc(StreamContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, startX{0}, startY{0}, endX{0}, endY{0}, mLineStyle{}, mLineWidth{} { } @@ -29,7 +29,7 @@ class PrimArc : public PrimBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Primitives/PrimBase.hpp b/src/Primitives/PrimBase.hpp index 8a0cffe..fb6e3e3 100644 --- a/src/Primitives/PrimBase.hpp +++ b/src/Primitives/PrimBase.hpp @@ -2,13 +2,13 @@ #define PRIMBASE_HPP -#include "CommonBase.hpp" +#include "Record.hpp" -class PrimBase : public CommonBase +class PrimBase : public Record { public: - PrimBase(ParserContext& aCtx) : CommonBase{aCtx} + PrimBase(StreamContext& aCtx) : Record{aCtx} { } }; diff --git a/src/Primitives/PrimBezier.cpp b/src/Primitives/PrimBezier.cpp index c3c5627..25746b7 100644 --- a/src/Primitives/PrimBezier.cpp +++ b/src/Primitives/PrimBezier.cpp @@ -1,126 +1,129 @@ -#include -#include -#include -#include - -#include -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimBezier.hpp" - - -size_t PrimBezier::getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount) -{ - size_t expectedByteLength; - - if(aVersion <= FileFormatVersion::A) - { - expectedByteLength = 10u + 4u * aPointCount; - } - else - { - expectedByteLength = 18u + 4u * aPointCount; - } - - return expectedByteLength; -} - - -void PrimBezier::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - if(aVersion == FileFormatVersion::Unknown) - { - aVersion = predictVersion(); - } - - const size_t startOffset = ds.getCurrentOffset(); - - const uint32_t byteLength = ds.readUint32(); - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - if(aVersion >= FileFormatVersion::B) - { - setLineStyle(ToLineStyle(ds.readUint32())); - setLineWidth(ToLineWidth(ds.readUint32())); - } - - const uint16_t pointCount = ds.readUint16(); - - spdlog::trace("pointCount = {}", pointCount); - - if(pointCount < 4) - { - throw std::runtime_error("At minimum 4 'BezierPoint's must occur but got " + std::to_string(pointCount) - + " points!"); - } - else - { - // Check correct number of points. - - // Example showing the overlapping ends of the points - // Bezier Segment 0: P0P1P2P3 - // Bezier Segment 1: P0P1P2P3 - // Bezier Segment 2: P0P1P2P3 - // Bezier Segment 3: P0P1P2P3 - - // n_b = Number of Bezier segments - // n_p = Number of BezierPoints - - // 3 * n_b + 1 = n_p - // <=> n_b = (n_p - 1) / 3 - - // Quotient = Dividend / Divisor - const auto isDivisible = [](int aDividend, int aDivisor) -> bool - { - aDividend = std::abs(aDividend); - aDivisor = std::abs(aDivisor); - - const auto rest = aDividend % aDivisor; - - return rest == 0; - }; - - if(!isDivisible(pointCount - 1, 3)) - { - throw std::runtime_error("Number of 'BezierPoint's is incorrect. Got " + std::to_string(pointCount) - + " points!"); - } - } - - for(size_t i = 0u; i < pointCount; ++i) - { - Point point{mCtx}; - point.read(); - points.push_back(point); - } - - // @todo - int byteDiff = static_cast(byteLength) - static_cast(ds.getCurrentOffset() - startOffset); - if(byteDiff > 0) - { - ds.printUnknownData(byteDiff); - } - - if(ds.getCurrentOffset() != startOffset + byteLength) - { - // throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); - } - - if(byteLength != getExpectedStructSize(aVersion, pointCount)) - { - // throw FileFormatChanged(std::string(nameof::nameof_type())); - } - - readPreamble(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include +#include + +#include +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimBezier.hpp" + + +size_t PrimBezier::getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount) +{ + size_t expectedByteLength; + + if(aVersion <= FileFormatVersion::A) + { + expectedByteLength = 10u + 4u * aPointCount; + } + else + { + expectedByteLength = 18u + 4u * aPointCount; + } + + return expectedByteLength; +} + + +void PrimBezier::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + if(aVersion == FileFormatVersion::Unknown) + { + const auto predictionFunc = [this](FileFormatVersion aVersion){ this->read(aVersion); }; + aVersion = parser.predictVersion(predictionFunc); + } + + const size_t startOffset = ds.getCurrentOffset(); + + const uint32_t byteLength = ds.readUint32(); + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + if(aVersion >= FileFormatVersion::B) + { + setLineStyle(ToLineStyle(ds.readUint32())); + setLineWidth(ToLineWidth(ds.readUint32())); + } + + const uint16_t pointCount = ds.readUint16(); + + spdlog::trace("pointCount = {}", pointCount); + + if(pointCount < 4) + { + throw std::runtime_error("At minimum 4 'BezierPoint's must occur but got " + std::to_string(pointCount) + + " points!"); + } + else + { + // Check correct number of points. + + // Example showing the overlapping ends of the points + // Bezier Segment 0: P0P1P2P3 + // Bezier Segment 1: P0P1P2P3 + // Bezier Segment 2: P0P1P2P3 + // Bezier Segment 3: P0P1P2P3 + + // n_b = Number of Bezier segments + // n_p = Number of BezierPoints + + // 3 * n_b + 1 = n_p + // <=> n_b = (n_p - 1) / 3 + + // Quotient = Dividend / Divisor + const auto isDivisible = [](int aDividend, int aDivisor) -> bool + { + aDividend = std::abs(aDividend); + aDivisor = std::abs(aDivisor); + + const auto rest = aDividend % aDivisor; + + return rest == 0; + }; + + if(!isDivisible(pointCount - 1, 3)) + { + throw std::runtime_error("Number of 'BezierPoint's is incorrect. Got " + std::to_string(pointCount) + + " points!"); + } + } + + for(size_t i = 0u; i < pointCount; ++i) + { + Point point{mCtx}; + point.read(); + points.push_back(point); + } + + // @todo + int byteDiff = static_cast(byteLength) - static_cast(ds.getCurrentOffset() - startOffset); + if(byteDiff > 0) + { + ds.printUnknownData(byteDiff); + } + + if(ds.getCurrentOffset() != startOffset + byteLength) + { + // throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); + } + + if(byteLength != getExpectedStructSize(aVersion, pointCount)) + { + // throw FileFormatChanged(std::string(nameof::nameof_type())); + } + + parser.readPreamble(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimBezier.hpp b/src/Primitives/PrimBezier.hpp index 2e439f5..bc5b1cd 100644 --- a/src/Primitives/PrimBezier.hpp +++ b/src/Primitives/PrimBezier.hpp @@ -1,103 +1,103 @@ -#ifndef PRIMBEZIER_HPP -#define PRIMBEZIER_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/Point.hpp" -#include "Primitives/PrimBase.hpp" - - -class PrimBezier : public PrimBase -{ -public: - PrimBezier(ParserContext& aCtx) : PrimBase{aCtx}, mLineStyle{}, mLineWidth{}, points{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - static size_t getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount); - - void setLineStyle(const LineStyle& aVal) - { - mLineStyle = std::make_optional(aVal); - } - - LineStyle getLineStyle() const - { - return mLineStyle.value_or(LineStyle::Solid); - } - - void setLineWidth(const LineWidth& aVal) - { - mLineWidth = std::make_optional(aVal); - } - - LineWidth getLineWidth() const - { - return mLineWidth.value_or(LineWidth::Default); - } - -private: - - std::optional mLineStyle; - std::optional mLineWidth; - -public: - - std::vector points; -}; - - -[[maybe_unused]] -static std::string to_string(const PrimBezier& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); - str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); - - str += fmt::format("{}points:\n", indent(1)); - for(size_t i = 0u; i < aObj.points.size(); ++i) - { - str += indent(fmt::format("{}: {}", i, to_string(aObj.points[i])), 2); - } - - return str; -} - - -inline std::string PrimBezier::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const PrimBezier& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef PRIMBEZIER_HPP +#define PRIMBEZIER_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "Primitives/Point.hpp" +#include "Primitives/PrimBase.hpp" + + +class PrimBezier : public PrimBase +{ +public: + PrimBezier(StreamContext& aCtx) : PrimBase{aCtx}, mLineStyle{}, mLineWidth{}, points{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + static size_t getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount); + + void setLineStyle(const LineStyle& aVal) + { + mLineStyle = std::make_optional(aVal); + } + + LineStyle getLineStyle() const + { + return mLineStyle.value_or(LineStyle::Solid); + } + + void setLineWidth(const LineWidth& aVal) + { + mLineWidth = std::make_optional(aVal); + } + + LineWidth getLineWidth() const + { + return mLineWidth.value_or(LineWidth::Default); + } + +private: + + std::optional mLineStyle; + std::optional mLineWidth; + +public: + + std::vector points; +}; + + +[[maybe_unused]] +static std::string to_string(const PrimBezier& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); + str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); + + str += fmt::format("{}points:\n", indent(1)); + for(size_t i = 0u; i < aObj.points.size(); ++i) + { + str += indent(fmt::format("{}: {}", i, to_string(aObj.points[i])), 2); + } + + return str; +} + + +inline std::string PrimBezier::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const PrimBezier& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // PRIMBEZIER_HPP \ No newline at end of file diff --git a/src/Primitives/PrimBitmap.cpp b/src/Primitives/PrimBitmap.cpp index 7566cf7..88ce46a 100644 --- a/src/Primitives/PrimBitmap.cpp +++ b/src/Primitives/PrimBitmap.cpp @@ -14,6 +14,7 @@ #include #include "General.hpp" +#include "GenericParser.hpp" #include "Primitives/PrimBitmap.hpp" @@ -22,8 +23,8 @@ namespace fs = std::filesystem; void PrimBitmap::read(FileFormatVersion /* aVersion */) { - auto& ctx = mCtx.get(); - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); @@ -67,14 +68,14 @@ void PrimBitmap::read(FileFormatVersion /* aVersion */) rawImgData.push_back(ds.readUint8()); } - fs::path filename = ctx.mExtractedCfbfPath / "data" / fmt::format("{}_img_{}.bmp", - ctx.mInputStream.stem().string(), ctx.mImgCtr); + fs::path filename = mCtx.mExtractedCfbfPath / "data" / fmt::format("{}_img_{}.bmp", + mCtx.mInputStream.stem().string(), mCtx.mImgCtr); filename = writeImgToFile(filename); spdlog::info("{}: Wrote bitmap file to {}", __func__, filename.string()); - ++ctx.mImgCtr; + ++mCtx.mImgCtr; if(ds.getCurrentOffset() != startOffset + byteLength) { @@ -86,7 +87,7 @@ void PrimBitmap::read(FileFormatVersion /* aVersion */) // throw FileFormatChanged("Bitmap"); } - readPreamble(); + parser.readPreamble(); spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); spdlog::trace(to_string()); diff --git a/src/Primitives/PrimBitmap.hpp b/src/Primitives/PrimBitmap.hpp index d75e704..97a2485 100644 --- a/src/Primitives/PrimBitmap.hpp +++ b/src/Primitives/PrimBitmap.hpp @@ -21,7 +21,7 @@ class PrimBitmap : public PrimBase { public: - PrimBitmap(ParserContext& aCtx) : PrimBase{aCtx}, locX{0}, locY{0}, + PrimBitmap(StreamContext& aCtx) : PrimBase{aCtx}, locX{0}, locY{0}, x1{0}, y1{0}, x2{0}, y2{0}, bmpWidth{0}, bmpHeight{0} { } @@ -29,7 +29,7 @@ class PrimBitmap : public PrimBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Primitives/PrimCommentText.cpp b/src/Primitives/PrimCommentText.cpp index 1575f57..de4dc1a 100644 --- a/src/Primitives/PrimCommentText.cpp +++ b/src/Primitives/PrimCommentText.cpp @@ -6,6 +6,7 @@ #include #include "General.hpp" +#include "GenericParser.hpp" #include "Library.hpp" #include "Primitives/PrimCommentText.hpp" #include "Win32/LOGFONTA.hpp" @@ -13,7 +14,8 @@ void PrimCommentText::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); @@ -80,7 +82,7 @@ void PrimCommentText::read(FileFormatVersion /* aVersion */) // throw FileFormatChanged("CommentText"); } - readPreamble(); + parser.readPreamble(); spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); spdlog::trace(to_string()); diff --git a/src/Primitives/PrimCommentText.hpp b/src/Primitives/PrimCommentText.hpp index 19563c7..aed34e6 100644 --- a/src/Primitives/PrimCommentText.hpp +++ b/src/Primitives/PrimCommentText.hpp @@ -20,14 +20,14 @@ struct Library; class PrimCommentText : public PrimBase { public: - PrimCommentText(ParserContext& aCtx) : PrimBase{aCtx}, locX{0}, locY{0}, name{}, x1{0}, y1{0}, x2{0}, y2{0}, textFontIdx{0} + PrimCommentText(StreamContext& aCtx) : PrimBase{aCtx}, locX{0}, locY{0}, name{}, x1{0}, y1{0}, x2{0}, y2{0}, textFontIdx{0} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Primitives/PrimEllipse.cpp b/src/Primitives/PrimEllipse.cpp index 35c10d7..c8db140 100644 --- a/src/Primitives/PrimEllipse.cpp +++ b/src/Primitives/PrimEllipse.cpp @@ -1,92 +1,94 @@ -#include -#include -#include - -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimEllipse.hpp" - - -size_t PrimEllipse::getExpectedStructSize(FileFormatVersion aVersion) -{ - size_t expectedByteLength; - - switch(aVersion) - { - case FileFormatVersion::A: - expectedByteLength = 24U; - break; - - case FileFormatVersion::B: - expectedByteLength = 32U; - break; - - case FileFormatVersion::C: - expectedByteLength = 40U; - break; - - default: - expectedByteLength = 0U; - break; - } - - return expectedByteLength; -} - - -void PrimEllipse::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const size_t startOffset = ds.getCurrentOffset(); - - uint32_t byteLength = ds.readUint32(); - - // Predict version - switch(byteLength) - { - case 24: aVersion = FileFormatVersion::A; break; - case 32: aVersion = FileFormatVersion::B; break; - case 40: aVersion = FileFormatVersion::C; break; - default: break; - } - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - x1 = ds.readInt32(); - y1 = ds.readInt32(); - x2 = ds.readInt32(); - y2 = ds.readInt32(); - - if(aVersion >= FileFormatVersion::B) - { - setLineStyle(ToLineStyle(ds.readUint32())); - setLineWidth(ToLineWidth(ds.readUint32())); - } - - if(aVersion >= FileFormatVersion::C) - { - setFillStyle(ToFillStyle(ds.readUint32())); - setHatchStyle(ToHatchStyle(ds.readInt32())); - } - - if(ds.getCurrentOffset() != startOffset + byteLength) - { - throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); - } - - if(byteLength != getExpectedStructSize(aVersion)) - { - throw FileFormatChanged(std::string(nameof::nameof_type())); - } - - readPreamble(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimEllipse.hpp" + + +size_t PrimEllipse::getExpectedStructSize(FileFormatVersion aVersion) +{ + size_t expectedByteLength; + + switch(aVersion) + { + case FileFormatVersion::A: + expectedByteLength = 24U; + break; + + case FileFormatVersion::B: + expectedByteLength = 32U; + break; + + case FileFormatVersion::C: + expectedByteLength = 40U; + break; + + default: + expectedByteLength = 0U; + break; + } + + return expectedByteLength; +} + + +void PrimEllipse::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + const size_t startOffset = ds.getCurrentOffset(); + + uint32_t byteLength = ds.readUint32(); + + // Predict version + switch(byteLength) + { + case 24: aVersion = FileFormatVersion::A; break; + case 32: aVersion = FileFormatVersion::B; break; + case 40: aVersion = FileFormatVersion::C; break; + default: break; + } + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + x1 = ds.readInt32(); + y1 = ds.readInt32(); + x2 = ds.readInt32(); + y2 = ds.readInt32(); + + if(aVersion >= FileFormatVersion::B) + { + setLineStyle(ToLineStyle(ds.readUint32())); + setLineWidth(ToLineWidth(ds.readUint32())); + } + + if(aVersion >= FileFormatVersion::C) + { + setFillStyle(ToFillStyle(ds.readUint32())); + setHatchStyle(ToHatchStyle(ds.readInt32())); + } + + if(ds.getCurrentOffset() != startOffset + byteLength) + { + throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); + } + + if(byteLength != getExpectedStructSize(aVersion)) + { + throw FileFormatChanged(std::string(nameof::nameof_type())); + } + + parser.readPreamble(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimEllipse.hpp b/src/Primitives/PrimEllipse.hpp index 317f1ef..af0d6e2 100644 --- a/src/Primitives/PrimEllipse.hpp +++ b/src/Primitives/PrimEllipse.hpp @@ -25,7 +25,7 @@ class PrimEllipse : public PrimBase { public: - PrimEllipse(ParserContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, + PrimEllipse(StreamContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, mLineStyle{}, mLineWidth{}, mFillStyle{}, mHatchStyle{} { } @@ -33,7 +33,7 @@ class PrimEllipse : public PrimBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Primitives/PrimLine.cpp b/src/Primitives/PrimLine.cpp index 62d73f9..0fdf148 100644 --- a/src/Primitives/PrimLine.cpp +++ b/src/Primitives/PrimLine.cpp @@ -1,76 +1,78 @@ -#include -#include -#include - -#include -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimLine.hpp" - - -size_t PrimLine::getExpectedStructSize(FileFormatVersion aVersion) -{ - size_t expectedByteLength; - - if(aVersion <= FileFormatVersion::A) - { - expectedByteLength = 24u; - } - else - { - expectedByteLength = 32u; - } - - return expectedByteLength; -} - - -void PrimLine::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const size_t startOffset = ds.getCurrentOffset(); - - const uint32_t byteLength = ds.readUint32(); - - // Predict version - switch(byteLength) - { - case 24: aVersion = FileFormatVersion::A; break; - case 32: aVersion = FileFormatVersion::B; break; - default: break; - } - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - x1 = ds.readInt32(); - y1 = ds.readInt32(); - x2 = ds.readInt32(); - y2 = ds.readInt32(); - - if(aVersion >= FileFormatVersion::B) - { - setLineStyle(ToLineStyle(ds.readUint32())); - setLineWidth(ToLineWidth(ds.readUint32())); - } - - if(ds.getCurrentOffset() != startOffset + byteLength) - { - throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); - } - - if(byteLength != getExpectedStructSize(aVersion)) - { - throw FileFormatChanged(std::string(nameof::nameof_type())); - } - - readPreamble(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimLine.hpp" + + +size_t PrimLine::getExpectedStructSize(FileFormatVersion aVersion) +{ + size_t expectedByteLength; + + if(aVersion <= FileFormatVersion::A) + { + expectedByteLength = 24u; + } + else + { + expectedByteLength = 32u; + } + + return expectedByteLength; +} + + +void PrimLine::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + const size_t startOffset = ds.getCurrentOffset(); + + const uint32_t byteLength = ds.readUint32(); + + // Predict version + switch(byteLength) + { + case 24: aVersion = FileFormatVersion::A; break; + case 32: aVersion = FileFormatVersion::B; break; + default: break; + } + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + x1 = ds.readInt32(); + y1 = ds.readInt32(); + x2 = ds.readInt32(); + y2 = ds.readInt32(); + + if(aVersion >= FileFormatVersion::B) + { + setLineStyle(ToLineStyle(ds.readUint32())); + setLineWidth(ToLineWidth(ds.readUint32())); + } + + if(ds.getCurrentOffset() != startOffset + byteLength) + { + throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); + } + + if(byteLength != getExpectedStructSize(aVersion)) + { + throw FileFormatChanged(std::string(nameof::nameof_type())); + } + + parser.readPreamble(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimLine.hpp b/src/Primitives/PrimLine.hpp index fdf5941..265f869 100644 --- a/src/Primitives/PrimLine.hpp +++ b/src/Primitives/PrimLine.hpp @@ -19,14 +19,14 @@ class PrimLine : public PrimBase { public: - PrimLine(ParserContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, mLineStyle{}, mLineWidth{} + PrimLine(StreamContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, mLineStyle{}, mLineWidth{} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Primitives/PrimPolygon.cpp b/src/Primitives/PrimPolygon.cpp index 6796382..2e7c046 100644 --- a/src/Primitives/PrimPolygon.cpp +++ b/src/Primitives/PrimPolygon.cpp @@ -1,110 +1,113 @@ -#include -#include -#include - -#include - -#include "Enums/FillStyle.hpp" -#include "Enums/HatchStyle.hpp" -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimPolygon.hpp" - - -size_t PrimPolygon::getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount) -{ - size_t expectedByteLength; - - if(aVersion <= FileFormatVersion::A) - { - expectedByteLength = 10u + 4u * aPointCount; - } - else if(aVersion <= FileFormatVersion::B) - { - expectedByteLength = 18u + 4u * aPointCount; - } - else - { - expectedByteLength = 26u + 4u * aPointCount; - } - - return expectedByteLength; -} - - -void PrimPolygon::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - if(aVersion == FileFormatVersion::Unknown) - { - aVersion = predictVersion(); - } - - const size_t startOffset = ds.getCurrentOffset(); - - const uint32_t byteLength = ds.readUint32(); - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - if(gFileFormatVersion >= FileFormatVersion::B) - { - setLineStyle(ToLineStyle(ds.readUint32())); - setLineWidth(ToLineWidth(ds.readUint32())); - } - - if(gFileFormatVersion >= FileFormatVersion::C) - { - fillStyle = ToFillStyle(ds.readUint32()); - hatchStyle = ToHatchStyle(ds.readInt32()); - } - else - { - // Default values - fillStyle = FillStyle::None; - hatchStyle = HatchStyle::LinesHorizontal; - } - - const uint16_t pointCount = ds.readUint16(); - - spdlog::trace("pointCount = {}", pointCount); - - if(pointCount < 3u) - { - // I've seen 2 points, even placed at the same coordinate - // throw std::runtime_error("The XSD allows Polygons with < 3 points but does this make any sense? Got " - // + std::to_string(pointCount) + "!"); - } - - for(size_t i = 0u; i < pointCount; ++i) - { - Point point{mCtx}; - point.read(); - points.push_back(point); - } - - // @todo - int byteDiff = static_cast(byteLength) - static_cast(ds.getCurrentOffset() - startOffset); - if(byteDiff > 0) - { - ds.printUnknownData(byteDiff); - } - - if(ds.getCurrentOffset() != startOffset + byteLength) - { - // throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); - } - - if(byteLength != getExpectedStructSize(gFileFormatVersion, pointCount)) - { - // throw FileFormatChanged(std::string(nameof::nameof_type())); - } - - readPreamble(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/FillStyle.hpp" +#include "Enums/HatchStyle.hpp" +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimPolygon.hpp" + + +size_t PrimPolygon::getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount) +{ + size_t expectedByteLength; + + if(aVersion <= FileFormatVersion::A) + { + expectedByteLength = 10u + 4u * aPointCount; + } + else if(aVersion <= FileFormatVersion::B) + { + expectedByteLength = 18u + 4u * aPointCount; + } + else + { + expectedByteLength = 26u + 4u * aPointCount; + } + + return expectedByteLength; +} + + +void PrimPolygon::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + if(aVersion == FileFormatVersion::Unknown) + { + const auto predictionFunc = [this](FileFormatVersion aVersion){ this->read(aVersion); }; + aVersion = parser.predictVersion(predictionFunc); + } + + const size_t startOffset = ds.getCurrentOffset(); + + const uint32_t byteLength = ds.readUint32(); + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + if(mCtx.mFileFormatVersion >= FileFormatVersion::B) + { + setLineStyle(ToLineStyle(ds.readUint32())); + setLineWidth(ToLineWidth(ds.readUint32())); + } + + if(mCtx.mFileFormatVersion >= FileFormatVersion::C) + { + fillStyle = ToFillStyle(ds.readUint32()); + hatchStyle = ToHatchStyle(ds.readInt32()); + } + else + { + // Default values + fillStyle = FillStyle::None; + hatchStyle = HatchStyle::LinesHorizontal; + } + + const uint16_t pointCount = ds.readUint16(); + + spdlog::trace("pointCount = {}", pointCount); + + if(pointCount < 3u) + { + // I've seen 2 points, even placed at the same coordinate + // throw std::runtime_error("The XSD allows Polygons with < 3 points but does this make any sense? Got " + // + std::to_string(pointCount) + "!"); + } + + for(size_t i = 0u; i < pointCount; ++i) + { + Point point{mCtx}; + point.read(); + points.push_back(point); + } + + // @todo + int byteDiff = static_cast(byteLength) - static_cast(ds.getCurrentOffset() - startOffset); + if(byteDiff > 0) + { + ds.printUnknownData(byteDiff); + } + + if(ds.getCurrentOffset() != startOffset + byteLength) + { + // throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); + } + + if(byteLength != getExpectedStructSize(mCtx.mFileFormatVersion, pointCount)) + { + // throw FileFormatChanged(std::string(nameof::nameof_type())); + } + + parser.readPreamble(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimPolygon.hpp b/src/Primitives/PrimPolygon.hpp index a1f2fbb..1272d17 100644 --- a/src/Primitives/PrimPolygon.hpp +++ b/src/Primitives/PrimPolygon.hpp @@ -1,110 +1,110 @@ -#ifndef PRIMPOLYGON_HPP -#define PRIMPOLYGON_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "Enums/FillStyle.hpp" -#include "Enums/HatchStyle.hpp" -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "Primitives/Point.hpp" -#include "Primitives/PrimBase.hpp" - - -class PrimPolygon : public PrimBase -{ -public: - - PrimPolygon(ParserContext& aCtx) : PrimBase{aCtx}, mLineStyle{}, mLineWidth{}, - fillStyle{}, hatchStyle{}, points{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - static size_t getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount); - - void setLineStyle(const LineStyle& aVal) - { - mLineStyle = std::make_optional(aVal); - } - - LineStyle getLineStyle() const - { - return mLineStyle.value_or(LineStyle::Solid); - } - - void setLineWidth(const LineWidth& aVal) - { - mLineWidth = std::make_optional(aVal); - } - - LineWidth getLineWidth() const - { - return mLineWidth.value_or(LineWidth::Default); - } - -private: - - std::optional mLineStyle; - std::optional mLineWidth; - -public: - - FillStyle fillStyle; - HatchStyle hatchStyle; - - std::vector points; -}; - - -[[maybe_unused]] -static std::string to_string(const PrimPolygon& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); - str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); - str += fmt::format("{}fillStyle = {}\n", indent(1), to_string(aObj.fillStyle)); - str += fmt::format("{}hatchStyle = {}\n", indent(1), to_string(aObj.hatchStyle)); - - str += fmt::format("{}points:\n", indent(1)); - for(size_t i = 0u; i < aObj.points.size(); ++i) - { - str += indent(fmt::format("{}: {}", i, to_string(aObj.points[i])), 2); - } - - return str; -} - - -inline std::string PrimPolygon::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const PrimPolygon& aVal) -{ - aOs << to_string(aVal); - return aOs; -} - - +#ifndef PRIMPOLYGON_HPP +#define PRIMPOLYGON_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "Enums/FillStyle.hpp" +#include "Enums/HatchStyle.hpp" +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "Primitives/Point.hpp" +#include "Primitives/PrimBase.hpp" + + +class PrimPolygon : public PrimBase +{ +public: + + PrimPolygon(StreamContext& aCtx) : PrimBase{aCtx}, mLineStyle{}, mLineWidth{}, + fillStyle{}, hatchStyle{}, points{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + static size_t getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount); + + void setLineStyle(const LineStyle& aVal) + { + mLineStyle = std::make_optional(aVal); + } + + LineStyle getLineStyle() const + { + return mLineStyle.value_or(LineStyle::Solid); + } + + void setLineWidth(const LineWidth& aVal) + { + mLineWidth = std::make_optional(aVal); + } + + LineWidth getLineWidth() const + { + return mLineWidth.value_or(LineWidth::Default); + } + +private: + + std::optional mLineStyle; + std::optional mLineWidth; + +public: + + FillStyle fillStyle; + HatchStyle hatchStyle; + + std::vector points; +}; + + +[[maybe_unused]] +static std::string to_string(const PrimPolygon& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); + str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); + str += fmt::format("{}fillStyle = {}\n", indent(1), to_string(aObj.fillStyle)); + str += fmt::format("{}hatchStyle = {}\n", indent(1), to_string(aObj.hatchStyle)); + + str += fmt::format("{}points:\n", indent(1)); + for(size_t i = 0u; i < aObj.points.size(); ++i) + { + str += indent(fmt::format("{}: {}", i, to_string(aObj.points[i])), 2); + } + + return str; +} + + +inline std::string PrimPolygon::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const PrimPolygon& aVal) +{ + aOs << to_string(aVal); + return aOs; +} + + #endif // PRIMPOLYGON_HPP \ No newline at end of file diff --git a/src/Primitives/PrimPolyline.cpp b/src/Primitives/PrimPolyline.cpp index f6ba55a..a96c944 100644 --- a/src/Primitives/PrimPolyline.cpp +++ b/src/Primitives/PrimPolyline.cpp @@ -1,91 +1,94 @@ -#include -#include -#include - -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimPolyline.hpp" - - -size_t PrimPolyline::getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount) -{ - size_t expectedByteLength; - - if(aVersion <= FileFormatVersion::A) - { - expectedByteLength = 10u + 4u * aPointCount; - } - else - { - expectedByteLength = 18u + 4u * aPointCount; - } - - return expectedByteLength; -} - - -void PrimPolyline::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - if(aVersion == FileFormatVersion::Unknown) - { - aVersion = predictVersion(); - } - - const size_t startOffset = ds.getCurrentOffset(); - - const uint32_t byteLength = ds.readUint32(); - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - if(aVersion >= FileFormatVersion::B) - { - setLineStyle(ToLineStyle(ds.readUint32())); - setLineWidth(ToLineWidth(ds.readUint32())); - } - - const uint16_t pointCount = ds.readUint16(); - - spdlog::trace("pointCount = {}", pointCount); - - if(pointCount < 2) - { - throw std::runtime_error("At minimum 2 'PolylinePoint's must occur but got " + std::to_string(pointCount) - + " points!"); - } - - for(size_t i = 0u; i < pointCount; ++i) - { - Point point{mCtx}; - point.read(); - points.push_back(point); - } - - // @todo - int byteDiff = static_cast(byteLength) - static_cast(ds.getCurrentOffset() - startOffset); - if(byteDiff > 0) - { - ds.printUnknownData(byteDiff); - } - - if(ds.getCurrentOffset() != startOffset + byteLength) - { - // throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); - } - - if(byteLength != getExpectedStructSize(aVersion, pointCount)) - { - // throw FileFormatChanged(std::string(nameof::nameof_type())); - } - - readPreamble(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimPolyline.hpp" + + +size_t PrimPolyline::getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount) +{ + size_t expectedByteLength; + + if(aVersion <= FileFormatVersion::A) + { + expectedByteLength = 10u + 4u * aPointCount; + } + else + { + expectedByteLength = 18u + 4u * aPointCount; + } + + return expectedByteLength; +} + + +void PrimPolyline::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + if(aVersion == FileFormatVersion::Unknown) + { + const auto predictionFunc = [this](FileFormatVersion aVersion){ this->read(aVersion); }; + aVersion = parser.predictVersion(predictionFunc); + } + + const size_t startOffset = ds.getCurrentOffset(); + + const uint32_t byteLength = ds.readUint32(); + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + if(aVersion >= FileFormatVersion::B) + { + setLineStyle(ToLineStyle(ds.readUint32())); + setLineWidth(ToLineWidth(ds.readUint32())); + } + + const uint16_t pointCount = ds.readUint16(); + + spdlog::trace("pointCount = {}", pointCount); + + if(pointCount < 2) + { + throw std::runtime_error("At minimum 2 'PolylinePoint's must occur but got " + std::to_string(pointCount) + + " points!"); + } + + for(size_t i = 0u; i < pointCount; ++i) + { + Point point{mCtx}; + point.read(); + points.push_back(point); + } + + // @todo + int byteDiff = static_cast(byteLength) - static_cast(ds.getCurrentOffset() - startOffset); + if(byteDiff > 0) + { + ds.printUnknownData(byteDiff); + } + + if(ds.getCurrentOffset() != startOffset + byteLength) + { + // throw MisinterpretedData(__func__, startOffset, byteLength, ds.getCurrentOffset()); + } + + if(byteLength != getExpectedStructSize(aVersion, pointCount)) + { + // throw FileFormatChanged(std::string(nameof::nameof_type())); + } + + parser.readPreamble(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimPolyline.hpp b/src/Primitives/PrimPolyline.hpp index 82f1bbd..158ee37 100644 --- a/src/Primitives/PrimPolyline.hpp +++ b/src/Primitives/PrimPolyline.hpp @@ -1,102 +1,102 @@ -#ifndef PRIMPOLYLINE_HPP -#define PRIMPOLYLINE_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "Primitives/Point.hpp" -#include "Primitives/PrimBase.hpp" - - -class PrimPolyline : public PrimBase -{ -public: - - PrimPolyline(ParserContext& aCtx) : PrimBase{aCtx}, mLineStyle{}, mLineWidth{}, points{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - static size_t getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount); - - void setLineStyle(const LineStyle& aVal) - { - mLineStyle = std::make_optional(aVal); - } - - LineStyle getLineStyle() const - { - return mLineStyle.value_or(LineStyle::Solid); - } - - void setLineWidth(const LineWidth& aVal) - { - mLineWidth = std::make_optional(aVal); - } - - LineWidth getLineWidth() const - { - return mLineWidth.value_or(LineWidth::Default); - } - -private: - - std::optional mLineStyle; - std::optional mLineWidth; - -public: - - std::vector points; -}; - - -[[maybe_unused]] -static std::string to_string(const PrimPolyline& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); - str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); - - str += fmt::format("{}points:\n", indent(1)); - for(size_t i = 0u; i < aObj.points.size(); ++i) - { - str += indent(fmt::format("{}: {}", i, to_string(aObj.points[i])), 2); - } - - return str; -} - - -inline std::string PrimPolyline::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const PrimPolyline& aVal) -{ - aOs << to_string(aVal); - return aOs; -} - - +#ifndef PRIMPOLYLINE_HPP +#define PRIMPOLYLINE_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "Primitives/Point.hpp" +#include "Primitives/PrimBase.hpp" + + +class PrimPolyline : public PrimBase +{ +public: + + PrimPolyline(StreamContext& aCtx) : PrimBase{aCtx}, mLineStyle{}, mLineWidth{}, points{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + static size_t getExpectedStructSize(FileFormatVersion aVersion, size_t aPointCount); + + void setLineStyle(const LineStyle& aVal) + { + mLineStyle = std::make_optional(aVal); + } + + LineStyle getLineStyle() const + { + return mLineStyle.value_or(LineStyle::Solid); + } + + void setLineWidth(const LineWidth& aVal) + { + mLineWidth = std::make_optional(aVal); + } + + LineWidth getLineWidth() const + { + return mLineWidth.value_or(LineWidth::Default); + } + +private: + + std::optional mLineStyle; + std::optional mLineWidth; + +public: + + std::vector points; +}; + + +[[maybe_unused]] +static std::string to_string(const PrimPolyline& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); + str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); + + str += fmt::format("{}points:\n", indent(1)); + for(size_t i = 0u; i < aObj.points.size(); ++i) + { + str += indent(fmt::format("{}: {}", i, to_string(aObj.points[i])), 2); + } + + return str; +} + + +inline std::string PrimPolyline::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const PrimPolyline& aVal) +{ + aOs << to_string(aVal); + return aOs; +} + + #endif // PRIMPOLYLINE_HPP \ No newline at end of file diff --git a/src/Primitives/PrimRect.cpp b/src/Primitives/PrimRect.cpp index d26be90..8b89c72 100644 --- a/src/Primitives/PrimRect.cpp +++ b/src/Primitives/PrimRect.cpp @@ -1,90 +1,93 @@ -#include -#include -#include - -#include -#include - -#include "Enums/FillStyle.hpp" -#include "Enums/HatchStyle.hpp" -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimRect.hpp" - - -size_t PrimRect::getExpectedStructSize(FileFormatVersion aVersion) -{ - size_t expectedByteLength; - - if(aVersion <= FileFormatVersion::A) - { - expectedByteLength = 24U; - } - else if(aVersion <= FileFormatVersion::B) - { - expectedByteLength = 32u; - } - else - { - expectedByteLength = 40u; - } - - return expectedByteLength; -} - - -void PrimRect::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - if(aVersion == FileFormatVersion::Unknown) - { - aVersion = predictVersion(); - } - - const size_t startOffset = ds.getCurrentOffset(); - - const uint32_t byteLength = ds.readUint32(); - - // @todo better move this if-statement into Rect::checkByteLength(byteLength, version) - if(byteLength != PrimRect::getExpectedStructSize(aVersion)) - { - throw FileFormatChanged("Rect"); - } - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); - - x1 = ds.readInt32(); - y1 = ds.readInt32(); - x2 = ds.readInt32(); - y2 = ds.readInt32(); - - if(aVersion >= FileFormatVersion::B) - { - setLineStyle(ToLineStyle(ds.readUint32())); - setLineWidth(ToLineWidth(ds.readUint32())); - } - - if(aVersion >= FileFormatVersion::C) - { - fillStyle = ToFillStyle(ds.readUint32()); - hatchStyle = ToHatchStyle(ds.readInt32()); - } - else - { - // Set default values - fillStyle = FillStyle::None; - hatchStyle = HatchStyle::LinesHorizontal; - } - - // @todo use for all read methods. - checkInterpretedDataLen(__func__, startOffset, ds.getCurrentOffset(), byteLength); - - readPreamble(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include +#include + +#include "Enums/FillStyle.hpp" +#include "Enums/HatchStyle.hpp" +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimRect.hpp" + + +size_t PrimRect::getExpectedStructSize(FileFormatVersion aVersion) +{ + size_t expectedByteLength; + + if(aVersion <= FileFormatVersion::A) + { + expectedByteLength = 24U; + } + else if(aVersion <= FileFormatVersion::B) + { + expectedByteLength = 32u; + } + else + { + expectedByteLength = 40u; + } + + return expectedByteLength; +} + + +void PrimRect::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + if(aVersion == FileFormatVersion::Unknown) + { + const auto predictionFunc = [this](FileFormatVersion aVersion){ this->read(aVersion); }; + aVersion = parser.predictVersion(predictionFunc); + } + + const size_t startOffset = ds.getCurrentOffset(); + + const uint32_t byteLength = ds.readUint32(); + + // @todo better move this if-statement into Rect::checkByteLength(byteLength, version) + if(byteLength != PrimRect::getExpectedStructSize(aVersion)) + { + throw FileFormatChanged("Rect"); + } + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 0"); + + x1 = ds.readInt32(); + y1 = ds.readInt32(); + x2 = ds.readInt32(); + y2 = ds.readInt32(); + + if(aVersion >= FileFormatVersion::B) + { + setLineStyle(ToLineStyle(ds.readUint32())); + setLineWidth(ToLineWidth(ds.readUint32())); + } + + if(aVersion >= FileFormatVersion::C) + { + fillStyle = ToFillStyle(ds.readUint32()); + hatchStyle = ToHatchStyle(ds.readInt32()); + } + else + { + // Set default values + fillStyle = FillStyle::None; + hatchStyle = HatchStyle::LinesHorizontal; + } + + // @todo use for all read methods. + parser.checkInterpretedDataLen(__func__, startOffset, ds.getCurrentOffset(), byteLength); + + parser.readPreamble(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimRect.hpp b/src/Primitives/PrimRect.hpp index 013963c..96baa0c 100644 --- a/src/Primitives/PrimRect.hpp +++ b/src/Primitives/PrimRect.hpp @@ -1,112 +1,112 @@ -#ifndef PRIMRECT_HPP -#define PRIMRECT_HPP - - -#include -#include -#include -#include - -#include -#include - -#include "Enums/FillStyle.hpp" -#include "Enums/HatchStyle.hpp" -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/Point.hpp" -#include "Primitives/PrimBase.hpp" - - -class PrimRect : public PrimBase -{ -public: - PrimRect(ParserContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, - mLineStyle{}, mLineWidth{}, fillStyle{}, hatchStyle{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - static size_t getExpectedStructSize(FileFormatVersion aVersion); - - void setLineStyle(const LineStyle& aVal) - { - mLineStyle = std::make_optional(aVal); - } - - LineStyle getLineStyle() const - { - return mLineStyle.value_or(LineStyle::Solid); - } - - void setLineWidth(const LineWidth& aVal) - { - mLineWidth = std::make_optional(aVal); - } - - LineWidth getLineWidth() const - { - return mLineWidth.value_or(LineWidth::Default); - } - - int32_t x1; - int32_t y1; - - int32_t x2; - int32_t y2; - -private: - - std::optional mLineStyle; - std::optional mLineWidth; - -public: - - FillStyle fillStyle; - HatchStyle hatchStyle; -}; - - -[[maybe_unused]] -static std::string to_string(const PrimRect& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}x1 = {}\n", indent(1), aObj.x1); - str += fmt::format("{}y1 = {}\n", indent(1), aObj.y1); - str += fmt::format("{}x2 = {}\n", indent(1), aObj.x2); - str += fmt::format("{}y2 = {}\n", indent(1), aObj.y2); - str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); - str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); - str += fmt::format("{}fillStyle = {}\n", indent(1), to_string(aObj.fillStyle)); - str += fmt::format("{}hatchStyle = {}\n", indent(1), to_string(aObj.hatchStyle)); - - return str; -} - - -inline std::string PrimRect::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const PrimRect& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef PRIMRECT_HPP +#define PRIMRECT_HPP + + +#include +#include +#include +#include + +#include +#include + +#include "Enums/FillStyle.hpp" +#include "Enums/HatchStyle.hpp" +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "General.hpp" +#include "Primitives/Point.hpp" +#include "Primitives/PrimBase.hpp" + + +class PrimRect : public PrimBase +{ +public: + PrimRect(StreamContext& aCtx) : PrimBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0}, + mLineStyle{}, mLineWidth{}, fillStyle{}, hatchStyle{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + static size_t getExpectedStructSize(FileFormatVersion aVersion); + + void setLineStyle(const LineStyle& aVal) + { + mLineStyle = std::make_optional(aVal); + } + + LineStyle getLineStyle() const + { + return mLineStyle.value_or(LineStyle::Solid); + } + + void setLineWidth(const LineWidth& aVal) + { + mLineWidth = std::make_optional(aVal); + } + + LineWidth getLineWidth() const + { + return mLineWidth.value_or(LineWidth::Default); + } + + int32_t x1; + int32_t y1; + + int32_t x2; + int32_t y2; + +private: + + std::optional mLineStyle; + std::optional mLineWidth; + +public: + + FillStyle fillStyle; + HatchStyle hatchStyle; +}; + + +[[maybe_unused]] +static std::string to_string(const PrimRect& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}x1 = {}\n", indent(1), aObj.x1); + str += fmt::format("{}y1 = {}\n", indent(1), aObj.y1); + str += fmt::format("{}x2 = {}\n", indent(1), aObj.x2); + str += fmt::format("{}y2 = {}\n", indent(1), aObj.y2); + str += fmt::format("{}lineStyle = {}\n", indent(1), to_string(aObj.getLineStyle())); + str += fmt::format("{}lineWidth = {}\n", indent(1), to_string(aObj.getLineWidth())); + str += fmt::format("{}fillStyle = {}\n", indent(1), to_string(aObj.fillStyle)); + str += fmt::format("{}hatchStyle = {}\n", indent(1), to_string(aObj.hatchStyle)); + + return str; +} + + +inline std::string PrimRect::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const PrimRect& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // PRIMRECT_HPP \ No newline at end of file diff --git a/src/Primitives/PrimSymbolVector.cpp b/src/Primitives/PrimSymbolVector.cpp index 0ec6000..b215c65 100644 --- a/src/Primitives/PrimSymbolVector.cpp +++ b/src/Primitives/PrimSymbolVector.cpp @@ -1,58 +1,61 @@ -#include -#include -#include - -#include -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "General.hpp" -#include "Primitives/PrimSymbolVector.hpp" - - -void PrimSymbolVector::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const auto readSmallPrefixPrimitive = [&, this]() -> Primitive - { - Primitive primitive = ToPrimitive(ds.readUint8()); - ds.assumeData({0x00}, getMethodName(this, __func__) + ": 0"); - ds.assumeData({static_cast(primitive)}, getMethodName(this, __func__) + ": 1"); - - return primitive; - }; - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(localFutureLst); - - readPreamble(); - - locX = ds.readInt16(); - locY = ds.readInt16(); - - const uint16_t lenPrimitives = ds.readUint16(); - - spdlog::trace("lenPrimitives = {}", lenPrimitives); - - for(size_t i = 0u; i < lenPrimitives; ++i) - { - const Primitive primitive = readSmallPrefixPrimitive(); - - readPrimitive(primitive); - } - - name = ds.readStringLenZeroTerm(); - - // @todo contains smallPrefixPrimitive - // ds.assumeData({0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x32, 0x00, 0x00, 0x00, 0x02, 0x00}, getMethodName(this, __func__) + ": 2"); - // ds.printUnknownData(12, getMethodName(this, __func__) + ": 2"); - - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "FutureData.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Primitives/PrimSymbolVector.hpp" + + +void PrimSymbolVector::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + const auto readSmallPrefixPrimitive = [&, this]() -> Primitive + { + Primitive primitive = ToPrimitive(ds.readUint8()); + ds.assumeData({0x00}, getMethodName(this, __func__) + ": 0"); + ds.assumeData({static_cast(primitive)}, getMethodName(this, __func__) + ": 1"); + + return primitive; + }; + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(localFutureLst); + + parser.readPreamble(); + + locX = ds.readInt16(); + locY = ds.readInt16(); + + const uint16_t lenPrimitives = ds.readUint16(); + + spdlog::trace("lenPrimitives = {}", lenPrimitives); + + for(size_t i = 0u; i < lenPrimitives; ++i) + { + const Primitive primitive = readSmallPrefixPrimitive(); + + parser.readPrimitive(primitive); + } + + name = ds.readStringLenZeroTerm(); + + // @todo contains smallPrefixPrimitive + // ds.assumeData({0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x32, 0x00, 0x00, 0x00, 0x02, 0x00}, getMethodName(this, __func__) + ": 2"); + // ds.printUnknownData(12, getMethodName(this, __func__) + ": 2"); + + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Primitives/PrimSymbolVector.hpp b/src/Primitives/PrimSymbolVector.hpp index 46de6c5..80f5f63 100644 --- a/src/Primitives/PrimSymbolVector.hpp +++ b/src/Primitives/PrimSymbolVector.hpp @@ -17,14 +17,14 @@ class PrimSymbolVector : public PrimBase // @todo probably derive from PrimBase, { public: - PrimSymbolVector(ParserContext& aCtx) : PrimBase{aCtx}, locX{0}, locY{0}, name{}, primitives{} + PrimSymbolVector(StreamContext& aCtx) : PrimBase{aCtx}, locX{0}, locY{0}, name{}, primitives{} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Record.hpp b/src/Record.hpp new file mode 100644 index 0000000..a7c8855 --- /dev/null +++ b/src/Record.hpp @@ -0,0 +1,27 @@ +#ifndef RECORD_HPP +#define RECORD_HPP + + +#include + +#include "General.hpp" +#include "StreamContext.hpp" +#include "VisitorPattern.hpp" + + +class Record : public Component +{ +public: + Record(StreamContext& aCtx) : mCtx{aCtx} + { } + + virtual std::string to_string() const = 0; + + virtual void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) = 0; + +protected: + StreamContext& mCtx; +}; + + +#endif // RECORD_HPP \ No newline at end of file diff --git a/src/RecordFactory.cpp b/src/RecordFactory.cpp new file mode 100644 index 0000000..d22842d --- /dev/null +++ b/src/RecordFactory.cpp @@ -0,0 +1,154 @@ +#include +#include + +#include +#include + +#include "Enums/Primitive.hpp" +#include "Enums/Structure.hpp" +#include "Primitives/Point.hpp" +#include "Primitives/PrimArc.hpp" +#include "Primitives/PrimBezier.hpp" +#include "Primitives/PrimBitmap.hpp" +#include "Primitives/PrimCommentText.hpp" +#include "Primitives/PrimEllipse.hpp" +#include "Primitives/PrimLine.hpp" +#include "Primitives/PrimPolygon.hpp" +#include "Primitives/PrimPolyline.hpp" +#include "Primitives/PrimRect.hpp" +#include "Primitives/PrimSymbolVector.hpp" +#include "Record.hpp" +#include "RecordFactory.hpp" +#include "StreamContext.hpp" +#include "Structures/StructAlias.hpp" +#include "Structures/StructBookMarkSymbolInst.hpp" +#include "Structures/StructBusEntry.hpp" +#include "Structures/StructERCSymbol.hpp" +#include "Structures/StructERCSymbolInst.hpp" +#include "Structures/StructGeneralProperties.hpp" +#include "Structures/StructGlobal.hpp" +#include "Structures/StructGlobalSymbol.hpp" +#include "Structures/StructGraphicArcInst.hpp" +#include "Structures/StructGraphicBezierInst.hpp" +#include "Structures/StructGraphicBitMapInst.hpp" +#include "Structures/StructGraphicBoxInst.hpp" +#include "Structures/StructGraphicCommentTextInst.hpp" +#include "Structures/StructGraphicEllipseInst.hpp" +#include "Structures/StructGraphicLineInst.hpp" +#include "Structures/StructGraphicOleEmbedInst.hpp" +#include "Structures/StructGraphicPolygonInst.hpp" +#include "Structures/StructGraphicPolylineInst.hpp" +#include "Structures/StructHierarchicSymbol.hpp" +#include "Structures/StructNetDbIdMapping.hpp" +#include "Structures/StructOffPageConnector.hpp" +#include "Structures/StructOffPageSymbol.hpp" +#include "Structures/StructPartInst.hpp" +#include "Structures/StructPinIdxMapping.hpp" +#include "Structures/StructPinShapeSymbol.hpp" +#include "Structures/StructPort.hpp" +#include "Structures/StructPrimitives.hpp" +#include "Structures/StructProperties.hpp" +#include "Structures/StructSthInHierarchy1.hpp" +#include "Structures/StructSthInHierarchy2.hpp" +#include "Structures/StructSthInHierarchy3.hpp" +#include "Structures/StructSthInPages0.hpp" +#include "Structures/StructSymbolBBox.hpp" +#include "Structures/StructSymbolDisplayProp.hpp" +#include "Structures/StructSymbolPinBus.hpp" +#include "Structures/StructSymbolPinScalar.hpp" +#include "Structures/StructT0x10.hpp" +#include "Structures/StructT0x1f.hpp" +#include "Structures/StructT0x34.hpp" +#include "Structures/StructT0x35.hpp" +#include "Structures/StructT0x45.hpp" +#include "Structures/StructT0x5b.hpp" +#include "Structures/StructTitleBlock.hpp" +#include "Structures/StructTitleBlockSymbol.hpp" +#include "Structures/StructWireBus.hpp" +#include "Structures/StructWireScalar.hpp" + + +std::unique_ptr RecordFactory::build(StreamContext& aCtx, Structure aStructure) +{ + switch(aStructure) + { + case Structure::Alias: return std::make_unique(aCtx); break; + case Structure::BookMarkSymbolInst: return std::make_unique(aCtx); break; + case Structure::BusEntry: return std::make_unique(aCtx); break; + case Structure::ERCSymbol: return std::make_unique(aCtx); break; + case Structure::ERCSymbolInst: return std::make_unique(aCtx); break; + case Structure::Global: return std::make_unique(aCtx); break; + case Structure::GlobalSymbol: return std::make_unique(aCtx); break; + case Structure::GraphicArcInst: return std::make_unique(aCtx); break; + case Structure::GraphicBezierInst: return std::make_unique(aCtx); break; + case Structure::GraphicBitMapInst: return std::make_unique(aCtx); break; + case Structure::GraphicBoxInst: return std::make_unique(aCtx); break; + case Structure::GraphicCommentTextInst: return std::make_unique(aCtx); break; + case Structure::GraphicEllipseInst: return std::make_unique(aCtx); break; + case Structure::GraphicLineInst: return std::make_unique(aCtx); break; + case Structure::GraphicOleEmbedInst: return std::make_unique(aCtx); break; + case Structure::GraphicPolygonInst: return std::make_unique(aCtx); break; + case Structure::GraphicPolylineInst: return std::make_unique(aCtx); break; + case Structure::NetDbIdMapping: return std::make_unique(aCtx); break; + case Structure::OffPageConnector: return std::make_unique(aCtx); break; + case Structure::OffPageSymbol: return std::make_unique(aCtx); break; + case Structure::PartInst: return std::make_unique(aCtx); break; + case Structure::PinIdxMapping: return std::make_unique(aCtx); break; + case Structure::PinShapeSymbol: return std::make_unique(aCtx); break; + case Structure::Port: return std::make_unique(aCtx); break; + case Structure::PortSymbol: return std::make_unique(aCtx); break; + case Structure::Primitives: return std::make_unique(aCtx); break; + case Structure::Properties: return std::make_unique(aCtx); break; + case Structure::SthInHierarchy1: return std::make_unique(aCtx); break; + case Structure::SthInHierarchy2: return std::make_unique(aCtx); break; + case Structure::SthInHierarchy3: return std::make_unique(aCtx); break; + case Structure::SthInPages0: return std::make_unique(aCtx); break; + case Structure::SymbolDisplayProp: return std::make_unique(aCtx); break; + case Structure::SymbolPinBus: return std::make_unique(aCtx); break; + case Structure::SymbolPinScalar: return std::make_unique(aCtx); break; + case Structure::T0x10: return std::make_unique(aCtx); break; + case Structure::T0x1f: return std::make_unique(aCtx); break; + case Structure::T0x34: return std::make_unique(aCtx); break; + case Structure::T0x35: return std::make_unique(aCtx); break; + case Structure::T0x45: return std::make_unique(aCtx); break; + case Structure::T0x5b: return std::make_unique(aCtx); break; + case Structure::TitleBlock: return std::make_unique(aCtx); break; + case Structure::TitleBlockSymbol: return std::make_unique(aCtx); break; + case Structure::WireBus: return std::make_unique(aCtx); break; + case Structure::WireScalar: return std::make_unique(aCtx); break; + default: + { + const std::string errMsg = fmt::format( + "RecordFactory can not yet build {}", to_string(aStructure)); + spdlog::error(errMsg); + } + } + + return std::unique_ptr{}; +} + + +std::unique_ptr RecordFactory::build(StreamContext& aCtx, Primitive aPrimitive) +{ + switch(aPrimitive) + { + case Primitive::Rect: return std::make_unique(aCtx); break; + case Primitive::Line: return std::make_unique(aCtx); break; + case Primitive::Arc: return std::make_unique(aCtx); break; + case Primitive::Ellipse: return std::make_unique(aCtx); break; + case Primitive::Polygon: return std::make_unique(aCtx); break; + case Primitive::Polyline: return std::make_unique(aCtx); break; + case Primitive::CommentText: return std::make_unique(aCtx); break; + case Primitive::Bitmap: return std::make_unique(aCtx); break; + case Primitive::SymbolVector: return std::make_unique(aCtx); break; + case Primitive::Bezier: return std::make_unique(aCtx); break; + default: + { + const std::string errMsg = fmt::format( + "RecordFactory can not yet build {}", to_string(aPrimitive)); + spdlog::error(errMsg); + } + } + + return std::unique_ptr{}; +} diff --git a/src/RecordFactory.hpp b/src/RecordFactory.hpp new file mode 100644 index 0000000..2249ecb --- /dev/null +++ b/src/RecordFactory.hpp @@ -0,0 +1,21 @@ +#ifndef RECORDFACTORY_HPP +#define RECORDFACTORY_HPP + + +#include + +#include "Enums/Primitive.hpp" +#include "Enums/Structure.hpp" +#include "Record.hpp" +#include "StreamContext.hpp" + + +class RecordFactory +{ +public: + static std::unique_ptr build(StreamContext& aCtx, Structure aStructure); + static std::unique_ptr build(StreamContext& aCtx, Primitive aPrimitive); +}; + + +#endif // RECORDFACTORY_HPP \ No newline at end of file diff --git a/src/Stream.hpp b/src/Stream.hpp new file mode 100644 index 0000000..b3a6e15 --- /dev/null +++ b/src/Stream.hpp @@ -0,0 +1,47 @@ +#ifndef STREAM_HPP +#define STREAM_HPP + + +#include +#include +#include +#include + +#include "ContainerContext.hpp" +#include "Enums/Structure.hpp" +#include "FutureData.hpp" +#include "General.hpp" +#include "Record.hpp" +#include "VisitorPattern.hpp" + + +class Stream : public Component +{ +public: + Stream(ContainerContext& aCtx, const fs::path& aInputStream) : mCtx{aCtx, aInputStream} + { } + + virtual std::string to_string() const = 0; + + virtual void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) = 0; + + void openFile() + { + spdlog::info("Opening file: {}", mCtx.mInputStream.string()); + + spdlog::info("File contains {} byte.", fs::file_size(mCtx.mInputStream)); + } + + void closeFile() + { + spdlog::info("Closing file: {}", mCtx.mInputStream.string()); + + mCtx.mDs.close(); + } + +// protected: + StreamContext mCtx; +}; + + +#endif // STREAM_HPP \ No newline at end of file diff --git a/src/StreamContext.hpp b/src/StreamContext.hpp new file mode 100644 index 0000000..0d1bf5d --- /dev/null +++ b/src/StreamContext.hpp @@ -0,0 +1,64 @@ +#ifndef STREAMCONTEXT_HPP +#define STREAMCONTEXT_HPP + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ContainerContext.hpp" +#include "DataStream.hpp" +#include "General.hpp" +// #include "Stream.hpp" + + +class Stream; + + +namespace fs = std::filesystem; + + +class StreamContext : public ContainerContext +{ +public: + + StreamContext(const ContainerContext& aCtx, const fs::path& aInputStream) + : ContainerContext{aCtx}, mCfbfStreamLocation{mInputStream, mExtractedCfbfPath}, + mDs{aInputStream}, mMtx{} + { + mInputStream = aInputStream; + mImgCtr = 0U; + mAttemptedParsing = false; + mParsedSuccessfully = std::nullopt; + } + + fs::path mInputStream; //!< Input CFBF stream as file in the file system + + CfbfStreamLocation mCfbfStreamLocation; //!< Location of the stream inside the CFBF container + + DataStream mDs; + + size_t mImgCtr; //!< Counts images per stream + + // True, iff the parser was run on this stream. It is + // not important wether the parser was successful or not + bool mAttemptedParsing; + + // True, if stream was parsed successfully. If there + // was no attempt to parse the stream yet, this variable + // is null. + std::optional mParsedSuccessfully; + + std::mutex mMtx; +}; + + +#endif // STREAMCONTEXT_HPP \ No newline at end of file diff --git a/src/StreamFactory.cpp b/src/StreamFactory.cpp index ef466f7..9050943 100644 --- a/src/StreamFactory.cpp +++ b/src/StreamFactory.cpp @@ -1,13 +1,14 @@ #include #include +#include #include #include #include #include -#include "CommonBase.hpp" -#include "ParserContext.hpp" +#include "ContainerContext.hpp" +#include "Stream.hpp" #include "StreamFactory.hpp" #include "Streams/StreamAdminData.hpp" #include "Streams/StreamCache.hpp" @@ -30,305 +31,297 @@ #include "Streams/StreamViewsDirectory.hpp" -std::unique_ptr StreamFactory::build(ParserContext& aCtx, const std::vector& aCfbfStreamLocation) +std::unique_ptr StreamFactory::build(ContainerContext& aCtx, const fs::path& aInputStream) { - const auto& loc = aCfbfStreamLocation; + auto streamLoc = CfbfStreamLocation{aInputStream, aCtx.mExtractedCfbfPath}; + const auto& loc = streamLoc.get_vector(); - std::string locStr{}; - for(const auto& locPart : loc) - { - locStr += "/" + locPart; - } + spdlog::debug("Got stream location: {}", ::to_string(streamLoc)); + + const auto getErrMsg = [](const std::vector>& aPattern, const CfbfStreamLocation& aStreamLoc) + { + std::string strPattern{}; + + for(const auto& part : aPattern) + { + strPattern += "/" + part.value_or("*"); + } + + return fmt::format( + "Detected `{}` matching `{}` but stream parser is not yet implemented!", + ::to_string(aStreamLoc), strPattern + ); + }; - spdlog::debug("Got stream location: {}", locStr); + std::vector> pattern; - // Match `AdminData` - if(loc.size() == 1U && loc.at(0U) == "AdminData") + // Match `/AdminData` + pattern = {"AdminData"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `Cache` - if(loc.size() == 1U && loc.at(0U) == "Cache") + // Match `/BundleMapData` + pattern = {"BundleMapData"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `Cells/*` - if(loc.size() == 2U && loc.at(0U) == "Cells") + // Match `/Cache` + pattern = {"Cache"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected Cell but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + return std::make_unique(aCtx, aInputStream); } - // Match `Cells Directory` - if(loc.size() == 1U && loc.at(0U) == "Cells Directory") + // Match `/Cells/*` + pattern = {"Cells", std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `CIS/CISSchematicStore/CISSchematicStream` - if(loc.size() == 3U && loc.at(0U) == "CIS" - && loc.at(1U) == "CISSchematicStore" - && loc.at(2U) == "CISSchematicStream") + // Match `/Cells Directory` + pattern = {"Cells Directory"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected CISSchematicStream but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + return std::make_unique(aCtx, aInputStream); } - // Match `CIS/VariantStore/BOM/BOMDataStream` - if(loc.size() == 4U && loc.at(0U) == "CIS" - && loc.at(1U) == "VariantStore" - && loc.at(2U) == "BOM" - && loc.at(3U) == "BOMDataStream") + // Match `/CIS/CISSchematicStore/CISSchematicStream` + pattern = {"CIS", "CISSchematicStore", "CISSchematicStream"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected BOMDataStream but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `CIS/VariantStore/Groups/GroupsDataStream` - if(loc.size() == 4U && loc.at(0U) == "CIS" - && loc.at(1U) == "VariantStore" - && loc.at(2U) == "Groups" - && loc.at(3U) == "GroupsDataStream") + // Match `/CIS/VariantStore/BOM/*/BOMAmbugity` + pattern = {"CIS", "VariantStore", "BOM", std::nullopt, "BOMAmbugity"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected GroupsDataStream but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `CIS/VariantStore/VariantNames` - if(loc.size() == 3U && loc.at(0U) == "CIS" - && loc.at(1U) == "VariantStore" - && loc.at(2U) == "VariantNames") + // Match `/CIS/VariantStore/BOM/*/BOMPartData` + pattern = {"CIS", "VariantStore", "BOM", std::nullopt, "BOMPartData"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected VariantName but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `DsnStream` - if(loc.size() == 1U && loc.at(0U) == "DsnStream") + // Match `/CIS/VariantStore/BOM/*/*` + pattern = {"CIS", "VariantStore", "BOM", std::nullopt, std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `ExportBlocks/*` - if(loc.size() == 2U && loc.at(0U) == "ExportBlocks") + // Match `/CIS/VariantStore/Groups/GroupsDataStream` + pattern = {"CIS", "VariantStore", "Groups", "GroupsDataStream"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected ExportBlock but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `ExportBlocks Directory` - if(loc.size() == 1U && loc.at(0U) == "ExportBlocks Directory") + // Match `/CIS/VariantStore/Groups/*/*` + pattern = {"CIS", "VariantStore", "Groups", std::nullopt, std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `Graphics/$Types$` - if(loc.size() == 2U && loc.at(0U) == "Graphics" - && loc.at(1U) == "$Types$") + // Match `/CIS/VariantStore/VariantNames` + pattern = {"CIS", "VariantStore", "VariantNames"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `Graphics/*` - if(loc.size() == 2U && loc.at(0U) == "Graphics" - && loc.at(1U) != "$Types$") + // Match `/DsnStream` + pattern = {"DsnStream"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected Graphic but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + return std::make_unique(aCtx, aInputStream); } - // Match `Graphics Directory` - if(loc.size() == 1U && loc.at(0U) == "Graphics Directory") + // Match `/ExportBlocks/*` + pattern = {"ExportBlocks", std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `HSObjects` - if(loc.size() == 1U && loc.at(0U) == "HSObjects") + // Match `/ExportBlocks Directory` + pattern = {"ExportBlocks Directory"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `LayoutReuse/ReuseSchematics` - if(loc.size() == 2U && loc.at(0U) == "LayoutReuse" - && loc.at(1U) == "ReuseSchematics") + // Match `/Graphics/$Types$` + pattern = {"Graphics", "$Types$"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected ReuseSchematic but stream parser is not yet implemented!"); - spdlog::warn(errMsg); - - return std::unique_ptr{}; + return std::make_unique(aCtx, aInputStream); } - // Match `Library` - if(loc.size() == 1U && loc.at(0U) == "Library") + // Match `/Graphics/*` + pattern = {"Graphics", std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `NetBundleMapData` - if(loc.size() == 1U && loc.at(0U) == "NetBundleMapData") + // Match `/Graphics Directory` + pattern = {"Graphics Directory"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `Packages/*` - if(loc.size() == 2U && loc.at(0U) == "Packages") + // Match `/HSObjects` + pattern = {"HSObjects"}; + if(streamLoc.matches_pattern(pattern)) { - // We extract embedded files into the same directory but do - // not want to parse them as stream. Therefore skip them. - // @todo This is just a workaround; needs some refactoring - // if(!fs::path(loc.at(1)).has_extension()) - { - return std::make_unique(aCtx); - } + return std::make_unique(aCtx, aInputStream); } - // Match `Packages Directory` - if(loc.size() == 1U && loc.at(0U) == "Packages Directory") + // Match `/LayoutReuse/ReuseSchematics` + pattern = {"LayoutReuse", "ReuseSchematics"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `Parts/*` - if(loc.size() == 2U && loc.at(0U) == "Parts") + // Match `/Library` + pattern = {"Library"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected Part but stream parser is not yet implemented!"); - spdlog::warn(errMsg); + return std::make_unique(aCtx, aInputStream); + } - return std::unique_ptr{}; + // Match `/NetBundleMapData` + pattern = {"NetBundleMapData"}; + if(streamLoc.matches_pattern(pattern)) + { + return std::make_unique(aCtx, aInputStream); } - // Match `Parts Directory` - if(loc.size() == 1U && loc.at(0U) == "Parts Directory") + // Match `/Packages/*` + pattern = {"Packages", std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `Symbols/$Types$` - if(loc.size() == 2U && loc.at(0U) == "Symbols" - && loc.at(1U) == "$Types$") + // Match `/Packages Directory` + pattern = {"Packages Directory"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected Symbols/$Types$ but stream parser is skipped!"); - spdlog::warn(errMsg); + return std::make_unique(aCtx, aInputStream); + } - return std::unique_ptr{}; + // Match `/Parts/*` + pattern = {"Parts", std::nullopt}; + if(streamLoc.matches_pattern(pattern)) + { + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `Symbols/ERC` - if(loc.size() == 2U && loc.at(0U) == "Symbols" - && loc.at(1U) == "ERC") + // Match `/Parts Directory` + pattern = {"Parts Directory"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected Symbols/ERC but stream parser is skipped!"); - spdlog::warn(errMsg); + return std::make_unique(aCtx, aInputStream); + } - return std::unique_ptr{}; + // Match `/Symbols/$Types$` + pattern = {"Symbols", "$Types$"}; + if(streamLoc.matches_pattern(pattern)) + { + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `Symbols/ERC_PHYSICAL` - if(loc.size() == 2U && loc.at(0U) == "Symbols" - && loc.at(1U) == "ERC_PHYSICAL") + // Match `/Symbols/ERC` + pattern = {"Symbols", "ERC"}; + if(streamLoc.matches_pattern(pattern)) { - // return std::make_unique(aCtx); - const std::string errMsg = fmt::format( - "Detected ERC_PHYSICAL but stream parser is not yet implemented!"); - spdlog::warn(errMsg); + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; + } - return std::unique_ptr{}; + // Match `/Symbols/ERC_PHYSICAL` + pattern = {"Symbols", "ERC_PHYSICAL"}; + if(streamLoc.matches_pattern(pattern)) + { + spdlog::warn(getErrMsg(pattern, streamLoc)); + return std::unique_ptr{}; } - // Match `Symbols/*` - if(loc.size() == 2U && loc.at(0U) == "Symbols" - && loc.at(1U) != "$Types$" - && loc.at(1U) != "ERC" - && loc.at(1U) != "ERC_PHYSICAL") + // Match `/Symbols/*` + pattern = {"Symbols", std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - // We extract embedded files into the same directory but do - // not want to parse them as stream. Therefore skip them. - // @todo This is just a workaround; needs some refactoring - // if(!fs::path(loc.at(1)).has_extension()) - { - return std::make_unique(aCtx); - } + return std::make_unique(aCtx, aInputStream); } - // Match `Symbols Directory` - if(loc.size() == 1U && loc.at(0U) == "Symbols Directory") + // Match `/Symbols Directory` + pattern = {"Symbols Directory"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `Views/*/Hierarchy/Hierarchy` - if(loc.size() == 4U && loc.at(0U) == "Views" - && loc.at(2U) == "Hierarchy" - && loc.at(3U) == "Hierarchy") + // Match `/Views/*/Hierarchy/Hierarchy` + pattern = {"Views", std::nullopt, "Hierarchy", "Hierarchy"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `Views/*/Pages/*` - if(loc.size() == 4U && loc.at(0U) == "Views" - && loc.at(2U) == "Pages") + // Match `/Views/*/Pages/*` + pattern = {"Views", std::nullopt, "Pages", std::nullopt}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `Views/*/Schematic` - if(loc.size() == 3U && loc.at(0U) == "Views" - && loc.at(2U) == "Schematic") + // Match `/Views/*/Schematic` + pattern = {"Views", std::nullopt, "Schematic"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - // Match `Views Directory` - if(loc.size() == 1U && loc.at(0U) == "Views Directory") + // Match `/Views Directory` + pattern = {"Views Directory"}; + if(streamLoc.matches_pattern(pattern)) { - return std::make_unique(aCtx); + return std::make_unique(aCtx, aInputStream); } - std::string locPath; - std::for_each(loc.cbegin(), loc.cend(), - [&locPath](const std::string& pathPart){ locPath += "/" + pathPart;}); + const std::string errMsg = fmt::format( + "Didn't find a suitable stream parser for stream location `{}`", + ::to_string(streamLoc) + ); - const std::string errMsg = fmt::format("Didn't find a suitable stream parser for loc = {}", locPath); spdlog::warn(errMsg); - return std::unique_ptr{}; + return std::unique_ptr{}; } \ No newline at end of file diff --git a/src/StreamFactory.hpp b/src/StreamFactory.hpp index b5b838e..f50ada3 100644 --- a/src/StreamFactory.hpp +++ b/src/StreamFactory.hpp @@ -2,18 +2,17 @@ #define STREAMFACTORY_HPP +#include #include -#include -#include -#include "CommonBase.hpp" -#include "ParserContext.hpp" +#include "ContainerContext.hpp" +#include "Stream.hpp" class StreamFactory { public: - static std::unique_ptr build(ParserContext& aCtx, const std::vector& aCfbfStreamLocation); + static std::unique_ptr build(ContainerContext& aCtx, const fs::path& aInputStream); }; diff --git a/src/Streams/StreamAdminData.cpp b/src/Streams/StreamAdminData.cpp index eaaf3ba..a3e7762 100644 --- a/src/Streams/StreamAdminData.cpp +++ b/src/Streams/StreamAdminData.cpp @@ -10,7 +10,7 @@ void StreamAdminData::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamAdminData.hpp b/src/Streams/StreamAdminData.hpp index 587c859..0b4ec20 100644 --- a/src/Streams/StreamAdminData.hpp +++ b/src/Streams/StreamAdminData.hpp @@ -8,22 +8,22 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Stream.hpp" -class StreamAdminData : public CommonBase +class StreamAdminData : public Stream { public: - StreamAdminData(ParserContext& aCtx) : CommonBase{aCtx} + StreamAdminData(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamCache.cpp b/src/Streams/StreamCache.cpp index 914298d..48840b3 100644 --- a/src/Streams/StreamCache.cpp +++ b/src/Streams/StreamCache.cpp @@ -6,17 +6,19 @@ #include "Enums/Structure.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Streams/StreamCache.hpp" void StreamCache::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); // Early out for empty caches - if(tryRead([&](){ ds.readBytes(10U); ds.sanitizeEoF(); })) + if(parser.tryRead([&](){ ds.readBytes(10U); ds.sanitizeEoF(); })) { ds.printUnknownData(10U, getMethodName(this, __func__) + ": 0"); } @@ -28,9 +30,9 @@ void StreamCache::read(FileFormatVersion /* aVersion */) { spdlog::trace("iteration i = {}", i); - const bool hasStrAfter8Byte = tryRead([&](){ ds.readBytes(8U); ds.readStringLenZeroTerm(); }); - const bool hasStrAfter2Byte = tryRead([&](){ ds.readBytes(2U); ds.readStringLenZeroTerm(); }); - const bool hasStrAfter0Byte = tryRead([&](){ ds.readBytes(0U); ds.readStringLenZeroTerm(); }); + const bool hasStrAfter8Byte = parser.tryRead([&](){ ds.readBytes(8U); ds.readStringLenZeroTerm(); }); + const bool hasStrAfter2Byte = parser.tryRead([&](){ ds.readBytes(2U); ds.readStringLenZeroTerm(); }); + const bool hasStrAfter0Byte = parser.tryRead([&](){ ds.readBytes(0U); ds.readStringLenZeroTerm(); }); spdlog::trace("hasStrAfter8Byte = {}", hasStrAfter8Byte); spdlog::trace("hasStrAfter2Byte = {}", hasStrAfter2Byte); @@ -71,7 +73,7 @@ void StreamCache::read(FileFormatVersion /* aVersion */) break; } - const bool hasMysterious2Byte = !tryRead([&](){ ds.readStringLenZeroTerm(); }); + const bool hasMysterious2Byte = !parser.tryRead([&](){ ds.readStringLenZeroTerm(); }); if(hasMysterious2Byte) { @@ -102,7 +104,7 @@ void StreamCache::read(FileFormatVersion /* aVersion */) const Structure my_struct = ToStructure(ds.readUint16()); spdlog::trace(::to_string(my_struct)); - readStructure(); + parser.readStructure(); } } diff --git a/src/Streams/StreamCache.hpp b/src/Streams/StreamCache.hpp index a858d55..fca954d 100644 --- a/src/Streams/StreamCache.hpp +++ b/src/Streams/StreamCache.hpp @@ -8,22 +8,22 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Stream.hpp" -class StreamCache : public CommonBase +class StreamCache : public Stream { public: - StreamCache(ParserContext& aCtx) : CommonBase{aCtx} + StreamCache(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamCellsDirectory.cpp b/src/Streams/StreamCellsDirectory.cpp index ec0a878..fa80f66 100644 --- a/src/Streams/StreamCellsDirectory.cpp +++ b/src/Streams/StreamCellsDirectory.cpp @@ -11,7 +11,7 @@ void StreamCellsDirectory::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamCellsDirectory.hpp b/src/Streams/StreamCellsDirectory.hpp index c6993ed..09c2c97 100644 --- a/src/Streams/StreamCellsDirectory.hpp +++ b/src/Streams/StreamCellsDirectory.hpp @@ -16,14 +16,14 @@ class StreamCellsDirectory : public StreamDirectoryStruct { public: - StreamCellsDirectory(ParserContext& aCtx) : StreamDirectoryStruct{aCtx} + StreamCellsDirectory(ContainerContext& aCtx, const fs::path& aInputStream) : StreamDirectoryStruct{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamDirectoryStruct.hpp b/src/Streams/StreamDirectoryStruct.hpp index 3ee832d..6c2fd17 100644 --- a/src/Streams/StreamDirectoryStruct.hpp +++ b/src/Streams/StreamDirectoryStruct.hpp @@ -10,9 +10,9 @@ #include #include -#include "CommonBase.hpp" #include "Enums/ComponentType.hpp" #include "General.hpp" +#include "Stream.hpp" class DirItemType @@ -64,11 +64,12 @@ static std::ostream& operator<<(std::ostream& aOs, const DirItemType& aVal) } -class StreamDirectoryStruct : public CommonBase +class StreamDirectoryStruct : public Stream { public: - StreamDirectoryStruct(ParserContext& aCtx) : CommonBase{aCtx}, lastModifiedDate{0}, items{} + StreamDirectoryStruct(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, + lastModifiedDate{0}, items{} { } std::string to_string() const; diff --git a/src/Streams/StreamDsnStream.cpp b/src/Streams/StreamDsnStream.cpp index 60a639d..5863fb4 100644 --- a/src/Streams/StreamDsnStream.cpp +++ b/src/Streams/StreamDsnStream.cpp @@ -6,6 +6,7 @@ #include "Enums/Structure.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Streams/StreamDsnStream.hpp" @@ -14,7 +15,8 @@ // I.e. parse `Library` first and later on `DsnStream` to avoid issues. void StreamDsnStream::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); @@ -24,9 +26,9 @@ void StreamDsnStream::read(FileFormatVersion /* aVersion */) // @todo return the parsed nameValueMapping from within read_single_short_prefix() // and save it in DsnStream. I.e. `Library guid` and `Time Format Index` // const Structure structure = read_prefixes(2); - auto_read_prefixes(Structure::DsnStream, localFutureLst); + parser.auto_read_prefixes(Structure::DsnStream, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Streams/StreamDsnStream.hpp b/src/Streams/StreamDsnStream.hpp index 97ee3fc..9a0010a 100644 --- a/src/Streams/StreamDsnStream.hpp +++ b/src/Streams/StreamDsnStream.hpp @@ -8,22 +8,22 @@ #include #include -#include "CommonBase.hpp" +#include "Stream.hpp" #include "General.hpp" -class StreamDsnStream : public CommonBase +class StreamDsnStream : public Stream { public: - StreamDsnStream(ParserContext& aCtx) : CommonBase{aCtx} + StreamDsnStream(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamERC.cpp b/src/Streams/StreamERC.cpp index 493f1b2..ad2a023 100644 --- a/src/Streams/StreamERC.cpp +++ b/src/Streams/StreamERC.cpp @@ -5,16 +5,18 @@ #include #include "General.hpp" +#include "GenericParser.hpp" #include "Streams/StreamERC.hpp" void StreamERC::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - ercSymbol = dynamic_pointer_cast(readStructure()); + ercSymbol = dynamic_pointer_cast(parser.readStructure()); if(!ds.isEoF()) { diff --git a/src/Streams/StreamERC.hpp b/src/Streams/StreamERC.hpp index c0163ad..c231367 100644 --- a/src/Streams/StreamERC.hpp +++ b/src/Streams/StreamERC.hpp @@ -9,23 +9,23 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Stream.hpp" #include "Structures/StructERCSymbol.hpp" -class StreamERC : public CommonBase +class StreamERC : public Stream { public: - StreamERC(ParserContext& aCtx) : CommonBase{aCtx}, ercSymbol{} + StreamERC(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, ercSymbol{} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamExportBlocksDirectory.cpp b/src/Streams/StreamExportBlocksDirectory.cpp index 60d72f5..6708f10 100644 --- a/src/Streams/StreamExportBlocksDirectory.cpp +++ b/src/Streams/StreamExportBlocksDirectory.cpp @@ -10,7 +10,7 @@ void StreamExportBlocksDirectory::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamExportBlocksDirectory.hpp b/src/Streams/StreamExportBlocksDirectory.hpp index bf0c36c..1c4d41e 100644 --- a/src/Streams/StreamExportBlocksDirectory.hpp +++ b/src/Streams/StreamExportBlocksDirectory.hpp @@ -16,14 +16,14 @@ class StreamExportBlocksDirectory : public StreamDirectoryStruct { public: - StreamExportBlocksDirectory(ParserContext& aCtx) : StreamDirectoryStruct{aCtx} + StreamExportBlocksDirectory(ContainerContext& aCtx, const fs::path& aInputStream) : StreamDirectoryStruct{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamGraphicsDirectory.cpp b/src/Streams/StreamGraphicsDirectory.cpp index 722a902..32d7849 100644 --- a/src/Streams/StreamGraphicsDirectory.cpp +++ b/src/Streams/StreamGraphicsDirectory.cpp @@ -11,7 +11,7 @@ void StreamGraphicsDirectory::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamGraphicsDirectory.hpp b/src/Streams/StreamGraphicsDirectory.hpp index ede44f6..09524ce 100644 --- a/src/Streams/StreamGraphicsDirectory.hpp +++ b/src/Streams/StreamGraphicsDirectory.hpp @@ -16,14 +16,14 @@ class StreamGraphicsDirectory : public StreamDirectoryStruct { public: - StreamGraphicsDirectory(ParserContext& aCtx) : StreamDirectoryStruct{aCtx} + StreamGraphicsDirectory(ContainerContext& aCtx, const fs::path& aInputStream) : StreamDirectoryStruct{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamHSObjects.cpp b/src/Streams/StreamHSObjects.cpp index cea6851..42b517a 100644 --- a/src/Streams/StreamHSObjects.cpp +++ b/src/Streams/StreamHSObjects.cpp @@ -10,7 +10,7 @@ void StreamHSObjects::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamHSObjects.hpp b/src/Streams/StreamHSObjects.hpp index 9e2a0d6..62d23f1 100644 --- a/src/Streams/StreamHSObjects.hpp +++ b/src/Streams/StreamHSObjects.hpp @@ -8,22 +8,22 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Stream.hpp" -class StreamHSObjects : public CommonBase +class StreamHSObjects : public Stream { public: - StreamHSObjects(ParserContext& aCtx) : CommonBase{aCtx} + StreamHSObjects(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamHierarchy.cpp b/src/Streams/StreamHierarchy.cpp index 6f210cb..41837a2 100644 --- a/src/Streams/StreamHierarchy.cpp +++ b/src/Streams/StreamHierarchy.cpp @@ -5,18 +5,21 @@ #include #include "General.hpp" +#include "GenericParser.hpp" #include "Streams/StreamHierarchy.hpp" void StreamHierarchy::read(FileFormatVersion aVersion) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); if(aVersion == FileFormatVersion::Unknown) { - aVersion = predictVersion(); + const auto predictionFunc = [this](FileFormatVersion aVersion){ this->read(aVersion); }; + aVersion = parser.predictVersion(predictionFunc); } ds.printUnknownData(9, getMethodName(this, __func__) + ": 0"); @@ -33,7 +36,7 @@ void StreamHierarchy::read(FileFormatVersion aVersion) for(size_t i = 0u; i < lenNetDbIdMappings; ++i) { - netDbIdMappings.push_back(dynamic_pointer_cast(readStructure())); + netDbIdMappings.push_back(dynamic_pointer_cast(parser.readStructure())); const uint32_t dbId = ds.readUint32(); @@ -50,7 +53,7 @@ void StreamHierarchy::read(FileFormatVersion aVersion) for(size_t i = 0u; i < lenSthInHierarchy3; ++i) { - sthInHierarchy3s.push_back(dynamic_pointer_cast(readStructure())); + sthInHierarchy3s.push_back(dynamic_pointer_cast(parser.readStructure())); ds.printUnknownData(8, getMethodName(this, __func__) + ": 1.5"); } @@ -61,7 +64,7 @@ void StreamHierarchy::read(FileFormatVersion aVersion) for(size_t i = 0u; i < lenT0x5bs; ++i) { - t0x5bs.push_back(dynamic_pointer_cast(readStructure())); + t0x5bs.push_back(dynamic_pointer_cast(parser.readStructure())); ds.printUnknownData(8, getMethodName(this, __func__) + ": 1.6"); } @@ -77,7 +80,7 @@ void StreamHierarchy::read(FileFormatVersion aVersion) for(size_t i = 0u; i < lenSthInHierarchy1; ++i) { - sthInHierarchy1s.push_back(dynamic_pointer_cast(readStructure())); + sthInHierarchy1s.push_back(dynamic_pointer_cast(parser.readStructure())); // Is one of [8, 27] // ds.printUnknownData(8, getMethodName(this, __func__) + ": 3"); @@ -89,7 +92,7 @@ void StreamHierarchy::read(FileFormatVersion aVersion) for(size_t i = 0u; i < lenSomeHierarchyBase; ++i) { - someHierarchyBases.push_back(dynamic_pointer_cast(readStructure())); + someHierarchyBases.push_back(dynamic_pointer_cast(parser.readStructure())); ds.printUnknownData(6, getMethodName(this, __func__) + ": 4"); } diff --git a/src/Streams/StreamHierarchy.hpp b/src/Streams/StreamHierarchy.hpp index fa113a5..5ef3d40 100644 --- a/src/Streams/StreamHierarchy.hpp +++ b/src/Streams/StreamHierarchy.hpp @@ -10,8 +10,8 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Stream.hpp" #include "Structures/StructNetDbIdMapping.hpp" #include "Structures/StructSomeHierarchyBase.hpp" #include "Structures/StructSthInHierarchy1.hpp" @@ -19,11 +19,11 @@ #include "Structures/StructT0x5b.hpp" -class StreamHierarchy : public CommonBase +class StreamHierarchy : public Stream { public: - StreamHierarchy(ParserContext& aCtx) : CommonBase{aCtx}, netDbIdMappings{}, + StreamHierarchy(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, netDbIdMappings{}, sthInHierarchy3s{}, t0x5bs{}, sthInHierarchy1s{}, someHierarchyBases{} { } @@ -31,7 +31,7 @@ class StreamHierarchy : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamLibrary.cpp b/src/Streams/StreamLibrary.cpp index 8c358be..fbd8541 100644 --- a/src/Streams/StreamLibrary.cpp +++ b/src/Streams/StreamLibrary.cpp @@ -1,153 +1,156 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "PageSettings.hpp" -#include "Streams/StreamLibrary.hpp" -#include "Win32/LOGFONTA.hpp" - - -void StreamLibrary::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - if(aVersion == FileFormatVersion::Unknown) - { - aVersion = predictVersion(); - } - - size_t startOffset = ds.getCurrentOffset(); - - introduction = ds.readStringZeroTerm(); - // Looks like OrCAD creates a fixed size buffer where the string - // is copied into. However, when the string does not require the - // full buffer size it contains still data from the previous - // application. When the buffer is written into the file this - // probably causes some privacy issues as the data at the end - // of the buffer should never end up in the symbols file. - // Some OrCAD code like this would cause the issue: - // char buffer[32]; - // strcpy(buffer, srcStr); - // write_data_to_file(buffer, sizeof(buffer)); - ds.padRest(startOffset, 32, false); - - spdlog::trace("introduction = {}", introduction); - - // I saw versions: - // 2.0; 3.2; 3.3 - const uint16_t versionMajor = ds.readUint16(); - const uint16_t versionMinor = ds.readUint16(); - - spdlog::trace("version = {}.{}", versionMajor, versionMinor); - - createDate = static_cast(ds.readUint32()); - modifyDate = static_cast(ds.readUint32()); - - ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 1"); - - // @todo the GUI specifies 15 fonts under - // `Options` -> `Design Templates...` -> `Fonts` - // is there some correlation? - const uint16_t textFontLen = ds.readUint16(); - - spdlog::trace("textFontLen = {}", textFontLen); - - if(textFontLen == 0u) - { - throw std::runtime_error("textFontLen == 0 doesn't make sense as it causes an succeeding underflow!"); - } - - for(int i = 0; i < static_cast(textFontLen) - 1; ++i) - { - LOGFONTA font{}; - font.read(mCtx); - textFonts.push_back(font); - } - - const uint16_t someLen = ds.readUint16(); - - spdlog::trace("someLen = {}", someLen); - - for(int i = 0; i < someLen; ++i) - { - const uint16_t someData = ds.readUint16(); - - spdlog::trace("someData [{}] = {}", i, someData); - } - - ds.printUnknownData(4, getMethodName(this, __func__) + ": 2.0"); - ds.printUnknownData(4, getMethodName(this, __func__) + ": 2.1"); - - // Property to Part Field Mapping - // See OrCAD: `Options` -> `Design Template...` -> `SDT Compatibility` - // -> `Property to Part Field Mapping` - const size_t partFields = 8U; // `Part Field 1` up to `Part Field 8` - for(size_t i = 0u; i < partFields; ++i) - { - strLstPartField.push_back(ds.readStringLenZeroTerm()); - - spdlog::trace("strLstPartField[{}] = {}", i, strLstPartField.back()); - } - - pageSettings.read(); - - uint32_t strLstLen = 0U; - - // @todo Versions were chosen randomly - if(aVersion == FileFormatVersion::A) - { - strLstLen = ds.readUint16(); - } - else - { - strLstLen = ds.readUint32(); - } - - spdlog::trace("strLstLen = {}", strLstLen); - - for(size_t i = 0u; i < strLstLen; ++i) - { - strLst.push_back(ds.readStringLenZeroTerm()); - - spdlog::trace("strLst[{}] = {}", i, strLst.back()); - } - - const uint16_t aliasLstLen = ds.readUint16(); - - spdlog::trace("aliasLstLen = {}", aliasLstLen); - - for(size_t i = 0u; i < aliasLstLen; ++i) - { - const std::string alias = ds.readStringLenZeroTerm(); - const std::string package = ds.readStringLenZeroTerm(); - partAliases.push_back(std::make_pair(alias, package)); - - spdlog::trace("partAliases[{}] = (alias = {}, package = {})", i, alias, package); - } - - if(gFileType == FileType::Schematic) - { - ds.printUnknownData(8, getMethodName(this, __func__) + ": 5"); - std::string schematicName = ds.readStringLenZeroTerm(); - spdlog::trace("schematicName = {}", schematicName); - } - - if(!ds.isEoF()) - { - throw std::runtime_error("Expected EoF but did not reach it!"); - } - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::info(to_string()); +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "GenericParser.hpp" +#include "PageSettings.hpp" +#include "Streams/StreamLibrary.hpp" +#include "Win32/LOGFONTA.hpp" + + +void StreamLibrary::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + if(aVersion == FileFormatVersion::Unknown) + { + const auto predictionFunc = [this](FileFormatVersion aVersion){ this->read(aVersion); }; + aVersion = parser.predictVersion(predictionFunc); + } + + size_t startOffset = ds.getCurrentOffset(); + + introduction = ds.readStringZeroTerm(); + // Looks like OrCAD creates a fixed size buffer where the string + // is copied into. However, when the string does not require the + // full buffer size it contains still data from the previous + // application. When the buffer is written into the file this + // probably causes some privacy issues as the data at the end + // of the buffer should never end up in the symbols file. + // Some OrCAD code like this would cause the issue: + // char buffer[32]; + // strcpy(buffer, srcStr); + // write_data_to_file(buffer, sizeof(buffer)); + ds.padRest(startOffset, 32, false); + + spdlog::trace("introduction = {}", introduction); + + // I saw versions: + // 2.0; 3.2; 3.3 + const uint16_t versionMajor = ds.readUint16(); + const uint16_t versionMinor = ds.readUint16(); + + spdlog::trace("version = {}.{}", versionMajor, versionMinor); + + createDate = static_cast(ds.readUint32()); + modifyDate = static_cast(ds.readUint32()); + + ds.assumeData({0x00, 0x00, 0x00, 0x00}, getMethodName(this, __func__) + ": 1"); + + // @todo the GUI specifies 15 fonts under + // `Options` -> `Design Templates...` -> `Fonts` + // is there some correlation? + const uint16_t textFontLen = ds.readUint16(); + + spdlog::trace("textFontLen = {}", textFontLen); + + if(textFontLen == 0u) + { + throw std::runtime_error("textFontLen == 0 doesn't make sense as it causes an succeeding underflow!"); + } + + for(int i = 0; i < static_cast(textFontLen) - 1; ++i) + { + LOGFONTA font{}; + font.read(mCtx); + textFonts.push_back(font); + } + + const uint16_t someLen = ds.readUint16(); + + spdlog::trace("someLen = {}", someLen); + + for(int i = 0; i < someLen; ++i) + { + const uint16_t someData = ds.readUint16(); + + spdlog::trace("someData [{}] = {}", i, someData); + } + + ds.printUnknownData(4, getMethodName(this, __func__) + ": 2.0"); + ds.printUnknownData(4, getMethodName(this, __func__) + ": 2.1"); + + // Property to Part Field Mapping + // See OrCAD: `Options` -> `Design Template...` -> `SDT Compatibility` + // -> `Property to Part Field Mapping` + const size_t partFields = 8U; // `Part Field 1` up to `Part Field 8` + for(size_t i = 0u; i < partFields; ++i) + { + strLstPartField.push_back(ds.readStringLenZeroTerm()); + + spdlog::trace("strLstPartField[{}] = {}", i, strLstPartField.back()); + } + + pageSettings.read(); + + uint32_t strLstLen = 0U; + + // @todo Versions were chosen randomly + if(aVersion == FileFormatVersion::A) + { + strLstLen = ds.readUint16(); + } + else + { + strLstLen = ds.readUint32(); + } + + spdlog::trace("strLstLen = {}", strLstLen); + + for(size_t i = 0u; i < strLstLen; ++i) + { + strLst.push_back(ds.readStringLenZeroTerm()); + + spdlog::trace("strLst[{}] = {}", i, strLst.back()); + } + + const uint16_t aliasLstLen = ds.readUint16(); + + spdlog::trace("aliasLstLen = {}", aliasLstLen); + + for(size_t i = 0u; i < aliasLstLen; ++i) + { + const std::string alias = ds.readStringLenZeroTerm(); + const std::string package = ds.readStringLenZeroTerm(); + partAliases.push_back(std::make_pair(alias, package)); + + spdlog::trace("partAliases[{}] = (alias = {}, package = {})", i, alias, package); + } + + if(mCtx.mFileType == FileType::Schematic) + { + ds.printUnknownData(8, getMethodName(this, __func__) + ": 5"); + std::string schematicName = ds.readStringLenZeroTerm(); + spdlog::trace("schematicName = {}", schematicName); + } + + if(!ds.isEoF()) + { + throw std::runtime_error("Expected EoF but did not reach it!"); + } + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::info(to_string()); } \ No newline at end of file diff --git a/src/Streams/StreamLibrary.hpp b/src/Streams/StreamLibrary.hpp index 6cb966f..e041338 100644 --- a/src/Streams/StreamLibrary.hpp +++ b/src/Streams/StreamLibrary.hpp @@ -12,24 +12,24 @@ #include #include -#include "CommonBase.hpp" #include "PageSettings.hpp" +#include "Stream.hpp" #include "Win32/LOGFONTA.hpp" -class StreamLibrary : public CommonBase +class StreamLibrary : public Stream { public: - StreamLibrary(ParserContext& aCtx) : CommonBase{aCtx}, introduction{}, createDate{0}, modifyDate{0}, - textFonts{}, strLstPartField{}, pageSettings{aCtx}, strLst{}, partAliases{} + StreamLibrary(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, introduction{}, createDate{0}, modifyDate{0}, + textFonts{}, strLstPartField{}, pageSettings{mCtx}, strLst{}, partAliases{} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamNetBundleMapData.cpp b/src/Streams/StreamNetBundleMapData.cpp index 14cbfe2..1de4af2 100644 --- a/src/Streams/StreamNetBundleMapData.cpp +++ b/src/Streams/StreamNetBundleMapData.cpp @@ -6,12 +6,14 @@ #include "Enums/Structure.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Streams/StreamNetBundleMapData.hpp" void StreamNetBundleMapData::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); @@ -32,9 +34,9 @@ void StreamNetBundleMapData::read(FileFormatVersion /* aVersion */) FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::NetGroup, localFutureLst); + parser.auto_read_prefixes(Structure::NetGroup, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Streams/StreamNetBundleMapData.hpp b/src/Streams/StreamNetBundleMapData.hpp index 77e2106..b62a537 100644 --- a/src/Streams/StreamNetBundleMapData.hpp +++ b/src/Streams/StreamNetBundleMapData.hpp @@ -7,22 +7,22 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Stream.hpp" -class StreamNetBundleMapData : public CommonBase +class StreamNetBundleMapData : public Stream { public: - StreamNetBundleMapData(ParserContext& aCtx) : CommonBase{aCtx} + StreamNetBundleMapData(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamPackage.cpp b/src/Streams/StreamPackage.cpp index ab6e1c9..7b095f6 100644 --- a/src/Streams/StreamPackage.cpp +++ b/src/Streams/StreamPackage.cpp @@ -1,44 +1,46 @@ -#include -#include - -#include -#include - -#include "General.hpp" -#include "Streams/StreamPackage.hpp" - - -void StreamPackage::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - const uint16_t lenProperties = ds.readUint16(); - - spdlog::trace("lenProperties = {}", lenProperties); - - for(size_t i = 0u; i < lenProperties; ++i) - { - properties.push_back(dynamic_pointer_cast(readStructure())); - - const uint16_t lenPrimitives = ds.readUint16(); - - spdlog::trace("lenPrimitives = {}", lenPrimitives); - - for(size_t i = 0u; i < lenPrimitives; ++i) - { - primitives.push_back(dynamic_pointer_cast(readStructure())); - } - } - - t0x1f = dynamic_pointer_cast(readStructure()); - - if(!ds.isEoF()) - { - throw std::runtime_error("Expected EoF but did not reach it!"); - } - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::info(to_string()); +#include +#include + +#include +#include + +#include "General.hpp" +#include "GenericParser.hpp" +#include "Streams/StreamPackage.hpp" + + +void StreamPackage::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + const uint16_t lenProperties = ds.readUint16(); + + spdlog::trace("lenProperties = {}", lenProperties); + + for(size_t i = 0u; i < lenProperties; ++i) + { + properties.push_back(dynamic_pointer_cast(parser.readStructure())); + + const uint16_t lenPrimitives = ds.readUint16(); + + spdlog::trace("lenPrimitives = {}", lenPrimitives); + + for(size_t i = 0u; i < lenPrimitives; ++i) + { + primitives.push_back(dynamic_pointer_cast(parser.readStructure())); + } + } + + t0x1f = dynamic_pointer_cast(parser.readStructure()); + + if(!ds.isEoF()) + { + throw std::runtime_error("Expected EoF but did not reach it!"); + } + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::info(to_string()); } \ No newline at end of file diff --git a/src/Streams/StreamPackage.hpp b/src/Streams/StreamPackage.hpp index 0d9fbf1..7c715ac 100644 --- a/src/Streams/StreamPackage.hpp +++ b/src/Streams/StreamPackage.hpp @@ -1,95 +1,95 @@ -#ifndef STREAMPACKAGE_HPP -#define STREAMPACKAGE_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "Structures/StructPinIdxMapping.hpp" -#include "Structures/StructPrimitives.hpp" -#include "Structures/StructProperties.hpp" -#include "Structures/StructT0x1f.hpp" - - -class StreamPackage : public CommonBase -{ -public: - - StreamPackage(ParserContext& aCtx) : CommonBase{aCtx}, properties{}, primitives{}, - t0x1f{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::vector> properties; - std::vector> primitives; - - std::unique_ptr t0x1f; -}; - - -[[maybe_unused]] -static std::string to_string(const StreamPackage& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += fmt::format("{}properties:\n", indent(1)); - for(size_t i = 0u; i < aObj.properties.size(); ++i) - { - if(aObj.properties[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.properties[i]->to_string()), 2); - } - } - - str += fmt::format("{}primitives:\n", indent(1)); - for(size_t i = 0u; i < aObj.primitives.size(); ++i) - { - if(aObj.primitives[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.primitives[i]->to_string()), 2); - } - } - - str += fmt::format("{}t0x1f:\n", indent(1)); - if(aObj.t0x1f) - { - str += indent(aObj.t0x1f->to_string(), 2); - } - - return str; -} - - -inline std::string StreamPackage::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StreamPackage& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STREAMPACKAGE_HPP +#define STREAMPACKAGE_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "Stream.hpp" +#include "Structures/StructPinIdxMapping.hpp" +#include "Structures/StructPrimitives.hpp" +#include "Structures/StructProperties.hpp" +#include "Structures/StructT0x1f.hpp" + + +class StreamPackage : public Stream +{ +public: + + StreamPackage(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, properties{}, primitives{}, + t0x1f{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::vector> properties; + std::vector> primitives; + + std::unique_ptr t0x1f; +}; + + +[[maybe_unused]] +static std::string to_string(const StreamPackage& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += fmt::format("{}properties:\n", indent(1)); + for(size_t i = 0u; i < aObj.properties.size(); ++i) + { + if(aObj.properties[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.properties[i]->to_string()), 2); + } + } + + str += fmt::format("{}primitives:\n", indent(1)); + for(size_t i = 0u; i < aObj.primitives.size(); ++i) + { + if(aObj.primitives[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.primitives[i]->to_string()), 2); + } + } + + str += fmt::format("{}t0x1f:\n", indent(1)); + if(aObj.t0x1f) + { + str += indent(aObj.t0x1f->to_string(), 2); + } + + return str; +} + + +inline std::string StreamPackage::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StreamPackage& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STREAMPACKAGE_HPP \ No newline at end of file diff --git a/src/Streams/StreamPackagesDirectory.cpp b/src/Streams/StreamPackagesDirectory.cpp index 792626a..e1f362c 100644 --- a/src/Streams/StreamPackagesDirectory.cpp +++ b/src/Streams/StreamPackagesDirectory.cpp @@ -10,7 +10,7 @@ void StreamPackagesDirectory::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamPackagesDirectory.hpp b/src/Streams/StreamPackagesDirectory.hpp index 963ba05..3d3c091 100644 --- a/src/Streams/StreamPackagesDirectory.hpp +++ b/src/Streams/StreamPackagesDirectory.hpp @@ -16,14 +16,14 @@ class StreamPackagesDirectory : public StreamDirectoryStruct { public: - StreamPackagesDirectory(ParserContext& aCtx) : StreamDirectoryStruct{aCtx} + StreamPackagesDirectory(ContainerContext& aCtx, const fs::path& aInputStream) : StreamDirectoryStruct{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamPage.cpp b/src/Streams/StreamPage.cpp index 6d2b738..428b6d4 100644 --- a/src/Streams/StreamPage.cpp +++ b/src/Streams/StreamPage.cpp @@ -5,22 +5,24 @@ #include #include "General.hpp" +#include "GenericParser.hpp" #include "PageSettings.hpp" #include "Streams/StreamPage.hpp" void StreamPage::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; // @todo Extract in separate structure parser - auto_read_prefixes(Structure::Page, localFutureLst); + parser.auto_read_prefixes(Structure::Page, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); @@ -40,7 +42,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenTitleBlocks; ++i) { - titleBlocks.push_back(dynamic_pointer_cast(readStructure())); + titleBlocks.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenT0x34s = ds.readUint16(); @@ -49,7 +51,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenT0x34s; ++i) { - t0x34s.push_back(dynamic_pointer_cast(readStructure())); + t0x34s.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenT0x35s = ds.readUint16(); @@ -58,7 +60,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenT0x35s; ++i) { - t0x35s.push_back(dynamic_pointer_cast(readStructure())); + t0x35s.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenB = ds.readUint16(); @@ -81,7 +83,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenWires; ++i) { - wires.push_back(dynamic_pointer_cast(readStructure())); + wires.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenPartInsts = ds.readUint16(); @@ -90,7 +92,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenPartInsts; ++i) { - partInsts.push_back(dynamic_pointer_cast(readStructure())); + partInsts.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenPorts = ds.readUint16(); @@ -99,7 +101,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenPorts; ++i) { - ports.push_back(dynamic_pointer_cast(readStructure())); + ports.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenGlobals = ds.readUint16(); @@ -108,7 +110,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenGlobals; ++i) { - globals.push_back(dynamic_pointer_cast(readStructure())); + globals.push_back(dynamic_pointer_cast(parser.readStructure())); ds.printUnknownData(5, fmt::format("{}: 0", getMethodName(this, __func__))); } @@ -119,7 +121,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenOffPageConnectors; ++i) { - offPageConnectors.push_back(dynamic_pointer_cast(readStructure())); + offPageConnectors.push_back(dynamic_pointer_cast(parser.readStructure())); ds.printUnknownData(5, fmt::format("{}: 1", getMethodName(this, __func__))); } @@ -130,7 +132,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenERCSymbolInsts; ++i) { - ercSymbolInsts.push_back(dynamic_pointer_cast(readStructure())); + ercSymbolInsts.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenBusEntries = ds.readUint16(); @@ -139,7 +141,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenBusEntries; ++i) { - busEntries.push_back(dynamic_pointer_cast(readStructure())); + busEntries.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenGraphicInsts = ds.readUint16(); @@ -148,7 +150,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenGraphicInsts; ++i) { - graphicInsts.push_back(dynamic_pointer_cast(readStructure())); + graphicInsts.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t len10 = ds.readUint16(); @@ -158,7 +160,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < len10; ++i) { // @todo push structure - const auto s = readStructure(); + const auto s = parser.readStructure(); if(s) { spdlog::debug("VERIFYING Page Structure10 is {}", NAMEOF_TYPE_RTTI(*s)); @@ -172,7 +174,7 @@ void StreamPage::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < len11; ++i) { // @todo push structure - const auto s = readStructure(); + const auto s = parser.readStructure(); if(s) { spdlog::debug("VERIFYING Page Structure11 is {}", NAMEOF_TYPE_RTTI(*s)); diff --git a/src/Streams/StreamPage.hpp b/src/Streams/StreamPage.hpp index 1217cec..b89ca71 100644 --- a/src/Streams/StreamPage.hpp +++ b/src/Streams/StreamPage.hpp @@ -9,9 +9,9 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" #include "PageSettings.hpp" +#include "Stream.hpp" #include "Structures/StructBusEntry.hpp" #include "Structures/StructERCSymbolInst.hpp" #include "Structures/StructGlobal.hpp" @@ -25,11 +25,11 @@ #include "Structures/StructWire.hpp" -class StreamPage : public CommonBase +class StreamPage : public Stream { public: - StreamPage(ParserContext& aCtx) : CommonBase{aCtx}, name{}, pageSize{}, pageSettings{aCtx}, + StreamPage(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, name{}, pageSize{}, pageSettings{mCtx}, titleBlocks{}, t0x34s{}, t0x35s{}, wires{}, partInsts{}, ports{}, globals{}, offPageConnectors{}, ercSymbolInsts{}, busEntries{}, graphicInsts{} { } @@ -38,7 +38,7 @@ class StreamPage : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamPartsDirectory.cpp b/src/Streams/StreamPartsDirectory.cpp index dd242f8..06f7d0b 100644 --- a/src/Streams/StreamPartsDirectory.cpp +++ b/src/Streams/StreamPartsDirectory.cpp @@ -11,7 +11,7 @@ void StreamPartsDirectory::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamPartsDirectory.hpp b/src/Streams/StreamPartsDirectory.hpp index 7eb6534..e504aaf 100644 --- a/src/Streams/StreamPartsDirectory.hpp +++ b/src/Streams/StreamPartsDirectory.hpp @@ -16,14 +16,14 @@ class StreamPartsDirectory : public StreamDirectoryStruct { public: - StreamPartsDirectory(ParserContext& aCtx) : StreamDirectoryStruct{aCtx} + StreamPartsDirectory(ContainerContext& aCtx, const fs::path& aInputStream) : StreamDirectoryStruct{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamSchematic.cpp b/src/Streams/StreamSchematic.cpp index 08f6e96..48bab78 100644 --- a/src/Streams/StreamSchematic.cpp +++ b/src/Streams/StreamSchematic.cpp @@ -5,21 +5,23 @@ #include #include "General.hpp" +#include "GenericParser.hpp" #include "Streams/StreamSchematic.hpp" void StreamSchematic::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; // @todo Extract in separate structure parser - auto_read_prefixes(Structure::SchLib, localFutureLst); + parser.auto_read_prefixes(Structure::SchLib, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Streams/StreamSchematic.hpp b/src/Streams/StreamSchematic.hpp index d249025..454da49 100644 --- a/src/Streams/StreamSchematic.hpp +++ b/src/Streams/StreamSchematic.hpp @@ -9,22 +9,22 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Stream.hpp" -class StreamSchematic : public CommonBase +class StreamSchematic : public Stream { public: - StreamSchematic(ParserContext& aCtx) : CommonBase{aCtx} + StreamSchematic(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamSymbol.cpp b/src/Streams/StreamSymbol.cpp index b23e32e..ff44b93 100644 --- a/src/Streams/StreamSymbol.cpp +++ b/src/Streams/StreamSymbol.cpp @@ -5,16 +5,18 @@ #include #include "General.hpp" +#include "GenericParser.hpp" #include "Streams/StreamSymbol.hpp" void StreamSymbol::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - symbol = dynamic_pointer_cast(readStructure()); + symbol = dynamic_pointer_cast(parser.readStructure()); if(!ds.isEoF()) { diff --git a/src/Streams/StreamSymbol.hpp b/src/Streams/StreamSymbol.hpp index 64a725c..bc4323d 100644 --- a/src/Streams/StreamSymbol.hpp +++ b/src/Streams/StreamSymbol.hpp @@ -1,93 +1,93 @@ -#ifndef STREAMSYMBOL_HPP -#define STREAMSYMBOL_HPP - - -#include -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "General.hpp" -#include "Structures/StructSymbol.hpp" -#include "Structures/StructSymbolDisplayProp.hpp" -#include "Structures/StructSymbolPin.hpp" - - -class StreamSymbol : public CommonBase -{ -public: - - StreamSymbol(ParserContext& aCtx) : CommonBase{aCtx}, symbolPins{}, symbolDisplayProps{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::unique_ptr symbol; - - std::vector> symbolPins; - std::vector> symbolDisplayProps; -}; - - -[[maybe_unused]] -static std::string to_string(const StreamSymbol& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += "symbol:\n"; - if(aObj.symbol) - { - str += indent(aObj.symbol->to_string(), 2); - } - - str += fmt::format("{}symbolPins:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) - { - if(aObj.symbolPins[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.symbolPins[i]->to_string()), 2); - } - } - - str += fmt::format("{}symbolDisplayProps:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) - { - if(aObj.symbolDisplayProps[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.symbolDisplayProps[i]->to_string()), 2); - } - } - - return str; -} - - -inline std::string StreamSymbol::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StreamSymbol& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STREAMSYMBOL_HPP +#define STREAMSYMBOL_HPP + + +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Stream.hpp" +#include "Structures/StructSymbol.hpp" +#include "Structures/StructSymbolDisplayProp.hpp" +#include "Structures/StructSymbolPin.hpp" + + +class StreamSymbol : public Stream +{ +public: + + StreamSymbol(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, symbolPins{}, symbolDisplayProps{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::unique_ptr symbol; + + std::vector> symbolPins; + std::vector> symbolDisplayProps; +}; + + +[[maybe_unused]] +static std::string to_string(const StreamSymbol& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += "symbol:\n"; + if(aObj.symbol) + { + str += indent(aObj.symbol->to_string(), 2); + } + + str += fmt::format("{}symbolPins:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) + { + if(aObj.symbolPins[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.symbolPins[i]->to_string()), 2); + } + } + + str += fmt::format("{}symbolDisplayProps:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) + { + if(aObj.symbolDisplayProps[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.symbolDisplayProps[i]->to_string()), 2); + } + } + + return str; +} + + +inline std::string StreamSymbol::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StreamSymbol& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STREAMSYMBOL_HPP \ No newline at end of file diff --git a/src/Streams/StreamSymbolsDirectory.cpp b/src/Streams/StreamSymbolsDirectory.cpp index 951a4fd..e47346a 100644 --- a/src/Streams/StreamSymbolsDirectory.cpp +++ b/src/Streams/StreamSymbolsDirectory.cpp @@ -12,7 +12,7 @@ void StreamSymbolsDirectory::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamSymbolsDirectory.hpp b/src/Streams/StreamSymbolsDirectory.hpp index 1cd8369..67cb4aa 100644 --- a/src/Streams/StreamSymbolsDirectory.hpp +++ b/src/Streams/StreamSymbolsDirectory.hpp @@ -16,14 +16,14 @@ class StreamSymbolsDirectory : public StreamDirectoryStruct { public: - StreamSymbolsDirectory(ParserContext& aCtx) : StreamDirectoryStruct{aCtx} + StreamSymbolsDirectory(ContainerContext& aCtx, const fs::path& aInputStream) : StreamDirectoryStruct{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamType.cpp b/src/Streams/StreamType.cpp index cf11307..8f73b32 100644 --- a/src/Streams/StreamType.cpp +++ b/src/Streams/StreamType.cpp @@ -10,7 +10,7 @@ void StreamType::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamType.hpp b/src/Streams/StreamType.hpp index 1c465c8..4e1945a 100644 --- a/src/Streams/StreamType.hpp +++ b/src/Streams/StreamType.hpp @@ -10,7 +10,7 @@ #include #include -#include "CommonBase.hpp" +#include "Stream.hpp" #include "Enums/ComponentType.hpp" @@ -57,18 +57,18 @@ static std::ostream& operator<<(std::ostream& aOs, const Type& aObj) } -class StreamType : public CommonBase +class StreamType : public Stream { public: - StreamType(ParserContext& aCtx) : CommonBase{aCtx}, types{} + StreamType(ContainerContext& aCtx, const fs::path& aInputStream) : Stream{aCtx, aInputStream}, types{} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Streams/StreamViewsDirectory.cpp b/src/Streams/StreamViewsDirectory.cpp index 0cdc7bd..303a883 100644 --- a/src/Streams/StreamViewsDirectory.cpp +++ b/src/Streams/StreamViewsDirectory.cpp @@ -11,7 +11,7 @@ void StreamViewsDirectory::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Streams/StreamViewsDirectory.hpp b/src/Streams/StreamViewsDirectory.hpp index 8941e02..e940376 100644 --- a/src/Streams/StreamViewsDirectory.hpp +++ b/src/Streams/StreamViewsDirectory.hpp @@ -16,14 +16,14 @@ class StreamViewsDirectory : public StreamDirectoryStruct { public: - StreamViewsDirectory(ParserContext& aCtx) : StreamDirectoryStruct{aCtx} + StreamViewsDirectory(ContainerContext& aCtx, const fs::path& aInputStream) : StreamDirectoryStruct{aCtx, aInputStream} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructAlias.cpp b/src/Structures/StructAlias.cpp index 044a5c1..eb613bf 100644 --- a/src/Structures/StructAlias.cpp +++ b/src/Structures/StructAlias.cpp @@ -1,54 +1,57 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructAlias.hpp" - - -void StructAlias::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::Alias, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - locX = ds.readInt32(); - locY = ds.readInt32(); - - spdlog::trace("locX = {}", locX); - spdlog::trace("locY = {}", locY); - - color = ToColor(ds.readUint32()); - - spdlog::trace("color = {}", ::to_string(color)); - - rotation = ToRotation(ds.readUint32()); // @todo Why is it 4 byte? Probably increase Rotation size - - spdlog::trace("rotation = {}", ::to_string(rotation)); - - uint32_t textFontIdx = ds.readUint32(); - - spdlog::trace("Alias fontIdx = {}", textFontIdx); - - name = ds.readStringLenZeroTerm(); - - spdlog::trace("name = {}", name); - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "FutureData.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructAlias.hpp" + + +void StructAlias::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::Alias, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + locX = ds.readInt32(); + locY = ds.readInt32(); + + spdlog::trace("locX = {}", locX); + spdlog::trace("locY = {}", locY); + + color = ToColor(ds.readUint32()); + + spdlog::trace("color = {}", ::to_string(color)); + + rotation = ToRotation(ds.readUint32()); // @todo Why is it 4 byte? Probably increase Rotation size + + spdlog::trace("rotation = {}", ::to_string(rotation)); + + uint32_t textFontIdx = ds.readUint32(); + + spdlog::trace("Alias fontIdx = {}", textFontIdx); + + name = ds.readStringLenZeroTerm(); + + spdlog::trace("name = {}", name); + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructAlias.hpp b/src/Structures/StructAlias.hpp index f7dcad4..4d31401 100644 --- a/src/Structures/StructAlias.hpp +++ b/src/Structures/StructAlias.hpp @@ -10,17 +10,17 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "Enums/Rotation.hpp" #include "General.hpp" +#include "Record.hpp" -class StructAlias : public CommonBase +class StructAlias : public Record { public: - StructAlias(ParserContext& aCtx) : CommonBase{aCtx}, locX{0}, locY{0}, + StructAlias(StreamContext& aCtx) : Record{aCtx}, locX{0}, locY{0}, color{Color::Default}, rotation{Rotation::Deg_0}, name{} { } @@ -28,7 +28,7 @@ class StructAlias : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructBookMarkSymbolInst.cpp b/src/Structures/StructBookMarkSymbolInst.cpp index ad08e9b..7a0f1e5 100644 --- a/src/Structures/StructBookMarkSymbolInst.cpp +++ b/src/Structures/StructBookMarkSymbolInst.cpp @@ -1,29 +1,31 @@ -#include -#include -#include - -#include - -#include "Container.hpp" -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructBookMarkSymbolInst.hpp" - - -void StructBookMarkSymbolInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::BookMarkSymbolInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Container.hpp" +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructBookMarkSymbolInst.hpp" + + +void StructBookMarkSymbolInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::BookMarkSymbolInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructBookMarkSymbolInst.hpp b/src/Structures/StructBookMarkSymbolInst.hpp index 1d77dbe..fc9001f 100644 --- a/src/Structures/StructBookMarkSymbolInst.hpp +++ b/src/Structures/StructBookMarkSymbolInst.hpp @@ -1,66 +1,65 @@ -#ifndef STRUCTBOOKMARKSYMBOLINST_HPP -#define STRUCTBOOKMARKSYMBOLINST_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructBookMarkSymbolInst : public StructGraphicInst -{ -public: - - StructBookMarkSymbolInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructBookMarkSymbolInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructBookMarkSymbolInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructBookMarkSymbolInst& aObj) -{ - aOs << to_string(aObj); - - return aOs; -} - - +#ifndef STRUCTBOOKMARKSYMBOLINST_HPP +#define STRUCTBOOKMARKSYMBOLINST_HPP + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructBookMarkSymbolInst : public StructGraphicInst +{ +public: + + StructBookMarkSymbolInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructBookMarkSymbolInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructBookMarkSymbolInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructBookMarkSymbolInst& aObj) +{ + aOs << to_string(aObj); + + return aOs; +} + + #endif // STRUCTBOOKMARKSYMBOLINST_HPP \ No newline at end of file diff --git a/src/Structures/StructBusEntry.cpp b/src/Structures/StructBusEntry.cpp index 6d15686..f0bd989 100644 --- a/src/Structures/StructBusEntry.cpp +++ b/src/Structures/StructBusEntry.cpp @@ -1,50 +1,53 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructBusEntry.hpp" - - -void StructBusEntry::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::BusEntry, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - color = ToColor(ds.readUint32()); - - spdlog::trace("color = {}", ::to_string(color)); - - startX = ds.readInt32(); - startY = ds.readInt32(); - - spdlog::trace("startX = {}", startX); - spdlog::trace("startY = {}", startY); - - endX = ds.readInt32(); - endY = ds.readInt32(); - - spdlog::trace("endX = {}", endX); - spdlog::trace("endY = {}", endY); - - ds.printUnknownData(8, getMethodName(this, __func__) + ": 0"); - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "FutureData.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructBusEntry.hpp" + + +void StructBusEntry::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::BusEntry, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + color = ToColor(ds.readUint32()); + + spdlog::trace("color = {}", ::to_string(color)); + + startX = ds.readInt32(); + startY = ds.readInt32(); + + spdlog::trace("startX = {}", startX); + spdlog::trace("startY = {}", startY); + + endX = ds.readInt32(); + endY = ds.readInt32(); + + spdlog::trace("endX = {}", endX); + spdlog::trace("endY = {}", endY); + + ds.printUnknownData(8, getMethodName(this, __func__) + ": 0"); + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructBusEntry.hpp b/src/Structures/StructBusEntry.hpp index 695f7cd..7b030f2 100644 --- a/src/Structures/StructBusEntry.hpp +++ b/src/Structures/StructBusEntry.hpp @@ -10,16 +10,16 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "General.hpp" +#include "Record.hpp" -class StructBusEntry : public CommonBase +class StructBusEntry : public Record { public: - StructBusEntry(ParserContext& aCtx) : CommonBase{aCtx}, color{Color::Default}, + StructBusEntry(StreamContext& aCtx) : Record{aCtx}, color{Color::Default}, startX{0}, startY{0}, endX{0}, endY{0} { } @@ -27,7 +27,7 @@ class StructBusEntry : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructERCSymbol.cpp b/src/Structures/StructERCSymbol.cpp index 9b6bfb9..65e5923 100644 --- a/src/Structures/StructERCSymbol.cpp +++ b/src/Structures/StructERCSymbol.cpp @@ -1,49 +1,51 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "FutureData.hpp" -#include "General.hpp" -#include "Structures/StructERCSymbol.hpp" -#include "Structures/StructSymbolBBox.hpp" - - -void StructERCSymbol::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::ERCSymbol, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - StructSthInPages0::read_raw(aVersion, localFutureLst); - - // @todo Move into read_raw above? - // @todo readStructure(); - // @todo not sure if this belongs into this structure and how do we know whether it - // is used or not? (BBox should be optional according to XSD) - // Probably defined by prefix? - // readPreamble(); - - // StructSymbolBBox bbox{mCtx}; - // bbox.read(); - // this->symbolBBox = bbox; - - ds.printUnknownData(4, getMethodName(this, __func__) + ": 0"); - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "FutureData.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructERCSymbol.hpp" +#include "Structures/StructSymbolBBox.hpp" + + +void StructERCSymbol::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::ERCSymbol, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + StructSthInPages0::read_raw(aVersion, localFutureLst); + + // @todo Move into read_raw above? + // @todo readStructure(); + // @todo not sure if this belongs into this structure and how do we know whether it + // is used or not? (BBox should be optional according to XSD) + // Probably defined by prefix? + // ds.readPreamble(); + + // StructSymbolBBox bbox{mCtx}; + // bbox.read(); + // this->symbolBBox = bbox; + + ds.printUnknownData(4, getMethodName(this, __func__) + ": 0"); + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructERCSymbol.hpp b/src/Structures/StructERCSymbol.hpp index 8d0861b..7133b35 100644 --- a/src/Structures/StructERCSymbol.hpp +++ b/src/Structures/StructERCSymbol.hpp @@ -18,14 +18,14 @@ class StructERCSymbol : public StructSymbol { public: - StructERCSymbol(ParserContext& aCtx) : StructSymbol{aCtx}, symbolBBox{aCtx} + StructERCSymbol(StreamContext& aCtx) : StructSymbol{aCtx}, symbolBBox{aCtx} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructERCSymbolInst.cpp b/src/Structures/StructERCSymbolInst.cpp index 34577f8..633e750 100644 --- a/src/Structures/StructERCSymbolInst.cpp +++ b/src/Structures/StructERCSymbolInst.cpp @@ -1,39 +1,41 @@ -#include -#include -#include - -#include - -#include "Container.hpp" -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructERCSymbolInst.hpp" - - -void StructERCSymbolInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::ERCSymbolInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - s0 = ds.readStringLenZeroTerm(); - s1 = ds.readStringLenZeroTerm(); - s2 = ds.readStringLenZeroTerm(); - - spdlog::trace("s0 = {}", s0); - spdlog::trace("s1 = {}", s1); - spdlog::trace("s2 = {}", s2); - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Container.hpp" +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructERCSymbolInst.hpp" + + +void StructERCSymbolInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::ERCSymbolInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + s0 = ds.readStringLenZeroTerm(); + s1 = ds.readStringLenZeroTerm(); + s2 = ds.readStringLenZeroTerm(); + + spdlog::trace("s0 = {}", s0); + spdlog::trace("s1 = {}", s1); + spdlog::trace("s2 = {}", s2); + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructERCSymbolInst.hpp b/src/Structures/StructERCSymbolInst.hpp index ec4dd0d..ecb1793 100644 --- a/src/Structures/StructERCSymbolInst.hpp +++ b/src/Structures/StructERCSymbolInst.hpp @@ -1,74 +1,73 @@ -#ifndef STRUCTERCSYMBOLINST_HPP -#define STRUCTERCSYMBOLINST_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructERCSymbolInst : public StructGraphicInst -{ -public: - - StructERCSymbolInst(ParserContext& aCtx) : StructGraphicInst{aCtx}, s0{}, s1{}, s2{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::string s0; - std::string s1; - std::string s2; -}; - - -[[maybe_unused]] -static std::string to_string(const StructERCSymbolInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructERCSymbolInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - str += fmt::format("{}s0 = {}\n", indent(1), s0); - str += fmt::format("{}s1 = {}\n", indent(1), s1); - str += fmt::format("{}s2 = {}\n", indent(1), s2); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructERCSymbolInst& aObj) -{ - aOs << to_string(aObj); - - return aOs; -} - - +#ifndef STRUCTERCSYMBOLINST_HPP +#define STRUCTERCSYMBOLINST_HPP + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructERCSymbolInst : public StructGraphicInst +{ +public: + + StructERCSymbolInst(StreamContext& aCtx) : StructGraphicInst{aCtx}, s0{}, s1{}, s2{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::string s0; + std::string s1; + std::string s2; +}; + + +[[maybe_unused]] +static std::string to_string(const StructERCSymbolInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructERCSymbolInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + str += fmt::format("{}s0 = {}\n", indent(1), s0); + str += fmt::format("{}s1 = {}\n", indent(1), s1); + str += fmt::format("{}s2 = {}\n", indent(1), s2); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructERCSymbolInst& aObj) +{ + aOs << to_string(aObj); + + return aOs; +} + + #endif // STRUCTERCSYMBOLINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGeneralProperties.cpp b/src/Structures/StructGeneralProperties.cpp index e6b3d19..070cbdb 100644 --- a/src/Structures/StructGeneralProperties.cpp +++ b/src/Structures/StructGeneralProperties.cpp @@ -14,7 +14,7 @@ void StructGeneralProperties::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Structures/StructGeneralProperties.hpp b/src/Structures/StructGeneralProperties.hpp index f4e9a52..95fc506 100644 --- a/src/Structures/StructGeneralProperties.hpp +++ b/src/Structures/StructGeneralProperties.hpp @@ -1,101 +1,101 @@ -#ifndef STRUCTGENERALPROPERTIES_HPP -#define STRUCTGENERALPROPERTIES_HPP - - -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "Enums/ImplementationType.hpp" - - -// @todo This is just a helper class but not a real structure -// Check if the same code is used multiple times, otherwise -// Inline this structure? -class StructGeneralProperties : public CommonBase -{ -public: - - StructGeneralProperties(ParserContext& aCtx) : CommonBase{aCtx}, implementationPath{}, - implementation{}, refDes{}, partValue{}, implementationType{ImplementationType::None}, - pinNameVisible{true}, pinNameRotate{false}, pinNumberVisible{true} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - // Implementation path to open the corresponding folder. - // See OrCAD: 'Property Sheet' -> 'Part Properties' -> 'Implementation Path' - std::string implementationPath; - - // Implementation of the symbol. - // See OrCAD: 'Property Sheet' -> 'Part Properties' -> 'Implementation' - std::string implementation; - - // Reference descriptor for the symbol. E.g. 'R' for resistor. - // See OrCAD: 'Property Sheet' -> 'Package Properties' -> 'Part Reference Prefix' - std::string refDes; - - // Value of the symbol. E.g. '10k' for a resistor. - // See OrCAD: 'Property Sheet' -> 'Part Properties' -> 'Value' - std::string partValue; - - // See OrCAD Dropdown Menu: 'Property Sheet' -> 'Part Properties' -> 'Implementation Type' - ImplementationType implementationType; - - // See OrCAD Checkbox: 'Property Sheet' -> 'Part Properties' -> 'Pin Name Visible' - bool pinNameVisible; - - // See OrCAD Checkbox: 'Property Sheet' -> 'Part Properties' -> 'Pin Name Rotate' - bool pinNameRotate; - - // See OrCAD Checkbox: 'Property Sheet' -> 'Part Properties' -> 'Pin Number Visible' - bool pinNumberVisible; -}; - - -[[maybe_unused]] -static std::string to_string(const StructGeneralProperties& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}implementationPath = {}\n", indent(1), aObj.implementationPath); - str += fmt::format("{}implementation = {}\n", indent(1), aObj.implementation); - str += fmt::format("{}refDes = {}\n", indent(1), aObj.refDes); - str += fmt::format("{}partValue = {}\n", indent(1), aObj.partValue); - str += fmt::format("{}implementationType = {}\n", indent(1), to_string(aObj.implementationType)); - str += fmt::format("{}pinNameVisible = {}\n", indent(1), aObj.pinNameVisible); - str += fmt::format("{}pinNameRotate = {}\n", indent(1), aObj.pinNameRotate); - str += fmt::format("{}pinNumberVisible = {}\n", indent(1), aObj.pinNumberVisible); - - return str; -} - - -inline std::string StructGeneralProperties::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGeneralProperties& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGENERALPROPERTIES_HPP +#define STRUCTGENERALPROPERTIES_HPP + + +#include +#include +#include + +#include +#include + +#include "Enums/ImplementationType.hpp" +#include "Record.hpp" + + +// @todo This is just a helper class but not a real structure +// Check if the same code is used multiple times, otherwise +// Inline this structure? +class StructGeneralProperties : public Record +{ +public: + + StructGeneralProperties(StreamContext& aCtx) : Record{aCtx}, implementationPath{}, + implementation{}, refDes{}, partValue{}, implementationType{ImplementationType::None}, + pinNameVisible{true}, pinNameRotate{false}, pinNumberVisible{true} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + // Implementation path to open the corresponding folder. + // See OrCAD: 'Property Sheet' -> 'Part Properties' -> 'Implementation Path' + std::string implementationPath; + + // Implementation of the symbol. + // See OrCAD: 'Property Sheet' -> 'Part Properties' -> 'Implementation' + std::string implementation; + + // Reference descriptor for the symbol. E.g. 'R' for resistor. + // See OrCAD: 'Property Sheet' -> 'Package Properties' -> 'Part Reference Prefix' + std::string refDes; + + // Value of the symbol. E.g. '10k' for a resistor. + // See OrCAD: 'Property Sheet' -> 'Part Properties' -> 'Value' + std::string partValue; + + // See OrCAD Dropdown Menu: 'Property Sheet' -> 'Part Properties' -> 'Implementation Type' + ImplementationType implementationType; + + // See OrCAD Checkbox: 'Property Sheet' -> 'Part Properties' -> 'Pin Name Visible' + bool pinNameVisible; + + // See OrCAD Checkbox: 'Property Sheet' -> 'Part Properties' -> 'Pin Name Rotate' + bool pinNameRotate; + + // See OrCAD Checkbox: 'Property Sheet' -> 'Part Properties' -> 'Pin Number Visible' + bool pinNumberVisible; +}; + + +[[maybe_unused]] +static std::string to_string(const StructGeneralProperties& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}implementationPath = {}\n", indent(1), aObj.implementationPath); + str += fmt::format("{}implementation = {}\n", indent(1), aObj.implementation); + str += fmt::format("{}refDes = {}\n", indent(1), aObj.refDes); + str += fmt::format("{}partValue = {}\n", indent(1), aObj.partValue); + str += fmt::format("{}implementationType = {}\n", indent(1), to_string(aObj.implementationType)); + str += fmt::format("{}pinNameVisible = {}\n", indent(1), aObj.pinNameVisible); + str += fmt::format("{}pinNameRotate = {}\n", indent(1), aObj.pinNameRotate); + str += fmt::format("{}pinNumberVisible = {}\n", indent(1), aObj.pinNumberVisible); + + return str; +} + + +inline std::string StructGeneralProperties::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGeneralProperties& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGENERALPROPERTIES_HPP \ No newline at end of file diff --git a/src/Structures/StructGlobal.cpp b/src/Structures/StructGlobal.cpp index 393751f..92602f6 100644 --- a/src/Structures/StructGlobal.cpp +++ b/src/Structures/StructGlobal.cpp @@ -1,29 +1,31 @@ -#include -#include -#include - -#include - -#include "Container.hpp" -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGlobal.hpp" - - -void StructGlobal::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::Global, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Container.hpp" +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGlobal.hpp" + + +void StructGlobal::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::Global, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGlobal.hpp b/src/Structures/StructGlobal.hpp index daf7330..4d84541 100644 --- a/src/Structures/StructGlobal.hpp +++ b/src/Structures/StructGlobal.hpp @@ -1,66 +1,65 @@ -#ifndef STRUCTGLOBAL_HPP -#define STRUCTGLOBAL_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGlobal : public StructGraphicInst -{ -public: - - StructGlobal(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGlobal& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGlobal::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGlobal& aObj) -{ - aOs << to_string(aObj); - - return aOs; -} - - +#ifndef STRUCTGLOBAL_HPP +#define STRUCTGLOBAL_HPP + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGlobal : public StructGraphicInst +{ +public: + + StructGlobal(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGlobal& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGlobal::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGlobal& aObj) +{ + aOs << to_string(aObj); + + return aOs; +} + + #endif // STRUCTGLOBAL_HPP \ No newline at end of file diff --git a/src/Structures/StructGlobalSymbol.cpp b/src/Structures/StructGlobalSymbol.cpp index cf7d06a..73ff69b 100644 --- a/src/Structures/StructGlobalSymbol.cpp +++ b/src/Structures/StructGlobalSymbol.cpp @@ -1,52 +1,54 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGlobalSymbol.hpp" - - -void StructGlobalSymbol::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GlobalSymbol, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - StructSthInPages0::read_raw(aVersion, localFutureLst); - - const uint16_t lenSymbolPins = ds.readUint16(); - - spdlog::trace("lenSymbolPins = {}", lenSymbolPins); - - for(size_t i = 0u; i < lenSymbolPins; ++i) - { - symbolPins.push_back(dynamic_pointer_cast(readStructure())); - } - - const uint16_t lenSymbolDisplayProps = ds.readUint16(); - - spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); - - for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) - { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); - } - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGlobalSymbol.hpp" + + +void StructGlobalSymbol::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GlobalSymbol, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + StructSthInPages0::read_raw(aVersion, localFutureLst); + + const uint16_t lenSymbolPins = ds.readUint16(); + + spdlog::trace("lenSymbolPins = {}", lenSymbolPins); + + for(size_t i = 0u; i < lenSymbolPins; ++i) + { + symbolPins.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + const uint16_t lenSymbolDisplayProps = ds.readUint16(); + + spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); + + for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) + { + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGlobalSymbol.hpp b/src/Structures/StructGlobalSymbol.hpp index 5694af0..f3c0579 100644 --- a/src/Structures/StructGlobalSymbol.hpp +++ b/src/Structures/StructGlobalSymbol.hpp @@ -21,7 +21,7 @@ class StructGlobalSymbol : public StructSymbol { public: - StructGlobalSymbol(ParserContext& aCtx) : StructSymbol{aCtx}, + StructGlobalSymbol(StreamContext& aCtx) : StructSymbol{aCtx}, symbolPins{}, symbolDisplayProps{} { } @@ -29,7 +29,7 @@ class StructGlobalSymbol : public StructSymbol void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructGraphicArcInst.cpp b/src/Structures/StructGraphicArcInst.cpp index a129d63..5b37105 100644 --- a/src/Structures/StructGraphicArcInst.cpp +++ b/src/Structures/StructGraphicArcInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicArcInst.hpp" - - -void StructGraphicArcInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicArcInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicArcInst.hpp" + + +void StructGraphicArcInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicArcInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicArcInst.hpp b/src/Structures/StructGraphicArcInst.hpp index 4368405..ab73686 100644 --- a/src/Structures/StructGraphicArcInst.hpp +++ b/src/Structures/StructGraphicArcInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICARCINST_HPP -#define STRUCTGRAPHICARCINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicArcInst : public StructGraphicInst -{ -public: - - StructGraphicArcInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicArcInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicArcInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicArcInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICARCINST_HPP +#define STRUCTGRAPHICARCINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicArcInst : public StructGraphicInst +{ +public: + + StructGraphicArcInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicArcInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicArcInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicArcInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICARCINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicBezierInst.cpp b/src/Structures/StructGraphicBezierInst.cpp index c25e630..def399f 100644 --- a/src/Structures/StructGraphicBezierInst.cpp +++ b/src/Structures/StructGraphicBezierInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicBezierInst.hpp" - - -void StructGraphicBezierInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicBezierInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicBezierInst.hpp" + + +void StructGraphicBezierInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicBezierInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicBezierInst.hpp b/src/Structures/StructGraphicBezierInst.hpp index 391fb7d..32b1959 100644 --- a/src/Structures/StructGraphicBezierInst.hpp +++ b/src/Structures/StructGraphicBezierInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICBEZIERINST_HPP -#define STRUCTGRAPHICBEZIERINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicBezierInst : public StructGraphicInst -{ -public: - - StructGraphicBezierInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicBezierInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicBezierInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicBezierInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICBEZIERINST_HPP +#define STRUCTGRAPHICBEZIERINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicBezierInst : public StructGraphicInst +{ +public: + + StructGraphicBezierInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicBezierInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicBezierInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicBezierInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICBEZIERINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicBitMapInst.cpp b/src/Structures/StructGraphicBitMapInst.cpp index 3219db9..7434221 100644 --- a/src/Structures/StructGraphicBitMapInst.cpp +++ b/src/Structures/StructGraphicBitMapInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicBitMapInst.hpp" - - -void StructGraphicBitMapInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicBitMapInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicBitMapInst.hpp" + + +void StructGraphicBitMapInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicBitMapInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicBitMapInst.hpp b/src/Structures/StructGraphicBitMapInst.hpp index bbf8cfd..e3f22fb 100644 --- a/src/Structures/StructGraphicBitMapInst.hpp +++ b/src/Structures/StructGraphicBitMapInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICBITMAPEINST_HPP -#define STRUCTGRAPHICBITMAPEINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicBitMapInst : public StructGraphicInst -{ -public: - - StructGraphicBitMapInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicBitMapInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicBitMapInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicBitMapInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICBITMAPEINST_HPP +#define STRUCTGRAPHICBITMAPEINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicBitMapInst : public StructGraphicInst +{ +public: + + StructGraphicBitMapInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicBitMapInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicBitMapInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicBitMapInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICBITMAPEINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicBoxInst.cpp b/src/Structures/StructGraphicBoxInst.cpp index 1faee08..b226c15 100644 --- a/src/Structures/StructGraphicBoxInst.cpp +++ b/src/Structures/StructGraphicBoxInst.cpp @@ -6,19 +6,21 @@ #include "Enums/Structure.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructGraphicBoxInst.hpp" // @todo is this a specialized instance for Rects or general for all types? void StructGraphicBoxInst::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::GraphicBoxInst, localFutureLst); + parser.auto_read_prefixes(Structure::GraphicBoxInst, localFutureLst); StructGraphicInst::read(localFutureLst); diff --git a/src/Structures/StructGraphicBoxInst.hpp b/src/Structures/StructGraphicBoxInst.hpp index 87ac663..c07ac26 100644 --- a/src/Structures/StructGraphicBoxInst.hpp +++ b/src/Structures/StructGraphicBoxInst.hpp @@ -19,14 +19,14 @@ class StructGraphicBoxInst : public StructGraphicInst { public: - StructGraphicBoxInst(ParserContext& aCtx) : StructGraphicInst{aCtx} + StructGraphicBoxInst(StreamContext& aCtx) : StructGraphicInst{aCtx} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructGraphicCommentTextInst.cpp b/src/Structures/StructGraphicCommentTextInst.cpp index fe2162c..de21f06 100644 --- a/src/Structures/StructGraphicCommentTextInst.cpp +++ b/src/Structures/StructGraphicCommentTextInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicCommentTextInst.hpp" - - -void StructGraphicCommentTextInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicCommentTextInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicCommentTextInst.hpp" + + +void StructGraphicCommentTextInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicCommentTextInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicCommentTextInst.hpp b/src/Structures/StructGraphicCommentTextInst.hpp index fb78f70..27a9670 100644 --- a/src/Structures/StructGraphicCommentTextInst.hpp +++ b/src/Structures/StructGraphicCommentTextInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICCOMMENTTEXTINST_HPP -#define STRUCTGRAPHICCOMMENTTEXTINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicCommentTextInst : public StructGraphicInst -{ -public: - - StructGraphicCommentTextInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicCommentTextInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicCommentTextInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicCommentTextInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICCOMMENTTEXTINST_HPP +#define STRUCTGRAPHICCOMMENTTEXTINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicCommentTextInst : public StructGraphicInst +{ +public: + + StructGraphicCommentTextInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicCommentTextInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicCommentTextInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicCommentTextInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICCOMMENTTEXTINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicEllipseInst.cpp b/src/Structures/StructGraphicEllipseInst.cpp index 01c9fb5..2930a80 100644 --- a/src/Structures/StructGraphicEllipseInst.cpp +++ b/src/Structures/StructGraphicEllipseInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicEllipseInst.hpp" - - -void StructGraphicEllipseInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicEllipseInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicEllipseInst.hpp" + + +void StructGraphicEllipseInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicEllipseInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicEllipseInst.hpp b/src/Structures/StructGraphicEllipseInst.hpp index b50c93a..830f95a 100644 --- a/src/Structures/StructGraphicEllipseInst.hpp +++ b/src/Structures/StructGraphicEllipseInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICELLIPSEINST_HPP -#define STRUCTGRAPHICELLIPSEINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicEllipseInst : public StructGraphicInst -{ -public: - - StructGraphicEllipseInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicEllipseInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicEllipseInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicEllipseInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICELLIPSEINST_HPP +#define STRUCTGRAPHICELLIPSEINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicEllipseInst : public StructGraphicInst +{ +public: + + StructGraphicEllipseInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicEllipseInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicEllipseInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicEllipseInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICELLIPSEINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicInst.cpp b/src/Structures/StructGraphicInst.cpp index 332d825..c5668ae 100644 --- a/src/Structures/StructGraphicInst.cpp +++ b/src/Structures/StructGraphicInst.cpp @@ -6,14 +6,16 @@ #include "Enums/Structure.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructGraphicInst.hpp" void StructGraphicInst::read(FutureDataLst& mLocalFutureLst, FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; - readPreamble(); + parser.readPreamble(); mLocalFutureLst.checkpoint(); @@ -59,7 +61,7 @@ void StructGraphicInst::read(FutureDataLst& mLocalFutureLst, FileFormatVersion / for(size_t i = 0; i < lenSymbolDisplayProps; ++i) { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); } // @todo This flag relates to Enums/Structure @@ -78,7 +80,7 @@ void StructGraphicInst::read(FutureDataLst& mLocalFutureLst, FileFormatVersion / // StructGraphicCommentTextInst // StructGraphicLineInst case 0x02: - sthInPages0 = dynamic_pointer_cast(readStructure()); + sthInPages0 = dynamic_pointer_cast(parser.readStructure()); break; case 0x21: // StructGlobal diff --git a/src/Structures/StructGraphicInst.hpp b/src/Structures/StructGraphicInst.hpp index be4dd85..6b9b754 100644 --- a/src/Structures/StructGraphicInst.hpp +++ b/src/Structures/StructGraphicInst.hpp @@ -11,9 +11,9 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "General.hpp" +#include "Record.hpp" #include "Structures/StructSthInPages0.hpp" #include "Structures/StructSymbolDisplayProp.hpp" @@ -24,11 +24,11 @@ are derived from it and extract common code into it. */ -class StructGraphicInst : public CommonBase +class StructGraphicInst : public Record { public: - StructGraphicInst(ParserContext& aCtx) : CommonBase{aCtx}, name{}, dbId{0}, + StructGraphicInst(StreamContext& aCtx) : Record{aCtx}, name{}, dbId{0}, locX{0}, locY{0}, x1{0}, y1{0}, x2{0}, y2{0}, color{Color::Default}, symbolDisplayProps{}, sthInPages0{} { } diff --git a/src/Structures/StructGraphicLineInst.cpp b/src/Structures/StructGraphicLineInst.cpp index a6c4c63..f18c465 100644 --- a/src/Structures/StructGraphicLineInst.cpp +++ b/src/Structures/StructGraphicLineInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicLineInst.hpp" - - -void StructGraphicLineInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicLineInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicLineInst.hpp" + + +void StructGraphicLineInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicLineInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicLineInst.hpp b/src/Structures/StructGraphicLineInst.hpp index b19f5df..b0e0b5e 100644 --- a/src/Structures/StructGraphicLineInst.hpp +++ b/src/Structures/StructGraphicLineInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICLINEINST_HPP -#define STRUCTGRAPHICLINEINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicLineInst : public StructGraphicInst -{ -public: - - StructGraphicLineInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicLineInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicLineInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicLineInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICLINEINST_HPP +#define STRUCTGRAPHICLINEINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicLineInst : public StructGraphicInst +{ +public: + + StructGraphicLineInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicLineInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicLineInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicLineInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICLINEINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicOleEmbedInst.cpp b/src/Structures/StructGraphicOleEmbedInst.cpp index 4c692bd..b7f0ee5 100644 --- a/src/Structures/StructGraphicOleEmbedInst.cpp +++ b/src/Structures/StructGraphicOleEmbedInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicOleEmbedInst.hpp" - - -void StructGraphicOleEmbedInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicOleEmbedInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicOleEmbedInst.hpp" + + +void StructGraphicOleEmbedInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicOleEmbedInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicOleEmbedInst.hpp b/src/Structures/StructGraphicOleEmbedInst.hpp index 678ec4d..b8625f4 100644 --- a/src/Structures/StructGraphicOleEmbedInst.hpp +++ b/src/Structures/StructGraphicOleEmbedInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICOLEEMBEDINST_HPP -#define STRUCTGRAPHICOLEEMBEDINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicOleEmbedInst : public StructGraphicInst -{ -public: - - StructGraphicOleEmbedInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicOleEmbedInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicOleEmbedInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicOleEmbedInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICOLEEMBEDINST_HPP +#define STRUCTGRAPHICOLEEMBEDINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicOleEmbedInst : public StructGraphicInst +{ +public: + + StructGraphicOleEmbedInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicOleEmbedInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicOleEmbedInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicOleEmbedInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICOLEEMBEDINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicPolygonInst.cpp b/src/Structures/StructGraphicPolygonInst.cpp index f051325..7e02b2a 100644 --- a/src/Structures/StructGraphicPolygonInst.cpp +++ b/src/Structures/StructGraphicPolygonInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicPolygonInst.hpp" - - -void StructGraphicPolygonInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicPolygonInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicPolygonInst.hpp" + + +void StructGraphicPolygonInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicPolygonInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicPolygonInst.hpp b/src/Structures/StructGraphicPolygonInst.hpp index c60105d..0e1cbb8 100644 --- a/src/Structures/StructGraphicPolygonInst.hpp +++ b/src/Structures/StructGraphicPolygonInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICPOLYGONINST_HPP -#define STRUCTGRAPHICPOLYGONINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicPolygonInst : public StructGraphicInst -{ -public: - - StructGraphicPolygonInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicPolygonInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicPolygonInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicPolygonInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICPOLYGONINST_HPP +#define STRUCTGRAPHICPOLYGONINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicPolygonInst : public StructGraphicInst +{ +public: + + StructGraphicPolygonInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicPolygonInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicPolygonInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicPolygonInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICPOLYGONINST_HPP \ No newline at end of file diff --git a/src/Structures/StructGraphicPolylineInst.cpp b/src/Structures/StructGraphicPolylineInst.cpp index 04fccc9..3a5af5b 100644 --- a/src/Structures/StructGraphicPolylineInst.cpp +++ b/src/Structures/StructGraphicPolylineInst.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructGraphicPolylineInst.hpp" - - -void StructGraphicPolylineInst::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::GraphicPolylineInst, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructGraphicPolylineInst.hpp" + + +void StructGraphicPolylineInst::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::GraphicPolylineInst, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructGraphicPolylineInst.hpp b/src/Structures/StructGraphicPolylineInst.hpp index d4fb5ec..3b78252 100644 --- a/src/Structures/StructGraphicPolylineInst.hpp +++ b/src/Structures/StructGraphicPolylineInst.hpp @@ -1,64 +1,64 @@ -#ifndef STRUCTGRAPHICPOLYLINEINST_HPP -#define STRUCTGRAPHICPOLYLINEINST_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructGraphicPolylineInst : public StructGraphicInst -{ -public: - - StructGraphicPolylineInst(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructGraphicPolylineInst& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructGraphicPolylineInst::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructGraphicPolylineInst& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTGRAPHICPOLYLINEINST_HPP +#define STRUCTGRAPHICPOLYLINEINST_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructGraphicPolylineInst : public StructGraphicInst +{ +public: + + StructGraphicPolylineInst(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructGraphicPolylineInst& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructGraphicPolylineInst::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructGraphicPolylineInst& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTGRAPHICPOLYLINEINST_HPP \ No newline at end of file diff --git a/src/Structures/StructHierarchicSymbol.cpp b/src/Structures/StructHierarchicSymbol.cpp index 503bbf7..b375be6 100644 --- a/src/Structures/StructHierarchicSymbol.cpp +++ b/src/Structures/StructHierarchicSymbol.cpp @@ -11,7 +11,7 @@ void StructHierarchicSymbol::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Structures/StructHierarchicSymbol.hpp b/src/Structures/StructHierarchicSymbol.hpp index 359ed03..7c95d44 100644 --- a/src/Structures/StructHierarchicSymbol.hpp +++ b/src/Structures/StructHierarchicSymbol.hpp @@ -10,22 +10,22 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" -class StructHierarchicSymbol : public CommonBase +class StructHierarchicSymbol : public Record { public: - StructHierarchicSymbol(ParserContext& aCtx) : CommonBase{aCtx} + StructHierarchicSymbol(StreamContext& aCtx) : Record{aCtx} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructNetDbIdMapping.cpp b/src/Structures/StructNetDbIdMapping.cpp index 9b480cc..f113297 100644 --- a/src/Structures/StructNetDbIdMapping.cpp +++ b/src/Structures/StructNetDbIdMapping.cpp @@ -4,21 +4,24 @@ #include +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructNetDbIdMapping.hpp" void StructNetDbIdMapping::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::NetDbIdMapping, localFutureLst); + parser.auto_read_prefixes(Structure::NetDbIdMapping, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructNetDbIdMapping.hpp b/src/Structures/StructNetDbIdMapping.hpp index 2712cdb..e9caafc 100644 --- a/src/Structures/StructNetDbIdMapping.hpp +++ b/src/Structures/StructNetDbIdMapping.hpp @@ -10,20 +10,20 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" -class StructNetDbIdMapping : public CommonBase +class StructNetDbIdMapping : public Record { public: - StructNetDbIdMapping(ParserContext& aCtx) : CommonBase{aCtx} + StructNetDbIdMapping(StreamContext& aCtx) : Record{aCtx} { } std::string to_string() const override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructOffPageConnector.cpp b/src/Structures/StructOffPageConnector.cpp index 46d3ee0..14eb877 100644 --- a/src/Structures/StructOffPageConnector.cpp +++ b/src/Structures/StructOffPageConnector.cpp @@ -1,28 +1,30 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructOffPageConnector.hpp" - - -void StructOffPageConnector::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::OffPageConnector, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructOffPageConnector.hpp" + + +void StructOffPageConnector::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::OffPageConnector, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructOffPageConnector.hpp b/src/Structures/StructOffPageConnector.hpp index fa03d08..f0d42f5 100644 --- a/src/Structures/StructOffPageConnector.hpp +++ b/src/Structures/StructOffPageConnector.hpp @@ -1,65 +1,65 @@ -#ifndef STRUCTOFFPAGECONNECTOR_HPP -#define STRUCTOFFPAGECONNECTOR_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructOffPageConnector : public StructGraphicInst -{ -public: - - StructOffPageConnector(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructOffPageConnector& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructOffPageConnector::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructOffPageConnector& aObj) -{ - aOs << to_string(aObj); - - return aOs; -} - - +#ifndef STRUCTOFFPAGECONNECTOR_HPP +#define STRUCTOFFPAGECONNECTOR_HPP + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructOffPageConnector : public StructGraphicInst +{ +public: + + StructOffPageConnector(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructOffPageConnector& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructOffPageConnector::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructOffPageConnector& aObj) +{ + aOs << to_string(aObj); + + return aOs; +} + + #endif // STRUCTOFFPAGECONNECTOR_HPP \ No newline at end of file diff --git a/src/Structures/StructOffPageSymbol.cpp b/src/Structures/StructOffPageSymbol.cpp index ef3dd91..0c7dcc2 100644 --- a/src/Structures/StructOffPageSymbol.cpp +++ b/src/Structures/StructOffPageSymbol.cpp @@ -1,52 +1,54 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructOffPageSymbol.hpp" - - -void StructOffPageSymbol::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::OffPageSymbol, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - StructSthInPages0::read_raw(aVersion, localFutureLst); - - const uint16_t lenSymbolPins = ds.readUint16(); - - spdlog::trace("lenSymbolPins = {}", lenSymbolPins); - - for(size_t i = 0u; i < lenSymbolPins; ++i) - { - symbolPins.push_back(dynamic_pointer_cast(readStructure())); - } - - const uint16_t lenSymbolDisplayProps = ds.readUint16(); - - spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); - - for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) - { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); - } - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructOffPageSymbol.hpp" + + +void StructOffPageSymbol::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::OffPageSymbol, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + StructSthInPages0::read_raw(aVersion, localFutureLst); + + const uint16_t lenSymbolPins = ds.readUint16(); + + spdlog::trace("lenSymbolPins = {}", lenSymbolPins); + + for(size_t i = 0u; i < lenSymbolPins; ++i) + { + symbolPins.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + const uint16_t lenSymbolDisplayProps = ds.readUint16(); + + spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); + + for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) + { + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructOffPageSymbol.hpp b/src/Structures/StructOffPageSymbol.hpp index 516d119..de338d7 100644 --- a/src/Structures/StructOffPageSymbol.hpp +++ b/src/Structures/StructOffPageSymbol.hpp @@ -1,90 +1,90 @@ -#ifndef STRUCTOFFPAGESYMBOL_HPP -#define STRUCTOFFPAGESYMBOL_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructSymbol.hpp" -#include "Structures/StructSymbolDisplayProp.hpp" -#include "Structures/StructSymbolPin.hpp" - - -class StructOffPageSymbol : public StructSymbol -{ -public: - - StructOffPageSymbol(ParserContext& aCtx) : StructSymbol{aCtx}, - symbolPins{}, symbolDisplayProps{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::vector> symbolPins; - std::vector> symbolDisplayProps; -}; - - -[[maybe_unused]] -static std::string to_string(const StructOffPageSymbol& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}name = {}\n", indent(1), aObj.name); - str += fmt::format("{}someStr0 = {}\n", indent(1), aObj.someStr0); - str += fmt::format("{}color = {}\n", indent(1), ::to_string(aObj.color)); - - str += fmt::format("{}symbolPins:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) - { - if(aObj.symbolPins[i]) - { - str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolPins[i]->to_string()), 2); - } - } - - str += fmt::format("{}symbolDisplayProps:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) - { - if(aObj.symbolDisplayProps[i]) - { - str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolDisplayProps[i]->to_string()), 2); - } - } - - return str; -} - - -inline std::string StructOffPageSymbol::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructOffPageSymbol& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTOFFPAGESYMBOL_HPP +#define STRUCTOFFPAGESYMBOL_HPP + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructSymbol.hpp" +#include "Structures/StructSymbolDisplayProp.hpp" +#include "Structures/StructSymbolPin.hpp" + + +class StructOffPageSymbol : public StructSymbol +{ +public: + + StructOffPageSymbol(StreamContext& aCtx) : StructSymbol{aCtx}, + symbolPins{}, symbolDisplayProps{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::vector> symbolPins; + std::vector> symbolDisplayProps; +}; + + +[[maybe_unused]] +static std::string to_string(const StructOffPageSymbol& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}name = {}\n", indent(1), aObj.name); + str += fmt::format("{}someStr0 = {}\n", indent(1), aObj.someStr0); + str += fmt::format("{}color = {}\n", indent(1), ::to_string(aObj.color)); + + str += fmt::format("{}symbolPins:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) + { + if(aObj.symbolPins[i]) + { + str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolPins[i]->to_string()), 2); + } + } + + str += fmt::format("{}symbolDisplayProps:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) + { + if(aObj.symbolDisplayProps[i]) + { + str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolDisplayProps[i]->to_string()), 2); + } + } + + return str; +} + + +inline std::string StructOffPageSymbol::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructOffPageSymbol& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTOFFPAGESYMBOL_HPP \ No newline at end of file diff --git a/src/Structures/StructPartInst.cpp b/src/Structures/StructPartInst.cpp index 353f390..fa67dd5 100644 --- a/src/Structures/StructPartInst.cpp +++ b/src/Structures/StructPartInst.cpp @@ -9,21 +9,24 @@ #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" #include "Enums/Structure.hpp" +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructPartInst.hpp" void StructPartInst::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::PartInst, localFutureLst); + parser.auto_read_prefixes(Structure::PartInst, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); @@ -53,7 +56,7 @@ void StructPartInst::read(FileFormatVersion /* aVersion */) for(size_t i = 0; i < lenSymbolDisplayProps; ++i) { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); } ds.printUnknownData(1, getMethodName(this, __func__) + ": 3"); @@ -72,7 +75,7 @@ void StructPartInst::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenT0x10s; ++i) { - t0x10s.push_back(dynamic_pointer_cast(readStructure())); + t0x10s.push_back(dynamic_pointer_cast(parser.readStructure())); } localFutureLst.checkpoint(); diff --git a/src/Structures/StructPartInst.hpp b/src/Structures/StructPartInst.hpp index 5124573..0848d7f 100644 --- a/src/Structures/StructPartInst.hpp +++ b/src/Structures/StructPartInst.hpp @@ -12,17 +12,17 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" #include "Structures/StructSymbolDisplayProp.hpp" #include "Structures/StructT0x10.hpp" -class StructPartInst : public CommonBase +class StructPartInst : public Record { public: - StructPartInst(ParserContext& aCtx) : CommonBase{aCtx}, symbolDisplayProps{}, + StructPartInst(StreamContext& aCtx) : Record{aCtx}, symbolDisplayProps{}, t0x10s{} { } @@ -30,7 +30,7 @@ class StructPartInst : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructPinIdxMapping.cpp b/src/Structures/StructPinIdxMapping.cpp index c1cce33..46b107e 100644 --- a/src/Structures/StructPinIdxMapping.cpp +++ b/src/Structures/StructPinIdxMapping.cpp @@ -7,21 +7,24 @@ #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" #include "Enums/Structure.hpp" +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructPinIdxMapping.hpp" void StructPinIdxMapping::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::PinIdxMapping, localFutureLst); + parser.auto_read_prefixes(Structure::PinIdxMapping, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructPinIdxMapping.hpp b/src/Structures/StructPinIdxMapping.hpp index 3b80902..ab59d73 100644 --- a/src/Structures/StructPinIdxMapping.hpp +++ b/src/Structures/StructPinIdxMapping.hpp @@ -14,16 +14,16 @@ #include #include -#include "CommonBase.hpp" +#include "Record.hpp" // @todo Probably called 'PhysicalPart' in the XSD // Structure should also contain 'PinShared' and 'PinSwap' -class StructPinIdxMapping : public CommonBase +class StructPinIdxMapping : public Record { public: - StructPinIdxMapping(ParserContext& aCtx) : CommonBase{aCtx}, unitRef{}, refDes{}, + StructPinIdxMapping(StreamContext& aCtx) : Record{aCtx}, unitRef{}, refDes{}, pinMap{}, pinIgnore{}, pinGroup{} { } @@ -31,7 +31,7 @@ class StructPinIdxMapping : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructPinShapeSymbol.cpp b/src/Structures/StructPinShapeSymbol.cpp index 162f5be..9f05b5e 100644 --- a/src/Structures/StructPinShapeSymbol.cpp +++ b/src/Structures/StructPinShapeSymbol.cpp @@ -5,21 +5,24 @@ #include #include "Enums/Structure.hpp" +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructPinShapeSymbol.hpp" void StructPinShapeSymbol::read(FileFormatVersion aVersion) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::PinShapeSymbol, localFutureLst); + parser.auto_read_prefixes(Structure::PinShapeSymbol, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); @@ -31,7 +34,7 @@ void StructPinShapeSymbol::read(FileFormatVersion aVersion) for(size_t i = 0u; i < lenSymbolPins; ++i) { - symbolPins.push_back(dynamic_pointer_cast(readStructure())); + symbolPins.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenSymbolDisplayProps = ds.readUint16(); @@ -40,7 +43,7 @@ void StructPinShapeSymbol::read(FileFormatVersion aVersion) for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); } localFutureLst.checkpoint(); diff --git a/src/Structures/StructPinShapeSymbol.hpp b/src/Structures/StructPinShapeSymbol.hpp index 18e4b32..1529acf 100644 --- a/src/Structures/StructPinShapeSymbol.hpp +++ b/src/Structures/StructPinShapeSymbol.hpp @@ -1,89 +1,89 @@ -#ifndef STRUCTPINSHAPESYMBOL_HPP -#define STRUCTPINSHAPESYMBOL_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructSymbol.hpp" -#include "Structures/StructSymbolDisplayProp.hpp" -#include "Structures/StructSymbolPin.hpp" - - -class StructPinShapeSymbol : public StructSymbol -{ -public: - - StructPinShapeSymbol(ParserContext& aCtx) : StructSymbol{aCtx}, - symbolPins{}, symbolDisplayProps{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::vector> symbolPins; - std::vector> symbolDisplayProps; -}; - - -[[maybe_unused]] -static std::string to_string(const StructPinShapeSymbol& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}name = {}\n", indent(1), aObj.name); - str += fmt::format("{}someStr0 = {}\n", indent(1), aObj.someStr0); - str += fmt::format("{}color = {}\n", indent(1), ::to_string(aObj.color)); - - str += fmt::format("{}symbolPins:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) - { - if(aObj.symbolPins[i]) - { - str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolPins[i]->to_string()), 2); - } - } - - str += fmt::format("{}symbolDisplayProps:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) - { - if(aObj.symbolDisplayProps[i]) - { - str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolDisplayProps[i]->to_string()), 2); - } - } - - return str; -} - - -inline std::string StructPinShapeSymbol::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructPinShapeSymbol& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTPINSHAPESYMBOL_HPP +#define STRUCTPINSHAPESYMBOL_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructSymbol.hpp" +#include "Structures/StructSymbolDisplayProp.hpp" +#include "Structures/StructSymbolPin.hpp" + + +class StructPinShapeSymbol : public StructSymbol +{ +public: + + StructPinShapeSymbol(StreamContext& aCtx) : StructSymbol{aCtx}, + symbolPins{}, symbolDisplayProps{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::vector> symbolPins; + std::vector> symbolDisplayProps; +}; + + +[[maybe_unused]] +static std::string to_string(const StructPinShapeSymbol& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}name = {}\n", indent(1), aObj.name); + str += fmt::format("{}someStr0 = {}\n", indent(1), aObj.someStr0); + str += fmt::format("{}color = {}\n", indent(1), ::to_string(aObj.color)); + + str += fmt::format("{}symbolPins:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) + { + if(aObj.symbolPins[i]) + { + str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolPins[i]->to_string()), 2); + } + } + + str += fmt::format("{}symbolDisplayProps:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) + { + if(aObj.symbolDisplayProps[i]) + { + str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolDisplayProps[i]->to_string()), 2); + } + } + + return str; +} + + +inline std::string StructPinShapeSymbol::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructPinShapeSymbol& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTPINSHAPESYMBOL_HPP \ No newline at end of file diff --git a/src/Structures/StructPort.cpp b/src/Structures/StructPort.cpp index 45ccafa..b8daa13 100644 --- a/src/Structures/StructPort.cpp +++ b/src/Structures/StructPort.cpp @@ -1,32 +1,34 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructPort.hpp" - - -void StructPort::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::Port, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - ds.printUnknownData(9, getMethodName(this, __func__) + ": 0"); - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructPort.hpp" + + +void StructPort::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::Port, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + ds.printUnknownData(9, getMethodName(this, __func__) + ": 0"); + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructPort.hpp b/src/Structures/StructPort.hpp index 633a658..935eb9b 100644 --- a/src/Structures/StructPort.hpp +++ b/src/Structures/StructPort.hpp @@ -1,65 +1,65 @@ -#ifndef STRUCTPORT_HPP -#define STRUCTPORT_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructPort : public StructGraphicInst -{ -public: - - StructPort(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructPort& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructPort::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructPort& aObj) -{ - aOs << to_string(aObj); - - return aOs; -} - - +#ifndef STRUCTPORT_HPP +#define STRUCTPORT_HPP + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructPort : public StructGraphicInst +{ +public: + + StructPort(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructPort& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructPort::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructPort& aObj) +{ + aOs << to_string(aObj); + + return aOs; +} + + #endif // STRUCTPORT_HPP \ No newline at end of file diff --git a/src/Structures/StructPrimitives.cpp b/src/Structures/StructPrimitives.cpp index 70dd2d4..6f2b2a3 100644 --- a/src/Structures/StructPrimitives.cpp +++ b/src/Structures/StructPrimitives.cpp @@ -8,21 +8,24 @@ #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" #include "Enums/Structure.hpp" +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructPrimitives.hpp" void StructPrimitives::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::Primitives, localFutureLst); + parser.auto_read_prefixes(Structure::Primitives, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); @@ -46,7 +49,7 @@ void StructPrimitives::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < len0; ++i) { - const Primitive primitive = readPrefixPrimitive(); + const Primitive primitive = parser.readPrefixPrimitive(); // @todo Hack to get SymbolVector working if(primitive == Primitive::SymbolVector) @@ -54,7 +57,7 @@ void StructPrimitives::read(FileFormatVersion /* aVersion */) ds.setCurrentOffset(ds.getCurrentOffset() - 1U); } - primitives.push_back(readPrimitive(primitive)); + primitives.push_back(parser.readPrimitive(primitive)); // @todo Sometimes there is trailing data after the primitives // but I don't know how many bytes, therefore discard them @@ -114,7 +117,7 @@ void StructPrimitives::read(FileFormatVersion /* aVersion */) continue; } - symbolPins.push_back(dynamic_pointer_cast(readStructure())); + symbolPins.push_back(dynamic_pointer_cast(parser.readStructure())); } const uint16_t lenSymbolDisplayProps = ds.readUint16(); @@ -123,7 +126,7 @@ void StructPrimitives::read(FileFormatVersion /* aVersion */) for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); } localFutureLst.checkpoint(); @@ -133,7 +136,7 @@ void StructPrimitives::read(FileFormatVersion /* aVersion */) spdlog::debug("Checking {} vs {}", localFutureLst.cbegin()->getStopOffset(), ds.getCurrentOffset()); if(localFutureLst.cbegin()->getStopOffset() > ds.getCurrentOffset()) { - readPreamble(); + parser.readPreamble(); for(std::size_t i{0U}; i < std::size_t{4U}; ++i) { diff --git a/src/Structures/StructPrimitives.hpp b/src/Structures/StructPrimitives.hpp index 7e9a76d..8207a45 100644 --- a/src/Structures/StructPrimitives.hpp +++ b/src/Structures/StructPrimitives.hpp @@ -1,105 +1,104 @@ -#ifndef STRUCTPRIMITIVES_HPP -#define STRUCTPRIMITIVES_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "Primitives/PrimBase.hpp" -#include "Structures/StructGeneralProperties.hpp" -#include "Structures/StructSymbolDisplayProp.hpp" -#include "Structures/StructSymbolPin.hpp" - - -class StructPrimitives : public CommonBase -{ -public: - - StructPrimitives(ParserContext& aCtx) : CommonBase{aCtx}, name{}, symbolPins{}, - symbolDisplayProps{}, generalProperties{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::string name; - - std::vector> primitives; - std::vector> symbolPins; - std::vector> symbolDisplayProps; - - StructGeneralProperties generalProperties; -}; - - -[[maybe_unused]] -static std::string to_string(const StructPrimitives& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}name = {}\n", indent(1), aObj.name); - - str += fmt::format("{}primitives:\n", indent(1)); - for(size_t i = 0u; i < aObj.primitives.size(); ++i) - { - if(aObj.primitives[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.primitives[i]->to_string()), 2); - } - } - - str += fmt::format("{}symbolPins:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) - { - if(aObj.symbolPins[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.symbolPins[i]->to_string()), 2); - } - } - - str += fmt::format("{}symbolDisplayProps:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) - { - if(aObj.symbolDisplayProps[i]) - { - str += indent(fmt::format("[{}]: {}", i, aObj.symbolDisplayProps[i]->to_string()), 2); - } - } - - str += fmt::format("{}generalProperties:\n", indent(1)); - str += aObj.generalProperties.to_string(); - - return str; -} - - -inline std::string StructPrimitives::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructPrimitives& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTPRIMITIVES_HPP +#define STRUCTPRIMITIVES_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "Record.hpp" +#include "Structures/StructGeneralProperties.hpp" +#include "Structures/StructSymbolDisplayProp.hpp" +#include "Structures/StructSymbolPin.hpp" + + +class StructPrimitives : public Record +{ +public: + + StructPrimitives(StreamContext& aCtx) : Record{aCtx}, name{}, symbolPins{}, + symbolDisplayProps{}, generalProperties{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::string name; + + std::vector> primitives; + std::vector> symbolPins; + std::vector> symbolDisplayProps; + + StructGeneralProperties generalProperties; +}; + + +[[maybe_unused]] +static std::string to_string(const StructPrimitives& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}name = {}\n", indent(1), aObj.name); + + str += fmt::format("{}primitives:\n", indent(1)); + for(size_t i = 0u; i < aObj.primitives.size(); ++i) + { + if(aObj.primitives[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.primitives[i]->to_string()), 2); + } + } + + str += fmt::format("{}symbolPins:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) + { + if(aObj.symbolPins[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.symbolPins[i]->to_string()), 2); + } + } + + str += fmt::format("{}symbolDisplayProps:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) + { + if(aObj.symbolDisplayProps[i]) + { + str += indent(fmt::format("[{}]: {}", i, aObj.symbolDisplayProps[i]->to_string()), 2); + } + } + + str += fmt::format("{}generalProperties:\n", indent(1)); + str += aObj.generalProperties.to_string(); + + return str; +} + + +inline std::string StructPrimitives::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructPrimitives& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTPRIMITIVES_HPP \ No newline at end of file diff --git a/src/Structures/StructProperties.cpp b/src/Structures/StructProperties.cpp index 547b81f..9090cca 100644 --- a/src/Structures/StructProperties.cpp +++ b/src/Structures/StructProperties.cpp @@ -8,21 +8,24 @@ #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" #include "Enums/Structure.hpp" +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructProperties.hpp" void StructProperties::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::Properties, localFutureLst); + parser.auto_read_prefixes(Structure::Properties, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructProperties.hpp b/src/Structures/StructProperties.hpp index b6bd2a9..4d0344d 100644 --- a/src/Structures/StructProperties.hpp +++ b/src/Structures/StructProperties.hpp @@ -9,14 +9,14 @@ #include #include -#include "CommonBase.hpp" +#include "Record.hpp" -class StructProperties : public CommonBase +class StructProperties : public Record { public: - StructProperties(ParserContext& aCtx) : CommonBase{aCtx}, ref{}, + StructProperties(StreamContext& aCtx) : Record{aCtx}, ref{}, normalName{}, convertName{} { } @@ -24,7 +24,7 @@ class StructProperties : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSomeHierarchyBase.hpp b/src/Structures/StructSomeHierarchyBase.hpp index 9124661..e724cb4 100644 --- a/src/Structures/StructSomeHierarchyBase.hpp +++ b/src/Structures/StructSomeHierarchyBase.hpp @@ -10,8 +10,8 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" /*! @@ -20,16 +20,16 @@ are derived from it and extract common code into it. */ -class StructSomeHierarchyBase : public CommonBase +class StructSomeHierarchyBase : public Record { public: - StructSomeHierarchyBase(ParserContext& aCtx) : CommonBase{aCtx} + StructSomeHierarchyBase(StreamContext& aCtx) : Record{aCtx} { } // std::string to_string() const override; - // virtual void accept(Visitor& aVisitor) const override + // void accept(Visitor& aVisitor) const override // { // aVisitor.visit(*this); // } diff --git a/src/Structures/StructSthInHierarchy1.cpp b/src/Structures/StructSthInHierarchy1.cpp index 292600f..a45d8a5 100644 --- a/src/Structures/StructSthInHierarchy1.cpp +++ b/src/Structures/StructSthInHierarchy1.cpp @@ -4,21 +4,24 @@ #include +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructSthInHierarchy1.hpp" void StructSthInHierarchy1::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::SthInHierarchy1, localFutureLst); + parser.auto_read_prefixes(Structure::SthInHierarchy1, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructSthInHierarchy1.hpp b/src/Structures/StructSthInHierarchy1.hpp index 362f07d..fec7e34 100644 --- a/src/Structures/StructSthInHierarchy1.hpp +++ b/src/Structures/StructSthInHierarchy1.hpp @@ -10,20 +10,20 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" -class StructSthInHierarchy1 : public CommonBase +class StructSthInHierarchy1 : public Record { public: - StructSthInHierarchy1(ParserContext& aCtx) : CommonBase{aCtx} + StructSthInHierarchy1(StreamContext& aCtx) : Record{aCtx} { } std::string to_string() const override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSthInHierarchy2.cpp b/src/Structures/StructSthInHierarchy2.cpp index b3c97e1..6c07480 100644 --- a/src/Structures/StructSthInHierarchy2.cpp +++ b/src/Structures/StructSthInHierarchy2.cpp @@ -4,21 +4,24 @@ #include +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructSthInHierarchy2.hpp" void StructSthInHierarchy2::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::SthInHierarchy2, localFutureLst); + parser.auto_read_prefixes(Structure::SthInHierarchy2, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructSthInHierarchy2.hpp b/src/Structures/StructSthInHierarchy2.hpp index c1fde82..eecdb2f 100644 --- a/src/Structures/StructSthInHierarchy2.hpp +++ b/src/Structures/StructSthInHierarchy2.hpp @@ -18,12 +18,12 @@ class StructSthInHierarchy2 : public StructSomeHierarchyBase { public: - StructSthInHierarchy2(ParserContext& aCtx) : StructSomeHierarchyBase{aCtx} + StructSthInHierarchy2(StreamContext& aCtx) : StructSomeHierarchyBase{aCtx} { } std::string to_string() const override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSthInHierarchy3.cpp b/src/Structures/StructSthInHierarchy3.cpp index 31351da..e333fb6 100644 --- a/src/Structures/StructSthInHierarchy3.cpp +++ b/src/Structures/StructSthInHierarchy3.cpp @@ -4,21 +4,24 @@ #include +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructSthInHierarchy3.hpp" void StructSthInHierarchy3::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::SthInHierarchy3, localFutureLst); + parser.auto_read_prefixes(Structure::SthInHierarchy3, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructSthInHierarchy3.hpp b/src/Structures/StructSthInHierarchy3.hpp index dfb435c..2122602 100644 --- a/src/Structures/StructSthInHierarchy3.hpp +++ b/src/Structures/StructSthInHierarchy3.hpp @@ -10,20 +10,20 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" -class StructSthInHierarchy3 : public CommonBase +class StructSthInHierarchy3 : public Record { public: - StructSthInHierarchy3(ParserContext& aCtx) : CommonBase{aCtx} + StructSthInHierarchy3(StreamContext& aCtx) : Record{aCtx} { } std::string to_string() const override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSthInPages0.cpp b/src/Structures/StructSthInPages0.cpp index 6c8742f..0259ff6 100644 --- a/src/Structures/StructSthInPages0.cpp +++ b/src/Structures/StructSthInPages0.cpp @@ -8,21 +8,23 @@ #include "Enums/Structure.hpp" #include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructSthInPages0.hpp" // @todo Probably a wrapper for Inst (Instances) void StructSthInPages0::read(FileFormatVersion aVersion) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::SthInPages0, localFutureLst); + parser.auto_read_prefixes(Structure::SthInPages0, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); @@ -37,7 +39,8 @@ void StructSthInPages0::read(FileFormatVersion aVersion) void StructSthInPages0::read_raw(FileFormatVersion /* aVersion */, FutureDataLst& aLocalFutureLst) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); @@ -68,11 +71,11 @@ void StructSthInPages0::read_raw(FileFormatVersion /* aVersion */, FutureDataLst const auto currOffset = ds.getCurrentOffset(); try { - const Primitive primitive = readPrefixPrimitive(); - readPrimitive(primitive); + const Primitive primitive = parser.readPrefixPrimitive(); + parser.readPrimitive(primitive); // Here in between could be additional data. // Check if this is the case - readPrefixPrimitive(); + parser.readPrefixPrimitive(); } catch(...) { @@ -81,9 +84,9 @@ void StructSthInPages0::read_raw(FileFormatVersion /* aVersion */, FutureDataLst ds.setCurrentOffset(currOffset); } - const Primitive primitive = readPrefixPrimitive(); + const Primitive primitive = parser.readPrefixPrimitive(); - readPrimitive(primitive); + parser.readPrimitive(primitive); if(hasAdditionalBytes) { diff --git a/src/Structures/StructSthInPages0.hpp b/src/Structures/StructSthInPages0.hpp index 799c6fe..74cec6b 100644 --- a/src/Structures/StructSthInPages0.hpp +++ b/src/Structures/StructSthInPages0.hpp @@ -12,18 +12,18 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "FutureData.hpp" #include "General.hpp" #include "Primitives/PrimBase.hpp" +#include "Record.hpp" -class StructSthInPages0 : public CommonBase +class StructSthInPages0 : public Record { public: - StructSthInPages0(ParserContext& aCtx) : CommonBase{aCtx}, + StructSthInPages0(StreamContext& aCtx) : Record{aCtx}, name{}, someStr0{}, color{Color::Default}, primitives{} { } @@ -31,7 +31,7 @@ class StructSthInPages0 : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSymbol.hpp b/src/Structures/StructSymbol.hpp index ca7ac58..1be36a4 100644 --- a/src/Structures/StructSymbol.hpp +++ b/src/Structures/StructSymbol.hpp @@ -23,7 +23,7 @@ class StructSymbol : public StructSthInPages0 { public: - StructSymbol(ParserContext& aCtx) : StructSthInPages0{aCtx} + StructSymbol(StreamContext& aCtx) : StructSthInPages0{aCtx} { } std::string to_string() const override; diff --git a/src/Structures/StructSymbolBBox.cpp b/src/Structures/StructSymbolBBox.cpp index cdf7583..3a2500a 100644 --- a/src/Structures/StructSymbolBBox.cpp +++ b/src/Structures/StructSymbolBBox.cpp @@ -12,7 +12,7 @@ // @todo is probably trailing data and not a struct object! void StructSymbolBBox::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); diff --git a/src/Structures/StructSymbolBBox.hpp b/src/Structures/StructSymbolBBox.hpp index 19191cf..f791888 100644 --- a/src/Structures/StructSymbolBBox.hpp +++ b/src/Structures/StructSymbolBBox.hpp @@ -9,22 +9,22 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" -class StructSymbolBBox : public CommonBase +class StructSymbolBBox : public Record { public: - StructSymbolBBox(ParserContext& aCtx) : CommonBase{aCtx}, x1{0}, y1{0}, x2{0}, y2{0} + StructSymbolBBox(StreamContext& aCtx) : Record{aCtx}, x1{0}, y1{0}, x2{0}, y2{0} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSymbolDisplayProp.cpp b/src/Structures/StructSymbolDisplayProp.cpp index 3f0e41f..59f077f 100644 --- a/src/Structures/StructSymbolDisplayProp.cpp +++ b/src/Structures/StructSymbolDisplayProp.cpp @@ -6,21 +6,23 @@ #include "Enums/Structure.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Library.hpp" #include "Structures/StructSymbolDisplayProp.hpp" void StructSymbolDisplayProp::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::SymbolDisplayProp, localFutureLst); + parser.auto_read_prefixes(Structure::SymbolDisplayProp, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructSymbolDisplayProp.hpp b/src/Structures/StructSymbolDisplayProp.hpp index 07b0eb8..a6ea1e7 100644 --- a/src/Structures/StructSymbolDisplayProp.hpp +++ b/src/Structures/StructSymbolDisplayProp.hpp @@ -9,16 +9,16 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "Enums/Rotation.hpp" +#include "Record.hpp" -class StructSymbolDisplayProp : public CommonBase +class StructSymbolDisplayProp : public Record { public: - StructSymbolDisplayProp(ParserContext& aCtx) : CommonBase{aCtx}, nameIdx{0}, textFontIdx{0}, + StructSymbolDisplayProp(StreamContext& aCtx) : Record{aCtx}, nameIdx{0}, textFontIdx{0}, rotation{Rotation::Deg_0}, x{0}, y{0}, propColor{Color::Default} { } @@ -26,7 +26,7 @@ class StructSymbolDisplayProp : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSymbolPin.cpp b/src/Structures/StructSymbolPin.cpp index a32c279..290eb71 100644 --- a/src/Structures/StructSymbolPin.cpp +++ b/src/Structures/StructSymbolPin.cpp @@ -7,22 +7,26 @@ #include "Enums/PortType.hpp" #include "Enums/Structure.hpp" +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "PinShape.hpp" #include "Structures/StructSymbolPin.hpp" void StructSymbolPin::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes({Structure::SymbolPinBus, Structure::SymbolPinScalar}, localFutureLst); + parser.auto_read_prefixes({Structure::SymbolPinBus, Structure::SymbolPinScalar}, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); @@ -47,7 +51,7 @@ void StructSymbolPin::read(FileFormatVersion /* aVersion */) for(size_t i = 0; i < lenSymbolDisplayProps; ++i) { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); } localFutureLst.checkpoint(); diff --git a/src/Structures/StructSymbolPin.hpp b/src/Structures/StructSymbolPin.hpp index f18a50c..f00138f 100644 --- a/src/Structures/StructSymbolPin.hpp +++ b/src/Structures/StructSymbolPin.hpp @@ -11,9 +11,9 @@ #include #include -#include "CommonBase.hpp" #include "Enums/PortType.hpp" #include "PinShape.hpp" +#include "Record.hpp" #include "Structures/StructSymbolDisplayProp.hpp" @@ -23,11 +23,11 @@ are derived from it and extract common code into it. */ -class StructSymbolPin : public CommonBase +class StructSymbolPin : public Record { public: - StructSymbolPin(ParserContext& aCtx) : CommonBase{aCtx}, name{}, startX{0}, startY{0}, + StructSymbolPin(StreamContext& aCtx) : Record{aCtx}, name{}, startX{0}, startY{0}, hotptX{0}, hotptY{0}, pinShape{}, portType{PortType::Input}, symbolDisplayProps{} { } @@ -35,7 +35,7 @@ class StructSymbolPin : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSymbolPinBus.hpp b/src/Structures/StructSymbolPinBus.hpp index 6801d72..c369e43 100644 --- a/src/Structures/StructSymbolPinBus.hpp +++ b/src/Structures/StructSymbolPinBus.hpp @@ -18,14 +18,14 @@ class StructSymbolPinBus : public StructSymbolPin { public: - StructSymbolPinBus(ParserContext& aCtx) : StructSymbolPin{aCtx} + StructSymbolPinBus(StreamContext& aCtx) : StructSymbolPin{aCtx} { } // std::string to_string() const override; // void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructSymbolPinScalar.hpp b/src/Structures/StructSymbolPinScalar.hpp index 4d08f0a..d415b49 100644 --- a/src/Structures/StructSymbolPinScalar.hpp +++ b/src/Structures/StructSymbolPinScalar.hpp @@ -18,14 +18,14 @@ class StructSymbolPinScalar : public StructSymbolPin { public: - StructSymbolPinScalar(ParserContext& aCtx) : StructSymbolPin{aCtx} + StructSymbolPinScalar(StreamContext& aCtx) : StructSymbolPin{aCtx} { } // std::string to_string() const override; // void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructT0x10.cpp b/src/Structures/StructT0x10.cpp index 222e9d0..aa9fad1 100644 --- a/src/Structures/StructT0x10.cpp +++ b/src/Structures/StructT0x10.cpp @@ -7,20 +7,22 @@ #include "Container.hpp" #include "Enums/Structure.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructT0x10.hpp" void StructT0x10::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::T0x10, localFutureLst); + parser.auto_read_prefixes(Structure::T0x10, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); @@ -48,7 +50,7 @@ void StructT0x10::read(FileFormatVersion /* aVersion */) for(size_t i = 0; i < lenSymbolDisplayProps; ++i) { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); } localFutureLst.checkpoint(); diff --git a/src/Structures/StructT0x10.hpp b/src/Structures/StructT0x10.hpp index 1538002..fbe1b90 100644 --- a/src/Structures/StructT0x10.hpp +++ b/src/Structures/StructT0x10.hpp @@ -12,23 +12,23 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" #include "Structures/StructSymbolDisplayProp.hpp" -class StructT0x10 : public CommonBase +class StructT0x10 : public Record { public: - StructT0x10(ParserContext& aCtx) : CommonBase{aCtx}, symbolDisplayProps{} + StructT0x10(StreamContext& aCtx) : Record{aCtx}, symbolDisplayProps{} { } std::string to_string() const override; void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructT0x1f.cpp b/src/Structures/StructT0x1f.cpp index 1b3103c..e559e84 100644 --- a/src/Structures/StructT0x1f.cpp +++ b/src/Structures/StructT0x1f.cpp @@ -1,62 +1,65 @@ -#include -#include -#include - -#include - -#include "Enums/LineStyle.hpp" -#include "Enums/LineWidth.hpp" -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructT0x1f.hpp" - - -// @todo Probably specifies the 'Package Properties' -void StructT0x1f::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::T0x1f, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - name = ds.readStringLenZeroTerm(); - - spdlog::trace("name = {}", name); - - std::string unknownStr0 = ds.readStringLenZeroTerm(); // @todo figure out - spdlog::trace("{}: unknownStr0 = {}", __func__, unknownStr0); - - localFutureLst.checkpoint(); - - refDes = ds.readStringLenZeroTerm(); - - spdlog::trace("refDes = {}", refDes); - - std::string unknownStr1 = ds.readStringLenZeroTerm(); // @todo figure out - spdlog::trace("{}: unknownStr1 = {}", __func__, unknownStr1); - - pcbFootprint = ds.readStringLenZeroTerm(); - - const uint16_t lenPinIdxMappings = ds.readUint16(); - - spdlog::trace("lenPinIdxMappings = {}", lenPinIdxMappings); - - for(size_t i = 0u; i < lenPinIdxMappings; ++i) - { - pinIdxMappings.push_back(dynamic_pointer_cast(readStructure())); - } - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/LineStyle.hpp" +#include "Enums/LineWidth.hpp" +#include "Enums/Structure.hpp" +#include "FutureData.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructT0x1f.hpp" + + +// @todo Probably specifies the 'Package Properties' +void StructT0x1f::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::T0x1f, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + name = ds.readStringLenZeroTerm(); + + spdlog::trace("name = {}", name); + + std::string unknownStr0 = ds.readStringLenZeroTerm(); // @todo figure out + spdlog::trace("{}: unknownStr0 = {}", __func__, unknownStr0); + + localFutureLst.checkpoint(); + + refDes = ds.readStringLenZeroTerm(); + + spdlog::trace("refDes = {}", refDes); + + std::string unknownStr1 = ds.readStringLenZeroTerm(); // @todo figure out + spdlog::trace("{}: unknownStr1 = {}", __func__, unknownStr1); + + pcbFootprint = ds.readStringLenZeroTerm(); + + const uint16_t lenPinIdxMappings = ds.readUint16(); + + spdlog::trace("lenPinIdxMappings = {}", lenPinIdxMappings); + + for(size_t i = 0u; i < lenPinIdxMappings; ++i) + { + pinIdxMappings.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructT0x1f.hpp b/src/Structures/StructT0x1f.hpp index a445af3..26a2f89 100644 --- a/src/Structures/StructT0x1f.hpp +++ b/src/Structures/StructT0x1f.hpp @@ -11,14 +11,14 @@ #include #include -#include "CommonBase.hpp" +#include "Record.hpp" #include "Structures/StructPinIdxMapping.hpp" -class StructT0x1f : public CommonBase +class StructT0x1f : public Record { public: - StructT0x1f(ParserContext& aCtx) : CommonBase{aCtx}, name{}, + StructT0x1f(StreamContext& aCtx) : Record{aCtx}, name{}, refDes{}, pcbFootprint{} { } @@ -26,7 +26,7 @@ class StructT0x1f : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructT0x34.cpp b/src/Structures/StructT0x34.cpp index 6706beb..ef517fc 100644 --- a/src/Structures/StructT0x34.cpp +++ b/src/Structures/StructT0x34.cpp @@ -11,16 +11,16 @@ void StructT0x34::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); // @todo Try to activate this part // FutureDataLst localFutureLst{mCtx}; - // auto_read_prefixes(Structure::T0x34, localFutureLst); + // ds.auto_read_prefixes(Structure::T0x34, localFutureLst); - // readPreamble(); + // ds.readPreamble(); // @todo Looks like Primitive types! // 0 Byte = structure id diff --git a/src/Structures/StructT0x34.hpp b/src/Structures/StructT0x34.hpp index 1af194a..986fb0c 100644 --- a/src/Structures/StructT0x34.hpp +++ b/src/Structures/StructT0x34.hpp @@ -10,18 +10,18 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" #include "General.hpp" +#include "Record.hpp" -class StructT0x34 : public CommonBase +class StructT0x34 : public Record { public: - StructT0x34(ParserContext& aCtx) : CommonBase{aCtx}, id{0}, color{Color::Default}, + StructT0x34(StreamContext& aCtx) : Record{aCtx}, id{0}, color{Color::Default}, lineStyle{LineStyle::Default}, lineWidth{LineWidth::Default} { } @@ -29,7 +29,7 @@ class StructT0x34 : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructT0x35.cpp b/src/Structures/StructT0x35.cpp index 522cf24..fdc9f8c 100644 --- a/src/Structures/StructT0x35.cpp +++ b/src/Structures/StructT0x35.cpp @@ -11,16 +11,16 @@ void StructT0x35::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); // @todo Try to activate this part // FutureDataLst localFutureLst{mCtx}; - // auto_read_prefixes(Structure::T0x35, localFutureLst); + // ds.auto_read_prefixes(Structure::T0x35, localFutureLst); - // readPreamble(); + // ds.readPreamble(); // @todo Looks like Primitive types! // 0 Byte = structure id diff --git a/src/Structures/StructT0x35.hpp b/src/Structures/StructT0x35.hpp index a1e34cd..1d8f9ef 100644 --- a/src/Structures/StructT0x35.hpp +++ b/src/Structures/StructT0x35.hpp @@ -10,18 +10,18 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" #include "General.hpp" +#include "Record.hpp" -class StructT0x35 : public CommonBase +class StructT0x35 : public Record { public: - StructT0x35(ParserContext& aCtx) : CommonBase{aCtx}, id{0}, color{Color::Default}, + StructT0x35(StreamContext& aCtx) : Record{aCtx}, id{0}, color{Color::Default}, lineStyle{LineStyle::Default}, lineWidth{LineWidth::Default} { } @@ -29,7 +29,7 @@ class StructT0x35 : public CommonBase void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructT0x45.cpp b/src/Structures/StructT0x45.cpp index 3aaa90e..f2c54b1 100644 --- a/src/Structures/StructT0x45.cpp +++ b/src/Structures/StructT0x45.cpp @@ -4,21 +4,24 @@ #include +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructT0x45.hpp" void StructT0x45::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::T0x45, localFutureLst); + parser.auto_read_prefixes(Structure::T0x45, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructT0x45.hpp b/src/Structures/StructT0x45.hpp index e7af8d7..0418e27 100644 --- a/src/Structures/StructT0x45.hpp +++ b/src/Structures/StructT0x45.hpp @@ -18,12 +18,12 @@ class StructT0x45 : public StructSomeHierarchyBase { public: - StructT0x45(ParserContext& aCtx) : StructSomeHierarchyBase{aCtx} + StructT0x45(StreamContext& aCtx) : StructSomeHierarchyBase{aCtx} { } std::string to_string() const override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructT0x5b.cpp b/src/Structures/StructT0x5b.cpp index e375958..63798c3 100644 --- a/src/Structures/StructT0x5b.cpp +++ b/src/Structures/StructT0x5b.cpp @@ -4,21 +4,24 @@ #include +#include "FutureData.hpp" #include "General.hpp" +#include "GenericParser.hpp" #include "Structures/StructT0x5b.hpp" void StructT0x5b::read(FileFormatVersion /* aVersion */) { - auto& ds = mCtx.get().mDs.get(); + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); FutureDataLst localFutureLst{mCtx}; - auto_read_prefixes(Structure::T0x5b, localFutureLst); + parser.auto_read_prefixes(Structure::T0x5b, localFutureLst); - readPreamble(); + parser.readPreamble(); localFutureLst.checkpoint(); diff --git a/src/Structures/StructT0x5b.hpp b/src/Structures/StructT0x5b.hpp index 3b4fc7a..265c845 100644 --- a/src/Structures/StructT0x5b.hpp +++ b/src/Structures/StructT0x5b.hpp @@ -10,20 +10,20 @@ #include #include -#include "CommonBase.hpp" #include "General.hpp" +#include "Record.hpp" -class StructT0x5b : public CommonBase +class StructT0x5b : public Record { public: - StructT0x5b(ParserContext& aCtx) : CommonBase{aCtx} + StructT0x5b(StreamContext& aCtx) : Record{aCtx} { } std::string to_string() const override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructTitleBlock.cpp b/src/Structures/StructTitleBlock.cpp index 9245eb5..7f3b33c 100644 --- a/src/Structures/StructTitleBlock.cpp +++ b/src/Structures/StructTitleBlock.cpp @@ -1,33 +1,34 @@ -#include -#include -#include - -#include - -#include "Container.hpp" -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructTitleBlock.hpp" - - -void StructTitleBlock::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::TitleBlock, localFutureLst); - - StructGraphicInst::read(localFutureLst); - - ds.printUnknownData(12, fmt::format("{}: 1", getMethodName(this, __func__))); - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructTitleBlock.hpp" + + +void StructTitleBlock::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::TitleBlock, localFutureLst); + + StructGraphicInst::read(localFutureLst); + + ds.printUnknownData(12, fmt::format("{}: 1", getMethodName(this, __func__))); + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructTitleBlock.hpp b/src/Structures/StructTitleBlock.hpp index 5133c86..124879d 100644 --- a/src/Structures/StructTitleBlock.hpp +++ b/src/Structures/StructTitleBlock.hpp @@ -1,66 +1,65 @@ -#ifndef STRUCTTITLEBLOCK_HPP -#define STRUCTTITLEBLOCK_HPP - - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "CommonBase.hpp" -#include "General.hpp" -#include "Structures/StructGraphicInst.hpp" - - -class StructTitleBlock : public StructGraphicInst -{ -public: - - StructTitleBlock(ParserContext& aCtx) : StructGraphicInst{aCtx} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } -}; - - -[[maybe_unused]] -static std::string to_string(const StructTitleBlock& aObj) -{ - return aObj.to_string(); -} - - -inline std::string StructTitleBlock::to_string() const -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - - str += StructGraphicInst::to_string(); - - return str; -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructTitleBlock& aObj) -{ - aOs << to_string(aObj); - - return aOs; -} - - +#ifndef STRUCTTITLEBLOCK_HPP +#define STRUCTTITLEBLOCK_HPP + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructGraphicInst.hpp" + + +class StructTitleBlock : public StructGraphicInst +{ +public: + + StructTitleBlock(StreamContext& aCtx) : StructGraphicInst{aCtx} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } +}; + + +[[maybe_unused]] +static std::string to_string(const StructTitleBlock& aObj) +{ + return aObj.to_string(); +} + + +inline std::string StructTitleBlock::to_string() const +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + + str += StructGraphicInst::to_string(); + + return str; +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructTitleBlock& aObj) +{ + aOs << to_string(aObj); + + return aOs; +} + + #endif // STRUCTTITLEBLOCK_HPP \ No newline at end of file diff --git a/src/Structures/StructTitleBlockSymbol.cpp b/src/Structures/StructTitleBlockSymbol.cpp index a57c932..a412312 100644 --- a/src/Structures/StructTitleBlockSymbol.cpp +++ b/src/Structures/StructTitleBlockSymbol.cpp @@ -1,57 +1,60 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructTitleBlockSymbol.hpp" - - -void StructTitleBlockSymbol::read(FileFormatVersion aVersion) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - if(aVersion == FileFormatVersion::Unknown) - { - aVersion = predictVersion(); - } - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes(Structure::TitleBlockSymbol, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - StructSthInPages0::read_raw(aVersion, localFutureLst); - - const uint16_t lenSymbolPins = ds.readUint16(); - - spdlog::trace("lenSymbolPins = {}", lenSymbolPins); - - for(size_t i = 0u; i < lenSymbolPins; ++i) - { - symbolPins.push_back(dynamic_pointer_cast(readStructure())); - } - - const uint16_t lenSymbolDisplayProps = ds.readUint16(); - - spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); - - for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) - { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); - } - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructTitleBlockSymbol.hpp" + + +void StructTitleBlockSymbol::read(FileFormatVersion aVersion) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + if(aVersion == FileFormatVersion::Unknown) + { + const auto predictionFunc = [this](FileFormatVersion aVersion){ this->read(aVersion); }; + aVersion = parser.predictVersion(predictionFunc); + } + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes(Structure::TitleBlockSymbol, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + StructSthInPages0::read_raw(aVersion, localFutureLst); + + const uint16_t lenSymbolPins = ds.readUint16(); + + spdlog::trace("lenSymbolPins = {}", lenSymbolPins); + + for(size_t i = 0u; i < lenSymbolPins; ++i) + { + symbolPins.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + const uint16_t lenSymbolDisplayProps = ds.readUint16(); + + spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); + + for(size_t i = 0u; i < lenSymbolDisplayProps; ++i) + { + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructTitleBlockSymbol.hpp b/src/Structures/StructTitleBlockSymbol.hpp index c342e61..b283913 100644 --- a/src/Structures/StructTitleBlockSymbol.hpp +++ b/src/Structures/StructTitleBlockSymbol.hpp @@ -1,89 +1,89 @@ -#ifndef STRUCTTITLEBLOCKSYMBOL_HPP -#define STRUCTTITLEBLOCKSYMBOL_HPP - - -#include -#include -#include -#include -#include - -#include -#include - -#include "General.hpp" -#include "Structures/StructSymbol.hpp" -#include "Structures/StructSymbolDisplayProp.hpp" -#include "Structures/StructSymbolPin.hpp" - - -class StructTitleBlockSymbol : public StructSymbol -{ -public: - - StructTitleBlockSymbol(ParserContext& aCtx) : StructSymbol{aCtx}, - symbolPins{}, symbolDisplayProps{} - { } - - std::string to_string() const override; - - void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - - virtual void accept(Visitor& aVisitor) const override - { - aVisitor.visit(*this); - } - - std::vector> symbolPins; - std::vector> symbolDisplayProps; -}; - - -[[maybe_unused]] -static std::string to_string(const StructTitleBlockSymbol& aObj) -{ - std::string str; - - str += fmt::format("{}:\n", nameof::nameof_type()); - str += fmt::format("{}name = {}\n", indent(1), aObj.name); - str += fmt::format("{}someStr0 = {}\n", indent(1), aObj.someStr0); - str += fmt::format("{}color = {}\n", indent(1), ::to_string(aObj.color)); - - str += fmt::format("{}symbolPins:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) - { - if(aObj.symbolPins[i]) - { - str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolPins[i]->to_string()), 2); - } - } - - str += fmt::format("{}symbolDisplayProps:\n", indent(1)); - for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) - { - if(aObj.symbolDisplayProps[i]) - { - str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolDisplayProps[i]->to_string()), 2); - } - } - - return str; -} - - -inline std::string StructTitleBlockSymbol::to_string() const -{ - return ::to_string(*this); -} - - -[[maybe_unused]] -static std::ostream& operator<<(std::ostream& aOs, const StructTitleBlockSymbol& aVal) -{ - aOs << to_string(aVal); - - return aOs; -} - - +#ifndef STRUCTTITLEBLOCKSYMBOL_HPP +#define STRUCTTITLEBLOCKSYMBOL_HPP + + +#include +#include +#include +#include +#include + +#include +#include + +#include "General.hpp" +#include "Structures/StructSymbol.hpp" +#include "Structures/StructSymbolDisplayProp.hpp" +#include "Structures/StructSymbolPin.hpp" + + +class StructTitleBlockSymbol : public StructSymbol +{ +public: + + StructTitleBlockSymbol(StreamContext& aCtx) : StructSymbol{aCtx}, + symbolPins{}, symbolDisplayProps{} + { } + + std::string to_string() const override; + + void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; + + void accept(Visitor& aVisitor) const override + { + aVisitor.visit(*this); + } + + std::vector> symbolPins; + std::vector> symbolDisplayProps; +}; + + +[[maybe_unused]] +static std::string to_string(const StructTitleBlockSymbol& aObj) +{ + std::string str; + + str += fmt::format("{}:\n", nameof::nameof_type()); + str += fmt::format("{}name = {}\n", indent(1), aObj.name); + str += fmt::format("{}someStr0 = {}\n", indent(1), aObj.someStr0); + str += fmt::format("{}color = {}\n", indent(1), ::to_string(aObj.color)); + + str += fmt::format("{}symbolPins:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolPins.size(); ++i) + { + if(aObj.symbolPins[i]) + { + str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolPins[i]->to_string()), 2); + } + } + + str += fmt::format("{}symbolDisplayProps:\n", indent(1)); + for(size_t i = 0u; i < aObj.symbolDisplayProps.size(); ++i) + { + if(aObj.symbolDisplayProps[i]) + { + str += indent(fmt::format("[{}]: {}\n", i, aObj.symbolDisplayProps[i]->to_string()), 2); + } + } + + return str; +} + + +inline std::string StructTitleBlockSymbol::to_string() const +{ + return ::to_string(*this); +} + + +[[maybe_unused]] +static std::ostream& operator<<(std::ostream& aOs, const StructTitleBlockSymbol& aVal) +{ + aOs << to_string(aVal); + + return aOs; +} + + #endif // STRUCTTITLEBLOCKSYMBOL_HPP \ No newline at end of file diff --git a/src/Structures/StructWire.cpp b/src/Structures/StructWire.cpp index 637777f..737b8af 100644 --- a/src/Structures/StructWire.cpp +++ b/src/Structures/StructWire.cpp @@ -1,84 +1,87 @@ -#include -#include -#include - -#include - -#include "Enums/Structure.hpp" -#include "General.hpp" -#include "Structures/StructWire.hpp" - - -void StructWire::read(FileFormatVersion /* aVersion */) -{ - auto& ds = mCtx.get().mDs.get(); - - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - - FutureDataLst localFutureLst{mCtx}; - - auto_read_prefixes({Structure::WireBus, Structure::WireScalar}, localFutureLst); - - readPreamble(); - - localFutureLst.checkpoint(); - - // @todo this 4 Byte and the following 4 byte ID - // might be swapped. I need to verify this! - ds.printUnknownData(4, fmt::format("{}: 0", getMethodName(this, __func__))); - - id = ds.readUint32(); - - spdlog::trace("id = {}", id); - - color = ToColor(ds.readUint32()); - - spdlog::trace("color = {}", ::to_string(color)); - - startX = ds.readInt32(); - startY = ds.readInt32(); - - spdlog::trace("startX = {}", startX); - spdlog::trace("startY = {}", startY); - - endX = ds.readInt32(); - endY = ds.readInt32(); - - spdlog::trace("endX = {}", endX); - spdlog::trace("endY = {}", endY); - - ds.printUnknownData(1, fmt::format("{}: 1", getMethodName(this, __func__))); - - const uint16_t lenAliases = ds.readUint16(); - - spdlog::trace("lenAliases = {}", lenAliases); - - for(size_t i = 0; i < lenAliases; ++i) - { - aliases.push_back(dynamic_pointer_cast(readStructure())); - } - - const uint16_t lenSymbolDisplayProps = ds.readUint16(); - - spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); - - for(size_t i = 0; i < lenSymbolDisplayProps; ++i) - { - symbolDisplayProps.push_back(dynamic_pointer_cast(readStructure())); - } - - lineWidth = ToLineWidth(ds.readUint32()); - - spdlog::trace("lineWidth = {}", ::to_string(lineWidth)); - - lineStyle = ToLineStyle(ds.readUint32()); - - spdlog::trace("lineStyle = {}", ::to_string(lineStyle)); - - localFutureLst.checkpoint(); - - localFutureLst.sanitizeCheckpoints(); - - spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); - spdlog::trace(to_string()); +#include +#include +#include + +#include + +#include "Enums/Structure.hpp" +#include "FutureData.hpp" +#include "General.hpp" +#include "GenericParser.hpp" +#include "Structures/StructWire.hpp" + + +void StructWire::read(FileFormatVersion /* aVersion */) +{ + auto& ds = mCtx.mDs; + GenericParser parser{mCtx}; + + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + + FutureDataLst localFutureLst{mCtx}; + + parser.auto_read_prefixes({Structure::WireBus, Structure::WireScalar}, localFutureLst); + + parser.readPreamble(); + + localFutureLst.checkpoint(); + + // @todo this 4 Byte and the following 4 byte ID + // might be swapped. I need to verify this! + ds.printUnknownData(4, fmt::format("{}: 0", getMethodName(this, __func__))); + + id = ds.readUint32(); + + spdlog::trace("id = {}", id); + + color = ToColor(ds.readUint32()); + + spdlog::trace("color = {}", ::to_string(color)); + + startX = ds.readInt32(); + startY = ds.readInt32(); + + spdlog::trace("startX = {}", startX); + spdlog::trace("startY = {}", startY); + + endX = ds.readInt32(); + endY = ds.readInt32(); + + spdlog::trace("endX = {}", endX); + spdlog::trace("endY = {}", endY); + + ds.printUnknownData(1, fmt::format("{}: 1", getMethodName(this, __func__))); + + const uint16_t lenAliases = ds.readUint16(); + + spdlog::trace("lenAliases = {}", lenAliases); + + for(size_t i = 0; i < lenAliases; ++i) + { + aliases.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + const uint16_t lenSymbolDisplayProps = ds.readUint16(); + + spdlog::trace("lenSymbolDisplayProps = {}", lenSymbolDisplayProps); + + for(size_t i = 0; i < lenSymbolDisplayProps; ++i) + { + symbolDisplayProps.push_back(dynamic_pointer_cast(parser.readStructure())); + } + + lineWidth = ToLineWidth(ds.readUint32()); + + spdlog::trace("lineWidth = {}", ::to_string(lineWidth)); + + lineStyle = ToLineStyle(ds.readUint32()); + + spdlog::trace("lineStyle = {}", ::to_string(lineStyle)); + + localFutureLst.checkpoint(); + + localFutureLst.sanitizeCheckpoints(); + + spdlog::debug(getClosingMsg(getMethodName(this, __func__), ds.getCurrentOffset())); + spdlog::trace(to_string()); } \ No newline at end of file diff --git a/src/Structures/StructWire.hpp b/src/Structures/StructWire.hpp index c1816f0..d07a4a8 100644 --- a/src/Structures/StructWire.hpp +++ b/src/Structures/StructWire.hpp @@ -12,11 +12,11 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" #include "General.hpp" +#include "Record.hpp" #include "Structures/StructAlias.hpp" #include "Structures/StructSymbolDisplayProp.hpp" @@ -26,11 +26,11 @@ are derived from it and extract common code into it. */ -class StructWire : public CommonBase +class StructWire : public Record { public: - StructWire(ParserContext& aCtx) : CommonBase{aCtx}, id{0}, color{Color::Default}, + StructWire(StreamContext& aCtx) : Record{aCtx}, id{0}, color{Color::Default}, startX{0}, startY{0}, endX{0}, endY{0}, lineWidth{LineWidth::Default}, lineStyle{LineStyle::Default} { } diff --git a/src/Structures/StructWireBus.hpp b/src/Structures/StructWireBus.hpp index ff0be6b..7973b6f 100644 --- a/src/Structures/StructWireBus.hpp +++ b/src/Structures/StructWireBus.hpp @@ -10,7 +10,6 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" @@ -22,14 +21,14 @@ class StructWireBus : public StructWire { public: - StructWireBus(ParserContext& aCtx) : StructWire{aCtx} + StructWireBus(StreamContext& aCtx) : StructWire{aCtx} { } // std::string to_string() const override; // void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Structures/StructWireScalar.hpp b/src/Structures/StructWireScalar.hpp index f8a7ee7..d9ff9bd 100644 --- a/src/Structures/StructWireScalar.hpp +++ b/src/Structures/StructWireScalar.hpp @@ -10,7 +10,6 @@ #include #include -#include "CommonBase.hpp" #include "Enums/Color.hpp" #include "Enums/LineStyle.hpp" #include "Enums/LineWidth.hpp" @@ -22,14 +21,14 @@ class StructWireScalar : public StructWire { public: - StructWireScalar(ParserContext& aCtx) : StructWire{aCtx} + StructWireScalar(StreamContext& aCtx) : StructWire{aCtx} { } // std::string to_string() const override; // void read(FileFormatVersion aVersion = FileFormatVersion::Unknown) override; - virtual void accept(Visitor& aVisitor) const override + void accept(Visitor& aVisitor) const override { aVisitor.visit(*this); } diff --git a/src/Win32/LOGFONTA.hpp b/src/Win32/LOGFONTA.hpp index e67e8e9..851cb32 100644 --- a/src/Win32/LOGFONTA.hpp +++ b/src/Win32/LOGFONTA.hpp @@ -11,7 +11,7 @@ #include #include "General.hpp" -#include "ParserContext.hpp" +#include "StreamContext.hpp" // See Win32 API for reference, where the original structure was copied from @@ -25,11 +25,11 @@ class tagLOGFONTA lfFaceName{""} { } - void read(ParserContext& aCtx) + void read(StreamContext& aCtx) { - spdlog::debug(getOpeningMsg(getMethodName(this, __func__), aCtx.mDs.get().getCurrentOffset())); + spdlog::debug(getOpeningMsg(getMethodName(this, __func__), aCtx.mDs.getCurrentOffset())); - const auto buffer = aCtx.mDs.get().readBytes(sizeof(*this)); + const auto buffer = aCtx.mDs.readBytes(sizeof(*this)); std::memcpy(this, buffer.data(), sizeof(*this)); @@ -48,7 +48,7 @@ class tagLOGFONTA throw std::runtime_error(fmt::format("lfQuality <= 6 must hold but lfQuality = {}", lfQuality)); } - spdlog::debug(getClosingMsg(getMethodName(this, __func__), aCtx.mDs.get().getCurrentOffset())); + spdlog::debug(getClosingMsg(getMethodName(this, __func__), aCtx.mDs.getCurrentOffset())); spdlog::trace(to_string()); } diff --git a/src/main.cpp b/src/main.cpp index 0e958c4..8e43d53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -155,7 +155,7 @@ int main(int argc, char* argv[]) Container parser{inputFile, cfg}; - ParserContext& ctx = parser.getContext(); + ContainerContext& ctx = parser.getContext(); if(printTree) {