7 #ifndef __CommandParser_h
8 #define __CommandParser_h
10 #include "TextInterfaceParser.h"
37 void initialize_readline ( const char*);
40 std::string readline ();
43 virtual std::string script ( const std::string& filename);
46 virtual std::string script ( const std::vector<std::string>& commands);
49 void standard_input ( const std::string& prompt);
52 std::string help ( const std::string& command = "");
55 std::string parse ( const std::string& commandargs);
58 std::string parse2 ( const std::string& command, const std::string& args);
61 std::string if_command ( const std::string& condition_command);
64 std::string while_command ( const std::string& condition_command);
67 std::string loop ( const std::string& indeces_command);
70 virtual bool evaluate ( const std::string& expression);
73 virtual std::string empty ();
90 bool interactive = true;
99 template < class Parser>
100 void add_command (std::string (Parser::*method)( const std::string&),
101 const std::string& command,
102 const std::string& help,
103 const std::string& detailed_help = "",
107 template < class Parser>
108 void add_command (std::string (Parser::*method)( const std::string&),
110 const std::string& command,
111 const std::string& help,
112 const std::string& detailed_help = "")
113 { add_command (method, command, help, detailed_help, shortcut); }
116 void import (CommandParser*);
119 void import (CommandParser*,
120 const std::string& command,
121 const std::string& help,
128 void add_command (Method*);
131 std::string get_command () const { return current_command; }
134 std::string usage () { return help(current_command); }
137 void conditional ( const std::string& text,
138 std::string& condition,
139 std::string& command);
146 std::vector<Method*> commands;
149 std::string current_command;
152 bool startCommand, endCommand;
155 static char** completion ( const char *text, int start, int end);
158 static char* command_generator ( const char* text, int state);
161 std::string loop_command;
163 std::string loop_result;
174 virtual std::string execute ( const std::string& command) = 0;
176 virtual std::string detail () const = 0;
191 const std::string& help,
193 std::string execute ( const std::string& command);
194 std::string detail () const;
202 friend class CommandParser;
204 typedef std::string (Parser::*Method) ( const std::string&);
208 Command (Parser* _instance, Method _method, const std::string& _command,
209 const std::string& _help, const std::string& _detailed_help,
225 std::string detail () const
241 void CommandParser::add_command (std::string (P::*method) ( const std::string&),
242 const std::string& cmd,
243 const std::string& help,
244 const std::string& detailed_help,
248 std::cerr << "CommandParser::add_command \"" << cmd << "\"" << std::endl;
250 P* instance = dynamic_cast<P* > ( this);
252 throw Error (InvalidState, "CommandParser::add_command",
253 "instance/method mis-match");
256 std::cerr << "CommandParser::add_command new Command<P>" << std::endl;
259 (instance, method, cmd, help, detailed_help, shortcut));
void add_index(TextIndex *) Add an index over which to loop. Definition: TextLoop.C:18
char shortcut The shortcut character corresponding to this method. Definition: CommandParser.h:183
Pure virtual base class of the template class Command. Definition: CommandParser.h:169
std::string command The command string corresponding to this method. Definition: CommandParser.h:179
void loop() Execute the job for each index in the stack. Definition: TextLoop.C:30
A convenient exception handling class. Definition: Error.h:54
ErrorCode get_code() const Get the error code. Definition: Error.h:92
std::string detailed_help The detailed help string for this method. Definition: CommandParser.h:236
An array of Value interfaces. Definition: TextInterfaceParser.h:35
std::string execute(const std::string &args) Execute method. Definition: CommandParser.h:222
Template class manages Reference::Able objects. Definition: Reference.h:74
Parser * instance Instance through which method is called. Definition: CommandParser.h:233
Manages Reference::To references to the instance. Definition: ReferenceAble.h:40
Nested CommandParser Method implementation. Definition: CommandParser.h:187
std::string help The help string for this method. Definition: CommandParser.h:181
void set_container(TextInterface::Parser *) Set the interface of the container to which the named indeces apply. Definition: TextLoop.C:24
const std::string get_message() const Get the error message. Definition: Error.C:133
Functor< void() > job Job defined by derived types. Definition: TextLoop.h:41
Method method Method of the sub-class to execute. Definition: CommandParser.h:230
Loop through ranges of indeces ascertained by a TextInterface. Definition: TextLoop.h:19
Parses and manages a named set of indeces. Definition: TextIndex.h:17
Stores a pointer to a CommandParser sub-class and one of its methods. Definition: CommandParser.h:200
Generated using doxygen 1.8.17
|