77 friend class Binary::Reader;
78 friend class Binary::Writer;
131 return m_root.operator[](path);
140 return m_root.operator[](path);
149 return m_root.operator[](path);
158 return m_root.operator[](path);
168 return m_root[index];
178 return m_root[index];
187 return m_root == config.m_root;
306 return static_cast<std::string
>(
Text());
314 void Save(std::ostream& stream,
Mode mode = Mode::Text)
const;
336 return m_root.Add(item.
Clone(), m_on_existing_action);
346 return m_root.Add(std::move(item.Move()), m_on_existing_action);
356 return m_root.Add(item, m_on_existing_action);
366 return m_root.Add(item, on_existing);
382 return m_root.Exists(path);
390 inline bool Exists(std::string_view path)
const {
391 return m_root.Exists(path);
407 inline void Remove(std::string_view path) {
417 m_root.Remove(index);
425 return m_root.
Size();
433 return m_root.Count();
440 constexpr std::span<const Item::Base::PointerType>
Items() noexcept {
441 return m_root.Items();
448 constexpr std::span<const Item::Base::PointerType>
Items() const noexcept {
449 return m_root.Items();
Configuration document (text or versioned binary).
Definition config.hxx:76
const Item::Base & operator[](std::string_view path) const
Gets a const reference to an item by a path view.
Definition config.hxx:157
HookFunctions m_before_read_hooks
Hooks executed before reading.
Definition config.hxx:504
friend Config & operator>>(const StormByte::Safe::String &str, Config &file)
Initializes configuration when String is on the left-hand side.
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:335
StormByte::Size Size() const noexcept
Gets the number of items in the current level.
Definition config.hxx:424
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:177
Item::Base & operator[](std::string_view path)
Gets a reference to an item by a path view.
Definition config.hxx:148
Config & operator=(Config &&config) noexcept
Move assignment operator.
bool Exists(const StormByte::Safe::String &path) const
Checks if an item exists by path.
Definition config.hxx:381
Item::Base & Add(Item::Base &&item)
Adds an item to the configuration (move).
Definition config.hxx:345
const Item::Base & operator[](const StormByte::Safe::String &path) const
Gets a const reference to an item by path.
Definition config.hxx:139
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.
void OnParseFailure(StormByte::Safe::Shared< FailureHook > hook)
Sets a stateful hook to execute on parse failure.
Config(const Config &config)
Copy constructor.
void Remove(const StormByte::Safe::String &path)
Removes an item by path.
Definition config.hxx:399
Config & operator>>(Config &dest) const
Output current configuration into another configuration.
bool operator==(const Config &config) const noexcept
Equality operator.
Definition config.hxx:186
void Remove(const StormByte::Size &index)
Removes an item by index.
Definition config.hxx:416
Item::Group m_root
Root group.
Definition config.hxx:502
OptionalFailureHook m_on_parse_failure_hook
Hook executed on failure.
Definition config.hxx:506
bool Exists(std::string_view path) const
Checks if an item exists by a path view.
Definition config.hxx:390
bool operator!=(const Config &config) const noexcept
Inequality operator.
Definition config.hxx:195
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:365
void Clear() noexcept
Clears all configuration items.
Definition config.hxx:372
void Remove(std::string_view path)
Removes an item by a path view.
Definition config.hxx:407
virtual ~Config() noexcept
Destructor.
void AddHookAfterRead(StormByte::Safe::Shared< ReadHook > hook)
Adds a stateful hook executed after a successful read.
Item::Base & operator[](const StormByte::Size &index)
Gets a reference to an item by index.
Definition config.hxx:167
Item::Base & Add(Item::Base::PointerType item)
Adds an item pointer to the configuration.
Definition config.hxx:355
constexpr std::span< const Item::Base::PointerType > Items() const noexcept
Items in the current level.
Definition config.hxx:448
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:440
StormByte::Config::OnExistingAction m_on_existing_action
Collision policy.
Definition config.hxx:507
void operator<<(const StormByte::Safe::String &str)
Initialize configuration from a string (text mode).
void OnParseFailure(OnFailureHook hook)
Sets a stateless function to execute on parse failure.
Config & operator=(const Config &config)
Copy assignment operator.
Config()
Default constructor.
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.
StormByte::Safe::String Text() const
Serialized document as StormByte text.
StormByte::Size Count() const noexcept
Gets the full number of items (including nested).
Definition config.hxx:432
void AddHookBeforeRead(StormByte::Safe::Shared< ReadHook > hook)
Adds a stateful hook executed before reading starts.
HookFunctions m_after_read_hooks
Hooks executed after successful reading.
Definition config.hxx:505
void AddHookBeforeRead(HookFunction hook)
Adds a stateless hook executed before reading starts.
Base class for all configuration items.
Definition base.hxx:65
Named container ({ ... }).
Definition group.hxx:56
virtual PointerType Clone() const=0
constexpr Size() noexcept
All the classes for item configuration.
Config module of the StormByte suite.
Definition alias.hxx:49
ReadHookFunction HookFunction
Stateless read hook.
Definition alias.hxx:50
std::vector< StormByte::Safe::Shared< ReadHook > > HookFunctions
Read hooks owned by Config.
Definition alias.hxx:51
OnExistingAction
Forward declaration of the configuration document.
Definition typedefs.hxx:55
FailureHookFunction OnFailureHook
Stateless failure hook.
Definition alias.hxx:52
StormByte::Expected< Config, StormByte::Exception > ExpectedConfig
Result of loading a configuration document (text or binary).
Definition typedefs.hxx:82
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:71
@ 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:52