55 friend class Binary::Reader;
56 friend class Binary::Writer;
109 return m_root.operator[](path);
118 return m_root.operator[](path);
128 return m_root[index];
138 return m_root[index];
147 return m_root == config.m_root;
156 return !operator==(config);
245 operator std::string()
const;
252 void Save(std::ostream& stream,
Mode mode = Mode::Text)
const;
274 return m_root.Add(item.Clone(), m_on_existing_action);
284 return m_root.Add(std::move(item.Move()), m_on_existing_action);
294 return m_root.Add(item, m_on_existing_action);
304 return m_root.Add(item, on_existing);
319 inline bool Exists(
const std::string& path)
const {
320 return m_root.Exists(path);
328 inline void Remove(
const std::string& path) {
337 inline void Remove(
const size_t& index) {
338 m_root.Remove(index);
345 constexpr virtual size_t Size() const noexcept {
346 return m_root.Size();
353 inline virtual size_t Count() const noexcept {
354 return m_root.Count();
361 constexpr std::span<Item::Base::PointerType>
Items() noexcept {
362 return m_root.Items();
369 constexpr std::span<const Item::Base::PointerType>
Items() const noexcept {
370 return m_root.Items();
384 m_on_existing_action = on_existing;
385 m_root.SetOnExistingAction(on_existing);
393 m_on_parse_failure_hook = hook;
402 m_before_read_hooks.push_back(hook);
411 m_after_read_hooks.push_back(hook);
Configuration document (text or versioned binary).
Definition config.hxx:54
HookFunctions m_before_read_hooks
Hooks executed before reading.
Definition config.hxx:418
friend std::ostream & operator<<(std::ostream &ostream, const Config &file)
Output configuration when ostream is on the left-hand side.
Item::Base & Add(const Item::Base &item)
Adds an item to the configuration.
Definition config.hxx:273
std::ostream & operator>>(std::ostream &ostream) const
Output configuration serialized to an output stream (text).
void operator<<(std::istream &istream)
Initialize configuration from an input stream (text mode).
virtual constexpr size_t Size() const noexcept
Gets the number of items in the current level.
Definition config.hxx:345
Item::Base & Add(Item::Base &&item)
Adds an item to the configuration (move).
Definition config.hxx:283
void OnExistingAction(const OnExistingAction &on_existing)
Sets the action to take when an item name/identity collision occurs.
Definition config.hxx:383
void operator<<(const std::string &str)
Initialize configuration from a string (text mode).
void Remove(const size_t &index)
Removes an item by index.
Definition config.hxx:337
std::string & operator>>(std::string &str) const
Output configuration serialized to a string (text).
void Save(std::ostream &stream, Mode mode=Mode::Text) const
Write this document to an output stream.
Config & operator<<(const Config &source)
Import data from another configuration.
constexpr void OnParseFailure(OnFailureHook hook)
Sets a function to execute on parse failure.
Definition config.hxx:392
static ExpectedConfig Load(std::istream &stream, Mode mode=Mode::Text)
Read a document from an input stream.
Config & operator>>(Config &dest) const
Output current configuration into another configuration.
bool operator==(const Config &config) const noexcept
Equality operator.
Definition config.hxx:146
Item::Group m_root
Root group.
Definition config.hxx:416
OptionalFailureHook m_on_parse_failure_hook
Hook executed on failure.
Definition config.hxx:420
Item::Base & operator[](const size_t &index)
Gets a reference to an item by index.
Definition config.hxx:127
Config(const Config &config)=default
Copy constructor.
const Item::Base & operator[](const size_t &index) const
Gets a const reference to an item by index.
Definition config.hxx:137
bool operator!=(const Config &config) const noexcept
Inequality operator.
Definition config.hxx:155
friend std::string & operator<<(std::string &, const Config &)
Output configuration when string is on the left-hand side.
constexpr void AddHookAfterRead(HookFunction hook)
Adds a hook executed after a successful read.
Definition config.hxx:410
friend Config & operator>>(const std::string &str, Config &file)
Initializes configuration when string is on the left-hand side.
constexpr std::span< Item::Base::PointerType > Items() noexcept
Gets the items in the current level.
Definition config.hxx:361
Item::Base & Add(Item::Base::PointerType item, const StormByte::Config::OnExistingAction &on_existing)
Adds an item pointer using an explicit policy.
Definition config.hxx:303
const Item::Base & operator[](const std::string &path) const
Gets a const reference to an item by path.
Definition config.hxx:117
void Clear() noexcept
Clears all configuration items.
Definition config.hxx:310
Config & operator=(Config &&config) noexcept=default
Move assignment operator.
void Remove(const std::string &path)
Removes an item by path.
Definition config.hxx:328
constexpr void AddHookBeforeRead(HookFunction hook)
Adds a hook executed before reading starts.
Definition config.hxx:401
Item::Base & Add(Item::Base::PointerType item)
Adds an item pointer to the configuration.
Definition config.hxx:293
constexpr std::span< const Item::Base::PointerType > Items() const noexcept
Gets the items in the current level (const).
Definition config.hxx:369
friend Config & operator>>(std::istream &istream, Config &file)
Initializes configuration when istream is on the left-hand side.
Item::Base & operator[](const std::string &path)
Gets a reference to an item by path.
Definition config.hxx:108
StormByte::Config::OnExistingAction m_on_existing_action
Collision policy.
Definition config.hxx:421
Config()
Default constructor.
Config(Config &&config) noexcept=default
Move constructor.
virtual ~Config()=default
Destructor.
Config & operator=(const Config &config)=default
Copy assignment operator.
virtual size_t Count() const noexcept
Gets the full number of items (including nested).
Definition config.hxx:353
HookFunctions m_after_read_hooks
Hooks executed after successful reading.
Definition config.hxx:419
bool Exists(const std::string &path) const
Checks if an item exists by path.
Definition config.hxx:319
The base class for all configuration items.
Definition base.hxx:45
Named container { … } that can hold items, subgroups and lists.
Definition group.hxx:38
Config module of the StormByte suite.
Definition alias.hxx:29
OnExistingAction
Forward declaration of the configuration document.
Definition typedefs.hxx:35
std::function< void(Item::Group &)> HookFunction
Function executed as a hook.
Definition alias.hxx:34
std::vector< HookFunction > HookFunctions
List of hook functions.
Definition alias.hxx:35
StormByte::Expected< Config, StormByte::Exception > ExpectedConfig
Result of loading a configuration document (text or binary).
Definition typedefs.hxx:62
std::ostream & operator<<(std::ostream &ostream, const Config &file)
Output configuration when ostream is on the left-hand side.
std::function< bool(const Item::Group &)> OnFailureHook
Function executed on failure.
Definition alias.hxx:36
std::optional< OnFailureHook > OptionalFailureHook
Optional failure hook.
Definition alias.hxx:37
Mode
Serialization / deserialization mode for configuration documents.
Definition typedefs.hxx:51
Config & operator>>(std::istream &istream, Config &file)
Initializes configuration when istream is on the left-hand side.
#define STORMBYTE_CONFIG_PUBLIC
Definition visibility.h:26