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::span< const boost::string_ref > 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
 
ObjectHandleoperator= (ObjectHandle const &)=delete
 
virtual ~ObjectHandle ()=default
 
boost::string_ref name () const
 
Contextcontext () 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.
 
auto get_valid_parameters () const
 
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)
 
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;
};
Bind parameters in the script interface.

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;
};
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.
Definition Variant.hpp:67

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

Definition at line 93 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

Member Function Documentation

◆ add_parameters()

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

Definition at line 115 of file AutoParameters.hpp.

References params.

Referenced by ScriptInterface::AutoParameters< Derived, Base >::AutoParameters(), ScriptInterface::Thermostat::Brownian::Brownian(), ScriptInterface::Coulomb::CoulombMMM1D::CoulombMMM1D(), ScriptInterface::Coulomb::CoulombP3M< Architecture >::CoulombP3M(), ScriptInterface::Coulomb::CoulombScafacos::CoulombScafacos(), ScriptInterface::Coulomb::DebyeHueckel::DebyeHueckel(), ScriptInterface::Dipoles::DipolarDirectSum::DipolarDirectSum(), ScriptInterface::Dipoles::DipolarLayerCorrection::DipolarLayerCorrection(), ScriptInterface::Dipoles::DipolarP3M< Architecture >::DipolarP3M(), ScriptInterface::Dipoles::DipolarScafacos::DipolarScafacos(), ScriptInterface::walberla::EKSpecies::EKSpecies(), ScriptInterface::Coulomb::ElectrostaticLayerCorrection::ElectrostaticLayerCorrection(), ScriptInterface::Interactions::InteractionBMHTF::InteractionBMHTF(), ScriptInterface::Interactions::InteractionBuckingham::InteractionBuckingham(), ScriptInterface::Interactions::InteractionDPD::InteractionDPD(), ScriptInterface::Interactions::InteractionGaussian::InteractionGaussian(), ScriptInterface::Interactions::InteractionGayBerne::InteractionGayBerne(), ScriptInterface::Interactions::InteractionHat::InteractionHat(), ScriptInterface::Interactions::InteractionHertzian::InteractionHertzian(), ScriptInterface::Interactions::InteractionLJ::InteractionLJ(), ScriptInterface::Interactions::InteractionLJcos::InteractionLJcos(), ScriptInterface::Interactions::InteractionLJcos2::InteractionLJcos2(), ScriptInterface::Interactions::InteractionLJGen::InteractionLJGen(), ScriptInterface::Interactions::InteractionMorse::InteractionMorse(), ScriptInterface::Interactions::InteractionSmoothStep::InteractionSmoothStep(), ScriptInterface::Interactions::InteractionSoftSphere::InteractionSoftSphere(), ScriptInterface::Interactions::InteractionTabulated::InteractionTabulated(), ScriptInterface::Interactions::InteractionThole::InteractionThole(), ScriptInterface::Interactions::InteractionWCA::InteractionWCA(), ScriptInterface::Thermostat::IsotropicNpt::IsotropicNpt(), ScriptInterface::Thermostat::Langevin::Langevin(), ScriptInterface::walberla::LBFluid::LBFluid(), ScriptInterface::Thermostat::LBThermostat::LBThermostat(), and ScriptInterface::Coulomb::ReactionField::ReactionField().

◆ do_set_parameter()

template<typename Derived , typename Base = ObjectHandle>
void ScriptInterface::AutoParameters< Derived, Base >::do_set_parameter ( const std::string &  name,
const Variant value 
)
inlinefinalvirtual

Reimplemented from ScriptInterface::ObjectHandle.

Definition at line 152 of file AutoParameters.hpp.

References ScriptInterface::ObjectHandle::name().

◆ get_parameter()

template<typename Derived , typename Base = ObjectHandle>
Variant ScriptInterface::AutoParameters< Derived, Base >::get_parameter ( const std::string &  name) const
inlinefinalvirtual

Reimplemented from ScriptInterface::ObjectHandle.

Definition at line 144 of file AutoParameters.hpp.

References ScriptInterface::ObjectHandle::name().

◆ 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 129 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 163 of file AutoParameters.hpp.

References ScriptInterface::ObjectHandle::get_parameters(), and params.

◆ valid_parameters()

template<typename Derived , typename Base = ObjectHandle>
std::span< const boost::string_ref > ScriptInterface::AutoParameters< Derived, Base >::valid_parameters ( ) const
inlinefinalvirtual

Reimplemented from ScriptInterface::ObjectHandle.

Definition at line 133 of file AutoParameters.hpp.


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