Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Werni2A committed Jul 4, 2024
1 parent 68309fd commit bb012ad
Show file tree
Hide file tree
Showing 194 changed files with 1,984 additions and 2,397 deletions.
23 changes: 6 additions & 17 deletions src/CfbfStreamLocation.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CFBFSTREAMLOCATION_HPP
#define CFBFSTREAMLOCATION_HPP


#include <cstdint>
#include <filesystem>
#include <functional>
Expand All @@ -12,15 +11,12 @@

#include "General.hpp"


namespace fs = std::filesystem;


class CfbfStreamLocation
{
public:
CfbfStreamLocation(
const fs::path& aStreamPath, const fs::path& aExtractedCfbfPath)
CfbfStreamLocation(const fs::path& aStreamPath, const fs::path& aExtractedCfbfPath)
{
std::vector<std::string> streamLocation{};

Expand Down Expand Up @@ -65,7 +61,7 @@ class CfbfStreamLocation
* 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<std::optional<std::string>>& aPattern)
{
if(get_vector().size() != aPattern.size())
Expand Down Expand Up @@ -93,13 +89,10 @@ class CfbfStreamLocation
}

private:

std::vector<std::string> mStreamLocation{};
};


[[maybe_unused]]
static std::string to_string(const CfbfStreamLocation& aLocation)
[[maybe_unused]] static std::string to_string(const CfbfStreamLocation& aLocation)
{
std::string locStr{};
for(const auto& locPart : aLocation.get_vector())
Expand All @@ -110,23 +103,19 @@ static std::string to_string(const CfbfStreamLocation& aLocation)
return locStr;
}

[[maybe_unused]]
static bool operator==(const CfbfStreamLocation& aLhs, const std::vector<std::string>& aRhs)
[[maybe_unused]] static bool operator==(const CfbfStreamLocation& aLhs, const std::vector<std::string>& aRhs)
{
return aLhs.get_vector() == aRhs;
}

[[maybe_unused]]
static bool operator==(const std::vector<std::string>& aLhs, const CfbfStreamLocation& aRhs)
[[maybe_unused]] static bool operator==(const std::vector<std::string>& aLhs, const CfbfStreamLocation& aRhs)
{
return aRhs == aLhs;
}

[[maybe_unused]]
static bool operator==(const CfbfStreamLocation& aLhs, const CfbfStreamLocation& aRhs)
[[maybe_unused]] static bool operator==(const CfbfStreamLocation& aLhs, const CfbfStreamLocation& aRhs)
{
return aLhs.get_vector() == aRhs.get_vector();
}


#endif // CFBFSTREAMLOCATION_HPP
53 changes: 22 additions & 31 deletions src/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
#include "Stream.hpp"
#include "StreamFactory.hpp"


namespace fs = std::filesystem;


Container::Container(const fs::path& aCfbfContainer, ParserConfig aCfg) :
mDb{}, mFileCtr{0U}, mFileErrCtr{0U}, mCtx{aCfbfContainer, "", aCfg, mDb}, mCfg{aCfg}
Container::Container(const fs::path& aCfbfContainer, ParserConfig aCfg)
: mDb{},
mFileCtr{0U},
mFileErrCtr{0U},
mCtx{aCfbfContainer, "", aCfg, mDb},
mCfg{aCfg}
{
// Extract to a unique folder in case two similar named files
// are extracted at the same time. E.g. in parallel execution.
Expand All @@ -51,7 +53,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;
mCtx.mExtractedCfbfPath = extractContainer(aCfbfContainer, extractTo);
mCtx.mExtractedCfbfPath = extractContainer(aCfbfContainer, extractTo);

// @todo This is a hack, since mExtractedCfbfPath is not available at construction of the context
const fs::path logPath = extractTo / "logs" / "OpenOrCadParser.log";
Expand All @@ -61,7 +63,6 @@ Container::Container(const fs::path& aCfbfContainer, ParserConfig aCfg) :
mCtx.mLogger.debug(to_string(mCfg));
}


Container::~Container()
{
if(!mCfg.mKeepTmpFiles)
Expand All @@ -73,7 +74,6 @@ Container::~Container()
}
}


void Container::parseDatabaseFileThread(std::deque<std::shared_ptr<Stream>> aStreamList)
{
for(auto& stream : aStreamList)
Expand All @@ -96,10 +96,8 @@ void Container::parseDatabaseFileThread(std::deque<std::shared_ptr<Stream>> aStr
}
}


