command_parser.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00033 #ifndef __command_parser__header__
00034 #define __command_parser__header__
00035 
00036 #include "gpucalc/singleton.h"
00037 #include "gpucalc/string_util.h"
00038 #include "gpucalc/application.h"
00039 #include "gpucalc/task_manager.h"
00040 #include "gpucalc/debugger/debugger.h"
00041 
00042 namespace gpucalc
00043 {
00044  namespace debugger
00045  {
00046 
00047   const char _CommandClassName [] = "debugger::Command";
00048 
00049   class _GpuCalcExport Command: public Object
00050   {
00051 
00052 
00053    OBJ_DISABLE_COPY(Command)
00054 
00055 
00056 
00057    public:
00058     Command(const std::string & CommandName): Object(_CommandClassName, CommandName)
00059     {
00060     }
00061 
00062 
00063     virtual ~Command()
00064     {
00065     }
00066 
00067     virtual const std::string & getCommandName() const = 0;
00068 
00069     virtual void process(const StringList & args) = 0;
00070   };
00071 
00072 
00073 
00074   class _GpuCalcExport RunCommand: public Command
00075   {
00076 
00077    OBJ_DISABLE_COPY(RunCommand)
00078 
00079    
00080    public:
00081     RunCommand(): Command("run")
00082     {
00083     }
00084 
00085 
00086     ~RunCommand()
00087     {
00088     }
00089 
00090 
00091     const std::string & getCommandName() const
00092     {
00093      return this->getObjectName();
00094     }
00095 
00096     void process(const StringList & args)
00097     {
00098      if (Debugger::getSingleton().isDebugging())
00099      {
00100       Warning<ERR_INVALID_STATE>(this, "Another Task is debugging, stopping previous debugging...", "debugger::RunCommand::process()",
00101        __FILE__, __LINE__);
00102       Debugger::getSingleton().stop();
00103      }
00104      else
00105      {
00106       Task * DebugTask = Application::getSingleton().getDefaultTaskManager()->find(args[1]);
00107       Debugger::getSingleton().setTask(DebugTask);
00108      }
00109     }
00110   };
00111 
00112 
00113 
00114   class _GpuCalcExport PrintCommand: public Command
00115   {
00116 
00117    
00118    OBJ_DISABLE_COPY(PrintCommand)
00119    
00120    
00121    public:
00122     PrintCommand(): Command("print")
00123     {
00124     }
00125 
00126 
00127     ~PrintCommand()
00128     {
00129     }
00130 
00131 
00132     const std::string & getCommandName() const
00133     {
00134      return this->getObjectName();
00135     }
00136 
00137 
00138     void process(const StringList & args)
00139     {
00140      if (Debugger::getSingleton().isDebugging())
00141      {
00142       // first argument is a name of command, so skipping it.
00143       for (StringList::const_iterator i = args.begin() + 1; i != args.end(); ++i)
00144       {
00145        Debugger::getSingleton().print(*i);
00146       }
00147      }
00148     }
00149   };
00150 
00151 
00152 
00153   class _GpuCalcExport BreakCommand: public Command
00154   {
00155 
00156    OBJ_DISABLE_COPY(BreakCommand)
00157 
00158 
00159    public:
00160     BreakCommand(): Command("break")
00161     {
00162     }
00163 
00164 
00165     ~BreakCommand()
00166     {
00167     }
00168 
00169 
00170     const std::string & getCommandName() const
00171     {
00172      return this->getObjectName();
00173     }
00174 
00175 
00176     void process(const StringList & args)
00177     {
00178      if (Debugger::getSingleton().isDebugging())
00179      {
00180       size_t line;
00181       auxillary::StringUtil::fromString(args[1], line);
00182       Debugger::getSingleton().setBreakPoint(line);
00183      }
00184     }
00185   };
00186 
00187 
00188 
00189   const char _CommandParserName [] = "debugger::CommandParser";
00190 
00191 
00192   class _GpuCalcExport CommandParser: public Singleton<CommandParser>
00193   {
00194 
00195    OBJ_DISABLE_COPY(CommandParser)
00196    
00197    
00198    public:
00199     CommandParser();
00200 
00201 
00202     ~CommandParser();
00203 
00204 
00208     void registerCommand(const SharedPtr<Command> & cmd);
00209 
00210 
00211     void process(const std::string & expression);
00212 
00213 
00217     static CommandParser * getSingletonPtr();
00218 
00219 
00223     static CommandParser & getSingleton();
00224 
00225 
00226    private:
00227 
00228     typedef std::map<std::string, SharedPtr<Command> >CommandPtrMap;
00229     CommandPtrMap mCommandPtrMap;
00230   };
00231  }
00232 }
00233 
00234 
00235 
00236 #endif

Generated on Thu Mar 5 22:36:42 2009 for gpucalc by  doxygen 1.5.6