32#include <unordered_map>
41template <
typename ManagedType,
class BaseType = ObjectHandle,
46 using Base::add_parameters;
49 std::unordered_map<KeyType, std::shared_ptr<ManagedType>> m_elements;
54 std::shared_ptr<ManagedType>
const &obj_ptr) = 0;
73 void insert(KeyType
const &key, std::shared_ptr<ManagedType>
const &element) {
75 m_elements[key] = element;
84 KeyType
insert(std::shared_ptr<ManagedType>
const &element) {
86 m_elements[key] = element;
95 void erase(KeyType
const &key) {
97 m_elements.erase(key);
103 auto const &
elements()
const {
return m_elements; }
109 for (
auto const &kv : m_elements) {
120 if (method ==
"insert") {
122 get_value<std::shared_ptr<ManagedType>>(parameters.at(
"object"));
124 if (parameters.count(
"key")) {
125 auto const key =
get_key(parameters.at(
"key"));
132 if (method ==
"erase") {
133 auto const key =
get_key(parameters.at(
"key"));
138 if (method ==
"get") {
139 auto const key =
get_key(parameters.at(
"key"));
140 return Variant{m_elements.at(key)};
143 if (method ==
"get_map") {
147 if (method ==
"keys") {
148 std::vector<Variant> res;
149 for (
auto const &kv : m_elements) {
150 res.push_back(kv.first);
155 if (method ==
"clear") {
160 if (method ==
"size") {
161 return static_cast<int>(m_elements.size());
164 if (method ==
"empty") {
165 return m_elements.empty();
168 if (method ==
"contains") {
169 return m_elements.find(
get_key(parameters.at(
"key"))) != m_elements.end();
172 return Base::do_call_method(method, parameters);
176 m_elements = get_value_or<decltype(m_elements)>(
params,
"_objects", {});
177 for (
auto const &[key, element] : m_elements) {
184 return get_value<KeyType>(key);
186 using namespace detail::demangle;
187 auto const actual = simplify_symbol_variant(key);
188 auto const target = simplify_symbol(
static_cast<KeyType *
>(
nullptr));
189 if (Base::context()->is_head_node()) {
190 throw std::invalid_argument(
"Key has to be of type '" + target +
191 "', got type '" + actual +
"'");
Owning map of ObjectHandles.
void insert(KeyType const &key, std::shared_ptr< ManagedType > const &element)
Add an element to the map.
virtual KeyType insert_in_core(std::shared_ptr< ManagedType > const &obj_ptr)=0
ObjectContainer< ObjectMap, ManagedType, BaseType > Base
void clear()
Clear the map.
virtual void insert_in_core(KeyType const &key, std::shared_ptr< ManagedType > const &obj_ptr)=0
KeyType get_key(Variant const &key) const
KeyType insert(std::shared_ptr< ManagedType > const &element)
Add an element to the map.
void do_construct(VariantMap const ¶ms) override=0
auto const & elements() const
Map elements.
void restore_from_checkpoint(VariantMap const ¶ms)
void erase(KeyType const &key)
Removes all occurrences of an element from the map.
Variant do_call_method(std::string const &method, VariantMap const ¶meters) override
virtual void erase_in_core(KeyType const &key)=0
std::unordered_map< std::string, Variant > VariantMap
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
std::conditional_t< std::is_same_v< BaseType, ObjectHandle >, AutoParameters< Container< ManagedType, BaseType >, BaseType >, BaseType > ObjectContainer
Base class for containers whose BaseType might be a full specialization of AutoParameters.
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
constexpr const None none
None-"literal".
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only