00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef COMMANDPARSER_HH
00026 #define COMMANDPARSER_HH
00027
00028 #include <string>
00029 #include <map>
00030
00031 #include "RefCount.hh"
00032
00033 namespace FbTk {
00034 class Command;
00035 };
00036
00039 class CommandFactory {
00040 public:
00041 CommandFactory();
00042 virtual ~CommandFactory();
00043 virtual FbTk::Command *stringToCommand(const std::string &command,
00044 const std::string &arguments) = 0;
00045 protected:
00046 void addCommand(const std::string &value);
00047 };
00048
00050 class CommandParser {
00051 public:
00052 typedef std::map<std::string, CommandFactory *> CommandFactoryMap;
00053
00055 FbTk::Command *parseLine(const std::string &line);
00056
00058 static CommandParser &instance();
00060 const CommandFactoryMap &factorys() const { return m_commandfactorys; }
00061 private:
00062
00063 friend class CommandFactory;
00065 void associateCommand(const std::string &name, CommandFactory &factory);
00067 void removeAssociation(CommandFactory &factory);
00068
00070 FbTk::Command *toCommand(const std::string &command,
00071 const std::string &arguments);
00072
00073 CommandFactoryMap m_commandfactorys;
00074
00075 };
00076
00077 #endif // COMMANDPARSER_HH