39#include <unordered_map>
47 m_context->notify_set_parameter(
this,
name, value);
58 m_context->notify_call_method(
this,
name, params);
70 state.
params.reserve(params.size());
75 std::ranges::transform(params, std::back_inserter(state.
params),
76 [&visitor](
auto const &kv) -> PackedMap::value_type {
77 auto const &[name, value] = kv;
78 return {name, std::visit(visitor, value)};
82 state.
objects.reserve(visitor.objects().size());
83 std::ranges::transform(visitor.objects(), std::back_inserter(state.objects),
85 auto const &[name, obj] = kv;
86 return std::make_pair(name, obj->serialize());
90 state.internal_state = get_internal_state();
99 std::unordered_map<ObjectId, ObjectRef> objects;
100 std::ranges::transform(state.objects, std::inserter(objects, objects.end()),
101 [&ctx](
auto const &kv) {
102 auto const &[name, buf] = kv;
103 return std::make_pair(name, deserialize(buf, ctx));
107 for (
auto const &[
name, variant] : state.params) {
112 o->set_internal_state(state.internal_state);
ScriptInterface::Context decorates ScriptInterface::ObjectHandle objects with a context: a creation p...
virtual std::shared_ptr< ObjectHandle > make_shared(std::string const &name, const VariantMap ¶meters)=0
Get a new reference counted instance of a script interface by name.
std::string serialize() const
Variant call_method(const std::string &name, const VariantMap ¶ms)
Call a method on the object.
virtual void do_set_parameter(const std::string &, const Variant &)
Local implementation of set_parameter.
virtual Variant do_call_method(const std::string &, const VariantMap &)
Local implementation of call_method.
virtual std::vector< std::pair< std::string, Variant > > serialize_parameters() const
Serialize parameters.
Context * context() const
Responsible context.
void set_parameter(const std::string &name, const Variant &value)
Set single parameter.
static ObjectRef deserialize(const std::string &state, Context &ctx)
Make object from serialized state.
std::string_view name() const
static scoped_instance make_shared_scoped(std::optional< int > excepts=std::nullopt)
Generate a shared trap with the lifetime of the current scope.
std::shared_ptr< ObjectHandle > ObjectRef
make_recursive_variant< ObjectRef > Variant
Possible types for parameters.
std::unordered_map< std::string, Variant > VariantMap
T unpack(std::string const &state)
Unpack a serialize type into a string.
std::string pack(T const &v)
Pack a serialize type into a string.
State of an object ready for serialization.
Visitor that converts a Variant to a PackedVariant.
auto const & objects() const
Map of objects whose references were replaced by ids.
Visitor that converts a PackedVariant to a Variant.