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;
 
   97        std::stringstream sstr;
 
   99        for (
const auto & entry: args){
 
  100            parameters[entry.first] = entry.second;
 
  106            sstr << entry.first << 
'=' << entry.second;
 
  108        lastParameters = sstr.str();
 
  119        getParameters()[key] = value;
 
  120        std::stringstream sstr;
 
  121        sstr << key << 
'=' << value;
 
  122        lastParameters = sstr.str();
 
 
  130    bool hasParameters()
 const {
 
  132        Logger mout(__FILE__, __FUNCTION__);
 
  137        const ReferenceMap::const_iterator it = params.begin();
 
  138        if (it == params.end()) 
 
  141            return it->second.getType() != 
typeid(void);  
 
  159    void run(
const std::string & params = 
"") final {
 
 
  192    const std::string & getLastParameters()
 const {
 
  193        return lastParameters;
 
  201    void getRelatedCommands(std::ostream & ostr = std::cout) 
const;
 
  222        relatedCommands.insert(cmdKey);
 
 
  235    void parameterKeysToStream(std::ostream & ostr)
 const {
 
  236        parameterKeysToStream(ostr, getParameters().getKeyList(), getParameters().separator);
 
  239    void parameterKeysToStream(std::ostream & ostr, 
const std::list<std::string> & list, 
char sep=
',') 
const;
 
  245    std::set<std::string> relatedCommands;
 
  257    ReferenceMap & getParameters() = 0;
 
  260    std::string lastParameters;
 
 
  265std::ostream & operator<<(std::ostream & ostr, 
const Command &cmd){
 
  266    ostr << cmd.getName();
 
  267    if (cmd.hasParameters()){
 
  268        ostr << 
' ' << cmd.getParameters(); 
 
  329template <
class B, 
class B2=B>
 
  338    BeanCommand(
const std::string & name, 
const std::string & description) : bean(name, description){
 
  357    const bean_t & getBean()
 const  { 
 
  371        return getBean().getName();
 
 
  375    const std::string & getDescription() const final {
 
  376        return getBean().getDescription();
 
  381        return getBean().getParameters();
 
  388        return getBean().getParameters();
 
 
  449    BasicCommand(
const std::string & name, 
const std::string & description);
 
 
  468template <
class T = std::
string>
 
  475    SimpleCommand(
const std::string & name, 
const std::string & description,
 
  476            const std::string & key=
"value", 
const T & initValue = T(), 
const std::string & unit = 
"") : 
BasicCommand(name, description) {
 
  479        getParameters().link(key, value = initValue, unit);
 
  482            Context & ctx = getContext<Context>();
 
  484            mout.
warn(
"Empty value key in command ", name, 
" (", description, 
")");
 
  493            const std::string & key, std::initializer_list<S> l , 
const std::string & unit = 
"") : 
BasicCommand(name, description) {
 
  496        getParameters().link(key, value);
 
  499            Context & ctx = getContext<Context>();
 
  501            mout.
warn(
"Empty value key in command ", name, 
" (", description, 
")");
 
 
  508        getParameters().
copyStruct(cmd.getParameters(), cmd, *
this);
 
 
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:445
Retrieves bean dynamically for each call.
Definition Command.h:330
const std::string & getName() const final
Returns the class name of this command, like "CmdVerbose".
Definition Command.h:370
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:182
void linkRelated(const std::string &cmdKey) const
Add related command(s), to appear in help after "See-also:" phrase.
Definition Command.h:221
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:159
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:175
void setParameter(const std::string &key, const T &value)
Set a value to a single parameter.
Definition Command.h:118
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:170
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:407
A single-parameter command.
Definition Command.h:469
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:492
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:85
Definition DataSelector.cpp:1277
Definition Sprinter.h:137