diff --git a/src/core/serializers/TomlReader.h b/src/core/serializers/TomlReader.h index 5ec6336..ea24f5c 100644 --- a/src/core/serializers/TomlReader.h +++ b/src/core/serializers/TomlReader.h @@ -1,16 +1,124 @@ #pragma once -#include ; +#include "File.h" + +#include +#include #include +#include using Path = std::filesystem::path; +class TomlSection +{ +public: + using Comment = std::pair; + + TomlSection(const std::string& tag) + : mTag(tag) + { + + } + + void addComment(const Comment& comment) + { + mComments.push_back(comment); + } + + void addSection(std::unique_ptr section) + { + mSections[section->getTag()] = std::move(section); + } + + void addValue(const std::string& key, const std::string& value) + { + mValues[key] = value; + } + + std::string getTag() const + { + return mTag; + } + +private: + unsigned mLineOffset{ 0 }; + std::string mTag; + std::unordered_map > mSections; + std::unordered_map mValues; + std::vector mComments; +}; + class TomlContent { - //using SectionContent +private: + std::unique_ptr mRootSection; }; class TomlReader { +public: + TomlReader() + : mContent(std::make_unique()) + { + } + + TomlContent* getContent() const + { + return mContent.get(); + } + + void read(const Path& input_path) + { + const auto lines = File(input_path).readLines(); + mLastSectionOffset = 0; + mWorkingSection = std::make_unique("root"); + + for (const auto& line : lines) + { + processLine(line); + mLastSectionOffset++; + } + } + + void processLine(const std::string& line) + { + bool in_comment{ false }; + bool in_tag{ false }; + std::string working_string; + for (auto c : line) + { + if (c == '#' && !in_comment) + { + in_comment = true; + } + else if (c == '[' && !in_comment && !in_tag) + { + in_tag = true; + } + else if (c == ']' && in_tag) + { + break; + } + else if (in_comment || in_tag) + { + working_string += c; + } + } + + if (in_comment) + { + std::cout << "Found comment at: " << mLastSectionOffset << " with value " << working_string; + mWorkingSection->addComment({ mLastSectionOffset, working_string }); + } + else if (in_tag) + { + std::cout << "Found tag at: " << mLastSectionOffset << " with value " << working_string; + } + } + +private: + unsigned mLastSectionOffset{ 0 }; + std::unique_ptr mContent; + std::unique_ptr mWorkingSection; }; \ No newline at end of file diff --git a/src/graphics/CMakeLists.txt b/src/graphics/CMakeLists.txt index 0afb8d4..1fa1858 100644 --- a/src/graphics/CMakeLists.txt +++ b/src/graphics/CMakeLists.txt @@ -44,7 +44,7 @@ target_include_directories(graphics PUBLIC "${PROJECT_SOURCE_DIR}/src/visual_elements/" ) -target_link_libraries(graphics PUBLIC visual_elements image GL ${platform_LIBS}) +target_link_libraries(graphics PUBLIC visual_elements image ${platform_LIBS}) set_property(TARGET graphics PROPERTY FOLDER src) set_target_properties( graphics PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) \ No newline at end of file diff --git a/test/core/TestTomlReader.cpp b/test/core/TestTomlReader.cpp index cae33b0..8152438 100644 --- a/test/core/TestTomlReader.cpp +++ b/test/core/TestTomlReader.cpp @@ -7,6 +7,8 @@ int main() const auto data_loc = std::filesystem::path(__FILE__) / "../data"; const auto sample_toml_file = data_loc / "sample_toml.toml"; + auto reader = TomlReader(); + reader.read(sample_toml_file); return 0; } \ No newline at end of file diff --git a/test/data/sample_toml.toml b/test/data/sample_toml.toml index 86873ac..f0a0982 100644 --- a/test/data/sample_toml.toml +++ b/test/data/sample_toml.toml @@ -1,4 +1,6 @@ +# Site Generator Config + [themes] location = "../personal-site-themes" active_theme = "basic" \ No newline at end of file