diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-04 22:06:39 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-04 22:06:39 +0800 |
| commit | 8bea03e0811588e741050b598b8123865b333999 (patch) | |
| tree | dab70865e53fca11960cb899454d64db9e8ed98d | |
| parent | 1a6111e3f02b0a9cff0f81fb524b4dfb7d69854b (diff) | |
| download | cru-8bea03e0811588e741050b598b8123865b333999.tar.gz cru-8bea03e0811588e741050b598b8123865b333999.tar.bz2 cru-8bea03e0811588e741050b598b8123865b333999.zip | |
Move toml to base.
| -rw-r--r-- | include/cru/base/toml/TomlDocument.h (renamed from include/cru/toml/TomlDocument.h) | 18 | ||||
| -rw-r--r-- | include/cru/base/toml/TomlParser.h (renamed from include/cru/toml/TomlParser.h) | 12 | ||||
| -rw-r--r-- | include/cru/toml/Base.h | 11 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/base/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/base/toml/TomlDocument.cpp (renamed from src/toml/TomlDocument.cpp) | 6 | ||||
| -rw-r--r-- | src/base/toml/TomlParser.cpp (renamed from src/toml/TomlParser.cpp) | 7 | ||||
| -rw-r--r-- | src/toml/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | test/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | test/base/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | test/base/toml/ParserTest.cpp (renamed from test/toml/ParserTest.cpp) | 4 | ||||
| -rw-r--r-- | test/toml/CMakeLists.txt | 6 |
12 files changed, 20 insertions, 56 deletions
diff --git a/include/cru/toml/TomlDocument.h b/include/cru/base/toml/TomlDocument.h index 22442096..c0dc68af 100644 --- a/include/cru/toml/TomlDocument.h +++ b/include/cru/base/toml/TomlDocument.h @@ -1,20 +1,13 @@ #pragma once -#include "Base.h" - -#include "cru/base/Base.h" +#include "../Base.h" #include <optional> #include <unordered_map> #include <string> namespace cru::toml { -class CRU_TOML_API TomlSection { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlSection) - CRU_DEFAULT_COPY(TomlSection) - CRU_DEFAULT_MOVE(TomlSection) - +class CRU_BASE_API TomlSection { public: std::optional<std::string> GetValue(const std::string& key) const; void SetValue(const std::string& key, std::string value); @@ -31,12 +24,7 @@ class CRU_TOML_API TomlSection { std::unordered_map<std::string, std::string> values_; }; -class CRU_TOML_API TomlDocument { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlDocument) - CRU_DEFAULT_COPY(TomlDocument) - CRU_DEFAULT_MOVE(TomlDocument) - +class CRU_BASE_API TomlDocument { public: TomlSection* GetSection(const std::string& name); TomlSection* GetSectionOrCreate(const std::string& name); diff --git a/include/cru/toml/TomlParser.h b/include/cru/base/toml/TomlParser.h index b6532931..ac7d0217 100644 --- a/include/cru/toml/TomlParser.h +++ b/include/cru/base/toml/TomlParser.h @@ -1,24 +1,20 @@ #pragma once -#include "cru/base/Exception.h" -#include "cru/toml/TomlDocument.h" +#include "../Exception.h" +#include "TomlDocument.h" #include <optional> namespace cru::toml { // A very simple and tolerant TOML parser. -class CRU_TOML_API TomlParsingException : public Exception { +class CRU_BASE_API TomlParsingException : public Exception { public: using Exception::Exception; }; -class CRU_TOML_API TomlParser { +class CRU_BASE_API TomlParser : public Object { public: explicit TomlParser(std::string input); - - CRU_DELETE_COPY(TomlParser) - CRU_DELETE_MOVE(TomlParser) - ~TomlParser(); public: diff --git a/include/cru/toml/Base.h b/include/cru/toml/Base.h deleted file mode 100644 index 76c7ee71..00000000 --- a/include/cru/toml/Base.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifdef CRU_IS_DLL -#ifdef CRU_TOML_EXPORT_API -#define CRU_TOML_API __declspec(dllexport) -#else -#define CRU_TOML_API __declspec(dllimport) -#endif -#else -#define CRU_TOML_API -#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9f9c205f..d4df1752 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,4 @@ add_subdirectory(base) add_subdirectory(platform) add_subdirectory(ui) add_subdirectory(parse) -add_subdirectory(toml) - add_subdirectory(ThemeBuilder) diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index ef5afe3c..3cffb125 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -14,6 +14,8 @@ add_library(CruBase io/MemoryStream.cpp log/Logger.cpp log/StdioLogTarget.cpp + toml/TomlDocument.cpp + toml/TomlParser.cpp xml/XmlNode.cpp xml/XmlParser.cpp ) diff --git a/src/toml/TomlDocument.cpp b/src/base/toml/TomlDocument.cpp index af9e2ac8..fa155c80 100644 --- a/src/toml/TomlDocument.cpp +++ b/src/base/toml/TomlDocument.cpp @@ -1,4 +1,4 @@ -#include "cru/toml/TomlDocument.h" +#include "cru/base/toml/TomlDocument.h" namespace cru::toml { std::optional<std::string> TomlSection::GetValue(const std::string& key) const { @@ -44,6 +44,8 @@ void TomlDocument::SetSection(const std::string& name, TomlSection section) { sections_[name] = std::move(section); } -void TomlDocument::DeleteSection(const std::string& name) { sections_.erase(name); } +void TomlDocument::DeleteSection(const std::string& name) { + sections_.erase(name); +} } // namespace cru::toml diff --git a/src/toml/TomlParser.cpp b/src/base/toml/TomlParser.cpp index 1aea5b73..a45af712 100644 --- a/src/toml/TomlParser.cpp +++ b/src/base/toml/TomlParser.cpp @@ -1,6 +1,6 @@ -#include "cru/toml/TomlParser.h" +#include "cru/base/toml/TomlParser.h" #include "cru/base/StringUtil.h" -#include "cru/toml/TomlDocument.h" +#include "cru/base/toml/TomlDocument.h" namespace cru::toml { TomlParser::TomlParser(std::string input) : input_(std::move(input)) {} @@ -18,7 +18,8 @@ TomlDocument TomlParser::Parse() { } void TomlParser::DoParse(TomlDocument& document) { - std::vector<std::string> lines = cru::string::Split(input_, "\n", cru::string::SplitOptions::RemoveSpace); + std::vector<std::string> lines = + cru::string::Split(input_, "\n", cru::string::SplitOptions::RemoveSpace); std::string current_section_name; diff --git a/src/toml/CMakeLists.txt b/src/toml/CMakeLists.txt deleted file mode 100644 index 33b31b8f..00000000 --- a/src/toml/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -add_library(CruToml - TomlDocument.cpp - TomlParser.cpp -) -target_compile_definitions(CruToml PRIVATE CRU_TOML_EXPORT_API) -target_link_libraries(CruToml PUBLIC CruBase) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 22f66e40..d9b5bc3a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,5 +17,4 @@ endfunction() add_subdirectory(base) add_subdirectory(platform) -add_subdirectory(toml) add_subdirectory(ui) diff --git a/test/base/CMakeLists.txt b/test/base/CMakeLists.txt index b36bbd23..38cb9d57 100644 --- a/test/base/CMakeLists.txt +++ b/test/base/CMakeLists.txt @@ -6,6 +6,7 @@ add_executable(CruBaseTest StringUtilTest.cpp SubProcessTest.cpp TimerTest.cpp + toml/ParserTest.cpp xml/ParserTest.cpp ) target_link_libraries(CruBaseTest PRIVATE CruBase CruTestBase) diff --git a/test/toml/ParserTest.cpp b/test/base/toml/ParserTest.cpp index 4a4ba212..2582e3c3 100644 --- a/test/toml/ParserTest.cpp +++ b/test/base/toml/ParserTest.cpp @@ -1,5 +1,5 @@ -#include "cru/toml/TomlDocument.h" -#include "cru/toml/TomlParser.h" +#include "cru/base/toml/TomlDocument.h" +#include "cru/base/toml/TomlParser.h" #include <catch2/catch_test_macros.hpp> diff --git a/test/toml/CMakeLists.txt b/test/toml/CMakeLists.txt deleted file mode 100644 index a0909349..00000000 --- a/test/toml/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -add_executable(CruTomlTest - ParserTest.cpp -) -target_link_libraries(CruTomlTest PRIVATE CruToml CruTestBase) - -cru_catch_discover_tests(CruTomlTest) |
