Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5136 in orxonox.OLD for trunk/src/util


Ignore:
Timestamp:
Aug 26, 2005, 1:24:02 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: registering singleton-Classes now

Location:
trunk/src/util
Files:
2 edited

Legend:

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

    r5135 r5136  
    7878  //void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, ...)
    7979
    80   ShellCommand<Shell>::registerCommand("clear", CL_NULL, this, &Shell::clear);
     80  ShellCommand<Shell>::registerCommand("clear", CL_NULL, &Shell::clear, true);
    8181}
    8282
  • trunk/src/util/shell_command.h

    r5135 r5136  
    7676};
    7777
     78template<class T> class ShellCommand;
    7879
     80template<class T> class ShellCommandSingleton : public ShellCommandBase
     81{
     82  friend class ShellCommand<T>;
     83  private:
     84    ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)())
     85    : ShellCommandBase (commandName, classID, 0)
     86    {
     87      this->functionPointer_NULL = functionPointer;
     88
     89    }
     90    void (T::*functionPointer_NULL)();
     91    virtual void executeCommand (const char* parameters)
     92    {
     93      if (this->paramCount == 0)
     94        (T::getInstance()->*functionPointer_NULL)();
     95    }
     96};
    7997
    8098
     
    85103    static void unregisterCommand(const char* commandNaame, ClassID classID);
    86104
    87     static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)())
     105    static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)(), bool isSingleton = false)
    88106    {
    89107      if (isRegistered(commandName, classID, 0)== true)
    90108        return;
    91109      else
    92         ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, functionPointer);
     110      {
     111        if (isSingleton == false)
     112          new ShellCommand<T>(commandName, classID, functionPointer);
     113        else
     114          new ShellCommandSingleton<T>(commandName, classID, functionPointer);
     115      }
    93116    }
     117
    94118  private:
    95119    void (T::*functionPointer_NULL)();
    96     ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)())
     120    ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
    97121      : ShellCommandBase (commandName, classID, 0)
    98122    {
    99123      this->functionPointer_NULL = functionPointer;
    100       this->objectPointer = object;
    101124    }
    102125    virtual void executeCommand (const char* parameters)
    103126    {
    104       if (this->paramCount == 0)
    105         (objectPointer->*functionPointer_NULL)();
     127/*      if (this->paramCount == 0)
     128        (objectPointer->*functionPointer_NULL)();*/
    106129    }
    107130
     
    114137
    115138  private:
    116 
    117 
    118   public:
    119     T*                   objectPointer;       //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
     139//    T*                   objectPointer;       //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
    120140};
    121141
Note: See TracChangeset for help on using the changeset viewer.