40 #include <drain/Log.h>
41 #include "drain/util/BeanLike.h"
42 #include "drain/util/ReferenceMap.h"
43 #include "drain/util/VariableMap.h"
73 const std::string & getName()
const = 0;
76 const std::string & getDescription()
const = 0;
92 void setParameters(
const std::string & args)
final;
119 std::stringstream sstr;
121 for (
const auto & entry: args){
122 parameters[entry.first] = entry.second;
128 sstr << entry.first <<
'=' << entry.second;
130 lastParameters = sstr.str();
141 getParameters()[key] = value;
142 std::stringstream sstr;
143 sstr << key <<
'=' << value;
144 lastParameters = sstr.str();
149 Command & addSection(drain::Flagger::ivalue_t i){
171 bool hasParameters()
const {
173 Logger mout(__FILE__, __FUNCTION__);
178 const ReferenceMap::const_iterator it = params.begin();
179 if (it == params.end())
182 return it->second.getType() !=
typeid(void);
188 static const std::string empty;
202 void run(
const std::string & params =
""){
203 setParameters(params);
223 return lastParameters;
231 std::string lastParameters;
237 std::ostream & operator<<(std::ostream & ostr,
const Command &cmd){
238 ostr << cmd.getName();
239 if (cmd.hasParameters()){
240 ostr <<
' ' << cmd.getParameters();
301 template <
class B,
class B2=B>
310 BeanCommand(
const std::string & name,
const std::string & description) : bean(name, description){
329 const bean_t & getBean()
const {
342 const std::string & getName()
const final {
343 return getBean().getName();
347 const std::string & getDescription()
const final {
348 return getBean().getDescription();
353 return getBean().getParameters();
360 return getBean().getParameters();
421 BasicCommand(
const std::string & name,
const std::string & description);
500 template <
class T = std::
string>
507 SimpleCommand(
const std::string & name,
const std::string & description,
508 const std::string & key=
"value",
const T & initValue = T(),
const std::string & unit =
"") :
BasicCommand(name, description) {
511 getParameters().link(key, value = initValue, unit);
514 Context & ctx = getContext<Context>();
516 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
525 const std::string & key, std::initializer_list<S> l ,
const std::string & unit =
"") :
BasicCommand(name, description) {
528 getParameters().link(key, value);
531 Context & ctx = getContext<Context>();
533 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
540 getParameters().
copyStruct(cmd.getParameters(), cmd, *
this);
Simple implementation of Command: adds name , description and parameters .
Definition: Command.h:417
Retrieves bean dynamically for each call.
Definition: Command.h:302
Definition: Command.h:391
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition: Command.h:54
virtual void exec() const
Run the command with current parameter values.
Definition: Command.h:194
void setParameter(const std::string &key, const T &value)
Set a value to a single parameter.
Definition: Command.h:140
int section
Definition: Command.h:213
virtual const std::string & getType() const
Description of result, comparable to a return type of a function. ?
Definition: Command.h:187
virtual void update()
Optional method for preparing command to execution.
Definition: Command.h:159
const std::string & getLastParameters() const
After executing this command run a routine, if defined.
Definition: Command.h:222
virtual void run(const std::string ¶ms="")
Convenience. Sets parameters and executes the command.
Definition: Command.h:202
Definition: Context.h:245
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Definition: ReferenceMap.h:207
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:399
A single-parameter command.
Definition: Command.h:501
SimpleCommand(const std::string &name, const std::string &description, const std::string &key, std::initializer_list< S > l, const std::string &unit="")
Constuctor designer for SimpleCommand<Unituple<> > .
Definition: Command.h:524
A base class for smart maps providing methods for importing and exporting values, among others.
Definition: SmartMap.h:66
char separator
Default character used for splitting input and output. See setValues.
Definition: SmartMap.h:85
Definition: DataSelector.cpp:1277
Definition: Sprinter.h:137