33#include <unordered_map>
40 m_context->notify_set_parameter(
this,
name, value);
48 m_context->notify_call_method(
this,
name,
params);
63 [&visit](
auto const &kv) -> PackedMap::value_type {
65 boost::apply_visitor(visit, kv.second)};
69 state.
objects.resize(visit.objects().size());
70 std::ranges::transform(
71 visit.objects(), state.objects.begin(), [](
auto const &kv) {
72 return std::make_pair(kv.first, kv.second->serialize());
75 state.name = name().to_string();
76 state.internal_state = get_internal_state();
81ObjectRef ObjectHandle::deserialize(
const std::string &packed_state,
83 auto const state = Utils::unpack<ObjectState>(packed_state);
85 std::unordered_map<ObjectId, ObjectRef> objects;
86 std::ranges::transform(state.objects, std::inserter(objects, objects.end()),
87 [&ctx](
auto const &kv) {
88 return std::make_pair(kv.first,
89 deserialize(kv.second, ctx));
93 for (
auto const &kv : state.params) {
98 o->set_internal_state(state.internal_state);
103boost::string_ref ObjectHandle::name()
const {
104 return context() ? context()->name(
this) : boost::string_ref{};
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.
boost::string_ref name() const
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::shared_ptr< ObjectHandle > ObjectRef
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::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.