19#ifndef ESPRESSO_SCRIPT_INTERFACE_OBJECTMANAGER_HPP
20#define ESPRESSO_SCRIPT_INTERFACE_OBJECTMANAGER_HPP
40#include <boost/mpi/communicator.hpp>
41#include <boost/serialization/utility.hpp>
47#include <unordered_map>
66 using ObjectId = std::size_t;
70 std::unordered_map<ObjectId, ObjectRef> m_local_objects;
72 std::shared_ptr<LocalContext> m_node_local_context;
74 boost::mpi::communicator
const &m_comm;
94 m_comm(
callbacks->comm()), m_is_head_node(m_comm.rank() == 0),
96 m_parallel_exception_handler(m_comm),
105 set_parameter(
id,
name, value);
108 [
this](ObjectId
id, std::string
const &
name,
113 [
this](ObjectId
id) { delete_handle(
id); }) {}
119 void make_handle(ObjectId
id,
const std::string &
name,
128 void remote_make_handle(ObjectId
id,
const std::string &
name,
135 void set_parameter(ObjectId
id, std::string
const &
name,
140 Variant const &value)
override;
146 void call_method(ObjectId
id, std::string
const &
name,
157 void delete_handle(ObjectId
id) { m_local_objects.erase(
id); }
166 std::shared_ptr<ObjectHandle>
168 std::shared_ptr<ObjectHandle>
172 boost::string_ref
name(
const ObjectHandle *
o)
const override;
178 boost::mpi::communicator
const &
get_comm()
const override {
return m_comm; }
ScriptInterface::Context decorates ScriptInterface::ObjectHandle objects with a context: a creation p...
Communication::MpiCallbacks manages MPI communication using a visitor pattern.
RAII handle for a callback.
Context of an object handle.
Global synchronizing context.
std::shared_ptr< ObjectHandle > make_shared(std::string const &name, const VariantMap ¶meters) override
Get a new reference counted instance of a script interface object by name.
void notify_set_parameter(const ObjectHandle *o, std::string const &name, Variant const &value) override
boost::string_ref name(const ObjectHandle *o) const override
boost::mpi::communicator const & get_comm() const override
GlobalContext(std::shared_ptr< Communication::MpiCallbacks > const &callbacks, std::shared_ptr< LocalContext > node_local_context)
bool is_head_node() const override
std::shared_ptr< ObjectHandle > make_shared_local(std::string const &name, VariantMap const ¶meters) override
void parallel_try_catch(std::function< void()> const &cb) const override
void notify_call_method(const ObjectHandle *o, std::string const &name, VariantMap const &arguments) override
Handle exceptions thrown in MPI parallel code.
void parallel_try_catch(std::function< void()> const &callback) const
Handle exceptions in synchronous code.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
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.
std::vector< std::pair< std::string, PackedVariant > > PackedMap
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectId, 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 PackedVariant
Packed version of Variant.