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);
141 virtual TextInterface::Parser* get_interface () {
return 0; }
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;
172 virtual ~Method () {}
174 virtual std::string execute (
const std::string&
command) = 0;
176 virtual std::string detail ()
const = 0;
189 Nested( CommandParser*,
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
241void 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));
Pure virtual base class of the template class Command.
Definition CommandParser.h:169
std::string help
The help string for this method.
Definition CommandParser.h:181
char shortcut
The shortcut character corresponding to this method.
Definition CommandParser.h:183
std::string command
The command string corresponding to this method.
Definition CommandParser.h:179
Nested CommandParser Method implementation.
Definition CommandParser.h:187
Stores a pointer to a CommandParser sub-class and one of its methods.
Definition CommandParser.h:201
std::string detailed_help
The detailed help string for this method.
Definition CommandParser.h:236
std::string execute(const std::string &args)
Execute method.
Definition CommandParser.h:222
Method method
Method of the sub-class to execute.
Definition CommandParser.h:230
Parser * instance
Instance through which method is called.
Definition CommandParser.h:233
A convenient exception handling class.
Definition Error.h:54
Manages Reference::To references to the instance.
Definition ReferenceAble.h:35
Template class manages Reference::Able objects.
Definition ReferenceTo.h:25