StormByte C++ Library: Config module 0.0.9999
StormByte-Config is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StormByte::Config::Item::Container Class Referenceabstract

Represents a container that can hold multiple configuration items. More...

#include <container.hxx>

Inheritance diagram for StormByte::Config::Item::Container:
Inheritance graph
[legend]
Collaboration diagram for StormByte::Config::Item::Container:
Collaboration graph
[legend]

Public Member Functions

 Container ()=default
 Constructs an empty Container.
 
 Container (const std::string &name)
 
 Container (std::string &&name)
 
 Container (const Container &base)=default
 
 Container (Container &&base) noexcept=default
 
Containeroperator= (const Container &base)=default
 
Containeroperator= (Container &&base) noexcept=default
 
virtual ~Container () noexcept override=default
 
Baseoperator[] (const size_t &index)
 
const Baseoperator[] (const size_t &index) const
 
Baseoperator[] (const std::string &path)
 
const Baseoperator[] (const std::string &path) const
 
bool operator== (const Container &container) const noexcept
 
bool operator!= (const Container &container) const noexcept
 
BaseAdd (const Base &item, const OnExistingAction &on_existing=OnExistingAction::ThrowException)
 
BaseAdd (Base &&item, const OnExistingAction &on_existing=OnExistingAction::ThrowException)
 
BaseAdd (Base::PointerType item, const OnExistingAction &on_existing)
 Adds an item to the container.
 
void Clear () noexcept
 
bool Exists (const std::string &path) const
 
void Remove (const size_t &index)
 
void Remove (const std::string &path)
 
std::string Serialize (const int &indent_level) const noexcept override
 
constexpr std::span< Base::PointerType > Items () noexcept
 
constexpr std::span< const Base::PointerType > Items () const noexcept
 
virtual constexpr Item::ContainerType ContainerType () const noexcept=0
 
constexpr std::string ContainerTypeToString () const noexcept
 
constexpr Item::Type Type () const noexcept override
 
constexpr size_t Size () const noexcept
 
size_t Count () const noexcept
 
- Public Member Functions inherited from StormByte::Config::Item::Base
 Base ()=default
 Constructs a Base item with an optional name.
 
 Base (const std::string &name)
 Constructs a Base item with an optional name.
 
 Base (const Base &base)=default
 
 Base (Base &&base) noexcept=default
 
Baseoperator= (const Base &base)=default
 
Baseoperator= (Base &&base) noexcept=default
 
virtual ~Base () noexcept=default
 
bool operator== (const Base &base) const noexcept
 
bool operator!= (const Base &base) const noexcept
 
constexpr const std::optional< std::string > & Name () const noexcept
 Gets the name of the item.
 
constexpr void Name (const std::string &name) noexcept
 
bool IsNameValid () const noexcept
 
constexpr std::string TypeToString () const noexcept
 
 operator std::string () const
 
template<typename T >
const T & Value () const
 
template<typename T >
T & Value ()
 

Static Public Member Functions

static constexpr std::pair< const char, const char > EnclosureCharacters (const ContainerType &type) noexcept
 
static constexpr const char EndCharacter (const ContainerType &type) noexcept
 

Protected Member Functions

virtual Base::PointerType BeforeAdditionActions (Base::PointerType item, const OnExistingAction onexisting)=0
 

Protected Attributes

std::vector< Base::PointerType > m_items
 Items in container.
 
- Protected Attributes inherited from StormByte::Config::Item::Base
std::optional< std::string > m_name
 Item name.
 

Detailed Description

Represents a container that can hold multiple configuration items.

Template Parameters
Tcontainer type

Constructor & Destructor Documentation

◆ Container() [1/4]

StormByte::Config::Item::Container::Container ( const std::string &  name)

Constructor

Parameters
namecontainer name

◆ Container() [2/4]

StormByte::Config::Item::Container::Container ( std::string &&  name)

Constructor

Parameters
namecontainer name

◆ Container() [3/4]

StormByte::Config::Item::Container::Container ( const Container base)
default

Copy constructor

Parameters
basecontainer to copy

◆ Container() [4/4]

StormByte::Config::Item::Container::Container ( Container &&  base)
defaultnoexcept

Move constructor

Parameters
basecontainer to move

◆ ~Container()

virtual StormByte::Config::Item::Container::~Container ( )
overridevirtualdefaultnoexcept

Destructor

Member Function Documentation

◆ Add() [1/3]

Base & StormByte::Config::Item::Container::Add ( Base &&  item,
const OnExistingAction &  on_existing = OnExistingAction::ThrowException 
)
inline

Adds an item to the container (rvalue reference)

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

◆ Add() [2/3]

Base & StormByte::Config::Item::Container::Add ( Base::PointerType  item,
const OnExistingAction &  on_existing 
)

Adds an item to the container.

