41#include "drain/util/BeanLike.h"
42#include "drain/util/ReferenceMap.h"
62 Command(
const Command & cmd) : section(cmd.section), lastParameters(cmd.lastParameters){
78 const std::string & getDescription()
const = 0;
95 std::stringstream sstr;
97 for (
const auto & entry: args){
98 parameters[entry.first] = entry.second;
104 sstr << entry.first <<
'=' << entry.second;
106 lastParameters = sstr.str();
117 getParameters()[key] = value;
118 std::stringstream sstr;
119 sstr << key <<
'=' << value;
120 lastParameters = sstr.str();
128 bool hasParameters()
const {
130 Logger mout(__FILE__, __FUNCTION__);
135 const ReferenceMap::const_iterator it = params.begin();
136 if (it == params.end())
139 return it->second.getType() !=
typeid(void);
157 void run(
const std::string & params =
"") final {
190 const std::string & getLastParameters()
const {
191 return lastParameters;
199 void getRelatedCommands(std::ostream & ostr = std::cout)
const;
220 relatedCommands.insert(cmdKey);
233 void parameterKeysToStream(std::ostream & ostr)
const {
234 parameterKeysToStream(ostr, getParameters().getKeyList(), getParameters().separator);
237 void parameterKeysToStream(std::ostream & ostr,
const std::list<std::string> & list,
char sep=
',')
const;
243 std::set<std::string> relatedCommands;
255 ReferenceMap & getParameters() = 0;
258 std::string lastParameters;
263std::ostream & operator<<(std::ostream & ostr,
const Command &cmd){
264 ostr << cmd.getName();
265 if (cmd.hasParameters()){
266 ostr <<
' ' << cmd.getParameters();
327template <
class B,
class B2=B>
336 BeanCommand(
const std::string & name,
const std::string & description) : bean(name, description){
355 const bean_t & getBean()
const {
369 return getBean().getName();
373 const std::string & getDescription() const final {
374 return getBean().getDescription();
379 return getBean().getParameters();
386 return getBean().getParameters();
447 BasicCommand(
const std::string & name,
const std::string & description);
466template <
class T = std::
string>
473 SimpleCommand(
const std::string & name,
const std::string & description,
474 const std::string & key=
"value",
const T & initValue = T(),
const std::string & unit =
"") :
BasicCommand(name, description) {
477 getParameters().link(key, value = initValue, unit);
480 Context & ctx = getContext<Context>();
482 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
491 const std::string & key, std::initializer_list<S> l ,
const std::string & unit =
"") :
BasicCommand(name, description) {
494 getParameters().link(key, value);
497 Context & ctx = getContext<Context>();
499 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
506 getParameters().
copyStruct(cmd.getParameters(), cmd, *
this);
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:443
Retrieves bean dynamically for each call.
Definition Command.h:328
const std::string & getName() const final
Returns the class name of this command, like "CmdVerbose".
Definition Command.h:368
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition Command.h:53
int cmd_section_type
Definition Command.h:180
void linkRelated(const std::string &cmdKey) const
Add related command(s), to appear in help after "See-also:" phrase.
Definition Command.h:219
virtual const std::string & getName() const =0
Returns the class name of this command, like "CmdVerbose".
virtual void run(const std::string ¶ms="") final
Description of result, comparable to a return type of a function. ?
Definition Command.h:157
virtual void parametersToStream(std::ostream &ostr, const std::string &indent=" ") const
By default, the "true", technical parameters.
Definition Command.cpp:132
virtual void exec() const
Run the command with current parameter values.
Definition Command.h:173
void setParameter(const std::string &key, const T &value)
Set a value to a single parameter.
Definition Command.h:116
virtual void setParameters(const std::string &args) final
Definition Command.cpp:40
virtual void update()
Optional method for preparing command to execution.
Definition Command.h:168
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
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:415
A single-parameter command.
Definition Command.h:467
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:490
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:81
Definition DataSelector.cpp:1277
Definition Sprinter.h:136