35#ifndef COMMAND_BANK_H_
36#define COMMAND_BANK_H_
40#include "drain/util/Bank.h"
41#include "drain/util/StringMapper.h"
48typedef int bank_section_t;
60 typedef data_t command_t;
80 template <
class D,
char PREFIX=0>
81 D & addExternal(
const D & entry,
char alias = 0){
82 std::string key(entry.getName());
90 D & addExternal(
char PREFIX,
const D & entry,
char alias=0){
91 std::string key(entry.getName());
96 template <
class D,
char PREFIX=0>
98 D & addExternal(
const D & entry,
const std::string & key,
char alias = 0){
138 bool scriptify(
const std::string & arg,
const std::string & argNext,
Script & script)
const;
154 void tokenize(
const std::string & cmdLine, std::list<std::string> & args);
163 append(script, ctx, prog);
168 void remove(
Program & prog)
const;
193 void traverseLoops(
Context & ctx,
ClonerBase<Context> & contextCloner, Loop::loopStack::const_iterator it, Loop::loopStack::const_iterator itEnd);
197 void help(std::ostream & ostr = std::cout);
200 void help(FlagResolver::ivalue_t sectionFilter, std::ostream & ostr = std::cout);
203 void help(
const std::string & key, std::ostream & ostr = std::cout);
206 void info(
const std::string & key,
const command_t & cmd, std::ostream & ostr = std::cout,
bool detailed=
true)
const ;
215 void exportStatus(std::map<std::string, T> & statusMap)
const;
224 void setScriptTriggerFlag(bank_section_t sectionFlag){
288 template <
class ...TT>
289 void linkRelatedCommands(
const TT & ... cmds){
290 std::set<std::string> cmdList;
300 template <
class ...TT>
301 void linkRelatedCommandList(std::set<std::string> & cmdList,
const std::string & cmd,
const TT & ... cmds){
307 template <
class ...TT>
317void CommandBank::exportStatus(std::map<std::string, T> & statusMap)
const {
318 for (map_t::const_iterator it = this->begin(); it!=this->end(); ++it){
319 statusMap[it->first] = it->second->getSource().getParameters().getValues();
A Bank with additional support for brief, single char keys.
Definition Bank.h:315
K key_t
Public key type. (Key type used in the public interface.)
Definition Bank.h:68
Container and execution tools for commands derived from Command.
Definition CommandBank.h:56
void linkRelatedCommandList(const std::set< std::string > &cmdList)
Adds command keys, intelinking all the commands in the list.
Definition CommandBank.cpp:1023
void commitAddedCommands(Context &ctx, Program &prog, Program::iterator it) const
Run a single command.
Definition CommandBank.cpp:499
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:183
void append(const Script &script, Program &prog) const
Converts command strings to executable command objects, appending them to a program.
Definition CommandBank.cpp:141
void run(const std::string &key, Command &cmd, Context &ctx) const
Run a single command.
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:249
std::string notFoundHandlerCmdKey
If defined, the command - key not getName() - to which all unresolved commands are directed.
Definition CommandBank.h:242
std::string execFileCmd
Command for reading and executing commands from a file in the current (running) context.
Definition CommandBank.h:285
static std::set< std::string > & trimWords()
Words that are moved from class name prior to composing a command name.
Definition CommandBank.cpp:58
void flushRoutine(Script &script, Context &ctx, Program &prog)
Append routine to program, and clear routine.
Definition CommandBank.h:162
bank_section_t scriptTriggerFlag
Member and methods for special commands.
Definition CommandBank.h:220
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:1108
void readFile(const std::string &filename, Program &prog) const
Definition CommandBank.cpp:362
std::string defaultCmdKey
Command that is used, if a plain argument is given.
Definition CommandBank.h:233
void help(std::ostream &ostr=std::cout)
Basic help dump, displays help commands to proceed.
Definition CommandBank.cpp:949
std::string scriptCmd
Command for storing a routine.
Definition CommandBank.h:254
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:1054
void readFileTXT(const std::string &filename, Script &script) const
Include commands from file, inserting them before iterator.
Definition CommandBank.cpp:426
void setScriptFileCmd(const std::string &s)
Set command for reading and executing commands from a file in the current (running) context.
Definition CommandBank.h:280
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:63
void setScriptCmd(const std::string &s)
Set command for storing a routine.
Definition CommandBank.h:261
void setDefaultCmdKey(const std::string &s)
Set command - key, not getName() - that is used if a plain argument is given.
Definition CommandBank.h:237
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition Command.h:53
Sequence consisting of Command:s retrieved from a CommandBank.
Definition Program.h:52
Definition CommandSequence.h:85
Definition StringMapper.h:114
Definition DataSelector.cpp:1277
CommandBank & getCommandBank()
Global program command registry. Optional utility.
Definition CommandBank.cpp:52