Skip to content

Commit

Permalink
Unify different Directory stream parsers since they all
Browse files Browse the repository at this point in the history
have the same structure
  • Loading branch information
Werni2A committed Dec 30, 2023
1 parent 0eabf60 commit 34ce20b
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 888 deletions.
15 changes: 1 addition & 14 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@ set(SOURCES
${LIB_SRC_DIR}/StreamFactory.cpp
${LIB_SRC_DIR}/Streams/StreamAdminData.cpp
${LIB_SRC_DIR}/Streams/StreamCache.cpp
${LIB_SRC_DIR}/Streams/StreamCellsDirectory.cpp
${LIB_SRC_DIR}/Streams/StreamCellsDirectory.hpp
${LIB_SRC_DIR}/Streams/StreamDirectoryStruct.cpp
${LIB_SRC_DIR}/Streams/StreamDsnStream.cpp
${LIB_SRC_DIR}/Streams/StreamERC.cpp
${LIB_SRC_DIR}/Streams/StreamExportBlocksDirectory.cpp
${LIB_SRC_DIR}/Streams/StreamExportBlocksDirectory.hpp
${LIB_SRC_DIR}/Streams/StreamGraphicsDirectory.cpp
${LIB_SRC_DIR}/Streams/StreamHierarchy.cpp
${LIB_SRC_DIR}/Streams/StreamHSObjects.cpp
${LIB_SRC_DIR}/Streams/StreamLibrary.cpp
${LIB_SRC_DIR}/Streams/StreamNetBundleMapData.cpp
${LIB_SRC_DIR}/Streams/StreamPackage.cpp
${LIB_SRC_DIR}/Streams/StreamPackagesDirectory.cpp
${LIB_SRC_DIR}/Streams/StreamPage.cpp
${LIB_SRC_DIR}/Streams/StreamPartsDirectory.cpp
${LIB_SRC_DIR}/Streams/StreamSchematic.cpp
${LIB_SRC_DIR}/Streams/StreamSymbol.cpp
${LIB_SRC_DIR}/Streams/StreamSymbolsDirectory.cpp
${LIB_SRC_DIR}/Streams/StreamType.cpp
${LIB_SRC_DIR}/Streams/StreamViewsDirectory.cpp
${LIB_SRC_DIR}/Structures/StructAlias.cpp
${LIB_SRC_DIR}/Structures/StructBookMarkSymbolInst.cpp
${LIB_SRC_DIR}/Structures/StructBusEntry.cpp
Expand Down Expand Up @@ -136,20 +128,15 @@ set(HEADERS
${LIB_INCLUDE_DIR}/Streams/StreamDirectoryStruct.hpp
${LIB_INCLUDE_DIR}/Streams/StreamDsnStream.hpp
${LIB_INCLUDE_DIR}/Streams/StreamERC.hpp
${LIB_INCLUDE_DIR}/Streams/StreamGraphicsDirectory.hpp
${LIB_INCLUDE_DIR}/Streams/StreamHierarchy.hpp
${LIB_INCLUDE_DIR}/Streams/StreamHSObjects.hpp
${LIB_INCLUDE_DIR}/Streams/StreamLibrary.hpp
${LIB_INCLUDE_DIR}/Streams/StreamNetBundleMapData.hpp
${LIB_INCLUDE_DIR}/Streams/StreamPackage.hpp
${LIB_INCLUDE_DIR}/Streams/StreamPackagesDirectory.hpp
${LIB_INCLUDE_DIR}/Streams/StreamPage.hpp
${LIB_INCLUDE_DIR}/Streams/StreamPartsDirectory.hpp
${LIB_INCLUDE_DIR}/Streams/StreamSchematic.hpp
${LIB_INCLUDE_DIR}/Streams/StreamSymbol.hpp
${LIB_INCLUDE_DIR}/Streams/StreamSymbolsDirectory.hpp
${LIB_INCLUDE_DIR}/Streams/StreamType.hpp
${LIB_INCLUDE_DIR}/Streams/StreamViewsDirectory.hpp
${LIB_INCLUDE_DIR}/Structures/StructAlias.hpp
${LIB_INCLUDE_DIR}/Structures/StructBookMarkSymbolInst.hpp
${LIB_INCLUDE_DIR}/Structures/StructBusEntry.hpp
Expand Down
22 changes: 8 additions & 14 deletions src/StreamFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@
#include "StreamFactory.hpp"
#include "Streams/StreamAdminData.hpp"
#include "Streams/StreamCache.hpp"
#include "Streams/StreamCellsDirectory.hpp"
#include "Streams/StreamDirectoryStruct.hpp"
#include "Streams/StreamDsnStream.hpp"
#include "Streams/StreamExportBlocksDirectory.hpp"
#include "Streams/StreamGraphicsDirectory.hpp"
#include "Streams/StreamHierarchy.hpp"
#include "Streams/StreamHSObjects.hpp"
#include "Streams/StreamLibrary.hpp"
#include "Streams/StreamNetBundleMapData.hpp"
#include "Streams/StreamPackage.hpp"
#include "Streams/StreamPackagesDirectory.hpp"
#include "Streams/StreamPage.hpp"
#include "Streams/StreamPartsDirectory.hpp"
#include "Streams/StreamSchematic.hpp"
#include "Streams/StreamSymbol.hpp"
#include "Streams/StreamSymbolsDirectory.hpp"
#include "Streams/StreamType.hpp"
#include "Streams/StreamViewsDirectory.hpp"


std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::path& aInputStream)
Expand Down Expand Up @@ -88,7 +82,7 @@ std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::p
pattern = {"Cells Directory"};
if(streamLoc.matches_pattern(pattern))
{
return std::make_unique<StreamCellsDirectory>(aCtx, aInputStream);
return std::make_unique<StreamDirectoryStruct>(aCtx, aInputStream);
}

// Match `/CIS/CISSchematicStore/CISSchematicStream`
Expand Down Expand Up @@ -174,7 +168,7 @@ std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::p
pattern = {"ExportBlocks Directory"};
if(streamLoc.matches_pattern(pattern))
{
return std::make_unique<StreamExportBlocksDirectory>(aCtx, aInputStream);
return std::make_unique<StreamDirectoryStruct>(aCtx, aInputStream);
}

// Match `/Graphics/$Types$`
Expand All @@ -196,7 +190,7 @@ std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::p
pattern = {"Graphics Directory"};
if(streamLoc.matches_pattern(pattern))
{
return std::make_unique<StreamGraphicsDirectory>(aCtx, aInputStream);
return std::make_unique<StreamDirectoryStruct>(aCtx, aInputStream);
}

// Match `/HSObjects`
Expand Down Expand Up @@ -239,7 +233,7 @@ std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::p
pattern = {"Packages Directory"};
if(streamLoc.matches_pattern(pattern))
{
return std::make_unique<StreamPackagesDirectory>(aCtx, aInputStream);
return std::make_unique<StreamDirectoryStruct>(aCtx, aInputStream);
}

// Match `/Parts/*`
Expand All @@ -254,7 +248,7 @@ std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::p
pattern = {"Parts Directory"};
if(streamLoc.matches_pattern(pattern))
{
return std::make_unique<StreamPartsDirectory>(aCtx, aInputStream);
return std::make_unique<StreamDirectoryStruct>(aCtx, aInputStream);
}

// Match `/Symbols/$Types$`
Expand Down Expand Up @@ -292,7 +286,7 @@ std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::p
pattern = {"Symbols Directory"};
if(streamLoc.matches_pattern(pattern))
{
return std::make_unique<StreamSymbolsDirectory>(aCtx, aInputStream);
return std::make_unique<StreamDirectoryStruct>(aCtx, aInputStream);
}

// Match `/Views/*/Hierarchy/Hierarchy`
Expand Down Expand Up @@ -320,7 +314,7 @@ std::unique_ptr<Stream> StreamFactory::build(ContainerContext& aCtx, const fs::p
pattern = {"Views Directory"};
if(streamLoc.matches_pattern(pattern))
{
return std::make_unique<StreamViewsDirectory>(aCtx, aInputStream);
return std::make_unique<StreamDirectoryStruct>(aCtx, aInputStream);
}

const std::string errMsg = fmt::format(
Expand Down
56 changes: 0 additions & 56 deletions src/Streams/StreamCellsDirectory.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#include <algorithm>
#include <cstdint>
#include <string>

#include <nameof.hpp>
#include <spdlog/spdlog.h>

#include "General.hpp"
#include "Streams/StreamCellsDirectory.hpp"
#include "Streams/StreamDirectoryStruct.hpp"


void StreamCellsDirectory::read(FileFormatVersion /* aVersion */)
void StreamDirectoryStruct::read(FileFormatVersion /* aVersion */)
{
auto& ds = mCtx.mDs;

mCtx.mLogger.debug(getOpeningMsg(getMethodName(this, __func__), ds.getCurrentOffset()));

lastModifiedDate = static_cast<time_t>(ds.readUint32());
mCtx.mLogger.trace("lastModifiedDate = {}", DateTimeToStr(lastModifiedDate));

const uint16_t size = ds.readUint16();
mCtx.mLogger.trace("size = {}", size);

for(size_t i = 0u; i < size; ++i)
{
Expand All @@ -31,16 +33,11 @@ void StreamCellsDirectory::read(FileFormatVersion /* aVersion */)

mCtx.mLogger.trace("componentType = {}", ::to_string(item.componentType));

if(item.componentType != ComponentType::Cell)
{
mCtx.mLogger.warn("{}: Unexpected ComponentType `{}`", __func__, ::to_string(item.componentType));
}

// @todo This changes with the version of the file format, so maybe it contains
// more details for the format? Or some hash of the specified stream?
ds.printUnknownData(14, fmt::format("item[{:>3}] - 0", i));

// @todo Just a guess that this is the version but's highly likely
// @todo Just a guess that this is the version but it's highly likely
item.fileFormatVersion = ds.readUint16();

mCtx.mLogger.trace("fileFormatVersion = {}", item.fileFormatVersion);
Expand All @@ -49,7 +46,7 @@ void StreamCellsDirectory::read(FileFormatVersion /* aVersion */)
// 471 in 17.4-2019 S012 (3898062) [10/18/202]
// 472 in 17.4-2019 S019 (3959056) [7/8/2021]
std::vector<uint16_t> knownFileVersions{
445, 446, 447, 448, 449,
445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457, 458, 459,
460, 461, 462, 463, 464, 465, 466, 467, 468, 469,
470, 471, 472
Expand Down
17 changes: 14 additions & 3 deletions src/Streams/StreamDirectoryStruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ static std::ostream& operator<<(std::ostream& aOs, const DirItemType& aVal)
}


// Used to parse
// - `Cells Directory`
// - `ExportBlocks Directory`
// - `Graphics Directory`
// - `Packages Directory`
// - `Parts Directory`
// - `Symbols Directory`
// - `Views Directory`
class StreamDirectoryStruct : public Stream
{
public:
Expand All @@ -74,9 +82,12 @@ class StreamDirectoryStruct : public Stream

std::string to_string() const;

// @todo This is more a workaround to get inheritance working for e.g. StreamExportBlocksDirectory
void read(FileFormatVersion /* aVersion */ = FileFormatVersion::Unknown) override
{ }
void read(FileFormatVersion /* aVersion */ = FileFormatVersion::Unknown);

void accept(Visitor& aVisitor) const override
{
aVisitor.visit(*this);
}

time_t lastModifiedDate;

Expand Down
70 changes: 0 additions & 70 deletions src/Streams/StreamExportBlocksDirectory.cpp

This file was deleted.

Loading

0 comments on commit 34ce20b

Please sign in to comment.