Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
CommandBank Class Reference

Container and execution tools for commands derived from Command. More...

#include <CommandBank.h>

Inheritance diagram for CommandBank:
Inheritance graph
[legend]
Collaboration diagram for CommandBank:
Collaboration graph
[legend]

Public Types

typedef data_t command_t
 
- Public Types inherited from BankSuper< Command >
typedef Bank< Command, std::string > bank_t
 
typedef bank_t::key_t key_t
 
typedef bank_t::bank_id bank_id
 
typedef Command data_t
 
- Public Types inherited from Bank< T, K >
typedef K key_t
 Public key type. (Key type used in the public interface.)
 
typedef T value_t
 Base type of cloned objects.
 
typedef ClonerBase< T > cloner_t
 
typedef std::map< K, cloner_t * > map_t
 Base class.
 
typedef std::set< K > key_set_t
 For enumerating keys. More...
 

Public Member Functions

 CommandBank (const CommandBank &bank)
 
template<class D , char PREFIX = 0>
D & addExternal (const D &entry, char alias=0)
 
template<class D >
D & addExternal (char PREFIX, const D &entry, char alias=0)
 
template<class D , char PREFIX = 0>
D & addExternal (const D &entry, const std::string &key, char alias=0)
 
void readFileTXT (const std::string &filename, Script &script) const
 Include commands from file, inserting them before iterator. More...
 
void readFile (const std::string &filename, Program &prog) const
 
void scriptify (int argc, const char **argv, Script &script) const
 Convert program arguments a script. Like in main(), actual command arguments start from 1. More...
 
void scriptify (const std::string &cmdLine, Script &script) const
 Splits a command line to a list of commands, that is, a script. More...
 
bool scriptify (const std::string &arg, const std::string &argNext, Script &script) const
 Converts a Unix/Linux command line to pairs (cmd,params) of strings. More...
 
void append (const Script &script, Program &prog) const
 Converts command strings to executable command objects, appending them to a program. More...
 
void flushRoutine (Script &script, Context &ctx, Program &prog)
 Append routine to program, and clear routine.
 
void remove (Program &prog) const
 
void run (const std::string &cmd, const std::string &params, Context &ctx)
 Run a single command.
 
void run (Program &prog, ClonerBase< Context > &contextCloner)
 Unlike compile, "interprets" script by running it command by command. More...
 
void help (std::ostream &ostr=std::cout)
 Basic help dump, displays help commands to proceed.
 
void help (Flagger::ivalue_t sectionFilter, std::ostream &ostr=std::cout)
 Basic help dump, displays help commands to proceed.
 
void help (const std::string &key, std::ostream &ostr=std::cout)
 Help on a specific command or section.
 
void info (const std::string &key, const command_t &cmd, std::ostream &ostr=std::cout, bool detailed=true) const
 Checked key and respective command. More...
 
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. More...
 
template<class T >
void exportStatus (std::map< std::string, T > &statusMap) const
 
void setScriptTriggerFlag (drain::Flagger::ivalue_t sectionFlag)
 
void setDefaultCmdKey (const std::string &s)
 Set command - key, not getName() - that is used if a plain argument is given. More...
 
void setNotFoundHandlerCmdKey (const std::string &s)
 Set command to be executed when a command - argument with leading hyphen(s) - is not found. More...
 
void setScriptCmd (const std::string &s)
 Set command for storing a routine.
 
void setScriptFileCmd (const std::string &s)
 Set command for reading and executing commands from a file in the current (running) context. More...
 
- Public Member Functions inherited from BankSuper< Command >
 BankSuper (const BankSuper &bank)
 
D & add (const std::string &key, char brief=0)
 
D & add (char brief=0)
 Add something that has getName()
 
D & addExternal (const D &entry, const std::string &key, char brief=0)
 
void setBriefKey (char brief, const std::string &value)
 Now, D::getName() is required.
 
bool hasAlias (const std::string &value) const
 
bool hasAlias (char brief) const
 
char getAlias (const std::string &value) const
 
const drain::Dictionary< char, key_t > & getAliases () const
 
virtual const std::string & resolve (const key_t &value) const
 Given brief or long key, returns the long key .
 
void setTitle (const std::string &title)
 Set name and brief description of a program, to appear in help dumps.
 
Flagger::ivalue_t addSection (const FlagResolver::dict_t::key_t &title, const FlagResolver::dict_t::value_t index=0)
 
- Public Member Functions inherited from Bank< T, K >
template<class D >
D & add (const K &key)
 Adds class D as an internal instance. More...
 
template<class D >
D & add ()
 
template<class D >
D & addExternal (const D &entry, const K &key)
 Adds class D using a copy constructor on an external instance. More...
 
bool has (const K &key) const
 Check if a cloner is defined for this key.
 
T & clone (const K &key) const
 Return a copy of the base instance.
 
