Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5161 in orxonox.OLD


Ignore:
Timestamp:
Sep 5, 2005, 10:19:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: better method to register Shell-Commands (now via the Factory-algorithm proposed)

BUT!! NOW ONLY SINGLETON IS SUPPORTED → fixing!!

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/orxonox.kdevelop

    r5160 r5161  
    140140  </kdevcppsupport>
    141141  <kdevfileview>
    142     <groups/>
     142    <groups>
     143      <hidenonprojectfiles>false</hidenonprojectfiles>
     144      <hidenonlocation>false</hidenonlocation>
     145    </groups>
    143146    <tree>
    144147      <hidepatterns>*.o,*.lo,*~,*in</hidepatterns>
    145148      <hidenonprojectfiles>false</hidenonprojectfiles>
     149      <showvcsfields>false</showvcsfields>
    146150    </tree>
    147151  </kdevfileview>
     
    149153    <filetemplates>
    150154      <interfacesuffix>.h</interfacesuffix>
    151       <implementationsuffix>.cpp</implementationsuffix>
     155      <implementationsuffix>.cc</implementationsuffix>
    152156    </filetemplates>
    153157  </cppsupportpart>
     
    160164  </kdevdocumentation>
    161165  <ctagspart>
    162     <customArguments></customArguments>
    163     <customTagfilePath></customTagfilePath>
     166    <customArguments/>
     167    <customTagfilePath/>
    164168  </ctagspart>
    165169</kdevelop>
  • trunk/src/lib/shell/shell.cc

    r5160 r5161  
    3232using namespace std;
    3333
     34ShellCommandBase* tmp = ShellCommand<Shell>::registerCommand("clear", "Shell", &Shell::clear);
    3435
    3536/**
     
    7879  //void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, ...)
    7980
    80   ShellCommand<Shell>::registerCommand("clear", CL_SHELL, &Shell::clear);
    81   ShellCommand<Shell>::registerCommand("testS", CL_SHELL, &Shell::testS);
     81
     82/*  ShellCommand<Shell>::registerCommand("testS", CL_SHELL, &Shell::testS);
    8283  ShellCommand<Shell>::registerCommand("testI", CL_SHELL, &Shell::testI, 5);
    8384  ShellCommand<Shell>::registerCommand("testB", CL_SHELL, &Shell::testB);
    8485  ShellCommand<Shell>::registerCommand("testF", CL_SHELL, &Shell::testF);
    85   ShellCommand<Shell>::registerCommand("testSF", CL_SHELL, &Shell::testSF);
     86  ShellCommand<Shell>::registerCommand("testSF", CL_SHELL, &Shell::testSF);*/
    8687}
    8788
  • trunk/src/lib/shell/shell_command.cc

    r5160 r5161  
    2828using namespace std;
    2929
    30 ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...)
     30ShellCommandBase::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...)
    3131{
    3232  this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
    3333  this->setName(commandName);
    3434
    35   this->classID = classID;
    36   this->className = ClassList::IDToString(classID);
    37 
    38   if (classID & CL_MASK_SINGLETON == CL_MASK_SINGLETON)
     35//  this->classID = classID;
     36  this->className = className; //ClassList::IDToString(classID);
     37
     38/*  if (classID & CL_MASK_SINGLETON == CL_MASK_SINGLETON)
    3939    this->isSingleton = true;
    40   else
    41     this->isSingleton = false;
     40  else*/
     41    this->isSingleton = true;
    4242
    4343  // handling parameters, and storing them:
     
    9292}
    9393
    94 
    9594tList<ShellCommandBase>* ShellCommandBase::commandList = NULL;
    9695
    97 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...)
     96
     97
     98bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)
    9899{
    99100  va_list parameterList;
     
    103104  {
    104105    ShellCommandBase::commandList = new tList<ShellCommandBase>;
    105     ShellCommand<ShellCommandBase>::registerCommand("debug", CL_SHELL_COMMAND, &ShellCommandBase::debug);
     106    ShellCommand<ShellCommandBase>::registerCommand("debug", "ShellCommand", &ShellCommandBase::debugDyn);
    106107    return false;
    107108  }
     
    111112  while(elem != NULL)
    112113  {
    113     if (classID == elem->classID && !strcmp(commandName, elem->getName()))
     114    if (!strcmp(className, elem->className) && !strcmp(commandName, elem->getName()))
    114115    {
    115116      PRINTF(2)("Command already registered\n");
     
    161162        PRINTF(4)("Command %s matches\n", elem->getName());
    162163        // getting singleton-reference
    163         tList<BaseObject>* list =  ClassList::getList(elem->classID);
     164        tList<BaseObject>* list =  ClassList::getList(elem->className);
    164165        if (list != NULL)
    165166          objectPointer = list->firstElement();
     
    170171        while(*commandBegin == ' ')
    171172          commandBegin++;
    172         tList<BaseObject>* list = ClassList::getList(elem->classID);
     173        tList<BaseObject>* list = ClassList::getList(elem->className);
    173174        if (list == NULL)
    174175          break;
     
    221222}
    222223
     224void ShellCommandBase::debugDyn()
     225{
     226  this->debug();
     227}
    223228
    224229void ShellCommandBase::debug()
  • trunk/src/lib/shell/shell_command.h

    r5160 r5161  
    2222template<class T> class tList;
    2323
     24
     25////////////////
     26// BASE CLASS //
     27////////////////
     28//! a baseClass for all possible ShellCommands
     29class ShellCommandBase : public BaseObject
     30{
     31  public:
     32    static bool execute (const char* executionString);
     33
     34    static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };
     35
     36//    static void unregisterCommand(const char* commandNaame, const char* className);
     37
     38    static void debug();
     39
     40  protected:
     41    ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...);
     42    ~ShellCommandBase();
     43
     44    static bool isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...);
     45    static const char* paramToString(long parameter);
     46
     47    void debugDyn();
     48
     49  private:
     50    virtual void executeCommand (BaseObject* object, const char* parameters) = NULL;
     51
     52  protected:
     53    void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
     54    unsigned int                     paramCount;          //!< the count of parameters
     55    unsigned int*                    parameters;          //!< Parameters
     56    bool                             isSingleton;         //!< if the Class is Singleton @todo autocheck
     57    char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];
     58    int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];
     59    float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS];
     60    bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];
     61
     62  private:
     63//    long                             classID;             //!< The ID of the Class associated to this Command
     64    const char*                      className;           //!< The Name of the Class associated to this Command
     65
     66    // STATIC MEMBERS
     67    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
     68};
     69
     70///////////////////////////////////////////////////
     71///////////////////////////////////////////////////
    2472
    2573///////////////////////
     
    3886// NO ARGUMENTS
    3987#define ShellCommandRegister0() \
    40   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)()) \
    41   { \
    42     if (isRegistered(commandName, classID, 0)== true) \
    43       return; \
    44     new ShellCommand<T>(commandName, classID, function); \
     88  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)()) \
     89  { \
     90    if (isRegistered(commandName, className, 0)== true) \
     91      return NULL; \
     92    return new ShellCommand<T>(commandName, className, function); \
    4593  }
    4694
    4795#define ShellCommandRegister1(t1) \
    48   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
    49   { \
    50     if (isRegistered(commandName, classID, 1, t1##_PARAM)== true) \
    51       return; \
    52     new ShellCommand<T>(commandName, classID, function, d1); \
     96  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
     97  { \
     98    if (isRegistered(commandName, className, 1, t1##_PARAM)== true) \
     99      return NULL; \
     100    return new ShellCommand<T>(commandName, className, function, d1); \
    53101  }
    54102
    55103#define ShellCommandRegister2(t1,t2) \
    56   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \
    57   { \
    58     if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM)== true) \
    59       return; \
    60     new ShellCommand<T>(commandName, classID, function, d1, d2); \
     104  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \
     105  { \
     106    if (isRegistered(commandName, className, 2, t1##_PARAM, t2##_PARAM)== true) \
     107      return NULL; \
     108    return new ShellCommand<T>(commandName, className, function, d1, d2); \
    61109  }
    62110
    63111#define ShellCommandRegister3(t1,t2,t3) \
    64   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \
    65   { \
    66     if (isRegistered(commandName, classID, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \
    67       return; \
    68     new ShellCommand<T>(commandName, classID, function, d1, d2, d3); \
     112  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \
     113  { \
     114    if (isRegistered(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \
     115      return NULL; \
     116    return new ShellCommand<T>(commandName, className, function, d1, d2, d3); \
    69117  }
    70118
    71119#define ShellCommandRegister4(t1,t2,t3,t4) \
    72   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \
    73   { \
    74     if (isRegistered(commandName, classID, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \
    75       return; \
    76     new ShellCommand<T>(commandName, classID, function, d1, d2, d3, d4); \
    77   }
     120  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \
     121  { \
     122    if (isRegistered(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \
     123      return NULL; \
     124    return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4); \
     125  }
     126
    78127#define ShellCommandRegister5(t1,t2,t3,t4,t5) \
    79   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \
    80   { \
    81     if (isRegistered(commandName, classID, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
    82       return; \
    83     new ShellCommand<T>(commandName, classID, function, d1, d2, d3, d4, d5); \
     128  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \
     129  { \
     130    if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
     131      return NULL; \
     132    return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4, d5); \
    84133  }
    85134
     
    89138#define ShellCommandConstructor0() \
    90139  void (T::*functionPointer_0)(); \
    91   ShellCommand(const char* commandName, ClassID classID, void (T::*function)()) \
    92   : ShellCommandBase(commandName, classID, 0) \
     140  ShellCommand(const char* commandName, const char* className, void (T::*function)()) \
     141  : ShellCommandBase(commandName, className, 0) \
    93142  { \
    94143    this->functionPointer_0 = function; \
     
    97146#define ShellCommandConstructor1(t1) \
    98147  void (T::*functionPointer_1_##t1)(t1##_TYPE); \
    99   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1) \
    100   : ShellCommandBase(commandName, classID, 1, t1##_PARAM, d1) \
     148  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE), t1##_TYPE d1) \
     149  : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \
    101150  { \
    102151    this->functionPointer_1_##t1 = function; \
     
    105154#define ShellCommandConstructor2(t1,t2) \
    106155  void (T::*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \
    107   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
    108   : ShellCommandBase(commandName, classID, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
     156  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
     157  : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
    109158  { \
    110159    this->functionPointer_2_##t1##_##t2 = function; \
     
    113162#define ShellCommandConstructor3(t1,t2,t3) \
    114163  void (T::*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \
    115   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \
    116   : ShellCommandBase(commandName, classID, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
     164  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \
     165  : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
    117166  { \
    118167    this->functionPointer_3_##t1##_##t2##_##t3 = function; \
     
    121170#define ShellCommandConstructor4(t1,t2,t3,t4) \
    122171  void (T::*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \
    123   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \
    124   : ShellCommandBase(commandName, classID, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
     172  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \
     173  : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
    125174  { \
    126175    this->functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \
     
    129178#define ShellCommandConstructor5(t1,t2,t3,t4,t5) \
    130179  void (T::*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \
    131   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \
    132   : ShellCommandBase(commandName, classID, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
     180  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \
     181  : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
    133182  { \
    134183    this->functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \
     
    163212
    164213
    165 
    166 ////////////////
    167 // BASE CLASS //
    168 ////////////////
    169 //! a baseClass for all possible ShellCommands
    170 class ShellCommandBase : public BaseObject
    171 {
    172   public:
    173     static bool execute (const char* executionString);
    174 
    175     static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };
    176 
    177 
    178   protected:
    179     ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...);
    180     ~ShellCommandBase();
    181 
    182     static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...);
    183     static const char* paramToString(long parameter);
    184 
    185     void debug();
    186   private:
    187     virtual void executeCommand (BaseObject* object, const char* parameters) = NULL;
    188 
    189   protected:
    190     void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    191     unsigned int                     paramCount;          //!< the count of parameters
    192     unsigned int*                    parameters;          //!< Parameters
    193     bool                             isSingleton;         //!< if the Class is Singleton @todo autocheck
    194     char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];
    195     int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];
    196     float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS];
    197     bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];
    198 
    199   private:
    200     long                             classID;             //!< The ID of the Class associated to this Command
    201     const char*                      className;           //!< The Name of the Class associated to this Command
    202 
    203     // STATIC MEMBERS
    204     static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
    205 };
    206 
    207214//! keeps information about a ShellCommand
    208215template<class T> class ShellCommand : public ShellCommandBase
    209216{
    210217  public:
    211     static void unregisterCommand(const char* commandNaame, ClassID classID);
    212218
    213219#ifdef FUNCTOR_LIST
  • trunk/src/util/loading/factory.cc

    r5156 r5161  
    7171  {
    7272    Factory::first = factory;
    73     ShellCommand<Factory>::registerCommand("create", CL_FACTORY, &Factory::fabricate);
     73    ShellCommand<Factory>::registerCommand("create", "Factory", &Factory::fabricate);
    7474  }
    7575  else
  • trunk/src/util/loading/game_loader.cc

    r5139 r5161  
    4444  this->setName("GameLoader");
    4545
    46   ShellCommand<GameLoader>::registerCommand("quit", CL_GAME_LOADER, &GameLoader::stop);
     46  ShellCommand<GameLoader>::registerCommand("quit", "GameLoader", &GameLoader::stop);
    4747}
    4848
Note: See TracChangeset for help on using the changeset viewer.