Parameters
itemThe item to add.
on_existingThe action to take if the item name already exists.
Returns
A reference to the added item.

◆ Add() [3/3]

Base & StormByte::Config::Item::Container::Add ( const Base item,
const OnExistingAction &  on_existing = OnExistingAction::ThrowException 
)
inline

Adds an item to the container (const reference)

Parameters
itemitem to add
on_existingaction to take if item name already exists
Exceptions
InvalidNameif item name is not allowed
ItemNameAlreadyExistsif item name already exists
Returns
reference to added item

◆ BeforeAdditionActions()

virtual Base::PointerType StormByte::Config::Item::Container::BeforeAdditionActions ( Base::PointerType  item,
const OnExistingAction  onexisting 
)
protectedpure virtual

Actions to be done before adding an item

Parameters
itemitem to check
onexistingaction to take if item name already exists
Exceptions
ItemNameAlreadyExistsif item name already exists

◆ Clear()

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

Clears all items

◆ ContainerType()

virtual constexpr Item::ContainerType StormByte::Config::Item::Container::ContainerType ( ) const
constexprpure virtualnoexcept

Gets the container type

Returns
Container type

Implemented in StormByte::Config::Item::Group, and StormByte::Config::Item::List.

◆ ContainerTypeToString()

constexpr std::string StormByte::Config::Item::Container::ContainerTypeToString ( ) const
inlineconstexprnoexcept

Gets the container type as string

Returns
Container type as string

◆ Count()

size_t StormByte::Config::Item::Container::Count ( ) const
noexcept

Gets the full number of items

Returns
size_t number of items

◆ EnclosureCharacters()

static constexpr std::pair< const char, const char > StormByte::Config::Item::Container::EnclosureCharacters ( const ContainerType type)
inlinestaticconstexprnoexcept

Gets the start character for the container type

Parameters
typecontainer type
Returns
start character

◆ EndCharacter()

static constexpr const char StormByte::Config::Item::Container::EndCharacter ( const ContainerType type)
inlinestaticconstexprnoexcept

Gets the end character for the container type

Parameters
typecontainer type
Returns
start character

◆ Exists()

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

Checks if item exists by path

Parameters
pathpath to item
Returns
bool exists?

◆ Items() [1/2]

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

Get all items in the container

Returns
std::span of items

◆ Items() [2/2]

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

Get all items in the container

Returns
std::span of items

◆ operator!=()

bool StormByte::Config::Item::Container::operator!= ( const Container container) const
inlinenoexcept

Inequality operator

Parameters
containercontainer to compare
Returns
is not equal?

◆ operator=() [1/2]

Container & StormByte::Config::Item::Container::operator= ( const Container base)
default

Assignment operator

Parameters
basecontainer to copy

◆ operator=() [2/2]

Container & StormByte::Config::Item::Container::operator= ( Container &&  base)
defaultnoexcept

Move assignment operator

Parameters
basecontainer to move

◆ operator==()

bool StormByte::Config::Item::Container::operator== ( const Container container) const
noexcept

Equality operator

Parameters
containercontainer to compare
Returns
is equal?

◆ operator[]() [1/4]

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

Gets a reference to Item by index

Exceptions
OutOfBoundsif index is out of bounds
Returns
size_t number of items

◆ operator[]() [2/4]

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

Gets a const reference to Item by index

Exceptions
OutOfBoundsif index is out of bounds
Returns
size_t number of items

◆ operator[]() [3/4]

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

Gets a reference to Item by path

Parameters
pathpath to item
Exceptions
InvalidPathif path is invalid
ItemNotFoundif item is not found
Returns
Item& item

◆ operator[]() [4/4]

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

Gets a const reference to Item by path

Parameters
pathpath to item
Exceptions
InvalidPathif path is invalid
ItemNotFoundif item is not found
Returns
Item& item

◆ Remove() [1/2]

void StormByte::Config::Item::Container::Remove ( const size_t &  index)

Removes an item by index

Parameters
indexindex to item
Exceptions
OutOfBoundsif index is out of bounds

◆ Remove() [2/2]

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

Removes an item by path

Parameters
pathpath to item
Exceptions
InvalidPathif path is invalid
ItemNotFoundif item is not found

◆ Serialize()

std::string StormByte::Config::Item::Container::Serialize ( const int &  indent_level) const
overridevirtualnoexcept

Returns a string representation of the container

Returns
string representation

Reimplemented from StormByte::Config::Item::Base.

◆ Size()

constexpr size_t StormByte::Config::Item::Container::Size ( ) const
inlineconstexprnoexcept

Gets the number of items in the current level

Returns
size_t number of items

◆ Type()

constexpr Item::Type StormByte::Config::Item::Container::Type ( ) const
inlineconstexproverridevirtualnoexcept

Gets the item type

Returns
item Type

Implements StormByte::Config::Item::Base.


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