3#include <StormByte/config/alias.hxx>
4#include <StormByte/config/item/value.hxx>
5#include <StormByte/config/item/comment.hxx>
6#include <StormByte/config/item/group.hxx>
7#include <StormByte/config/item/list.hxx>
8#include <StormByte/config/type.hxx>
9#include <StormByte/serializable.hxx>
15namespace StormByte::Config {
29 class STORMBYTE_CONFIG_PUBLIC
Config {
30 friend class StormByte::Serializable<
Config>;
72 return m_root.operator[](path);
81 return m_root.operator[](path);
101 return m_root[index];
110 return m_root == config.m_root;
119 return !operator==(config);
181 friend STORMBYTE_CONFIG_PUBLIC std::ostream&
operator<<(std::ostream& ostream,
const Config& file);
193 operator std::string()
const;
202 return m_root.Add(item.Clone(), m_on_existing_action);
212 return m_root.Add(std::move(item.Move()), m_on_existing_action);
227 inline bool Exists(
const std::string& path)
const {
228 return m_root.Exists(path);
236 inline void Remove(
const std::string& path) {
255 m_on_existing_action = on_existing;
263 m_on_parse_failure_hook = hook;
271 m_before_read_hooks.push_back(hook);
279 m_after_read_hooks.push_back(hook);
286 constexpr virtual size_t Size() const noexcept {
287 return m_root.Size();
294 inline virtual size_t Count() const noexcept {
295 return m_root.Count();
302 constexpr std::span<Item::Base::PointerType>
Items() noexcept {
303 return m_root.Items();
310 constexpr std::span<const Item::Base::PointerType>
Items() const noexcept {
311 return m_root.Items();
337 STORMBYTE_CONFIG_PUBLIC
Config& operator>>(std::istream& istream,
Config& file);
344 STORMBYTE_CONFIG_PUBLIC
Config& operator>>(
const std::string& str,
Config& file);
351 STORMBYTE_CONFIG_PUBLIC std::ostream& operator<<(std::ostream& ostream,
const Config& file);
358 STORMBYTE_CONFIG_PUBLIC std::string& operator<<(std::string& str,
const Config& file);
HookFunctions m_before_read_hooks
Hooks executed before reading.
Definition config.hxx:321
Item::Base & Add(const Item::Base &item)
Adds an item to the configuration.
Definition config.hxx:201
void Remove(const size_t &path)
Definition config.hxx:245
std::ostream & operator>>(std::ostream &ostream) const
void operator<<(std::istream &istream)
virtual constexpr size_t Size() const noexcept
Definition config.hxx:286
Item::Base & Add(Item::Base &&item)
Definition config.hxx:211
void operator<<(const std::string &str)
std::string & operator>>(std::string &str) const
Config & operator<<(const Config &source)
constexpr void OnParseFailure(OnFailureHook hook)
Definition config.hxx:262
Config & operator>>(Config &dest) const
bool operator==(const Config &config) const noexcept
Definition config.hxx:109
Item::Group m_root
Root group.
Definition config.hxx:315
OptionalFailureHook m_on_parse_failure_hook
Hook executed on failure.
Definition config.hxx:323
Item::Base & operator[](const size_t &index)
Definition config.hxx:90
Config(const Config &config)=default
const Item::Base & operator[](const size_t &index) const
Definition config.hxx:100
friend STORMBYTE_CONFIG_PUBLIC Config & operator>>(std::istream &istream, Config &file)
bool operator!=(const Config &config) const noexcept
Definition config.hxx:118
constexpr void AddHookAfterRead(HookFunction hook)
Definition config.hxx:278
friend STORMBYTE_CONFIG_PUBLIC std::string & operator<<(std::string &, const Config &)
friend STORMBYTE_CONFIG_PUBLIC Config & operator>>(const std::string &str, Config &file)
constexpr std::span< Item::Base::PointerType > Items() noexcept
Definition config.hxx:302
const Item::Base & operator[](const std::string &path) const
Definition config.hxx:80
void Clear() noexcept
Definition config.hxx:218
Config & operator=(Config &&config) noexcept=default
friend STORMBYTE_CONFIG_PUBLIC std::ostream & operator<<(std::ostream &ostream, const Config &file)
void Remove(const std::string &path)
Definition config.hxx:236
constexpr void AddHookBeforeRead(HookFunction hook)
Definition config.hxx:270
constexpr std::span< const Item::Base::PointerType > Items() const noexcept
Definition config.hxx:310
Item::Base & operator[](const std::string &path)
Definition config.hxx:71
StormByte::Config::OnExistingAction m_on_existing_action
Action to take when item name already exists.
Definition config.hxx:330
Config(Config &&config) noexcept=default
virtual ~Config()=default
Config & operator=(const Config &config)=default
virtual size_t Count() const noexcept
Definition config.hxx:294
HookFunctions m_after_read_hooks
Hooks executed after successful reading.
Definition config.hxx:322
constexpr void OnExistingAction(const OnExistingAction &on_existing)
Definition config.hxx:254
bool Exists(const std::string &path) const
Definition config.hxx:227
The base class for all configuration items.
Definition base.hxx:29
Represents a group in a configuration file that can hold other items, subgroups, and sublists recursi...
Definition group.hxx:20
Contains type aliases and utilities for configuration handling.