Template Class DataBank#

Class Documentation#

template<typename ...Ts>
class DataBank#

Storage of the data exchanged by operators at runtime. There is one pool per type, all the pools share the same IDs sequence so an ID identifies a single item. The ID 0 (null_data) is never attributed.

Public Functions

template<typename T>
inline std::map<data_id_t, T> &get_pool()#
template<typename T>
inline const std::map<data_id_t, T> &get_pool() const#
template<typename T>
inline data_id_t add(const T &value)#
Returns:

The ID of the new item.

template<typename T>
inline std::optional<T> get(data_id_t id) const#
inline bool contains(data_id_t id) const#
Returns:

true if any pool contains this ID.

inline void erase(data_id_t id)#
inline data_id_t reserve_id()#

Reserves an ID that can later be filled with store.

inline data_id_t get_next_id() const#
template<typename ...Args>
inline bool load(data_id_t id, std::variant<Args...> &var) const#

Fills var with the item id, using the first alternative of the variant having an item with this ID.

Returns:

false if none of the alternatives has an item with this ID.

template<typename ...Args>
inline bool store(data_id_t id, const std::variant<Args...> &var)#

Stores the content of var under id, replacing any previous item with this ID, whatever its type.

Returns:

false if there is no pool for the type held by the variant.

inline data_id_t add_from_string(const std::string &str)#

Parses the string with the Parser of each type, in the order of the template parameters, and adds the first successful result.

Returns:

The ID of the new item, or null_data if no parser accepted the string.

Public Static Attributes

template<typename T>
static constexpr bool has_pool = (std::is_same_v<T, Ts> || ...)#