31#ifndef DRAIN_BEANLIKE_H_
32#define DRAIN_BEANLIKE_H_
41#include <drain/StringBuilder.h>
44#include "ReferenceMap.h"
110 throw std::runtime_error(p +
": no such parameter (BeanLike::getParameter)");
132 std::stringstream sstr;
134 for (
const auto & entry: args){
141 sstr << entry.first <<
'=' << entry.second;
190 void setParameters(
const std::string &p,
char assignmentSymbol=
'=',
char separatorSymbol=0){
262 void setParameter(
const std::string &p, std::initializer_list<F> value){
288 std::ostream &
toStream(std::ostream & ostr,
bool compact =
true)
const;
329std::ostream & operator<<(std::ostream &ostr,
const BeanLike & bean){
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:58
const std::string description
Brief, human-readable description of this bean.
Definition BeanLike.h:309
map_t parameters
Parameters (name -> linked variable), typically linked to member variables of the derived class.
Definition BeanLike.h:313
ReferenceMap map_t
Reference map type used to store this bean's parameters (name -> linked variable).
Definition BeanLike.h:64
BeanLike(const std::string &name, const std::string &description="")
Constructor.
Definition BeanLike.h:81
virtual const std::string & getName() const
Return the name of an instance.
Definition BeanLike.h:89
virtual const std::string & getDescription() const
Return a brief description.
Definition BeanLike.h:94
F getParameter(const std::string &p) const
Gets a single parameter.
Definition BeanLike.h:106
bool hasParameters() const
Tells if any parameters have been linked (registered) for this bean.
Definition BeanLike.h:100
BeanLike(const BeanLike &b)
Copy constructor. Re-links parameters to the member variables of this (new) instance.
Definition BeanLike.h:71
BeanLike & operator=(const BeanLike &b)
Assigns the parameter values of another bean (by key) to this one's own parameters.
Definition BeanLike.h:275
void setParameter(const std::string &p, const VariableT< T > &value)
Definition BeanLike.h:234
void setParameters(const std::map< std::string, T > &args)
Set parameters.
Definition BeanLike.h:201
virtual std::ostream & toStream(std::ostream &ostr, bool compact=true) const
Prints the name, description and current parameter values.
Definition BeanLike.cpp:37
void setParameter(const std::string &p, std::initializer_list< F > value)
Sets a single parameter.
Definition BeanLike.h:262
virtual void setParameters(const std::string &p, char assignmentSymbol='=', char separatorSymbol=0)
Sets comma-separated parameters in a predetermined order "a,b,c" or by specifing them "b=2".
Definition BeanLike.h:190
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition BeanLike.h:157
map_t & getParameters()
Returns the parameter map.
Definition BeanLike.h:120
void setParameters(const SmartMap< T > &args)
Set parameters.
Definition BeanLike.h:214
void setParameter(const std::string &p, const F &value)
Sets a single parameter.
Definition BeanLike.h:252
void setParametersFromEntries(const F &args)
Sets several parameters at once from a sequence of key-value pairs.
Definition BeanLike.h:129
const map_t & getParameters() const
Returns the parameter map (const access).
Definition BeanLike.h:116
void setParameter(const std::string &p, const Castable &value)
Sets a single parameter.
Definition BeanLike.h:224
const std::string name
Name of this bean, typically also the name of the (derived) class.
Definition BeanLike.h:306
virtual void storeLastArguments(const std::string &p)
Called after setParameters()
Definition BeanLike.h:317
virtual void updateBean() const
Called after setParameters()
Definition BeanLike.h:321
Definition ReferenceMap.h:215
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition ReferenceMap.h:412
@ RESERVE
Definition ReferenceMap.h:398
A base class for smart maps providing methods for importing and exporting values, among others.
Definition SmartMap.h:62
void setValues(const std::string &entries, char assignmentChar='=', char separatorChar=0)
Sets values. If strictness==STRICTLY_CLOSED, throws exception if tries to assign a non-existing entry...
Definition SmartMap.h:299
void importMap(const std::map< std::string, S > &m)
Assign values from a map, overriding existing entries.
Definition SmartMap.h:253
Definition StringBuilder.h:58
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87