Changeset 5161 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Sep 5, 2005, 10:19:44 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell.cc
r5160 r5161 32 32 using namespace std; 33 33 34 ShellCommandBase* tmp = ShellCommand<Shell>::registerCommand("clear", "Shell", &Shell::clear); 34 35 35 36 /** … … 78 79 //void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, ...) 79 80 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); 82 83 ShellCommand<Shell>::registerCommand("testI", CL_SHELL, &Shell::testI, 5); 83 84 ShellCommand<Shell>::registerCommand("testB", CL_SHELL, &Shell::testB); 84 85 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);*/ 86 87 } 87 88 -
trunk/src/lib/shell/shell_command.cc
r5160 r5161 28 28 using namespace std; 29 29 30 ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...)30 ShellCommandBase::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...) 31 31 { 32 32 this->setClassID(CL_SHELL_COMMAND, "ShellCommand"); 33 33 this->setName(commandName); 34 34 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) 39 39 this->isSingleton = true; 40 else 41 this->isSingleton = false;40 else*/ 41 this->isSingleton = true; 42 42 43 43 // handling parameters, and storing them: … … 92 92 } 93 93 94 95 94 tList<ShellCommandBase>* ShellCommandBase::commandList = NULL; 96 95 97 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...) 96 97 98 bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...) 98 99 { 99 100 va_list parameterList; … … 103 104 { 104 105 ShellCommandBase::commandList = new tList<ShellCommandBase>; 105 ShellCommand<ShellCommandBase>::registerCommand("debug", CL_SHELL_COMMAND, &ShellCommandBase::debug);106 ShellCommand<ShellCommandBase>::registerCommand("debug", "ShellCommand", &ShellCommandBase::debugDyn); 106 107 return false; 107 108 } … … 111 112 while(elem != NULL) 112 113 { 113 if ( classID == elem->classID&& !strcmp(commandName, elem->getName()))114 if (!strcmp(className, elem->className) && !strcmp(commandName, elem->getName())) 114 115 { 115 116 PRINTF(2)("Command already registered\n"); … … 161 162 PRINTF(4)("Command %s matches\n", elem->getName()); 162 163 // getting singleton-reference 163 tList<BaseObject>* list = ClassList::getList(elem->class ID);164 tList<BaseObject>* list = ClassList::getList(elem->className); 164 165 if (list != NULL) 165 166 objectPointer = list->firstElement(); … … 170 171 while(*commandBegin == ' ') 171 172 commandBegin++; 172 tList<BaseObject>* list = ClassList::getList(elem->class ID);173 tList<BaseObject>* list = ClassList::getList(elem->className); 173 174 if (list == NULL) 174 175 break; … … 221 222 } 222 223 224 void ShellCommandBase::debugDyn() 225 { 226 this->debug(); 227 } 223 228 224 229 void ShellCommandBase::debug() -
trunk/src/lib/shell/shell_command.h
r5160 r5161 22 22 template<class T> class tList; 23 23 24 25 //////////////// 26 // BASE CLASS // 27 //////////////// 28 //! a baseClass for all possible ShellCommands 29 class 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 /////////////////////////////////////////////////// 24 72 25 73 /////////////////////// … … 38 86 // NO ARGUMENTS 39 87 #define ShellCommandRegister0() \ 40 static void registerCommand(const char* commandName, ClassID classID, void (T::*function)()) \41 { \ 42 if (isRegistered(commandName, class ID, 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); \ 45 93 } 46 94 47 95 #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, class ID, 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); \ 53 101 } 54 102 55 103 #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, class ID, 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); \ 61 109 } 62 110 63 111 #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, class ID, 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); \ 69 117 } 70 118 71 119 #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 78 127 #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, class ID, 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); \ 84 133 } 85 134 … … 89 138 #define ShellCommandConstructor0() \ 90 139 void (T::*functionPointer_0)(); \ 91 ShellCommand(const char* commandName, ClassID classID, void (T::*function)()) \92 : ShellCommandBase(commandName, class ID, 0) \140 ShellCommand(const char* commandName, const char* className, void (T::*function)()) \ 141 : ShellCommandBase(commandName, className, 0) \ 93 142 { \ 94 143 this->functionPointer_0 = function; \ … … 97 146 #define ShellCommandConstructor1(t1) \ 98 147 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, class ID, 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) \ 101 150 { \ 102 151 this->functionPointer_1_##t1 = function; \ … … 105 154 #define ShellCommandConstructor2(t1,t2) \ 106 155 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, class ID, 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) \ 109 158 { \ 110 159 this->functionPointer_2_##t1##_##t2 = function; \ … … 113 162 #define ShellCommandConstructor3(t1,t2,t3) \ 114 163 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, class ID, 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) \ 117 166 { \ 118 167 this->functionPointer_3_##t1##_##t2##_##t3 = function; \ … … 121 170 #define ShellCommandConstructor4(t1,t2,t3,t4) \ 122 171 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, class ID, 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) \ 125 174 { \ 126 175 this->functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \ … … 129 178 #define ShellCommandConstructor5(t1,t2,t3,t4,t5) \ 130 179 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, class ID, 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) \ 133 182 { \ 134 183 this->functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \ … … 163 212 164 213 165 166 ////////////////167 // BASE CLASS //168 ////////////////169 //! a baseClass for all possible ShellCommands170 class ShellCommandBase : public BaseObject171 {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 parameters192 unsigned int* parameters; //!< Parameters193 bool isSingleton; //!< if the Class is Singleton @todo autocheck194 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 Command201 const char* className; //!< The Name of the Class associated to this Command202 203 // STATIC MEMBERS204 static tList<ShellCommandBase>* commandList; //!< A list of availiable commands.205 };206 207 214 //! keeps information about a ShellCommand 208 215 template<class T> class ShellCommand : public ShellCommandBase 209 216 { 210 217 public: 211 static void unregisterCommand(const char* commandNaame, ClassID classID);212 218 213 219 #ifdef FUNCTOR_LIST
Note: See TracChangeset
for help on using the changeset viewer.