StormByte C++ Library: Config module 1.0.1.9999
StormByte-Config is the configuration module of the StormByte C++ suite.
Loading...
Searching...
No Matches
Protected Attributes | Friends | List of all members
StormByte::Config::Config Class Reference

Configuration document (text or versioned binary). More...

#include <config.hxx>

Collaboration diagram for StormByte::Config::Config:
Collaboration graph
[legend]

Public Member Functions

Construction
 Config ()
 Default constructor.
 
 Config (const Config &config)=default
 Copy constructor.
 
 Config (Config &&config) noexcept=default
 Move constructor.
 
Configoperator= (const Config &config)=default
 Copy assignment operator.
 
Configoperator= (Config &&config) noexcept=default
 Move assignment operator.
 
virtual ~Config ()=default
 Destructor.
 
Access
Item::Baseoperator[] (const std::string &path)
 Gets a reference to an item by path.
 
const Item::Baseoperator[] (const std::string &path) const
 Gets a const reference to an item by path.
 
Item::Baseoperator[] (const size_t &index)
 Gets a reference to an item by index.
 
const Item::Baseoperator[] (const size_t &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::BaseAdd (const Item::Base &item)
 Adds an item to the configuration.
 
Item::BaseAdd (Item::Base &&item)
 Adds an item to the configuration (move).
 
void Clear () noexcept
 Clears all configuration items.
 
bool Exists (const std::string &path) const
 Checks if an item exists by path.
 
void Remove (const std::string &path)
 Removes an item by path.
 
void Remove (const size_t &index)
 Removes an item by index.
 
virtual constexpr size_t Size () const noexcept
 Gets the number of items in the current level.
 
virtual size_t Count () const noexcept
 Gets the full number of items (including nested).
 
constexpr std::span< Item::Base::PointerType > Items () noexcept
 Gets the items in the current level.
 
constexpr std::span< const Item::Base::PointerType > Items () const noexcept
 Gets the items in the current level (const).
 
Policy
void OnExistingAction (const 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.
 
constexpr void OnParseFailure (OnFailureHook hook)
 Sets a function to execute on parse failure.
 
constexpr void AddHookBeforeRead (HookFunction hook)
 Adds a hook executed before reading starts. Hooks run in order.
 
constexpr void AddHookAfterRead (HookFunction hook)
 Adds a hook executed after a successful read. Hooks run in order.
 

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

STORMBYTE_CONFIG_PUBLIC Configoperator>> (std::istream &istream, Config &file)
 Initializes configuration when istream is on the left-hand side.
 
STORMBYTE_CONFIG_PUBLIC Configoperator>> (const std::string &str, Config &file)
 Initializes configuration when string is on the left-hand side.
 
Configoperator<< (const Config &source)
 Import data from another configuration.
 
void operator<< (std::istream &istream)
 Initialize configuration from an input stream (text mode).
 
void operator<< (const std::string &str)
 Initialize configuration from a string (text mode).
 

Output

STORMBYTE_CONFIG_PUBLIC std::ostream & operator<< (std::ostream &ostream, const Config &file)
 Output configuration when ostream is on the left-hand side.
 
STORMBYTE_CONFIG_PUBLIC std::string & operator<< (std::string &, const Config &)
 Output configuration when string is on the left-hand side.
 
Configoperator>> (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
 Output configuration serialized to a string (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.
 

Detailed Description

Configuration document (text or versioned binary).

A document holds:

Constructor & Destructor Documentation

◆ Config() [1/2]

StormByte::Config::Config::Config ( const Config config)
default

Copy constructor.

Parameters
configConfiguration to copy.

◆ Config() [2/2]

StormByte::Config::Config::Config ( Config &&  config)
defaultnoexcept

Move constructor.

Parameters
configConfiguration to move.

Member Function Documentation

◆ Add() [1/2]

Item::Base & StormByte::Config::Config::Add ( const Item::Base item)
inline

Adds an item to the configuration.

Parameters
itemThe item to add.
Exceptions
ItemNameAlreadyExistsif the item's name already exists.
Returns
A reference to the added item.

◆ Add() [2/2]

Item::Base & StormByte::Config::Config::Add ( Item::Base &&  item)
inline

Adds an item to the configuration (move).

Parameters
itemItem to add.
Exceptions
ItemNameAlreadyExistsif item name already exists.
Returns
Reference to the added item.

◆ AddHookAfterRead()

constexpr void StormByte::Config::Config::AddHookAfterRead ( HookFunction  hook)
inlineconstexpr

Adds a hook executed after a successful read. Hooks run in order.

Parameters
hookHook function.

◆ AddHookBeforeRead()

constexpr void StormByte::Config::Config::AddHookBeforeRead ( HookFunction  hook)
inlineconstexpr

Adds a hook executed before reading starts. Hooks run in order.

Parameters
hookHook function.

◆ Count()

virtual size_t StormByte::Config::Config::Count ( ) const
inlinevirtualnoexcept

Gets the full number of items (including nested).

Returns
Total number of items.

◆ Exists()

bool StormByte::Config::Config::Exists ( const std::string &  path) const
inline

Checks if an item exists by path.

Parameters
pathPath to the item.
Returns
true if the item exists.

◆ Items() [1/2]

constexpr std::span< const Item::Base::PointerType > StormByte::Config::Config::Items ( ) const
inlineconstexprnoexcept

Gets the items in the current level (const).

Returns
Const span of items.

◆ Items() [2/2]

constexpr std::span< Item::Base::PointerType > StormByte::Config::Config::Items ( )
inlineconstexprnoexcept

Gets the items in the current level.

Returns
Span of items.

◆ Load()

static ExpectedConfig StormByte::Config::Config::Load ( std::istream &  stream,
Mode  mode = Mode::Text 
)
static

Read a document from an input stream.

Parameters
streamSource (file, stringstream, etc.).
modeText (default): config syntax; Binary: versioned wire format.
Returns
Config on success, or a StormByte::Exception derivative on failure.

◆ OnExistingAction()

void StormByte::Config::Config::OnExistingAction ( const OnExistingAction on_existing)
inline

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.

Parameters
on_existingThe policy to use.

◆ OnParseFailure()

constexpr void StormByte::Config::Config::OnParseFailure ( OnFailureHook  hook)
inlineconstexpr

Sets a function to execute on parse failure.

Parameters
hookFunction to execute.

◆ operator std::string()

StormByte::Config::Config::operator std::string ( ) const

Converts the current configuration to a string (text form).

Returns
Serialized configuration text.

◆ operator!=()

bool StormByte::Config::Config::operator!= ( const Config config) const
inlinenoexcept

Inequality operator.

Parameters
configConfiguration to compare.
Returns
true if not equal.

◆ operator<<() [1/3]

Config & StormByte::Config::Config::operator<< ( const Config source)

Import data from another configuration.

Parameters
sourceSource configuration to import.
Returns
Reference to this configuration.

◆ operator<<() [2/3]

void StormByte::Config::Config::operator<< ( const std::string &  str)

Initialize configuration from a string (text mode).

Parameters
strInput string.

◆ operator<<() [3/3]

void StormByte::Config::Config::operator<< ( std::istream &  istream)

Initialize configuration from an input stream (text mode).

Parameters
istreamInput stream.

◆ operator=() [1/2]

Config & StormByte::Config::Config::operator= ( Config &&  config)
defaultnoexcept

Move assignment operator.

Parameters
configConfiguration to move.
Returns
Reference to this Config.

◆ operator=() [2/2]

Config & StormByte::Config::Config::operator= ( const Config config)
default

Copy assignment operator.

Parameters
configConfiguration to assign.
Returns
Reference to this Config.

◆ operator==()

bool StormByte::Config::Config::operator== ( const Config config) const
inlinenoexcept

Equality operator.

Parameters
configConfiguration to compare.
Returns
true if equal.

◆ operator>>() [1/3]

Config & StormByte::Config::Config::operator>> ( Config dest) const

Output current configuration into another configuration.

Parameters
destDestination configuration.
Returns
Reference to the destination configuration.

◆ operator>>() [2/3]

std::ostream & StormByte::Config::Config::operator>> ( std::ostream &  ostream) const

Output configuration serialized to an output stream (text).

Parameters
ostreamOutput stream.
Returns
Reference to the output stream.

◆ operator>>() [3/3]

std::string & StormByte::Config::Config::operator>> ( std::string &  str) const

Output configuration serialized to a string (text).

Parameters
strOutput string.
Returns
Reference to the string.

◆ operator[]() [1/4]

Item::Base & StormByte::Config::Config::operator[] ( const size_t &  index)
inline

Gets a reference to an item by index.

Parameters
indexIndex of the item.
Exceptions
OutOfBoundsif index is out of bounds.
Returns
Item reference.

◆ operator[]() [2/4]

const Item::Base & StormByte::Config::Config::operator[] ( const size_t &  index) const
inline

Gets a const reference to an item by index.

Parameters
indexIndex of the item.
Exceptions
OutOfBoundsif index is out of bounds.
Returns
Item const reference.

◆ operator[]() [3/4]

Item::Base & StormByte::Config::Config::operator[] ( const std::string &  path)
inline

Gets a reference to an item by path.

Parameters
pathPath to the item.
Returns
Item reference.

◆ operator[]() [4/4]

const Item::Base & StormByte::Config::Config::operator[] ( const std::string &  path) const
inline

Gets a const reference to an item by path.

Parameters
pathPath to the item.
Returns
Item const reference.

◆ Remove() [1/2]

void StormByte::Config::Config::Remove ( const size_t &  index)
inline

Removes an item by index.

Parameters
indexIndex of the item.
Exceptions
OutOfBoundsif index is out of bounds.

◆ Remove() [2/2]

void StormByte::Config::Config::Remove ( const std::string &  path)
inline

Removes an item by path.

Parameters
pathItem path.
Exceptions
ItemNotFoundif item is not found.

◆ Save()

void StormByte::Config::Config::Save ( std::ostream &  stream,
Mode  mode = Mode::Text 
) const

Write this document to an output stream.

Parameters
streamDestination (file, stringstream, etc.).
modeText (default): config syntax; Binary: versioned wire format.

◆ Size()

virtual constexpr size_t StormByte::Config::Config::Size ( ) const
inlineconstexprvirtualnoexcept

Gets the number of items in the current level.

Returns
Number of items.

Friends And Related Symbol Documentation

◆ operator<< [1/2]

STORMBYTE_CONFIG_PUBLIC std::ostream & operator<< ( std::ostream &  ostream,
const Config file 
)
friend

Output configuration when ostream is on the left-hand side.

Parameters
ostreamOutput stream.
fileConfig to get data from.
Returns
Reference to the output stream.

◆ operator<< [2/2]

STORMBYTE_CONFIG_PUBLIC std::string & operator<< ( std::string &  ,
const Config  
)
friend

Output configuration when string is on the left-hand side.

Parameters
strOutput string.
fileConfig to get data from.
Returns
Reference to the string.

◆ operator>> [1/2]

STORMBYTE_CONFIG_PUBLIC Config & operator>> ( const std::string &  str,
Config file 
)
friend

Initializes configuration when string is on the left-hand side.

Parameters
strInput string.
fileConfig to put data into.
Returns
Reference to the Config.

◆ operator>> [2/2]

STORMBYTE_CONFIG_PUBLIC Config & operator>> ( std::istream &  istream,
Config file 
)
friend

Initializes configuration when istream is on the left-hand side.

Parameters
istreamInput stream.
fileConfig to put data into.
Returns
Reference to the Config.

The documentation for this class was generated from the following file: