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 Member Functions | Protected Attributes | List of all members
StormByte::Config::Item::Container Class Referenceabstract

Holds child items. Group and List derive from this. 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

Construction
 Container ()=default
 Constructs an empty Container.
 
 Container (const std::string &name)
 Constructs a Container with the given name.
 
 Container (std::string &&name)
 Constructs a Container with the given name (move).
 
 Container (const Container &base)=default
 Copy constructor.
 
 Container (Container &&base) noexcept=default
 Move constructor.
 
Containeroperator= (const Container &base)=default
 Copy assignment operator.
 
Containeroperator= (Container &&base) noexcept=default
 Move assignment operator.
 
virtual ~Container () noexcept override=default
 Destructor.
 
Items
BaseAdd (const Base &item, const StormByte::Config::OnExistingAction &on_existing)
 Adds an item (const reference) using an explicit policy.
 
BaseAdd (Base &&item, const StormByte::Config::OnExistingAction &on_existing)
 Adds an item (rvalue) using an explicit policy.
 
BaseAdd (const Base &item)
 Adds an item using the container's current OnExistingAction policy.
 
BaseAdd (Base &&item)
 Adds an item using the container's current OnExistingAction policy (move).
 
BaseAdd (Base::PointerType item, const StormByte::Config::OnExistingAction &on_existing)
 Adds an item to the container.
 
void Clear () noexcept
 Clears all items from the container.
 
bool Exists (const std::string &path) const
 Checks if an item exists by path.
 
void Remove (const size_t &index)
 Removes an item by index.
 
void Remove (const std::string &path)
 Removes an item by path.
 
constexpr std::span< Base::PointerType > Items () noexcept
 Returns a span of all items in the container.
 
constexpr std::span< const Base::PointerType > Items () const noexcept
 Returns a const span of all items in the container.
 
constexpr size_t Size () const noexcept
 Gets the number of items in the current level.
 
size_t Count () const noexcept
 Gets the total number of items including nested ones.
 
Policy
void SetOnExistingAction (StormByte::Config::OnExistingAction action) noexcept
 Sets the action to take when an item with the same identity already exists.
 
StormByte::Config::OnExistingAction GetOnExistingAction () const noexcept
 Gets the current OnExistingAction policy.
 
- Public Member Functions inherited from StormByte::Config::Item::Base
 Base ()=default
 Default constructor.
 
 Base (const std::string &name)
 Constructs a Base item with a name.
 
 Base (const Base &base)=default
 Copy constructor.
 
 Base (Base &&base) noexcept=default
 Move constructor.
 
Baseoperator= (const Base &base)=default
 Copy assignment operator.
 
Baseoperator= (Base &&base) noexcept=default
 Move assignment operator.
 
virtual ~Base () noexcept=default
 Destructor.
 
bool operator== (const Base &other) const noexcept
 Equality operator.
 
bool operator!= (const Base &other) const noexcept
 Inequality operator.
 
constexpr const std::optional< std::string > & Name () const noexcept
 Gets the name of the item.
 
constexpr void Name (const std::string &name) noexcept
 Sets the item name.
 
bool IsNameValid () const noexcept
 Checks if the current name is valid.
 
virtual std::optional< CommentTypeGetCommentType () const noexcept
 Returns the comment type if this item is a Comment, otherwise std::nullopt.
 
constexpr std::string TypeToString () const noexcept
 Gets the item type as a string.
 
 operator std::string () const
 Converts the item to a string.
 
template<typename T >
const T & Value () const
 Gets the item value (const).
 
template<typename T >
T & Value ()
 Gets the item value (mutable).
 

Protected Member Functions

virtual Base::PointerType BeforeAdditionActions (Base::PointerType item, const StormByte::Config::OnExistingAction onexisting)=0
 Actions performed before adding an item.
 

Protected Attributes

std::vector< Base::PointerType > m_items
 Items stored in the container.
 
StormByte::Config::OnExistingAction m_on_existing_action = StormByte::Config::OnExistingAction::ThrowException
 Collision policy.
 
- Protected Attributes inherited from StormByte::Config::Item::Base
std::optional< std::string > m_name
 Item name.
 

Access

bool Equals (const Base &other) const noexcept override
 Polymorphic equality comparison.
 
Baseoperator[] (const size_t &index)
 Gets a reference to an item by index.
 
const Baseoperator[] (const size_t &index) const
 Gets a const reference to an item by index.
 
Baseoperator[] (const std::string &path)
 Gets a reference to an item by path.
 
const Baseoperator[] (const std::string &path) const
 Gets a const reference to an item by path.
 
bool operator== (const Container &container) const noexcept
 Equality operator.
 
bool operator!= (const Container &container) const noexcept
 Inequality operator.
 
std::string Serialize (const int &indent_level) const noexcept override
 Serializes the container to a string.
 
