Changeset 5166 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Sep 6, 2005, 1:45:46 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell.cc
r5164 r5166 78 78 } 79 79 80 81 void Shell::testI (int i)82 {83 PRINTF(3)("This is the Test for one Int '%d'\n", i);84 }85 86 void Shell::testS (const char* s)87 {88 PRINTF(3)("This is the Test for one String '%s'\n", s);89 }90 91 void Shell::testB (bool b)92 {93 PRINTF(3)("This is the Test for one Bool: ");94 if (b)95 PRINTF(3)("true\n");96 else97 PRINTF(3)("false\n");98 }99 100 void Shell::testF (float f)101 {102 PRINTF(3)("This is the Test for one Float '%f'\n", f);103 }104 105 void Shell::testSF (const char* s, float f)106 {107 PRINTF(3)("This is the Test for one String '%s' and one Float '%f'\n",s , f);108 }109 110 111 112 80 Shell* Shell::singletonRef = NULL; 113 81 … … 270 238 * adds a new Line to the List of Buffers 271 239 * @param line the Line as in the first argument in printf 272 * @param args the arguments as a va_list273 240 */ 274 241 bool Shell::addBufferLineStatic(const char* line, ...) … … 445 412 /** 446 413 * adds multiple Characters to thr inputLine 447 * @param characters a '\0'terminated char-array to add to the InputLine414 * @param characters a \\0 terminated char-array to add to the InputLine 448 415 */ 449 416 void Shell::addCharacters(const char* characters) … … 497 464 } 498 465 466 /** 467 * clears the Shell (empties all buffers) 468 */ 499 469 void Shell::clear() 500 470 { … … 729 699 } 730 700 701 /** 702 * completes a Function 703 * @param functionBegin the beginning of the function String 704 */ 731 705 bool Shell::functionComplete(const char* functionBegin) 732 706 { … … 849 823 } 850 824 825 /** 826 * prints out some nice help about the Shell 827 */ 851 828 void Shell::help() const 852 829 { … … 862 839 // HELPER FUNCTIONS // 863 840 /////////////////////// 841 842 /** 843 * calculates the position of a Buffer-Display Line 844 * @param lineNumber the lineNumber from the bottom to calculate the position from 845 * @returns the Position of the Line. 846 */ 864 847 Vector Shell::calculateLinePosition(unsigned int lineNumber) 865 848 { … … 887 870 } 888 871 } 872 873 874 875 // void Shell::testI (int i) 876 // { 877 // PRINTF(3)("This is the Test for one Int '%d'\n", i); 878 // } 879 // 880 // void Shell::testS (const char* s) 881 // { 882 // PRINTF(3)("This is the Test for one String '%s'\n", s); 883 // } 884 // 885 // void Shell::testB (bool b) 886 // { 887 // PRINTF(3)("This is the Test for one Bool: "); 888 // if (b) 889 // PRINTF(3)("true\n"); 890 // else 891 // PRINTF(3)("false\n"); 892 // } 893 // 894 // void Shell::testF (float f) 895 // { 896 // PRINTF(3)("This is the Test for one Float '%f'\n", f); 897 // } 898 // 899 // void Shell::testSF (const char* s, float f) 900 // { 901 // PRINTF(3)("This is the Test for one String '%s' and one Float '%f'\n",s , f); 902 // } -
trunk/src/lib/shell/shell.h
r5160 r5166 39 39 inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; 40 40 41 void testI (int i);42 void testS (const char* s);43 void testB (bool b);44 void testF (float f);45 void testSF (const char* s, float f);46 47 41 void activate(); 48 42 void deactivate(); … … 52 46 53 47 // BUFFER // 48 /** @param bufferSize the new Buffer-Size */ 54 49 void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; 55 50 void setBufferDisplaySize(unsigned int bufferDisplaySize); … … 59 54 void printToDisplayBuffer(const char* text); 60 55 void moveBuffer(unsigned int lineCount); 61 void moveBufferTo(unsigned int lineNumber);56 // void moveBufferTo(unsigned int lineNumber); 62 57 const char* getBufferLine(unsigned int lineNumber); 63 58 … … 93 88 const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin); 94 89 const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin); 95 const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin);90 // const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin); 96 91 97 92 // helpers // 98 93 Vector calculateLinePosition(unsigned int lineNumber); 99 94 // void testI (int i); 95 // void testS (const char* s); 96 // void testB (bool b); 97 // void testF (float f); 98 // void testSF (const char* s, float f); 100 99 101 100 private: … … 126 125 char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing 127 126 char keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. 128 bool keepBuffer; 127 bool keepBuffer; //!< if the keepbuffer contains unfinished lines. 129 128 130 129 // completion -
trunk/src/lib/shell/shell_command.cc
r5165 r5166 28 28 using namespace std; 29 29 30 /** 31 * constructs and registers a new Command 32 * @param commandName the name of the Command 33 * @param className the name of the class to apply this command to 34 * @param paramCount the count of parameters this command takes 35 * @return self 36 */ 30 37 ShellCommandBase::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...) 31 38 { … … 83 90 } 84 91 92 /** 93 * deconstructs a ShellCommand 94 * @return 95 */ 85 96 ShellCommandBase::~ShellCommandBase() 86 97 { … … 88 99 } 89 100 101 /** 102 * unregisters all Commands that exist 103 */ 90 104 void ShellCommandBase::unregisterAllCommands() 91 105 { … … 104 118 } 105 119 106 107 void unregisterCommand(const char* commandName, const char* className) 120 /** 121 * unregister an existing commandName 122 * @param className the name of the Class the command belongs to. 123 * @param commandName the name of the command itself 124 * 125 * @todo implement 126 */ 127 void ShellCommandBase::unregisterCommand(const char* commandName, const char* className) 108 128 { 109 129 PRINTF(1)("IMPLEMENT THIS\n"); … … 113 133 114 134 115 135 /** 136 * checks if a command has already been registered. 137 * @param commandName the name of the Command 138 * @param className the name of the Class the command should apply to. 139 * @param paramCount how many arguments the Command takes 140 * @returns true, if the command is registered/false otherwise 141 * 142 * This is used internally, to see, if we have multiple command subscriptions. 143 * This is checked in the registerCommand-function. 144 */ 116 145 bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...) 117 146 { … … 240 269 } 241 270 242 271 /** 272 * lets a command be described 273 * @param description the description of the Given command 274 */ 243 275 ShellCommandBase* ShellCommandBase::describe(const char* description) 244 276 { … … 252 284 } 253 285 286 /** 287 * see ShellCommandBase::debug() 288 */ 254 289 void ShellCommandBase::debugDyn() 255 290 { … … 257 292 } 258 293 294 /** 295 * prints out nice information about the Shells Commands 296 */ 259 297 void ShellCommandBase::debug() 260 298 { … … 269 307 while(elem != NULL) 270 308 { 271 PRINT(0)("Class %s registered command %s with %d parameters: ", elem->className, elem->getName(), elem->paramCount);309 PRINT(0)("Class:'%s':command:'%s':params:%d: ", elem->className, elem->getName(), elem->paramCount); 272 310 for (unsigned int i = 0; i< elem->paramCount; i++) 273 311 printf("%s ", ShellCommandBase::paramToString(elem->parameters[i])); … … 281 319 } 282 320 283 284 321 /** 322 * converts a Parameter to a String 323 * @param parameter the Parameter we have. 324 * @returns the Name of the Parameter at Hand 325 */ 285 326 const char* ShellCommandBase::paramToString(long parameter) 286 327 { -
trunk/src/lib/shell/shell_command.h
r5165 r5166 15 15 #include <stdarg.h> 16 16 17 #define SHELL_COMMAND_MAX_SIZE17 #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command 18 18 19 19 … … 22 22 template<class T> class tList; 23 23 24 /** 25 * an easy to use Macro to create a Command 26 * @param command the name of the command (without "" around the string) 27 * @param class the name of the class to apply this command to (without the "" around the string) 28 * @param function the function to call 29 */ 24 30 #define SHELL_COMMAND(command, class, function) \ 25 31 ShellCommandBase* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function) … … 37 43 ShellCommandBase* describe(const char* description); 38 44 45 /** @returns the CommandList of the Shell */ 39 46 static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; }; 40 47 41 48 static void unregisterAllCommands(); 42 static void unregisterCommand(const char* commandNa ame, const char* className);49 static void unregisterCommand(const char* commandName, const char* className); 43 50 44 51 static void debug(); … … 54 61 55 62 private: 63 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ 56 64 virtual void executeCommand (BaseObject* object, const char* parameters) = NULL; 57 65 58 66 protected: 59 67 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) 60 unsigned int paramCount; //!< the count of parameters 61 unsigned int* parameters; //!< Parameters 62 char* defaultStrings[FUNCTOR_MAX_ARGUMENTS]; 63 int defaultInts[FUNCTOR_MAX_ARGUMENTS]; 64 float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; 65 bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; 68 unsigned int paramCount; //!< the count of parameters. 69 unsigned int* parameters; //!< Parameters the function of this Command takes. 70 char* defaultStrings[FUNCTOR_MAX_ARGUMENTS];//!< A list of default Strings stored. 71 int defaultInts[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Ints stored. 72 float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Floats stored. 73 bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Bools stored. 66 74 67 75 private: … … 69 77 const char* className; //!< The Name of the Class associated to this Command 70 78 71 const char* description; 79 const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); 72 80 73 81 // STATIC MEMBERS … … 81 89 // MACRO DEFINITIONS // 82 90 /////////////////////// 91 //! where to chek for default BOOL values 83 92 #define l_BOOL_DEFGRAB(i) this->defaultBools[i] 93 //! where to chek for default INT values 84 94 #define l_INT_DEFGRAB(i) this->defaultInts[i] 95 //! where to chek for default UINT values 85 96 #define l_UINT_DEFGRAB(i) (unsigned int)this->defaultInts[i] 97 //! where to chek for default LONG values 86 98 #define l_LONG_DEFGRAB(i) (long)this->defaultInts[i] 99 //! where to chek for default FLOAT values 87 100 #define l_FLOAT_DEFGRAB(i) this->defaultFloats[i] 101 //! where to chek for default STRING values 88 102 #define l_STRING_DEFGRAB(i) this->defaultStrings[i] 89 103 … … 91 105 // COMMAND REGISTRATION // 92 106 ////////////////////////// 93 // NO ARGUMENTS107 //! registers a command without any parameters 94 108 #define ShellCommandRegister0() \ 95 109 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)()) \ … … 100 114 } 101 115 116 //! registers a command with 1 parameter 102 117 #define ShellCommandRegister1(t1) \ 103 118 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \ … … 108 123 } 109 124 125 //! registers a command with 2 parameters 110 126 #define ShellCommandRegister2(t1,t2) \ 111 127 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) \ … … 116 132 } 117 133 134 //! registers a command with 3 parameters 118 135 #define ShellCommandRegister3(t1,t2,t3) \ 119 136 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) \ … … 124 141 } 125 142 143 //! registers a command with 4 parameters 126 144 #define ShellCommandRegister4(t1,t2,t3,t4) \ 127 145 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) \ … … 132 150 } 133 151 152 //! registers a command with 5 parameters 134 153 #define ShellCommandRegister5(t1,t2,t3,t4,t5) \ 135 154 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) \ … … 143 162 // CONSTRUCTORS // 144 163 ///////////////// 164 //! creates a command that takes no parameters 145 165 #define ShellCommandConstructor0() \ 146 166 void (T::*functionPointer_0)(); \ … … 151 171 } 152 172 173 //! creates a command that takes one parameter 153 174 #define ShellCommandConstructor1(t1) \ 154 175 void (T::*functionPointer_1_##t1)(t1##_TYPE); \ … … 159 180 } 160 181 182 //! creates a command that takes two parameters 161 183 #define ShellCommandConstructor2(t1,t2) \ 162 184 void (T::*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \ … … 167 189 } 168 190 191 //! creates a command that takes three parameter 169 192 #define ShellCommandConstructor3(t1,t2,t3) \ 170 193 void (T::*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \ … … 175 198 } 176 199 200 //! creates a command that takes four parameter 177 201 #define ShellCommandConstructor4(t1,t2,t3,t4) \ 178 202 void (T::*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \ … … 183 207 } 184 208 209 //! creates a command that takes five parameter 185 210 #define ShellCommandConstructor5(t1,t2,t3,t4,t5) \ 186 211 void (T::*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \ … … 194 219 // EXECUTION // 195 220 /////////////// 221 //! execute-macro for functions with no parameters 196 222 #define ShellCommandExecute0() \ 197 223 if (this->paramCount == 0) \ 198 224 (dynamic_cast<T*>(object)->*functionPointer_0)() 199 225 226 //! execute-macro for functions with one parameter 200 227 #define ShellCommandExecute1(t1) \ 201 228 else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \ 202 229 (dynamic_cast<T*>(object)->*functionPointer_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0))) 203 230 231 //! execute-macro for functions with two parameters 204 232 #define ShellCommandExecute2(t1,t2) \ 205 233 else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \ 206 234 (dynamic_cast<T*>(object)->*functionPointer_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1))) 207 235 236 //! execute-macro for functions with three parameters 208 237 #define ShellCommandExecute3(t1,t2,t3) \ 209 238 else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \ 210 239 (dynamic_cast<T*>(object)->*functionPointer_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2))) 211 240 241 //! execute-macro for functions with four parameters 212 242 #define ShellCommandExecute4(t1,t2,t3,t4) \ 213 243 else if (this->paramCount == 4 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM) \ 214 244 (dynamic_cast<T*>(object)->*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3))) 215 245 246 //! execute-macro for functions with five parameters 216 247 #define ShellCommandExecute5(t1,t2,t3,t4,t5) \ 217 248 else if (this->paramCount == 5 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM && this->parameters[4] == t5##_PARAM) \ … … 228 259 #endif 229 260 261 //! FUNCTOR_LIST is the List of command-registerers 230 262 #define FUNCTOR_LIST(x) ShellCommandRegister ## x 231 263 #include "functor_list.h" … … 234 266 235 267 private: 268 //! FUNCTOR_LIST is the List of CommandConstructors 236 269 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x 237 270 #include "functor_list.h" … … 242 275 // if (parameters != NULL) 243 276 SubString sub(parameters); 277 //! FUNCTOR_LIST is the List of Executive Functions 244 278 #define FUNCTOR_LIST(x) ShellCommandExecute ## x 245 279 #include "functor_list.h"
Note: See TracChangeset
for help on using the changeset viewer.