diff options
author | pommicket <pommicket@gmail.com> | 2025-09-16 17:08:19 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-16 17:08:19 -0400 |
commit | 62bb1ffdee060819657161e260e75e3e1df017ac (patch) | |
tree | d47eba6dda1528850c869e067944cdfa009198f9 /cpp/pom.hpp | |
parent | 7ededc16f36099acbfac457f8e4e268879b0ce62 (diff) |
C++ library fixes
Diffstat (limited to 'cpp/pom.hpp')
-rw-r--r-- | cpp/pom.hpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/cpp/pom.hpp b/cpp/pom.hpp index f9d7475..69a979d 100644 --- a/cpp/pom.hpp +++ b/cpp/pom.hpp @@ -53,11 +53,13 @@ public: } void set_error_language(std::string_view lang); private: + void check_version() const; void to_C(void *C) const; friend class Configuration; char m_error_lang[16] = {}; std::shared_ptr<Allocator> m_allocator; - uint32_t version = 1; // future-proofing + // to allow for future extensions without breaking backwards compatibility + const uint32_t version = 1; }; class Reader { @@ -78,6 +80,20 @@ public: virtual uint64_t line() const noexcept = 0; }; +class Location { +public: + inline std::string_view file() const { return m_file; } + inline uint64_t line() const { return m_line; } +private: + inline Location(std::string file, uint64_t line): + m_file(file), m_line(line) {} + friend class Configuration; + std::string m_file; + uint64_t m_line; + void *_reserved[4] = {}; +}; +std::ostream &operator<<(std::ostream &, const Location &); + class Configuration { public: Configuration(); @@ -88,6 +104,7 @@ public: Configuration(std::string_view path, const Settings *settings = nullptr); Configuration(std::string_view filename, std::string_view string, const Settings *settings = nullptr); ~Configuration(); + std::optional<Location> location(std::string_view key) const; std::optional<std::string> get(std::string_view key) const; std::string get_or_default(std::string_view key, std::string_view dflt) const; std::optional<int64_t> get_int(std::string_view key) const; @@ -98,12 +115,15 @@ public: double get_float_or_default(std::string_view key, double dflt) const; std::optional<bool> get_bool(std::string_view key) const; bool get_bool_or_default(std::string_view key, bool dflt) const; + std::optional<std::vector<std::string>> get_list(std::string_view key) const; + std::vector<std::string> get_list_or_default(std::string_view key, const std::vector<std::string> &dflt) const; Configuration section(std::string_view name) const; std::vector<std::string> unread_keys() const; std::vector<std::string> keys() const; std::vector<std::shared_ptr<Item>> items() const; void merge(const Configuration &other); private: + void load(std::string_view filename, Reader &source, const Settings *settings); explicit Configuration(void *c): C(c) {} void *C; }; |