ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ScriptInterface::AutoParameters< Derived, Base > Class Template Reference

Bind parameters in the script interface. More...

#include <AutoParameters.hpp>

Inheritance diagram for ScriptInterface::AutoParameters< Derived, Base >:
Collaboration diagram for ScriptInterface::AutoParameters< Derived, Base >:

Classes

struct  UnknownParameter
 Exception thrown when accessing an unknown parameter. More...
struct  WriteError
 Exception thrown when writing to a read-only parameter. More...

Public Member Functions

std::vector< std::string_view > valid_parameters () const final
Variant get_parameter (const std::string &name) const final
void do_set_parameter (const std::string &name, const Variant &value) final
std::vector< std::pair< std::string, Variant > > serialize_parameters () const final
Public Member Functions inherited from ScriptInterface::ObjectHandle
 ObjectHandle ()=default
 ObjectHandle (ObjectHandle const &)=delete
ObjectHandle & operator= (ObjectHandle const &)=delete
virtual ~ObjectHandle ()=default
std::string_view name () const
Context * context () const
 Responsible context.
void construct (VariantMap const &params)
 Construct the handled object.
virtual void do_construct (VariantMap const &params)
VariantMap get_parameters () const
 Get current parameters.
void set_parameter (const std::string &name, const Variant &value)
 Set single parameter.
Variant call_method (const std::string &name, const VariantMap &params)
 Call a method on the object.
virtual Variant do_call_method (const std::string &, const VariantMap &)
 Local implementation of call_method.
std::string serialize () const

Protected Member Functions

 AutoParameters ()=default
 AutoParameters (std::vector< AutoParameter > &&params)
 ~AutoParameters () override=default
bool has_parameter (std::string const &name) const override
void add_parameters (std::vector< AutoParameter > &&params)
auto const & get_parameter_insertion_order () const

Additional Inherited Members

Static Public Member Functions inherited from ScriptInterface::ObjectHandle
static ObjectRef deserialize (const std::string &state, Context &ctx)
 Make object from serialized state.

Detailed Description

template<typename Derived, typename Base = ObjectHandle>
class ScriptInterface::AutoParameters< Derived, Base >

Bind parameters in the script interface.

This class implements ScriptInterfaceBase, binding the parameters added by add_parameters or by the constructor. To use it, derive from this class and add parameters. For example, given a class A

class A {
public:
int i() { return m_i; }
private:
int m_i;
};

that should have i exposed, this can be achieved by extending it like this:

class A : public AutoParameters {
public:
A() : AutoParameters({"name_for_i", i}) {}
int i() { return m_i; }
private:
int m_i;
};

If there is more complicated logic needed, specific setters and getters can be provided. E.g. given a class B like

class B {
public:
void set_i(int);
int get_i();
private:
int m_i;
};

we can use a lambdas to set and get the parameter like this:

class B : public AutoParameters {
public:
B() : AutoParameters({"name_for_i",
[this](Variant const& v) {set_i(get_value<int>(v));},
[this]() {return get_i();}
}) {}
void set_i(int);
int get_i();
private:
int m_i;
};
make_recursive_variant< ObjectRef > Variant
Possible types for parameters.
Definition Variant.hpp:131
T get_value(Variant const &v)
Extract value of specific type T from a Variant.

(this has to be captured in the lambdas to have access to the member functions of the class).

Definition at line 94 of file AutoParameters.hpp.

Constructor & Destructor Documentation

◆ AutoParameters() [1/2]

template<typename Derived, typename Base = ObjectHandle>
ScriptInterface::AutoParameters< Derived, Base >::AutoParameters ( )
protecteddefault

◆ AutoParameters() [2/2]

template<typename Derived, typename Base = ObjectHandle>
ScriptInterface::AutoParameters< Derived, Base >::AutoParameters ( std::vector< AutoParameter > && params)
inlineexplicitprotected

Definition at line 114 of file AutoParameters.hpp.

◆ ~AutoParameters()

template<typename Derived, typename Base = ObjectHandle>
ScriptInterface::AutoParameters< Derived, Base >::~AutoParameters ( )
overrideprotecteddefault

Member Function Documentation

◆ add_parameters()

◆ do_set_parameter()

◆ get_parameter()

◆ get_parameter_insertion_order()

template<typename Derived, typename Base = ObjectHandle>
auto const & ScriptInterface::AutoParameters< Derived, Base >::get_parameter_insertion_order ( ) const
inlineprotected

Definition at line 137 of file AutoParameters.hpp.

◆ has_parameter()

template<typename Derived, typename Base = ObjectHandle>
bool ScriptInterface::AutoParameters< Derived, Base >::has_parameter ( std::string const & name) const
inlineoverrideprotectedvirtual

Reimplemented from ScriptInterface::ObjectHandle.

Definition at line 119 of file AutoParameters.hpp.

◆ serialize_parameters()

template<typename Derived, typename Base = ObjectHandle>
std::vector< std::pair< std::string, Variant > > ScriptInterface::AutoParameters< Derived, Base >::serialize_parameters ( ) const
inlinefinalvirtual

Reimplemented from ScriptInterface::ObjectHandle.

Definition at line 165 of file AutoParameters.hpp.

◆ valid_parameters()

template<typename Derived, typename Base = ObjectHandle>
std::vector< std::string_view > ScriptInterface::AutoParameters< Derived, Base >::valid_parameters ( ) const
inlinefinalvirtual

Reimplemented from ScriptInterface::ObjectHandle.

Reimplemented in ScriptInterface::Interactions::InteractionPotentialInterface< CoreIA >, ScriptInterface::Interactions::InteractionPotentialInterface<::BMHTF_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::Buckingham_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::DPD_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::Gaussian_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::GayBerne_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::Hat_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::Hertzian_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::LJ_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::LJcos2_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::LJcos_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::LJGen_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::Morse_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::SmoothStep_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::SoftSphere_Parameters >, ScriptInterface::Interactions::InteractionPotentialInterface<::TabulatedPotential >, ScriptInterface::Interactions::InteractionPotentialInterface<::Thole_Parameters >, and ScriptInterface::Interactions::InteractionPotentialInterface<::WCA_Parameters >.

Definition at line 141 of file AutoParameters.hpp.


The documentation for this class was generated from the following file: