Configuration document (text or versioned binary). More...
#include <StormByte/config/config.hxx>

Public Member Functions | |
Construction | |
| Config () | |
| Default constructor. | |
| Config (const Config &config) | |
| Copy constructor. | |
| Config (Config &&config) noexcept | |
| Move constructor. | |
| Config & | operator= (const Config &config) |
| Copy assignment operator. | |
| Config & | operator= (Config &&config) noexcept |
| Move assignment operator. | |
| virtual | ~Config () noexcept |
| Destructor. | |
Access | |
| Item::Base & | operator[] (const StormByte::String::String &path) |
| Gets a reference to an item by path. | |
| const Item::Base & | operator[] (const StormByte::String::String &path) const |
| Gets a const reference to an item by path. | |
| Item::Base & | operator[] (std::string_view path) |
| Gets a reference to an item by a path view. | |
| const Item::Base & | operator[] (std::string_view path) const |
| Gets a const reference to an item by a path view. | |
| Item::Base & | operator[] (const StormByte::Size &index) |
| Gets a reference to an item by index. | |
| const Item::Base & | operator[] (const StormByte::Size &index) const |
| Gets a const reference to an item by index. | |
| bool | operator== (const Config &config) const noexcept |
| Equality operator. | |
| bool | operator!= (const Config &config) const noexcept |
| Inequality operator. | |
Items | |
| Item::Base & | Add (const Item::Base &item) |
| Adds an item to the configuration. | |
| Item::Base & | Add (Item::Base &&item) |
| Adds an item to the configuration (move). | |
| Item::Base & | Add (Item::Base::PointerType item) |
| Adds an item pointer to the configuration. | |
| Item::Base & | Add (Item::Base::PointerType item, const StormByte::Config::OnExistingAction &on_existing) |
| Adds an item pointer using an explicit policy. | |
| void | Clear () noexcept |
| Clears all configuration items. | |
| bool | Exists (const StormByte::String::String &path) const |
| Checks if an item exists by path. | |
| bool | Exists (std::string_view path) const |
| Checks if an item exists by a path view. | |
| void | Remove (const StormByte::String::String &path) |
| Removes an item by path. | |
| void | Remove (std::string_view path) |
| Removes an item by a path view. | |
| void | Remove (const StormByte::Size &index) |
| Removes an item by index. | |
| StormByte::Size | Size () const noexcept |
| Gets the number of items in the current level. | |
| StormByte::Size | Count () const noexcept |
| Gets the full number of items (including nested). | |
| constexpr std::span< const Item::Base::PointerType > | Items () noexcept |
| Items in the current level. | |
| constexpr std::span< const Item::Base::PointerType > | Items () const noexcept |
| Items in the current level. | |
Policy | |
| void | OnExistingAction (const StormByte::Config::OnExistingAction &on_existing) |
| Sets the action to take when an item name/identity collision occurs. | |
| void | OnParseFailure (OnFailureHook hook) |
| Sets a stateless function to execute on parse failure. | |
| void | OnParseFailure (StormByte::Shared< FailureHook > hook) |
| Sets a stateful hook to execute on parse failure. | |
| void | AddHookBeforeRead (HookFunction hook) |
| Adds a stateless hook executed before reading starts. | |
| void | AddHookBeforeRead (StormByte::Shared< ReadHook > hook) |
| Adds a stateful hook executed before reading starts. | |
| void | AddHookAfterRead (HookFunction hook) |
| Adds a stateless hook executed after a successful read. | |
| void | AddHookAfterRead (StormByte::Shared< ReadHook > hook) |
| Adds a stateful hook executed after a successful read. | |
Protected Attributes | |
| Item::Group | m_root |
| Root group. | |
| HookFunctions | m_before_read_hooks |
| Hooks executed before reading. | |
| HookFunctions | m_after_read_hooks |
| Hooks executed after successful reading. | |
| OptionalFailureHook | m_on_parse_failure_hook |
| Hook executed on failure. | |
| StormByte::Config::OnExistingAction | m_on_existing_action |
| Collision policy. | |
Friends | |
| class | Binary::Reader |
| class | Binary::Writer |
Input | |
| Config & | operator>> (std::istream &istream, Config &file) |
| Initializes configuration when istream is on the left-hand side. | |
| Config & | operator>> (const StormByte::String::String &str, Config &file) |
| Initializes configuration when String is on the left-hand side. | |
| Config & | operator>> (const std::string &str, Config &file) |
| Initializes configuration when string is on the left-hand side. | |
| Config & | operator<< (const Config &source) |
| Import data from another configuration. | |
| void | operator<< (std::istream &istream) |
| Initialize configuration from an input stream (text mode). | |
| void | operator<< (const StormByte::String::String &str) |
| Initialize configuration from a string (text mode). | |
| void | operator<< (const std::string &str) |
Initialize configuration from a caller-owned std::string (text mode). | |
Output | |
| std::ostream & | operator<< (std::ostream &ostream, const Config &file) |
| Output configuration when ostream is on the left-hand side. | |
| std::string & | operator<< (std::string &str, const Config &file) |
| Output configuration when string is on the left-hand side. | |
| Config & | operator>> (Config &dest) const |
| Output current configuration into another configuration. | |
| std::ostream & | operator>> (std::ostream &ostream) const |
| Output configuration serialized to an output stream (text). | |
| std::string & | operator>> (std::string &str) const |
| Append serialized text to a caller-owned string. | |
| StormByte::String::String | Text () const |
| Serialized document as StormByte text. | |
| operator std::string () const | |
| Converts the current configuration to a string (text form). | |
| void | Save (std::ostream &stream, Mode mode=Mode::Text) const |
| Write this document to an output stream. | |
| static ExpectedConfig | Load (std::istream &stream, Mode mode=Mode::Text) |
| Read a document from an input stream. | |
Configuration document (text or versioned binary).
A document holds:
| StormByte::Config::Config::Config | ( | ) |
Default constructor.
| StormByte::Config::Config::Config | ( | const Config & | config | ) |
Copy constructor.
| config | Configuration to copy. |
|
noexcept |
Move constructor.
| config | Configuration to move. |
|
virtualnoexcept |
Destructor.
Defined in this module so catch matches across a DLL.
|
inline |
Adds an item to the configuration.
| item | The item to add. |
| ItemNameAlreadyExists | if the item's name already exists. |
|
inline |
Adds an item to the configuration (move).
| item | Item to add. |
| ItemNameAlreadyExists | if item name already exists. |
|
inline |
Adds an item pointer to the configuration.
| item | Item pointer to add. |
| ItemNameAlreadyExists | if item name already exists. |
|
inline |
Adds an item pointer using an explicit policy.
| item | Item pointer to add. |
| on_existing | Action to take if the item already exists. |
| void StormByte::Config::Config::AddHookAfterRead | ( | HookFunction | hook | ) |
Adds a stateless hook executed after a successful read.
| hook | Function pointer. |
| void StormByte::Config::Config::AddHookAfterRead | ( | StormByte::Shared< ReadHook > | hook | ) |
Adds a stateful hook executed after a successful read.
| hook | Hook allocated with MakePointer / MakeReadHook. |
| void StormByte::Config::Config::AddHookBeforeRead | ( | HookFunction | hook | ) |
Adds a stateless hook executed before reading starts.
| hook | Function pointer. |
| void StormByte::Config::Config::AddHookBeforeRead | ( | StormByte::Shared< ReadHook > | hook | ) |
Adds a stateful hook executed before reading starts.
| hook | Hook allocated with MakePointer / MakeReadHook. |
|
inlinenoexcept |
Clears all configuration items.
|
inlinenoexcept |
Gets the full number of items (including nested).
|
inline |
Checks if an item exists by path.
| path | Path to the item. |
|
inline |
Checks if an item exists by a path view.
| path | Path to the item. |
|
inlineconstexprnoexcept |
Items in the current level.
|
inlineconstexprnoexcept |
Items in the current level.
The span cannot reseat or grow the store; each pointer's item is mutable.
|
static |
Read a document from an input stream.
| stream | Source (file, stringstream, etc.). |
| mode | Text (default): config syntax; Binary: versioned wire format. |
| void StormByte::Config::Config::OnExistingAction | ( | const StormByte::Config::OnExistingAction & | on_existing | ) |
Sets the action to take when an item name/identity collision occurs.
The policy is applied to the root container and will be inherited by all nested containers.
| on_existing | The policy to use. |
| void StormByte::Config::Config::OnParseFailure | ( | OnFailureHook | hook | ) |
Sets a stateless function to execute on parse failure.
| hook | Function to execute. Return false to swallow the error. |
| void StormByte::Config::Config::OnParseFailure | ( | StormByte::Shared< FailureHook > | hook | ) |
Sets a stateful hook to execute on parse failure.
| hook | Hook allocated with MakePointer / MakeFailureHook. |
|
inlineexplicit |
Converts the current configuration to a string (text form).
|
inlinenoexcept |
Inequality operator.
| config | Configuration to compare. |
Import data from another configuration.
| source | Source configuration to import. |
| void StormByte::Config::Config::operator<< | ( | const std::string & | str | ) |
Initialize configuration from a caller-owned std::string (text mode).
| str | Input text. |
| void StormByte::Config::Config::operator<< | ( | const StormByte::String::String & | str | ) |
Initialize configuration from a string (text mode).
| str | Input text. Copied into the parser; not stored as std::string. |
| void StormByte::Config::Config::operator<< | ( | std::istream & | istream | ) |
Initialize configuration from an input stream (text mode).
| istream | Input stream. |
Copy assignment operator.
| config | Configuration to assign. |
|
inlinenoexcept |
Equality operator.
| config | Configuration to compare. |
Output current configuration into another configuration.
| dest | Destination configuration. |
| std::ostream & StormByte::Config::Config::operator>> | ( | std::ostream & | ostream | ) | const |
Output configuration serialized to an output stream (text).
| ostream | Output stream. |
| std::string & StormByte::Config::Config::operator>> | ( | std::string & | str | ) | const |
Append serialized text to a caller-owned string.
| str | Output string. |
|
inline |
Gets a reference to an item by index.
| index | Index of the item. |
| OutOfBounds | if index is out of bounds. |
|
inline |
Gets a const reference to an item by index.
| index | Index of the item. |
| OutOfBounds | if index is out of bounds. |
|
inline |
|
inline |
Gets a const reference to an item by path.
| path | Path to the item. |
|
inline |
|
inline |
Gets a const reference to an item by a path view.
| path | Path to the item. |
|
inline |
Removes an item by index.
| index | Index of the item. |
| OutOfBounds | if index is out of bounds. |
|
inline |
|
inline |
Removes an item by a path view.
| path | Item path. |
| void StormByte::Config::Config::Save | ( | std::ostream & | stream, |
| Mode | mode = Mode::Text |
||
| ) | const |
Write this document to an output stream.
| stream | Destination (file, stringstream, etc.). |
| mode | Text (default): config syntax; Binary: versioned wire format. |
|
inlinenoexcept |
Gets the number of items in the current level.
| StormByte::String::String StormByte::Config::Config::Text | ( | ) | const |
Serialized document as StormByte text.
|
friend |
|
friend |
|
friend |
Output configuration when ostream is on the left-hand side.
| ostream | Output stream. |
| file | Config to get data from. |
|
friend |
Output configuration when string is on the left-hand side.
| str | Output string. |
| file | Config to get data from. |
|
friend |
|
protected |
Hooks executed after successful reading.
|
protected |
Hooks executed before reading.
|
protected |
Collision policy.
|
protected |
Hook executed on failure.
|
protected |
Root group.