39#include <unordered_map>
47 m_context->notify_set_parameter(
this,
name, value);
58 m_context->notify_call_method(
this,
name,
params);
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)};
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();
95ObjectRef ObjectHandle::deserialize(
const std::string &packed_state,
97 auto const state = Utils::unpack<ObjectState>(packed_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);
117std::string_view ObjectHandle::name()
const {
118 return context() ? context()->name(
this) : std::string_view{};
ScriptInterface::Context decorates ScriptInterface::ObjectHandle objects with a context: a creation p...
Context of an object handle.
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.
void set_parameter(const std::string &name, const Variant &value)
Set single parameter.
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
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
std::string pack(T const &v)
Pack a serialize type into a string.
static SteepestDescentParameters params
Currently active steepest descent instance.
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.
Recursive variant implementation.