22#include <StormByte/config/exception.hxx>
23#include <StormByte/config/item/base.hxx>
24#include <StormByte/config/typedefs.hxx>
102 bool Equals(const
Base& other) const noexcept override;
110 Base& operator[](const
size_t& index);
118 const
Base& operator[](const
size_t& index) const;
127 Base& operator[](const std::
string& path);
136 inline const
Base& operator[](const std::
string& path)
const {
153 return !operator==(container);
161 std::string
Serialize(
const int& indent_level)
const noexcept override;
168 static constexpr std::pair<const char, const char>
EnclosureCharacters(
const ContainerType& type)
noexcept {
170 case ContainerType::Group:
return {
'{',
'}'};
171 case ContainerType::List:
return {
'[',
']'};
172 default:
return {
'\0',
'\0'};
181 static constexpr const char EndCharacter(
const ContainerType& type)
noexcept {
183 case ContainerType::Group:
return '}';
184 case ContainerType::List:
return ']';
185 default:
return '\0';
199 constexpr std::
string ContainerTypeToString() const noexcept {
208 return Item::Type::Container;
223 return Add(std::move(*item.Clone()), on_existing);
233 return Add(item.Move(), on_existing);
242 return Add(std::move(*item.Clone()), m_on_existing_action);
251 return Add(item.Move(), m_on_existing_action);
274 bool Exists(
const std::string& path)
const;
295 constexpr std::span<Base::PointerType>
Items() noexcept {
296 return std::span(m_items);
303 constexpr std::span<const Base::PointerType>
Items() const noexcept {
304 return std::span(m_items);
311 constexpr size_t Size() const noexcept {
312 return m_items.size();
331 m_on_existing_action = action;
339 return m_on_existing_action;
361 virtual std::string ContentsToString(
const int& level)
const noexcept;
368 static bool IsPathValid(
const std::string& name)
noexcept;
375 const Base& LookUp(
const std::string& path)
const;
382 const Base& LookUp(std::queue<std::string>& path)
const;
388 void Remove(std::queue<std::string>& path);
Configuration document (text or versioned binary).
Definition config.hxx:54
The base class for all configuration items.
Definition base.hxx:44
Holds child items. Group and List derive from this.
Definition container.hxx:38
Base & Add(Base &&item)
Adds an item using the container's current OnExistingAction policy (move).
Definition container.hxx:250
constexpr size_t Size() const noexcept
Gets the number of items in the current level.
Definition container.hxx:311
void Remove(const std::string &path)
Removes an item by path.
constexpr Item::Type Type() const noexcept override
Gets the item type.
Definition container.hxx:207
constexpr std::span< Base::PointerType > Items() noexcept
Returns a span of all items in the container.
Definition container.hxx:295
Container & operator=(Container &&base) noexcept=default
Move assignment operator.
Container()=default
Constructs an empty Container.
Container & operator=(const Container &base)=default
Copy assignment operator.
virtual Base::PointerType BeforeAdditionActions(Base::PointerType item, const StormByte::Config::OnExistingAction onexisting)=0
Actions performed before adding an item.
Base & Add(const Base &item, const StormByte::Config::OnExistingAction &on_existing)
Adds an item (const reference) using an explicit policy.
Definition container.hxx:222
Base & Add(const Base &item)
Adds an item using the container's current OnExistingAction policy.
Definition container.hxx:241
StormByte::Config::OnExistingAction GetOnExistingAction() const noexcept
Gets the current OnExistingAction policy.
Definition container.hxx:338
void Clear() noexcept
Clears all items from the container.
Definition container.hxx:265
Base & Add(Base &&item, const StormByte::Config::OnExistingAction &on_existing)
Adds an item (rvalue) using an explicit policy.
Definition container.hxx:232
static constexpr const char EndCharacter(const ContainerType &type) noexcept
Returns the closing character for a given container type.
Definition container.hxx:181
static constexpr std::pair< const char, const char > EnclosureCharacters(const ContainerType &type) noexcept
Returns the enclosure characters for a given container type.
Definition container.hxx:168
void Remove(const size_t &index)
Removes an item by index.
constexpr std::span< const Base::PointerType > Items() const noexcept
Returns a const span of all items in the container.
Definition container.hxx:303
std::string Serialize(const int &indent_level) const noexcept override
Serializes the container to a string.
Container(Container &&base) noexcept=default
Move constructor.
std::vector< Base::PointerType > m_items
Items stored in the container.
Definition container.hxx:344
virtual constexpr Item::ContainerType ContainerType() const noexcept=0
Gets the container type.
bool operator==(const Container &container) const noexcept
Equality operator.
Container(const std::string &name)
Constructs a Container with the given name.
size_t Count() const noexcept
Gets the total number of items including nested ones.
bool Exists(const std::string &path) const
Checks if an item exists by path.
virtual ~Container() noexcept override=default
Destructor.
Container(std::string &&name)
Constructs a Container with the given name (move).
Base & Add(Base::PointerType item, const StormByte::Config::OnExistingAction &on_existing)
Adds an item to the container.
Container(const Container &base)=default
Copy constructor.
bool operator!=(const Container &container) const noexcept
Inequality operator.
Definition container.hxx:152
Configuration items (values, comments, groups, lists).
Definition alias.hxx:30
enum STORMBYTE_CONFIG_PUBLIC ContainerType
Group of named items.
Definition type.hxx:95
Type
Represents the type of a configuration item.
Definition type.hxx:39
OnExistingAction
Forward declaration of the configuration document.
Definition typedefs.hxx:35
@ ThrowException
Throw an exception to indicate the conflict.