// Equally distribute elements into new lists of pointers to the original elements
void distributeStreamsToThreadJobsForParsing(
std::size_t aNumberParallelJobs,
void distributeStreamsToThreadJobsForParsing(std::size_t aNumberParallelJobs,
const std::vector<std::shared_ptr<Stream>>& aStreams, //!< Streams to distribute
std::deque<std::shared_ptr<Stream>>& aSequentialJobList,
std::vector<std::deque<std::shared_ptr<Stream>>>& aParallelJobLists)
Expand Down Expand Up @@ -138,7 +136,6 @@ void distributeStreamsToThreadJobsForParsing(
}
}


/**
* @brief Parse the whole database file.
*/
Expand Down Expand Up @@ -192,8 +189,8 @@ void Container::parseDatabaseFile()

// Print sequential job assignment
{
mCtx.mLogger.info("Assigning main thread with the following {}/{} jobs (sequential):",
sequentialJobList.size(), mFileCtr);
mCtx.mLogger.info(
"Assigning main thread with the following {}/{} jobs (sequential):", sequentialJobList.size(), mFileCtr);

for(const auto& job : sequentialJobList)
{
Expand All @@ -204,8 +201,8 @@ void Container::parseDatabaseFile()
// Print parallel job assignment
for(std::size_t i{0U}; i < parallelJobsLists.size(); ++i)
{
mCtx.mLogger.info("Assigning thread {} with the following {}/{} jobs (parallel):",
i, parallelJobsLists.at(i).size(), mFileCtr);
mCtx.mLogger.info("Assigning thread {} with the following {}/{} jobs (parallel):", i,
parallelJobsLists.at(i).size(), mFileCtr);

const auto& parallelJobList = parallelJobsLists.at(i);

Expand Down Expand Up @@ -246,15 +243,13 @@ void Container::parseDatabaseFile()

std::string errCtrStr = fmt::format("Errors in {}/{} files!", mFileErrCtr, mFileCtr);

errCtrStr = fmt::format((mFileErrCtr == 0u) ? fg(fmt::color::green) : fg(fmt::color::crimson),
errCtrStr);
errCtrStr = fmt::format((mFileErrCtr == 0u) ? fg(fmt::color::green) : fg(fmt::color::crimson), errCtrStr);

mCtx.mLogger.info(errCtrStr);

// mCtx.mLogger.info(to_string(mLibrary));
}


fs::path Container::extractContainer(const fs::path& aFile, const fs::path& aOutDir) const
{
ContainerExtractor extractor{aFile};
Expand All @@ -264,35 +259,31 @@ fs::path Container::extractContainer(const fs::path& aFile, const fs::path& aOut
return extractor.extract(aOutDir);
}


fs::path Container::extractContainer(const fs::path& aOutDir) const
{
return extractContainer(mCtx.mInputCfbfFile, aOutDir);
}


void Container::printContainerTree() const
{
ContainerExtractor extractor{mCtx.mInputCfbfFile};
extractor.printContainerTree();
}


std::optional<DatabaseType> Container::getDatabaseTypeByFileExtension(const fs::path& aFile) const
{
std::string extension = aFile.extension().string();

// Ignore case of extension
std::transform(extension.begin(), extension.end(), extension.begin(),
[] (unsigned char c) { return std::toupper(c); });

const std::map<std::string, DatabaseType> extensionFileTypeMap =
{
{".DSN", DatabaseType::Design},
{".DBK", DatabaseType::Design}, // Backup file
{".OLB", DatabaseType::Library},
{".OBK", DatabaseType::Library} // Backup file
};
std::transform(
extension.begin(), extension.end(), extension.begin(), [](unsigned char c) { return std::toupper(c); });

const std::map<std::string, DatabaseType> extensionFileTypeMap = {
{".DSN", DatabaseType::Design },
{".DBK", DatabaseType::Design }, // Backup file
{".OLB", DatabaseType::Library},
{".OBK", DatabaseType::Library} // Backup file
};

if(extensionFileTypeMap.count(extension) == 0U)
{
Expand Down
9 changes: 1 addition & 8 deletions src/Container.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CONTAINER_HPP
#define CONTAINER_HPP


#include <deque>
#include <filesystem>
#include <fstream>
Expand All @@ -12,25 +11,21 @@
#include <vector>

#include "ContainerContext.hpp"
#include "Database.hpp"
#include "DataStream.hpp"
#include "Database.hpp"
#include "Enums/Primitive.hpp"
#include "Enums/Structure.hpp"
#include "FutureData.hpp"
#include "General.hpp"
#include "Primitives/PrimBase.hpp"
#include "Stream.hpp"



namespace fs = std::filesystem;


// @todo rename to DatabaseParser
class Container
{
public:

Container(const fs::path& aFile, ParserConfig aCfg);

~Container();
Expand Down Expand Up @@ -91,7 +86,6 @@ class Container
void parseDatabaseFile();

private:

Database mDb;

size_t mFileCtr; //!< Counts all files that were opened for parsing
Expand All @@ -102,5 +96,4 @@ class Container
ParserConfig mCfg;
};


#endif // CONTAINER_HPP
28 changes: 14 additions & 14 deletions src/ContainerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@
// #include "Database.hpp"
#include "General.hpp"


class Database;


namespace fs = std::filesystem;


ContainerContext::ContainerContext(const fs::path& aInputCfbfFile,
const fs::path& aExtractedCfbfPath, ParserConfig aCfg, Database& aDb) : mDb{aDb},
mLogger{"tmp"}
ContainerContext::ContainerContext(
const fs::path& aInputCfbfFile, const fs::path& aExtractedCfbfPath, ParserConfig aCfg, Database& aDb)
: mDb{aDb},
mLogger{"tmp"}
{
mInputCfbfFile = aInputCfbfFile;
mInputCfbfFile = aInputCfbfFile;
mExtractedCfbfPath = aExtractedCfbfPath;
mCfg = aCfg;
mCfg = aCfg;
mFileFormatVersion = FileFormatVersion::C;
mLogLevel = spdlog::level::trace;
mLogLevel = spdlog::level::trace;

const fs::path logPath = mExtractedCfbfPath / "logs" / "OpenOrCadParser.log";
configureLogger(logPath);
}

ContainerContext::ContainerContext(const ContainerContext& aCtx) : mDb{aCtx.mDb}, mLogger{"tmp"}
ContainerContext::ContainerContext(const ContainerContext& aCtx)
: mDb{aCtx.mDb},
mLogger{"tmp"}
{
mInputCfbfFile = aCtx.mInputCfbfFile;
mInputCfbfFile = aCtx.mInputCfbfFile;
mExtractedCfbfPath = aCtx.mExtractedCfbfPath;
mCfg = aCtx.mCfg;
mCfg = aCtx.mCfg;
mFileFormatVersion = aCtx.mFileFormatVersion;
mLogLevel = aCtx.mLogLevel;
mLogLevel = aCtx.mLogLevel;
}

void ContainerContext::configureLogger(const fs::path& aLogPath)
Expand All @@ -52,7 +52,7 @@ void ContainerContext::configureLogger(const fs::path& aLogPath)
}

auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(aLogPath.string());
mLogger = spdlog::logger{"file logger", {file_sink}};
mLogger = spdlog::logger{"file logger", {file_sink}};
mLogger.set_pattern("[%^%l%$] %v");
mLogger.set_level(mLogLevel);

Expand Down
18 changes: 5 additions & 13 deletions src/ContainerContext.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CONTAINERCONTEXT_HPP
#define CONTAINERCONTEXT_HPP


#include <cstdint>
#include <filesystem>
#include <functional>
Expand All @@ -16,16 +15,14 @@
// #include "Database.hpp"
#include "General.hpp"


class Database;


namespace fs = std::filesystem;


struct ParserConfig
{
std::size_t mThreadCount{std::thread::hardware_concurrency()}; //!< Number of threads used for parsing streams in parallel
std::size_t mThreadCount{
std::thread::hardware_concurrency()}; //!< Number of threads used for parsing streams in parallel

bool mSkipUnknownPrim{true}; //!< Unknown primitives should be skipped during parsing
bool mSkipInvalidPrim{true}; //!< Invalid primitives should be skipped during parsing
Expand All @@ -36,9 +33,7 @@ struct ParserConfig
bool mKeepTmpFiles{true}; //!< Do not delete temporary files after parser completed
};


[[maybe_unused]]
static std::string to_string(const ParserConfig& aCfg)
[[maybe_unused]] static std::string to_string(const ParserConfig& aCfg)
{
std::string str;
str += fmt::format("mSkipUnknownPrim = {}\n", aCfg.mSkipUnknownPrim);
Expand All @@ -50,13 +45,11 @@ static std::string to_string(const ParserConfig& aCfg)
return str;
}


class ContainerContext
{
public:

ContainerContext(const fs::path& aInputCfbfFile,
const fs::path& aExtractedCfbfPath, ParserConfig aCfg, Database& aDb);
ContainerContext(
const fs::path& aInputCfbfFile, const fs::path& aExtractedCfbfPath, ParserConfig aCfg, Database& aDb);

ContainerContext(const ContainerContext& aCtx);

Expand All @@ -75,5 +68,4 @@ class ContainerContext
spdlog::logger mLogger;
};


#endif // CONTAINERCONTEXT_HPP
Loading

0 comments on commit bb012ad

Please sign in to comment.