41#include "drain/util/BeanLike.h"
42#include "drain/util/Flags.h"
43#include "drain/util/ReferenceMap.h"
44#include "drain/util/VariableMap.h"
64 Command(
const Command & cmd) : section(cmd.section), lastParameters(cmd.lastParameters){
80 const std::string & getDescription()
const = 0;
99 std::stringstream sstr;
101 for (
const auto & entry: args){
102 parameters[entry.first] = entry.second;
108 sstr << entry.first <<
'=' << entry.second;
110 lastParameters = sstr.str();
121 getParameters()[key] = value;
122 std::stringstream sstr;
123 sstr << key <<
'=' << value;
124 lastParameters = sstr.str();
132 bool hasParameters()
const {
134 Logger mout(__FILE__, __FUNCTION__);
139 const ReferenceMap::const_iterator it = params.begin();
140 if (it == params.end())
143 return it->second.getType() !=
typeid(void);
161 void run(
const std::string & params =
"") final {
194 const std::string & getLastParameters()
const {
195 return lastParameters;
200 void help(std::ostream & ostr = std::cout,
bool DETAILED=
false)
const;
203 void getRelatedCommands(std::ostream & ostr = std::cout)
const;
230 Command & linkRelatedCommands(){
239 std::string lastParameters;
244std::ostream & operator<<(std::ostream & ostr,
const Command &cmd){
245 ostr << cmd.getName();
246 if (cmd.hasParameters()){
247 ostr <<
' ' << cmd.getParameters();
308template <
class B,
class B2=B>
317 BeanCommand(
const std::string & name,
const std::string & description) : bean(name, description){
336 const bean_t & getBean()
const {
350 return getBean().getName();
354 const std::string & getDescription() const final {
355 return getBean().getDescription();
360 return getBean().getParameters();
367 return getBean().getParameters();
428 BasicCommand(
const std::string & name,
const std::string & description);
447template <
class T = std::
string>
454 SimpleCommand(
const std::string & name,
const std::string & description,
455 const std::string & key=
"value",
const T & initValue = T(),
const std::string & unit =
"") :
BasicCommand(name, description) {
458 getParameters().link(key, value = initValue, unit);
461 Context & ctx = getContext<Context>();
463 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
472 const std::string & key, std::initializer_list<S> l ,
const std::string & unit =
"") :
BasicCommand(name, description) {
475 getParameters().link(key, value);
478 Context & ctx = getContext<Context>();
480 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
487 getParameters().
copyStruct(cmd.getParameters(), cmd, *
this);
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:424
Retrieves bean dynamically for each call.
Definition Command.h:309
const std::string & getName() const final
Returns the class name of this command, like "CmdVerbose".
Definition Command.h:349
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition Command.h:55
int cmd_section_type
Definition Command.h:184
std::set< std::string > relatedCommands
Add related command(s), to appear in help after "See-also:" phrase.
Definition Command.h:223
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:161
virtual void exec() const
Run the command with current parameter values.
Definition Command.h:177
void setParameter(const std::string &key, const T &value)
Set a value to a single parameter.
Definition Command.h:120
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:172
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
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:448
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:471
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:85
Definition DataSelector.cpp:1277
Definition Sprinter.h:137