41#include "drain/util/BeanLike.h"
42#include "drain/util/ReferenceMap.h"
83 const std::string & getDescription()
const = 0;
101 std::stringstream sstr;
103 for (
const auto & entry: args){
104 parameters[entry.first] = entry.second;
110 sstr << entry.first <<
'=' << entry.second;
123 getParameters()[key] = value;
124 std::stringstream sstr;
125 sstr << key <<
'=' << value;
137 Logger mout(__FILE__, __FUNCTION__);
142 const ReferenceMap::const_iterator it = params.begin();
143 if (it == params.end())
146 return it->second.getType() !=
typeid(void);
164 void run(
const std::string & params =
"") final {
249 void parameterKeysToStream(std::ostream & ostr,
const std::list<std::string> & list,
char sep=
',')
const;
275std::ostream & operator<<(std::ostream & ostr,
const Command &cmd){
278 ostr <<
' ' << cmd.getParameters();
339template <
class B,
class B2=B>
349 BeanCommand(
const std::string & name,
const std::string & description) :
bean(name, description){
391 return getBean().getDescription();
397 return getBean().getParameters();
404 return getBean().getParameters();
466 BasicCommand(
const std::string & name,
const std::string & description);
486template <
class T = std::
string>
495 const std::string & key=
"value",
const T & initValue = T(),
const std::string & unit =
"") :
BasicCommand(name, description) {
501 Context & ctx = getContext<Context>();
503 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
512 const std::string & key, std::initializer_list<S> l ,
const std::string & unit =
"") :
BasicCommand(name, description) {
518 Context & ctx = getContext<Context>();
520 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:461
BasicCommand(const BasicCommand &cmd)
Copy constructor.
Definition Command.h:471
Retrieves bean dynamically for each call.
Definition Command.h:340
virtual const bean_t & getBean() const
Returns the wrapped bean.
Definition Command.h:370
virtual bean_t & getBean()
Returns the wrapped bean.
Definition Command.h:376
const std::string & getName() const final
Returns the command name.
Definition Command.h:384
virtual const drain::ReferenceMap & getParameters() const
Returns the command parameters.
Definition Command.h:396
const std::string & getDescription() const final
Returns the command description.
Definition Command.h:390
BeanCommand(const BeanCommand &cmd)
Copy constructor.
Definition Command.h:353
BeanCommand(const std::string &name, const std::string &description)
Constructor.
Definition Command.h:349
B bean_t
The bean type.
Definition Command.h:362
BeanCommand(B &b)
Constructor wrapping an existing bean.
Definition Command.h:359
B2 bean
The wrapped bean instance.
Definition Command.h:365
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:58
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:187
std::set< std::string > relatedCommands
Set of related command keys shown in help.
Definition Command.h:255
void linkRelated(const std::string &cmdKey) const
Add related command(s), to appear in help after "See-also:" phrase.
Definition Command.h:229
std::string lastParameters
String record of the last argument(s) passed.
Definition Command.h:270
virtual const std::string & getName() const =0
Returns the class name of this command, like "CmdVerbose".
bool hasParameters() const
Returns true if this command has parameters.
Definition Command.h:135
virtual void run(const std::string ¶ms="") final
Description of result, comparable to a return type of a function. ?
Definition Command.h:164
cmd_section_type section
Section bitmask; zero means hidden from help.
Definition Command.h:188
static const SprinterLayout cmdArgLayout
Layout flag for command argument handling.
Definition Command.h:89
virtual void getRelatedCommands(std::ostream &ostr=std::cout) const
Writes related command names to stream.
Definition Command.cpp:166
virtual void parameterKeysToStream(std::ostream &ostr) const
Writes parameter keys to stream.
Definition Command.h:244
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:180
void setParameter(const std::string &key, const T &value)
Set a value to a single parameter.
Definition Command.h:122
void setParameters(const T &args)
Sets parameters from argument.
Definition Command.h:98
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:175
Command(const Command &cmd)
Copy constructor.
Definition Command.h:67
Command & addSection(int i)
Marks this command as belonging to section i.
Definition Command.h:192
const std::string & getLastParameters() const
Returns the parameters from the last execution.
Definition Command.h:199
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:440
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
A single-parameter command.
Definition Command.h:487
SimpleCommand(const SimpleCommand &cmd)
Copy constructor.
Definition Command.h:526
SimpleCommand(const std::string &name, const std::string &description, const std::string &key="value", const T &initValue=T(), const std::string &unit="")
Constructor.
Definition Command.h:494
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:511
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:81
Definition Sprinter.h:136