31 #ifndef DRAIN_BEANLIKE_H_
32 #define DRAIN_BEANLIKE_H_
42 #include <drain/Log.h>
43 #include <drain/StringBuilder.h>
46 #include "ReferenceMap.h"
69 const std::string &
getName()
const {
return name; };
80 bool hasParameters()
const {
81 return !parameters.empty();
87 if (parameters.hasKey(p))
90 throw std::runtime_error(p +
": no such parameter (BeanLike::getParameter)");
95 const ReferenceMap & getParameters()
const {
return parameters; };
98 ReferenceMap & getParameters() {
return parameters; };
103 void setParametersFromEntries(
const F & args){
105 ReferenceMap & parameters = getParameters();
106 std::stringstream sstr;
108 for (
const auto & entry: args){
109 parameters[entry.first] = entry.second;
115 sstr << entry.first <<
'=' << entry.second;
133 setParametersFromEntries(args);
164 void setParameters(
const std::string &p,
char assignmentSymbol=
'=',
char separatorSymbol=0){
165 parameters.setValues(p, assignmentSymbol, separatorSymbol);
176 setParametersFromEntries(args);
189 setParametersFromEntries(args);
199 parameters[p].assignCastable(value);
209 parameters[p].assignCastable(value);
227 parameters[p] = value;
236 void setParameter(
const std::string &p, std::initializer_list<F> value){
237 parameters[p] = value;
246 parameters.importMap(b.getParameters());
253 std::ostream & toStream(std::ostream & ostr,
bool compact =
true)
const;
266 BeanLike(
const BeanLike & b) : name(b.name), description(b.description){
272 BeanLike(
const std::string & name,
const std::string & description=
"") : name(name), description(description) {
279 const std::string name;
281 const std::string description;
283 ReferenceMap parameters;
299 std::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:60
F getParameter(const std::string &p) const
Gets a single parameter.
Definition: BeanLike.h:86
void setParameter(const std::string &p, const VariableT< T > &value)
Definition: BeanLike.h:208
void setParameters(const std::map< std::string, T > &args)
Set parameters.
Definition: BeanLike.h:175
void setParameter(const std::string &p, std::initializer_list< F > value)
Sets a single parameter.
Definition: BeanLike.h:236
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:164
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition: BeanLike.h:131
void setParameters(const SmartMap< T > &args)
Set parameters.
Definition: BeanLike.h:188
void setParameter(const std::string &p, const F &value)
Sets a single parameter.
Definition: BeanLike.h:226
void setParameter(const std::string &p, const Castable &value)
Sets a single parameter.
Definition: BeanLike.h:198
virtual void storeLastArguments(const std::string &p)
Called after setParameters()
Definition: BeanLike.h:287
virtual const std::string & getName() const
Return the name of an instance.
Definition: BeanLike.h:69
virtual const std::string & getDescription() const
Return a brief description.
Definition: BeanLike.h:74
virtual void updateBean() const
Called after setParameters()
Definition: BeanLike.h:291
Definition: Castable.h:76
Definition: ReferenceMap.h:207
@ RESERVE
Definition: ReferenceMap.h:385
A base class for smart maps providing methods for importing and exporting values, among others.
Definition: SmartMap.h:66
Definition: StringBuilder.h:58
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition: VariableT.h:87
Definition: DataSelector.cpp:1277