Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Aug 27, 2005, 2:15:44 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: one parameter-functions should be executable…. dubugging

Location:
trunk/src/util
Files:
4 edited

Legend:

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

    r5141 r5145  
    7979
    8080  ShellCommand<Shell>::registerCommand("clear", CL_SHELL, &Shell::clear);
    81 }
     81  ShellCommand<Shell>::registerCommand("testI", CL_SHELL, &Shell::testI);
     82  ShellCommand<Shell>::registerCommand("testS", CL_SHELL, &Shell::testS);
     83}
     84
     85
     86void Shell::testI (int i)
     87{
     88  printf("This is the Test for one Int '%d'\n", i);
     89}
     90
     91void Shell::testS (const char* s)
     92{
     93  printf("This is the Test for one String '%s'\n", s);
     94
     95}
     96
    8297
    8398Shell* Shell::singletonRef = NULL;
  • trunk/src/util/shell.h

    r5141 r5145  
    3838    /** @returns a Pointer to the only object of this Class */
    3939    inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
     40
     41    void testI (int i);
     42    void testS (const char* s);
    4043
    4144    void activate();
  • trunk/src/util/shell_command.cc

    r5144 r5145  
    123123
    124124
     125/**
     126 * executes commands
     127 * @param executionString the string containing the following input
     128 * <ClassName> [<ObjectName>] <functionName> [parameter1[,parameter2[,...]]]
     129 * @return true on success, false otherwise.
     130 */
    125131bool ShellCommandBase::execute(const char* executionString)
    126132{
     
    139145      const char* commandBegin = executionString + strlen(elem->className);
    140146
    141       PRINTF(4)("Class %s matches\n", elem->className);
     147      PRINTF(5)("Class %s matches\n", elem->className);
    142148      BaseObject* objectPointer = NULL;
    143149      if (elem->isSingleton)
     
    151157        }
    152158        // getting singleton-reference
    153         objectPointer = ClassList::getList(elem->classID)->firstElement();
     159        tList<BaseObject>* list =  ClassList::getList(elem->classID);
     160        if (list)
     161          objectPointer = list->firstElement();
    154162      }
    155163      else
     
    158166        while(*commandBegin == ' ')
    159167          commandBegin++;
    160         tIterator<BaseObject>* iterBO = ClassList::getList(elem->classID)->getIterator();
     168        tList<BaseObject>* list =  ClassList::getList(elem->classID);
     169        if (list == NULL)
     170          break;
     171        tIterator<BaseObject>* iterBO = list->getIterator();
    161172        BaseObject* enumBO = iterBO->firstElement();
    162173        while(enumBO != NULL)
     
    164175          if(!strncmp(commandBegin, enumBO->getName(), strlen(enumBO->getName())))
    165176          {
    166             PRINTF(4)("Object %s matches\n", enumBO->getName());
     177            PRINTF(5)("Object %s matches\n", enumBO->getName());
    167178            objectPointer = enumBO;
    168179            break;
     
    184195          continue;
    185196        }
    186         PRINTF(3)("Function '%s' found\n", commandBegin);
     197        PRINTF(5)("Function '%s' found\n", commandBegin);
    187198      }
    188199      const char* paramBegin = strchr(commandBegin, ' ');
  • trunk/src/util/shell_command.h

    r5143 r5145  
    1111#include "helper_functions.h"
    1212#include "functor_list.h"
     13#include "substring.h"
    1314
    1415#include <stdarg.h>
    1516
    16 #define MAX_SHELL_COMMAND_SIZE
     17#define SHELL_COMMAND_MAX_SIZE
    1718
    1819
     
    2930// NO ARGUMENTS
    3031#define ShellCommandRegister0 \
    31   static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \
     32  static void registerCommand(const char* commandName, ClassID classID, void (T::*function)()) \
    3233  { \
    3334    if (isRegistered(commandName, classID, 0)== true) \
    3435      return; \
    35     new ShellCommand<T>(commandName, classID, functionPointer); \
     36    new ShellCommand<T>(commandName, classID, function); \
     37  }
     38
     39#define ShellCommandRegister1(t1) \
     40  static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
     41  { \
     42    if (isRegistered(commandName, classID, 1, t1##_PARAM)== true) \
     43      return; \
     44    new ShellCommand<T>(commandName, classID, function, d1); \
    3645  }
    3746
    3847
    3948#define ShellCommandConstructor0 \
    40   void (T::*functionPointer_NULL)(); \
    41   ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \
    42   : ShellCommandBase (commandName, classID, 0) \
     49  void (T::*functionPointer_0)(); \
     50  ShellCommand(const char* commandName, ClassID classID, void (T::*function)()) \
     51  : ShellCommandBase(commandName, classID, 0) \
    4352  { \
    44     this->functionPointer_NULL = functionPointer; \
     53    this->functionPointer_0 = function; \
     54  }
     55
     56#define ShellCommandConstructor1(t1) \
     57  void (T::*functionPointer_1_##t1)(t1##_TYPE); \
     58  ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1) \
     59  : ShellCommandBase(commandName, classID, 1, t1##_PARAM, d1) \
     60  { \
     61    this->functionPointer_1_##t1 = function; \
    4562  }
    4663
    4764
    4865
     66#define ShellCommandExecute0 \
     67  if (this->paramCount == 0) \
     68    (dynamic_cast<T*>(object)->*functionPointer_0)()
    4969
    50 #define ShellCommandRegister2(t1, t2) \
    51   static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \
    52                               t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \
    53   { \
    54      if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM) == true) \
    55        return; \
    56      else \
    57        ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \
    58   }
    59 
    60 // CONSTRUCTORS AND POINTERS
    61 #define ShellCommandConstructor2(t1, t2) \
    62   void (T::*functionPointer_##t1_##t2)(t1##_TYPE, t2##_TYPE); \
    63   ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \
    64                               t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \
    65   { \
    66     this->functionPointer_##t1_##t2 = function; \
    67   }
    68 
    69 //#define ShellCommand
     70#define ShellCommandExecute1(t1) \
     71   else if (this->paramCount == 1 && this->parameters[0] & t1##_PARAM) \
     72       (dynamic_cast<T*>(object)->*functionPointer_1_##t1)(0)//t1##_FUNC(parameters, 0))
    7073
    7174
     
    141144//#include "functor_list.h"
    142145FUNCTOR_LIST(0);
     146FUNCTOR_LIST(1)(l_INT);
     147FUNCTOR_LIST(1)(l_STRING);
    143148#undef FUNCTOR_LIST
    144149
     
    148153//#include "functor_list.h"
    149154  FUNCTOR_LIST(0);
     155  FUNCTOR_LIST(1)(l_INT);
     156  FUNCTOR_LIST(1)(l_STRING);
    150157#undef FUNCTOR_LIST
    151158
    152159    virtual void executeCommand (BaseObject* object, const char* parameters)
    153160    {
    154      printf("not implemented yet\n");
    155      if (this->paramCount == 0)
    156        (dynamic_cast<T*>(object)->*functionPointer_NULL)();
     161      SubString params(parameters, ',');
     162#define FUNCTOR_LIST(x) ShellCommandExecute ## x
     163//#include "functor_list.h"
     164  FUNCTOR_LIST(0);
     165  FUNCTOR_LIST(1)(l_INT);
     166  FUNCTOR_LIST(1)(l_STRING);
     167#undef FUNCTOR_LIST
    157168    }
    158 
    159 
    160 
    161 #define FUNCTOR_LIST(x) ShellCommand ## x
    162 //#include "functor_list.h"
    163 //FUNCTOR_LIST(2)(l_INT, l_INT);
    164 #undef FUNCTOR_LIST
    165 
    166169};
    167170
    168 
    169 
    170171#endif /* _SHELL_COMMAND_H */
Note: See TracChangeset for help on using the changeset viewer.