From 74bb9cd27242b9320f99ff4d2b50c3051576cc14 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 16:53:51 +0800 Subject: ... --- include/cru/toml/Base.h | 11 ++++++++ include/cru/toml/Base.hpp | 11 -------- include/cru/toml/TomlDocument.h | 57 +++++++++++++++++++++++++++++++++++++++ include/cru/toml/TomlDocument.hpp | 57 --------------------------------------- include/cru/toml/TomlParser.h | 36 +++++++++++++++++++++++++ include/cru/toml/TomlParser.hpp | 36 ------------------------- 6 files changed, 104 insertions(+), 104 deletions(-) create mode 100644 include/cru/toml/Base.h delete mode 100644 include/cru/toml/Base.hpp create mode 100644 include/cru/toml/TomlDocument.h delete mode 100644 include/cru/toml/TomlDocument.hpp create mode 100644 include/cru/toml/TomlParser.h delete mode 100644 include/cru/toml/TomlParser.hpp (limited to 'include/cru/toml') diff --git a/include/cru/toml/Base.h b/include/cru/toml/Base.h new file mode 100644 index 00000000..de1d558c --- /dev/null +++ b/include/cru/toml/Base.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef CRU_PLATFORM_WINDOWS +#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/include/cru/toml/Base.hpp b/include/cru/toml/Base.hpp deleted file mode 100644 index de1d558c..00000000 --- a/include/cru/toml/Base.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifdef CRU_PLATFORM_WINDOWS -#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/include/cru/toml/TomlDocument.h b/include/cru/toml/TomlDocument.h new file mode 100644 index 00000000..6da5ad74 --- /dev/null +++ b/include/cru/toml/TomlDocument.h @@ -0,0 +1,57 @@ +#pragma once + +#include "Base.h" + +#include "cru/common/Base.h" +#include "cru/common/String.h" + +#include +#include + +namespace cru::toml { +class CRU_TOML_API TomlSection { + public: + CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlSection) + CRU_DEFAULT_COPY(TomlSection) + CRU_DEFAULT_MOVE(TomlSection) + + public: + std::optional GetValue(const String& key) const; + void SetValue(const String& key, String value); + void DeleteValue(const String& key); + + auto begin() { return values_.begin(); } + auto end() { return values_.end(); } + auto begin() const { return values_.begin(); } + auto end() const { return values_.end(); } + auto cbegin() const { return values_.cbegin(); } + auto cend() const { return values_.cend(); } + + private: + std::unordered_map values_; +}; + +class CRU_TOML_API TomlDocument { + public: + CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlDocument) + CRU_DEFAULT_COPY(TomlDocument) + CRU_DEFAULT_MOVE(TomlDocument) + + public: + TomlSection* GetSection(const String& name); + TomlSection* GetSectionOrCreate(const String& name); + const TomlSection* GetSection(const String& name) const; + void SetSection(const String& name, TomlSection section); + void DeleteSection(const String& name); + + auto begin() { return sections_.begin(); } + auto end() { return sections_.end(); } + auto begin() const { return sections_.begin(); } + auto end() const { return sections_.end(); } + auto cbegin() const { return sections_.cbegin(); } + auto cend() const { return sections_.cend(); } + + private: + std::unordered_map sections_; +}; +} // namespace cru::toml diff --git a/include/cru/toml/TomlDocument.hpp b/include/cru/toml/TomlDocument.hpp deleted file mode 100644 index 1e5caf71..00000000 --- a/include/cru/toml/TomlDocument.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include "Base.hpp" - -#include "cru/common/Base.hpp" -#include "cru/common/String.hpp" - -#include -#include - -namespace cru::toml { -class CRU_TOML_API TomlSection { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlSection) - CRU_DEFAULT_COPY(TomlSection) - CRU_DEFAULT_MOVE(TomlSection) - - public: - std::optional GetValue(const String& key) const; - void SetValue(const String& key, String value); - void DeleteValue(const String& key); - - auto begin() { return values_.begin(); } - auto end() { return values_.end(); } - auto begin() const { return values_.begin(); } - auto end() const { return values_.end(); } - auto cbegin() const { return values_.cbegin(); } - auto cend() const { return values_.cend(); } - - private: - std::unordered_map values_; -}; - -class CRU_TOML_API TomlDocument { - public: - CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlDocument) - CRU_DEFAULT_COPY(TomlDocument) - CRU_DEFAULT_MOVE(TomlDocument) - - public: - TomlSection* GetSection(const String& name); - TomlSection* GetSectionOrCreate(const String& name); - const TomlSection* GetSection(const String& name) const; - void SetSection(const String& name, TomlSection section); - void DeleteSection(const String& name); - - auto begin() { return sections_.begin(); } - auto end() { return sections_.end(); } - auto begin() const { return sections_.begin(); } - auto end() const { return sections_.end(); } - auto cbegin() const { return sections_.cbegin(); } - auto cend() const { return sections_.cend(); } - - private: - std::unordered_map sections_; -}; -} // namespace cru::toml diff --git a/include/cru/toml/TomlParser.h b/include/cru/toml/TomlParser.h new file mode 100644 index 00000000..dcef2920 --- /dev/null +++ b/include/cru/toml/TomlParser.h @@ -0,0 +1,36 @@ +#pragma once + +#include "cru/common/Exception.h" +#include "cru/toml/TomlDocument.h" + +#include + +namespace cru::toml { +// A very simple and tolerant TOML parser. +class CRU_TOML_API TomlParsingException : public Exception { + public: + using Exception::Exception; +}; + +class CRU_TOML_API TomlParser { + public: + explicit TomlParser(String input); + + CRU_DELETE_COPY(TomlParser) + CRU_DELETE_MOVE(TomlParser) + + ~TomlParser(); + + public: + TomlDocument Parse(); + + private: + // The document is empty to begin with. + void DoParse(TomlDocument& document); + + private: + String input_; + + std::optional cache_; +}; +} // namespace cru::toml diff --git a/include/cru/toml/TomlParser.hpp b/include/cru/toml/TomlParser.hpp deleted file mode 100644 index c3091bad..00000000 --- a/include/cru/toml/TomlParser.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "cru/common/Exception.hpp" -#include "cru/toml/TomlDocument.hpp" - -#include - -namespace cru::toml { -// A very simple and tolerant TOML parser. -class CRU_TOML_API TomlParsingException : public Exception { - public: - using Exception::Exception; -}; - -class CRU_TOML_API TomlParser { - public: - explicit TomlParser(String input); - - CRU_DELETE_COPY(TomlParser) - CRU_DELETE_MOVE(TomlParser) - - ~TomlParser(); - - public: - TomlDocument Parse(); - - private: - // The document is empty to begin with. - void DoParse(TomlDocument& document); - - private: - String input_; - - std::optional cache_; -}; -} // namespace cru::toml -- cgit v1.2.3