78 friend class Binary::Reader;
79 friend class Binary::Writer;
132 return m_root.operator[](path);
141 return m_root.operator[](path);
150 return m_root.operator[](path);
159 return m_root.operator[](path);
169 return m_root[index];
179 return m_root[index];
188 return m_root == config.m_root;
307 return static_cast<std::string
>(
Text());
315 void Save(std::ostream& stream,
Mode mode = Mode::Text)
const;
337 return m_root.Add(item.
Clone(), m_on_existing_action);
347 return m_root.Add(std::move(item.Move()), m_on_existing_action);
357 return m_root.Add(item, m_on_existing_action);
367 return m_root.Add(item, on_existing);
383 return m_root.Exists(path);
391 inline bool Exists(std::string_view path)
const {
392 return m_root.Exists(path);
408 inline void Remove(std::string_view path) {
418 m_root.Remove(index);
426 return m_root.
Size();
434 return m_root.Count();
441 constexpr std::span<const Item::Base::PointerType>
Items() noexcept {
442 return m_root.Items();
449 constexpr std::span<const Item::Base::PointerType>
Items() const noexcept {
450 return m_root.Items();
virtual PointerType Clone() const=0
Configuration document (text or versioned binary).
Definition config.hxx:77
const Item::Base & operator[](std::string_view path) const
Gets a const reference to an item by a path view.
Definition config.hxx:158
HookFunctions m_before_read_hooks
Hooks executed before reading.
Definition config.hxx:505
friend std::ostream & operator<<(std::ostream &ostream, const Config &file)
Output configuration when ostream is on the left-hand side.
void operator<<(const StormByte::String::String &str)
Initialize configuration from a string (text mode).
Item::Base & Add(const Item::Base &item)
Adds an item to the configuration.
Definition config.hxx:336
StormByte::Size Size() const noexcept
Gets the number of items in the current level.
Definition config.hxx:425
void AddHookAfterRead(HookFunction hook)
Adds a stateless hook executed after a successful read.
void OnExistingAction(const StormByte::Config::OnExistingAction &on_existing)
Sets the action to take when an item name/identity collision occurs.
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).
const Item::Base & operator[](const StormByte::Size &index) const
Gets a const reference to an item by index.
Definition config.hxx:178
Item::Base & operator[](std::string_view path)
Gets a reference to an item by a path view.
Definition config.hxx:149
void OnParseFailure(StormByte::Shared< FailureHook > hook)
Sets a stateful hook to execute on parse failure.
Config & operator=(Config &&config) noexcept
Move assignment operator.
Item::Base & Add(Item::Base &&item)
Adds an item to the configuration (move).
Definition config.hxx:346
void operator<<(const std::string &str)
Initialize configuration from a caller-owned std::string (text mode).
std::string & operator>>(std::string &str) const
Append serialized text to a caller-owned string.
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.
static ExpectedConfig Load(std::istream &stream, Mode mode=Mode::Text)
Read a document from an input stream.
Config(const Config &config)
Copy constructor.
Config & operator>>(Config &dest) const
Output current configuration into another configuration.
bool operator==(const Config &config) const noexcept
Equality operator.
Definition config.hxx:187
void Remove(const StormByte::Size &index)
Removes an item by index.
Definition config.hxx:417
Item::Group m_root
Root group.
Definition config.hxx:503
OptionalFailureHook m_on_parse_failure_hook
Hook executed on failure.
Definition config.hxx:507
bool Exists(std::string_view path) const
Checks if an item exists by a path view.
Definition config.hxx:391
bool Exists(const StormByte::String::String &path) const
Checks if an item exists by path.
Definition config.hxx:382
bool operator!=(const Config &config) const noexcept
Inequality operator.
Definition config.hxx:196
friend Config & operator>>(const std::string &str, Config &file)
Initializes configuration when string is on the left-hand side.
Item::Base & Add(Item::Base::PointerType item, const StormByte::Config::OnExistingAction &on_existing)
Adds an item pointer using an explicit policy.
Definition config.hxx:366
void AddHookBeforeRead(StormByte::Shared< ReadHook > hook)
Adds a stateful hook executed before reading starts.
void Clear() noexcept
Clears all configuration items.
Definition config.hxx:373
void Remove(std::string_view path)
Removes an item by a path view.
Definition config.hxx:408
StormByte::String::String Text() const
Serialized document as StormByte text.
virtual ~Config() noexcept
Destructor.
Item::Base & operator[](const StormByte::Size &index)
Gets a reference to an item by index.
Definition config.hxx:168
const Item::Base & operator[](const StormByte::String::String &path) const
Gets a const reference to an item by path.
Definition config.hxx:140
Item::Base & Add(Item::Base::PointerType item)
Adds an item pointer to the configuration.
Definition config.hxx:356
constexpr std::span< const Item::Base::PointerType > Items() const noexcept
Items in the current level.
Definition config.hxx:449
friend Config & operator>>(std::istream &istream, Config &file)
Initializes configuration when istream is on the left-hand side.
constexpr std::span< const Item::Base::PointerType > Items() noexcept
Items in the current level.
Definition config.hxx:441
StormByte::Config::OnExistingAction m_on_existing_action
Collision policy.
Definition config.hxx:508
void OnParseFailure(OnFailureHook hook)
Sets a stateless function to execute on parse failure.
Config & operator=(const Config &config)
Copy assignment operator.
void Remove(const StormByte::String::String &path)
Removes an item by path.
Definition config.hxx:400
Config()
Default constructor.
friend Config & operator>>(const StormByte::String::String &str, Config &file)
Initializes configuration when String is on the left-hand side.
Config(Config &&config) noexcept
Move constructor.
friend std::string & operator<<(std::string &str, const Config &file)
Output configuration when string is on the left-hand side.
void AddHookAfterRead(StormByte::Shared< ReadHook > hook)
Adds a stateful hook executed after a successful read.
StormByte::Size Count() const noexcept
Gets the full number of items (including nested).
Definition config.hxx:433
HookFunctions m_after_read_hooks
Hooks executed after successful reading.
Definition config.hxx:506
void AddHookBeforeRead(HookFunction hook)
Adds a stateless hook executed before reading starts.
Base class for all configuration items.
Definition base.hxx:66
Named container ({ ... }).
Definition group.hxx:57
constexpr Size() noexcept
All the classes for item configuration.
Config module of the StormByte suite.
Definition alias.hxx:50
ReadHookFunction HookFunction
Stateless read hook.
Definition alias.hxx:51
std::vector< StormByte::Shared< ReadHook > > HookFunctions
Read hooks owned by Config.
Definition alias.hxx:52
OnExistingAction
Forward declaration of the configuration document.
Definition typedefs.hxx:56
FailureHookFunction OnFailureHook
Stateless failure hook.
Definition alias.hxx:53
StormByte::Expected< Config, StormByte::Exception > ExpectedConfig
Result of loading a configuration document (text or binary).
Definition typedefs.hxx:83
std::ostream & operator<<(std::ostream &ostream, const Config &file)
Output configuration when ostream is on the left-hand side.
Mode
Serialization / deserialization mode for configuration documents.
Definition typedefs.hxx:72
@ Text
Human-readable configuration syntax (UTF-8 text).
Config & operator>>(std::istream &istream, Config &file)
Initializes configuration when istream is on the left-hand side.
bool operator==(std::span< const std::byte > bytes, const BinaryData &data) noexcept
#define STORMBYTE_CONFIG_PUBLIC
Definition visibility.h:53