virtual constexpr Item::ContainerType ContainerType () const noexcept=0
 Gets the container type.
 
constexpr std::string ContainerTypeToString () const noexcept
 Gets the container type as string.
 
constexpr Item::Type Type () const noexcept override
 Gets the item type.
 
static constexpr std::pair< const char, const char > EnclosureCharacters (const ContainerType &type) noexcept
 Returns the enclosure characters for a given container type.
 
static constexpr const char EndCharacter (const ContainerType &type) noexcept
 Returns the closing character for a given container type.
 

Detailed Description

Holds child items. Group and List derive from this.

Constructor & Destructor Documentation

◆ Container() [1/4]

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

Constructs a Container with the given name.

Parameters
nameThe name of the container.

◆ Container() [2/4]

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

Constructs a Container with the given name (move).

Parameters
nameThe name of the container.

◆ 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.

Member Function Documentation

◆ Add() [1/5]

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

Adds an item using the container's current OnExistingAction policy (move).

Parameters
itemItem to add.
Returns
Reference to the added item.

◆ Add() [2/5]

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

Adds an item (rvalue) using an explicit policy.

Parameters
itemItem to add.
on_existingAction to take if the item already exists.
Returns
Reference to the added item.

◆ Add() [3/5]

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

Adds an item to the container.

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

◆ Add() [4/5]

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

Adds an item using the container's current OnExistingAction policy.

Parameters
itemItem to add.
Returns
Reference to the added item.

◆ Add() [5/5]

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

Adds an item (const reference) using an explicit policy.

Parameters
itemItem to add.
on_existingAction to take if the item already exists.
Returns
Reference to the added item.

◆ BeforeAdditionActions()

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

Actions performed before adding an item.

Parameters
itemItem to check.
onexistingAction to take if the item already exists.
Returns
Pointer to the existing item if kept, otherwise nullptr.

◆ 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 total number of items including nested ones.

Returns
Total number of items.

◆ EnclosureCharacters()

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

Returns the enclosure characters for a given container type.

Parameters
typeContainer type.
Returns
Pair of opening and closing characters.

◆ EndCharacter()

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

Returns the closing character for a given container type.

Parameters
typeContainer type.
Returns
Closing character.

◆ Equals()

bool StormByte::Config::Item::Container::Equals ( const Base other) const
overridevirtualnoexcept

Polymorphic equality comparison.

Parameters
otherThe other item to compare against.
Returns
true if both containers have the same type, name and contents.

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

◆ Exists()

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

Checks if an item exists by path.

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

◆ GetOnExistingAction()

StormByte::Config::OnExistingAction StormByte::Config::Item::Container::GetOnExistingAction ( ) const
inlinenoexcept

Gets the current OnExistingAction policy.

Returns
The current policy.

◆ Items() [1/2]

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

Returns a const span of all items in the container.

Returns
Const span of items.

◆ Items() [2/2]

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

Returns a span of all items in the container.

Returns
Span of items.

◆ operator!=()

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

Inequality operator.

Parameters
containerContainer to compare.
Returns
true if not equal.

◆ operator=() [1/2]

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

Copy assignment operator.

Parameters
baseContainer to copy.
Returns
Reference to this Container.

◆ operator=() [2/2]

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

Move assignment operator.

Parameters
baseContainer to move.
Returns
Reference to this Container.

◆ operator==()

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

Equality operator.

Parameters
containerContainer to compare.
Returns
true if equal.

◆ operator[]() [1/4]

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

Gets a reference to an item by index.

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

◆ operator[]() [2/4]

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

Gets a const reference to an item by index.

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

◆ operator[]() [3/4]

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

Gets a reference to an item by path.

Parameters
pathPath to the item.
Exceptions
InvalidPathif path is invalid.
ItemNotFoundif item is not found.
Returns
Reference to the item.

◆ operator[]() [4/4]

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

Gets a const reference to an item by path.

Parameters
pathPath to the item.
Exceptions
InvalidPathif path is invalid.
ItemNotFoundif item is not found.
Returns
Const reference to the item.

◆ Remove() [1/2]

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

Removes an item by index.

Parameters
indexIndex of the item to remove.
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 the item to remove.
Exceptions
InvalidPathif path is invalid.
ItemNotFoundif item is not found.

◆ Serialize()

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

Serializes the container to a string.

Parameters
indent_levelIndentation level.
Returns
Serialized string representation.

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

◆ SetOnExistingAction()

void StormByte::Config::Item::Container::SetOnExistingAction ( StormByte::Config::OnExistingAction  action)
inlinenoexcept

Sets the action to take when an item with the same identity already exists.

Parameters
actionThe policy to apply on name/identity collision.

◆ Size()

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

Gets the number of items in the current level.

Returns
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: