35#ifndef COMMAND_BANK_H_
36#define COMMAND_BANK_H_
40#include "drain/util/Bank.h"
41#include "drain/util/StringMapper.h"
71 typedef data_t command_t;
98 template <
class D,
char PREFIX=0>
100 std::string key(entry.getName());
113 std::string key(entry.getName());
122 template <
class D,
char PREFIX=0>
124 D &
addExternal(
const D & entry,
const std::string & key,
char alias = 0){
174 bool scriptify(
const std::string & arg,
const std::string & argNext,
Script & script)
const;
190 void tokenize(
const std::string & cmdLine, std::list<std::string> & args);
199 append(script, ctx, prog);
204 void remove(
Program & prog)
const;
229 void traverseLoops(
Context & ctx,
ClonerBase<Context> & contextCloner, Loop::loopStack::const_iterator it, Loop::loopStack::const_iterator itEnd);
233 void help(std::ostream & ostr = std::cout);
236 void help(FlagResolver::ivalue_t sectionFilter, std::ostream & ostr = std::cout);
239 void help(
const std::string & key, std::ostream & ostr = std::cout);
242 void info(
const std::string & key,
const command_t & cmd, std::ostream & ostr = std::cout,
bool detailed=
true)
const ;
251 void exportStatus(std::map<std::string, T> & statusMap)
const;
324 template <
class ...TT>
325 void linkRelatedCommands(
const TT & ... cmds){
326 std::set<std::string> cmdList;
336 template <
class ...TT>
337 void linkRelatedCommandList(std::set<std::string> & cmdList,
const std::string & cmd,
const TT & ... cmds){
343 template <
class ...TT>
353void CommandBank::exportStatus(std::map<std::string, T> & statusMap)
const {
354 for (map_t::const_iterator it = this->begin(); it!=this->end(); ++it){
355 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:67
D & addExternal(char PREFIX, const D &entry, char alias=0)
Add a command.
Definition CommandBank.h:112
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:285
std::string notFoundHandlerCmdKey
If defined, the command - key not getName() - to which all unresolved commands are directed.
Definition CommandBank.h:278
std::string execFileCmd
Command for reading and executing commands from a file in the current (running) context.
Definition CommandBank.h:321
static std::set< std::string > & trimWords()
Words that should be removed from class name when automatically 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:198
D & addExternal(const D &entry, char alias=0)
Add a command.
Definition CommandBank.h:99
bank_section_t scriptTriggerFlag
Member and methods for special commands.
Definition CommandBank.h:256
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
D & addExternal(const D &entry, const std::string &key, char alias=0)
Add a command.
Definition CommandBank.h:124
std::string defaultCmdKey
Command that is used, if a plain argument is given.
Definition CommandBank.h:269
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:290
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:316
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:297
void setDefaultCmdKey(const std::string &s)
Set command - key, not getName() - that is used if a plain argument is given.
Definition CommandBank.h:273
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
int bank_section_t
Class to be used as one base class.
Definition CommandBank.h:59
CommandBank & getCommandBank()
Global program command registry. Optional utility.
Definition CommandBank.cpp:52