aboutsummaryrefslogtreecommitdiff
path: root/src/CommandParser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/CommandParser.cc')
-rw-r--r--src/CommandParser.cc26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/CommandParser.cc b/src/CommandParser.cc
index 1355cf9..aebb99a 100644
--- a/src/CommandParser.cc
+++ b/src/CommandParser.cc
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: CommandParser.cc,v 1.2 2003/07/01 01:49:09 rathnor Exp $ 23// $Id: CommandParser.cc,v 1.3 2003/07/01 09:04:52 fluxgen Exp $
24 24
25#include "CommandParser.hh" 25#include "CommandParser.hh"
26 26
@@ -28,8 +28,8 @@
28 28
29#include <vector> 29#include <vector>
30#include <iostream> 30#include <iostream>
31#include <iterator>
32using namespace std; 31using namespace std;
32
33namespace { 33namespace {
34 34
35string::size_type removeFirstWhitespace(std::string &str) { 35string::size_type removeFirstWhitespace(std::string &str) {
@@ -60,7 +60,7 @@ CommandParser &CommandParser::instance() {
60} 60}
61 61
62FbTk::Command *CommandParser::parseLine(const std::string &line) { 62FbTk::Command *CommandParser::parseLine(const std::string &line) {
63 63
64 // parse arguments and command 64 // parse arguments and command
65 string command = line; 65 string command = line;
66 string arguments; 66 string arguments;
@@ -70,7 +70,7 @@ FbTk::Command *CommandParser::parseLine(const std::string &line) {
70 // ok we have arguments, parsing them here 70 // ok we have arguments, parsing them here
71 arguments = command.substr(second_pos); 71 arguments = command.substr(second_pos);
72 removeFirstWhitespace(arguments); 72 removeFirstWhitespace(arguments);
73 command.erase(second_pos); // remove argument from command 73 command.erase(second_pos); // remove argument from command
74 } 74 }
75 75
76 // now we have parsed command and arguments 76 // now we have parsed command and arguments
@@ -82,23 +82,12 @@ FbTk::Command *CommandParser::parseLine(const std::string &line) {
82 command = FbTk::StringUtil::toLower(command); 82 command = FbTk::StringUtil::toLower(command);
83 83
84 // we didn't find any matching command in default commands, 84 // we didn't find any matching command in default commands,
85 // so we search in the command creators modules for a matching command string 85 // so we search in the command creators modules for a
86 // matching command string
86 return toCommand(command, arguments); 87 return toCommand(command, arguments);
87 88
88} 89}
89 90
90ostream &operator << (ostream &the_stream, const CommandParser::CommandFactoryMap::value_type &value) {
91 the_stream<<value.first;
92 return the_stream;
93}
94
95void CommandParser::showCommands(std::ostream &the_stream) const {
96 // copy command strings to stream
97 copy(m_commandfactorys.begin(),
98 m_commandfactorys.end(),
99 ostream_iterator<CommandFactoryMap::value_type>(the_stream, "\n"));
100}
101
102FbTk::Command *CommandParser::toCommand(const std::string &command_str, const std::string &arguments) { 91FbTk::Command *CommandParser::toCommand(const std::string &command_str, const std::string &arguments) {
103 if (m_commandfactorys[command_str] != 0) 92 if (m_commandfactorys[command_str] != 0)
104 return m_commandfactorys[command_str]->stringToCommand(command_str, arguments); 93 return m_commandfactorys[command_str]->stringToCommand(command_str, arguments);
@@ -115,7 +104,8 @@ void CommandParser::associateCommand(const std::string &command, CommandFactory
115} 104}
116 105
117void CommandParser::removeAssociation(CommandFactory &factory) { 106void CommandParser::removeAssociation(CommandFactory &factory) {
118 std::vector<std::string> commands; // commands that are associated with the factory 107 // commands that are associated with the factory
108 std::vector<std::string> commands;
119 // find associations 109 // find associations
120 CommandFactoryMap::iterator factory_it = m_commandfactorys.begin(); 110 CommandFactoryMap::iterator factory_it = m_commandfactorys.begin();
121 const CommandFactoryMap::iterator factory_it_end = m_commandfactorys.end(); 111 const CommandFactoryMap::iterator factory_it_end = m_commandfactorys.end();