35#ifndef COMMAND_BANK_H_
36#define COMMAND_BANK_H_
40#include "drain/util/Bank.h"
41#include "drain/util/Flags.h"
48typedef int bank_section_t;
60 typedef data_t command_t;
83 template <
class D,
char PREFIX=0>
84 D & addExternal(
const D & entry,
char alias = 0){
85 std::string key(entry.getName());
93 D & addExternal(
char PREFIX,
const D & entry,
char alias=0){
94 std::string key(entry.getName());
99 template <
class D,
char PREFIX=0>
101 D & addExternal(
const D & entry,
const std::string & key,
char alias = 0){
141 bool scriptify(
const std::string & arg,
const std::string & argNext,
Script & script)
const;
157 void tokenize(
const std::string & cmdLine, std::list<std::string> & args);
166 append(script, ctx, prog);
171 void remove(
Program & prog)
const;
174 void run(
const std::string & cmd,
const std::string & params,
Context & ctx);
185 void help(std::ostream & ostr = std::cout);
188 void help(FlagResolver::ivalue_t sectionFilter, std::ostream & ostr = std::cout);
191 void help(
const std::string & key, std::ostream & ostr = std::cout);
194 void info(
const std::string & key,
const command_t & cmd, std::ostream & ostr = std::cout,
bool detailed=
true)
const ;
200 const std::string &
resolveFull(
const key_t & key)
const;
203 void exportStatus(std::map<std::string, T> & statusMap)
const;
212 void setScriptTriggerFlag(bank_section_t sectionFlag){
276 template <
class ...TT>
277 void linkRelatedCommands(
const TT & ... cmds){
278 std::set<std::string> cmdList;
279 linkRelatedCommandList(cmdList, cmds...);
282 void linkRelatedCommandList(
const std::set<std::string> & cmdList);
294 template <
class ...TT>
295 void linkRelatedCommandList(std::set<std::string> & cmdList,
const std::string & cmd,
const TT & ... cmds){
297 linkRelatedCommandList(cmdList, cmds...);
301 template <
class ...TT>
302 void linkRelatedCommandList(std::set<std::string> & cmdList,
const char *cmd,
const TT & ... cmds){
304 linkRelatedCommandList(cmdList, cmds...);
332void CommandBank::exportStatus(std::map<std::string, T> & statusMap)
const {
333 for (map_t::const_iterator it = this->begin(); it!=this->end(); ++it){
334 statusMap[it->first] = it->second->getSource().getParameters().getValues();
A Bank with additional support for brief, single char keys.
Definition Bank.h:314
Container and execution tools for commands derived from Command.
Definition CommandBank.h:56
void scriptify(int argc, const char **argv, Script &script) const
Convert program arguments a script. Like in main(), actual command arguments start from 1.
Definition CommandBank.cpp:180
void append(const Script &script, Program &prog) const
Converts command strings to executable command objects, appending them to a program.
Definition CommandBank.cpp:140
void setNotFoundHandlerCmdKey(const std::string &s)
Set command to be executed when a command - argument with leading hyphen(s) - is not found.
Definition CommandBank.h:237
std::string notFoundHandlerCmdKey
If defined, the command - key not getName() - to which all unresolved commands are directed.
Definition CommandBank.h:230
std::string execFileCmd
Command for reading and executing commands from a file in the current (running) context.
Definition CommandBank.h:273
static std::set< std::string > & trimWords()
Words that are moved from class name prior to composing a command name.
Definition CommandBank.cpp:57
void flushRoutine(Script &script, Context &ctx, Program &prog)
Append routine to program, and clear routine.
Definition CommandBank.h:165
bank_section_t scriptTriggerFlag
Member and methods for special commands.
Definition CommandBank.h:208
const std::string & resolveFull(const key_t &key) const
Given an alias or a long key, possibly prefixed by hyphens, return the long key if a command exists.
Definition CommandBank.cpp:1073
void run(const std::string &cmd, const std::string ¶ms, Context &ctx)
Run a single command.
Definition CommandBank.cpp:494
void readFile(const std::string &filename, Program &prog) const
Definition CommandBank.cpp:384
std::string defaultCmdKey
Command that is used, if a plain argument is given.
Definition CommandBank.h:221
void help(std::ostream &ostr=std::cout)
Basic help dump, displays help commands to proceed.
Definition CommandBank.cpp:860
std::string scriptCmd
Command for storing a routine.
Definition CommandBank.h:242
void info(const std::string &key, const command_t &cmd, std::ostream &ostr=std::cout, bool detailed=true) const
Checked key and respective command.
Definition CommandBank.cpp:960
void readFileTXT(const std::string &filename, Script &script) const
Include commands from file, inserting them before iterator.
Definition CommandBank.cpp:448
void setScriptFileCmd(const std::string &s)
Set command for reading and executing commands from a file in the current (running) context.
Definition CommandBank.h:268
static void deriveCmdName(std::string &name, char prefix=0)
Given a command class name like MyFileReadCommand, derives a respective command line option ("myFileR...
Definition CommandBank.cpp:62
void setScriptCmd(const std::string &s)
Set command for storing a routine.
Definition CommandBank.h:249
void setDefaultCmdKey(const std::string &s)
Set command - key, not getName() - that is used if a plain argument is given.
Definition CommandBank.h:225
Sequence consisting of Command:s retrieved from a CommandBank.
Definition Program.h:101
A tool for expanding variables embedded in a std::string to literals.
Definition StringMapper.h:275
Definition DataSelector.cpp:1277
CommandBank & getCommandBank()
Global program command registry. Optional utility.
Definition CommandBank.cpp:51