const T & get (const K &key) const
 Returns the base instance.
 
T & get (const K &key)
 Returns the base instance.
 
template<class D >
map_t::const_iterator get () const
 Returns a map entry: pair<Key,D *>()
 
cloner_tgetCloner (const K &key) const
 Return the internal static entry.
 
const map_tgetMap () const
 
void toStream (std::ostream &ostr=std::cout) const
 
key_set_tgetKeys ()
 

Static Public Member Functions

static std::set< std::string > & trimWords ()
 Words that are moved from class name prior to composing a command name.
 
static void deriveCmdName (std::string &name, char prefix=0)
 Given a command class name like MyFileReadCommand, derives a respective command line option ("myFileRead")
 
- Static Public Member Functions inherited from Bank< T, K >
template<class D >
static Cloner< T, D > & getCloner ()
 

Public Attributes

drain::StringMapper logFileSyntax
 
drain::Flagger::ivalue_t scriptTriggerFlag
 Member and methods for special commands.
 
std::string defaultCmdKey
 Command that is used, if a plain argument is given. More...
 
std::string notFoundHandlerCmdKey
 If defined, the command - key not getName() - to which all unresolved commands are directed.
 
std::string scriptCmd
 Command for storing a routine.
 
std::string execFileCmd
 Command for reading and executing commands from a file in the current (running) context.
 
- Public Attributes inherited from BankSuper< Command >
FlagResolver::dict_t sections
 

Protected Member Functions

void append (const Script &script, Context &ctx, Program &prog) const
 Appends program with commands of the script.
 
void tokenize (const std::string &cmdLine, std::list< std::string > &args) const
 
- Protected Member Functions inherited from Bank< T, K >
drain::ClonerBase< T > & set (const std::string &key, drain::ClonerBase< T > &cloner)
 

Additional Inherited Members

- Protected Attributes inherited from BankSuper< Command >
drain::Dictionary< char, std::string > briefKeys
 
std::string title
 For example, name of the program, to appear in help dumps etc.
 
- Protected Attributes inherited from Bank< T, K >
key_set_t keys
 

Detailed Description

Container and execution tools for commands derived from Command.

Storage for commands, providing list, help and cloning facilities

Utilities for creating scripts and programs

Member Function Documentation

◆ append()

void append ( const Script script,
Program prog 
) const

Converts command strings to executable command objects, appending them to a program.

Note: appends commands to the end of the program, use prog.clear() if needed.

◆ info()

void info ( const std::string &  key,
const command_t &  cmd,
std::ostream &  ostr = std::cout,
bool  detailed = true 
) const

Checked key and respective command.

Iterate variable keys

◆ readFileTXT()

void readFileTXT ( const std::string &  filename,
Script script 
) const

Include commands from file, inserting them before iterator.

A mini program executed after each cmd until ']' or ')' is encountered Read commands from a text file and insert them into a string.

◆ resolveFull()

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.

Given alias or long key, possibly prefixed by hyphens, return the long key if a command exists.

◆ run()

void run ( Program prog,
ClonerBase< Context > &  contextCloner 
)

Unlike compile, "interprets" script by running it command by command.

See also
compile()

MAIN

◆ scriptify() [1/3]

bool scriptify ( const std::string &  arg,
const std::string &  argNext,
Script script 
) const

Converts a Unix/Linux command line to pairs (cmd,params) of strings.

CommandBank is needed in checking if a command has arguments.

Returns
- true if command argument (argNext) was digested.

◆ scriptify() [2/3]

void scriptify ( const std::string &  cmdLine,
Script script 
) const

Splits a command line to a list of commands, that is, a script.

CommandBank is needed in checking if a command has arguments.

◆ scriptify() [3/3]

void scriptify ( int  argc,
const char **  argv,
Script script 
) const

Convert program arguments a script. Like in main(), actual command arguments start from 1.

Converts linux command line to pairs of strings: (<cmd>, [params])

CommandBank is needed in checking if a command has arguments.

Starts from argument 1 instead of 0.

◆ setDefaultCmdKey()

void setDefaultCmdKey ( const std::string &  s)
inline

Set command - key, not getName() - that is used if a plain argument is given.

See also

◆ setNotFoundHandlerCmdKey()

void setNotFoundHandlerCmdKey ( const std::string &  s)
inline

Set command to be executed when a command - argument with leading hyphen(s) - is not found.

The argument will be passed to the command.

◆ setScriptFileCmd()

void setScriptFileCmd ( const std::string &  s)
inline

Set command for reading and executing commands from a file in the current (running) context.

Set command for reading and executing commands from a file in the current (running) context

Member Data Documentation

◆ defaultCmdKey

std::string defaultCmdKey

Command that is used, if a plain argument is given.

Technically, plain <argument> is replaced by defaultCmd <argument>


The documentation for this class was generated from the following files: