StormByte-Config 2.0.0
C++26 configuration-document module of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::Config::Item::Container Class Referenceabstract

Holds child items. More...

#include <StormByte/config/item/container.hxx>

Inheritance diagram for StormByte::Config::Item::Container:
Collaboration diagram for StormByte::Config::Item::Container:

Public Member Functions

Construction
 Container ()
 Constructs an empty Container.
 
 Container (const StormByte::String::String &name)
 Constructs a Container with the given name.
 
 Container (StormByte::String::String &&name)
 Constructs a Container with the given name (move).
 
 Container (const Container &base)
 Copy constructor.
 
 Container (Container &&base) noexcept
 Move constructor.
 
Container & operator= (const Container &base)
 Copy assignment operator.
 
Container & operator= (Container &&base) noexcept
 Move assignment operator.
 
virtual ~Container () noexcept override
 Destructor.
 
Items
Base & Add (const Base &item, const StormByte::Config::OnExistingAction &on_existing)
 Adds an item (const reference) using an explicit policy.
 
Base & Add (Base &&item, const StormByte::Config::OnExistingAction &on_existing)
 Adds an item (rvalue) using an explicit policy.
 
Base & Add (const Base &item)
 Adds an item using the container's current OnExistingAction policy.
 
Base & Add (Base &&item)
 Adds an item using the container's current OnExistingAction policy (move).
 
Base & Add (Base::PointerType item)
 Adds an item to the container using current policy.
 
Base & Add (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 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::Size &index)
 Removes an item by index.
 
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.
 
constexpr std::span< const Base::PointerType > Items () noexcept
 Items in this level.
 
constexpr std::span< const Base::PointerType > Items () const noexcept
 Items in this level.
 
StormByte::Size Size () const noexcept
 Gets the number of items in the current level.
 
StormByte::Size 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 () noexcept
 Constructor.
 
 Base (const StormByte::String::String &name)
 Constructor.
 
 Base (const Base &base) noexcept=default
 Copy constructor.
 
 Base (Base &&base) noexcept=default
 Move constructor.
 
Base & operator= (const Base &base) noexcept=default
 Assignment operator.
 
Base & operator= (Base &&base) noexcept=default
 Move assignment operator.
 
 ~Base () noexcept override
 Destructor.
 
bool operator== (const Base &base) const noexcept
 Compares two items.
 
bool operator!= (const Base &base) const noexcept
 Compares two items.
 
constexpr const StormByte::String::String & Name () const noexcept
 Gets the name of the item.
 
constexpr void Name (const StormByte::String::String &name)
 Sets the name of the item.
 
void Name (std::string_view name)
 Sets the name of the item.
 
constexpr std::string_view TypeToString () const noexcept
 Gets the type as string.
 
template<class T >
decltype(auto) As ()
 Typed view of this item.
 
template<class T >
decltype(auto) As () const
 Typed view of this item.
 
- Public Member Functions inherited from StormByte::Clonable< Base, StormByte::Shared< Base > >
constexpr Clonable ()=default
 
constexpr Clonable (const Clonable &)=default
 
constexpr Clonable (Clonable &&) noexcept=default
 
constexpr Clonable & operator= (const Clonable &)=default
 
constexpr Clonable & operator= (Clonable &&) noexcept=default
 
virtual constexpr ~Clonable () noexcept=default
 
virtual PointerType Clone () const =0
 
virtual PointerType Move ()=0
 

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
StormByte::String::String m_name
 Name of the item.
 

Access

bool Equals (const Base &other) const noexcept override
 Polymorphic equality comparison.
 
Base & operator[] (const StormByte::Size &index)
 Gets a reference to an item by index.
 
const Base & operator[] (const StormByte::Size &index) const
 Gets a const reference to an item by index.
 
Base & operator[] (const StormByte::String::String &path)
 Gets a reference to an item by path.
 
const Base & operator[] (const StormByte::String::String &path) const
 Gets a const reference to an item by path.
 
Base & operator[] (std::string_view path)
 Gets a reference to an item by a path view.
 
const Base & operator[] (std::string_view path) const
 Gets a const reference to an item by a path view.
 
bool operator== (const Container &container) const noexcept
 Equality operator.
 
bool operator!= (const Container &container) const noexcept
 Inequality operator.
 
StormByte::String::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_view 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.
 

Additional Inherited Members

- Public Types inherited from StormByte::Clonable< Base, StormByte::Shared< Base > >
typedef SmartPointer PointerType
 
- Static Public Member Functions inherited from StormByte::Config::Item::Base
static bool IsNameValid (const StormByte::String::String &name) noexcept
 Checks if name is valid.
 
static bool IsNameValid (std::string_view name) noexcept
 Checks if name is valid.
 
- Static Public Member Functions inherited from StormByte::Clonable< Base, StormByte::Shared< Base > >
static PointerType MakePointer (Args &&... args)
 

Detailed Description

Holds child items.

Group and List derive from this.

Constructor & Destructor Documentation

◆ Container() [1/5]

StormByte::Config::Item::Container::Container ( )

Constructs an empty Container.

◆ Container() [2/5]

StormByte::Config::Item::Container::Container ( const StormByte::String::String &  name)

Constructs a Container with the given name.

Parameters
nameThe name of the container.

◆ Container() [3/5]

StormByte::Config::Item::Container::Container ( StormByte::String::String &&  name)

Constructs a Container with the given name (move).

Parameters
nameThe name of the container.

◆ Container() [4/5]

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

Copy constructor.

Parameters
baseContainer to copy.

◆ Container() [5/5]

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

Move constructor.

Parameters
baseContainer to move.

◆ ~Container()

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

Destructor.

Defined in this module so catch matches across a DLL.

Member Function Documentation

◆ Add() [1/6]

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/6]

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/6]

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

Adds an item to the container using current policy.

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

◆ Add() [4/6]

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() [5/6]

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() [6/6]

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.

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

◆ Clear()

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

Clears all items from the container.

◆ 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_view StormByte::Config::Item::Container::ContainerTypeToString ( ) const
inlineconstexprnoexcept

Gets the container type as string.

Returns
Container type as string.

◆ Count()

StormByte::Size 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() [1/2]

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

Checks if an item exists by path.

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

◆ Exists() [2/2]

bool StormByte::Config::Item::Container::Exists ( std::string_view  path) const
inline

Checks if an item exists by a path view.

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

Items in this level.

Returns
Span of item pointers.

◆ Items() [2/2]

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

Items in this level.

The span cannot reseat or grow the store; each pointer's item is mutable.

Returns
Span of item pointers.

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

Copy assignment operator.

Parameters
baseContainer to copy.
Returns
Reference to this Container.

◆ operator=() [2/2]

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

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/6]

Base & StormByte::Config::Item::Container::operator[] ( const StormByte::Size &  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/6]

const Base & StormByte::Config::Item::Container::operator[] ( const StormByte::Size &  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/6]

Base & StormByte::Config::Item::Container::operator[] ( const StormByte::String::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/6]

const Base & StormByte::Config::Item::Container::operator[] ( const StormByte::String::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.

◆ operator[]() [5/6]

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

Gets a reference to an item by a path view.

Parameters
pathPath to the item.
Returns
Reference to the item.

◆ operator[]() [6/6]

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

Gets a const reference to an item by a path view.

Parameters
pathPath to the item.
Returns
Const reference to the item.

◆ Remove() [1/3]

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

Removes an item by index.

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

◆ Remove() [2/3]

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

Removes an item by path.

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

◆ Remove() [3/3]

void StormByte::Config::Item::Container::Remove ( std::string_view  path)
inline

Removes an item by a path view.

Parameters
pathPath to the item to remove.

◆ Serialize()

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

Serializes the container to a string.

Parameters
indent_levelIndentation level.
Returns
Serialized text.

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()

StormByte::Size StormByte::Config::Item::Container::Size ( ) const
noexcept

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.

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

Member Data Documentation

◆ m_items

std::vector<Base::PointerType> StormByte::Config::Item::Container::m_items
protected

Items stored in the container.

◆ m_on_existing_action

StormByte::Config::OnExistingAction StormByte::Config::Item::Container::m_on_existing_action = StormByte::Config::OnExistingAction::ThrowException
protected

Collision policy.


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