Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5130 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Aug 26, 2005, 12:04:43 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: flush

Location:
trunk/src/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/shell.cc

    r5129 r5130  
    7676    evh->subscribe(this, ES_SHELL, i);
    7777
    78 
    79 //  this->registerCommand("clear", Shell::)
     78  //void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, ...)
     79
     80  ShellCommand<Shell>::registerCommand("clear", CL_NULL, this, &Shell::clear, 0, 1);
    8081}
    8182
     
    458459  if (!strcmp(this->inputLine, "clear"))
    459460  {
    460     this->flushBuffers();
    461     this->addBufferLine("orxonox - shell\n ==================== \n", NULL);
     461    this->clear();
    462462  }
    463463
     
    465465
    466466  return false;
     467}
     468
     469void Shell::clear()
     470{
     471  this->flushBuffers();
     472  this->addBufferLine("orxonox - shell\n ==================== \n", NULL);
    467473}
    468474
  • trunk/src/util/shell.h

    r5129 r5130  
    6161    bool executeCommand();
    6262
     63    void clear();
     64
    6365    void setRepeatDelay(float repeatDelay, float repeatRate);
    6466
  • trunk/src/util/shell_command.cc

    r5129 r5130  
    2828using namespace std;
    2929
    30 ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID)
     30ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters)
    3131{
    3232  this->classID = classID;
     33  this->functionPointer = functionPointer;
    3334  this->commandName = new char[strlen(commandName)+1];
    3435  strcpy(this->commandName, commandName);
    3536
     37  // handling parameters, and storing them:
     38  this->paramCount = paramCount;
     39  this->parameters = new ShellParameterType[paramCount];
     40
     41  for (unsigned int i = 0; i < paramCount; i++)
     42    parameters[i] = va_arg(parameters, long);
     43
     44  // adding this ShellCommand to the list of known Commands
    3645  ShellCommandBase::commandList->add(this);
    3746}
    3847
     48ShellCommandBase::~ShellCommandBase()
     49{
     50  delete[] this->commandName;
     51  delete[] this->parameters;
     52}
    3953
    4054
    4155tList<ShellCommandBase>* ShellCommandBase::commandList = NULL;
    4256
    43 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID)
     57bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters)
    4458{
    4559  if (ShellCommandBase::commandList == NULL)
  • trunk/src/util/shell_command.h

    r5129 r5130  
    1111#include <stdarg.h>
    1212
     13#define MAX_SHELL_COMMAND_SIZE
     14
    1315typedef enum ShellParameterType
    1416{
     
    2224};
    2325
     26
    2427// FORWARD DECLARATION
    2528template<class T> class tList;
    2629template<class T> class tIterator;
    27 #define MAX_SHELL_COMMAND_SIZE
    2830
    29 class ShellCommandBase
     31class ShellCommandBase : public BaseObject
    3032{
    3133  public:
    3234    static bool execute (const char* executionString);
    3335
     36//    virtual void execute (...);
     37
    3438  protected:
    35     ShellCommandBase(const char* commandName, ClassID classID);
     39    ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters);
     40    ~ShellCommandBase();
    3641
    37     static bool isRegistered(const char* commandName, ClassID classID);
     42    static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters);
    3843
     44
     45  protected:
     46    void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
     47    unsigned int                     paramCount;          //!< the count of parameters
     48    ShellParameterType*              parameters;          //!< Parameters
    3949
    4050  private:
     
    4252    long                             classID;             //!< The ID of the Class asociated to this Command
    4353
    44 
     54    // STATIC MEMBERS
    4555    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
    4656};
     
    5060{
    5161  public:
    52     static void registerCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object = NULL);
     62    static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...);
    5363
    5464    static void unregisterCommand(const char* commandNaame, ClassID classID);
    5565
    5666  private:
    57     ShellCommand(const char* command, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object = NULL);
     67    ShellCommand(const char* command, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters);
    5868
    5969
    6070  public:
    61     void*                functionPointer;     //!< The pointer to the function of the Class (or static pointer if ClassID == CL_NULL )
    62     T*                   Object;              //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
     71    T*                   objectPointer;       //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
    6372};
    6473
    6574template<class T>
    66     ShellCommand<T>::ShellCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object)
    67   : ShellCommandBase (command, classID)
     75    ShellCommand<T>::ShellCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters)
     76  : ShellCommandBase (commandName, classID, functionPointer, paramCount, parameters)
    6877{
    6978
     
    7180
    7281template<class T>
    73     void ShellCommand<T>::registerCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object)
     82    void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...)
    7483{
    75   if (isRegistered() == true)
     84  va_list parameters;
     85  va_start(parameters, paramCount);
     86
     87  if (isRegistered(commandName, classID, paramCount, parameters) == true)
    7688    return;
    7789  else
    7890  {
    79     ShellCommand<T>* newCommand = new ShellCommand<T>(command);
    80     elem->functionPointer = pointerToFunction;
    81     elem->parameter1 = param1Type;
    82     elem->Object = Object;
    8391
    84 
     92//    ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, functionPointer, paramCount, parameters);
    8593  }
    8694}
Note: See TracChangeset for help on using the changeset viewer.