StormByte C++ Library: Config module 0.0.9999
StormByte-Config is a StormByte library module for parsing configuration files
All Classes Namespaces Functions Variables Friends Pages Concepts
Public Member Functions | Protected Attributes | Friends | List of all members
StormByte::Config::Config Class Reference

Abstract class representing a configuration file. More...

#include <config.hxx>

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

Public Member Functions

 Config ()
 
 Config (const Config &config)=default
 
 Config (Config &&config) noexcept=default
 
Configoperator= (const Config &config)=default
 
Configoperator= (Config &&config) noexcept=default
 
virtual ~Config ()=default
 
Item::Baseoperator[] (const std::string &path)
 
const Item::Baseoperator[] (const std::string &path) const
 
Item::Baseoperator[] (const size_t &index)
 
const Item::Baseoperator[] (const size_t &index) const
 
bool operator== (const Config &config) const noexcept
 
bool operator!= (const Config &config) const noexcept
 
Configoperator<< (const Config &source)
 
void operator<< (std::istream &istream)
 
void operator<< (const std::string &str)
 
Configoperator>> (Config &dest) const
 
std::ostream & operator>> (std::ostream &ostream) const
 
std::string & operator>> (std::string &str) const
 
 operator std::string () const
 
Item::BaseAdd (const Item::Base &item)
 Adds an item to the configuration.
 
Item::BaseAdd (Item::Base &&item)
 
void Clear () noexcept
 
bool Exists (const std::string &path) const
 
void Remove (const std::string &path)
 
void Remove (const size_t &path)
 
constexpr void OnExistingAction (const OnExistingAction &on_existing)
 
constexpr void OnParseFailure (OnFailureHook hook)
 
constexpr void AddHookBeforeRead (HookFunction hook)
 
constexpr void AddHookAfterRead (HookFunction hook)
 
virtual constexpr size_t Size () const noexcept
 
virtual size_t Count () const noexcept
 
constexpr std::span< Item::Base::PointerType > Items () noexcept
 
constexpr std::span< const Item::Base::PointerType > Items () const noexcept
 

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
 Action to take when item name already exists.
 

Friends

class StormByte::Serializable< Config >
 
STORMBYTE_CONFIG_PUBLIC Configoperator>> (std::istream &istream, Config &file)
 
STORMBYTE_CONFIG_PUBLIC Configoperator>> (const std::string &str, Config &file)
 
STORMBYTE_CONFIG_PUBLIC std::ostream & operator<< (std::ostream &ostream, const Config &file)
 
STORMBYTE_CONFIG_PUBLIC std::string & operator<< (std::string &, const Config &)
 

Detailed Description

Abstract class representing a configuration file.

A configuration file can contain various elements, including:

Constructor & Destructor Documentation

◆ Config() [1/3]

StormByte::Config::Config::Config ( )

Constructor

◆ Config() [2/3]

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

Copy constructor

Parameters
configconfiguration to copy

◆ Config() [3/3]

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

Move constructor

Parameters
configconfiguration to move

◆ ~Config()

virtual StormByte::Config::Config::~Config ( )
virtualdefault

Destructor

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 container

Parameters
itemitem to add
Exceptions
ItemNameAlreadyExistsif item name already exists
Returns
reference to added item

◆ AddHookAfterRead()

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

Adds a hook which will take Config as parameter and will be executed on successful read Hooks will be executed in order

◆ AddHookBeforeRead()

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

Adds a hook which will take Config as parameter and will be executed before read start Hooks will be executed in order

◆ Clear()

void StormByte::Config::Config::Clear ( )
inlinenoexcept

Clears all configuration items

◆ Count()

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

Gets the full number of items

Returns
size_t number of items

◆ Exists()

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

Checks if item exists by path

Parameters
pathpath to item
Returns
bool exists?

◆ Items() [1/2]

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

Gets the items in the current level

Returns
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

◆ OnExistingAction()

constexpr void StormByte::Config::Config::OnExistingAction ( const OnExistingAction &  on_existing)
inlineconstexpr

Sets a function to execute on name collission when inserting

Parameters
on_existingfunction to select element on collission
See also
Container::OnExistingAction

◆ OnParseFailure()

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

Sets a function to execute on failure

Parameters
hookfunction to execute

◆ operator std::string()

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

Converts current configuration to string

◆ operator!=()

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

Inequality operator

Parameters
configconfiguration to compare
Returns
is not equal?

◆ operator<<() [1/3]

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

Take data from another configuration

Parameters
sourcesource configuration to import
Returns
Reference to configuration

◆ operator<<() [2/3]

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

Initialize configuration with a string

Parameters
strinput string

◆ operator<<() [3/3]

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

Initialize configuration with an input stream

Parameters
istreaminput stream

◆ operator=() [1/2]

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

Move assignment operator

Parameters
configconfiguration to move

◆ operator=() [2/2]

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

Assignment operator

Parameters
configconfiguration to assign

◆ operator==()

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

Equality operator

Parameters
configconfiguration to compare
Returns
is equal?

◆ operator>>() [1/3]

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

Outut current configuration to another configuration

Parameters
destconfiguration destination
Returns
a reference to destination conf

◆ operator>>() [2/3]

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

Output configuration serialized to output stream

Parameters
ostreamoutput stream

◆ operator>>() [3/3]

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

Output configuration serialized to string

Parameters
stroutput string

◆ operator[]() [1/4]

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

Gets a reference to item by index

Parameters
indexindex of 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 item by index

Parameters
indexindex of 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 item by path

Parameters
pathpath to 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 item by path

Parameters
pathpath to item
Returns
item const reference

◆ Remove() [1/2]

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

Removes an item by position

Parameters
pathitem path
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

◆ Size()

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

Gets the number of items in the current level

Returns
size_t 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 serialized to output stream (when output stream is in the left part)

Parameters
ostreamoutput stream
fileConfig to get data from

◆ operator<< [2/2]

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

Output configuration serialized to string (when string is in the left part)

Parameters
stroutput string
fileConfig to get data from

◆ operator>> [1/2]

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

Initializes configuration with string (when string is in the left part)

Parameters
strinput string
fileConfig to put data to

◆ operator>> [2/2]

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

Initializes configuration with istream (when istream is in the left part)

Parameters
istreaminput stream
fileConfig to put data to

Member Data Documentation

◆ m_before_read_hooks

HookFunctions StormByte::Config::Config::m_before_read_hooks
protected

Hooks executed before reading.

Ordered hook list which will be executed sequentially in their corresponding event

◆ m_on_existing_action

StormByte::Config::OnExistingAction StormByte::Config::Config::m_on_existing_action
protected

Action to take when item name already exists.

Function to override the default action when duplicate name is found when inserting Takes 3 parameters: current configuration, existing item and new item and will return the item to be inserted (or might throw to cancel the insert)


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