Changeset 5641 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Nov 18, 2005, 9:22:23 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r5640 r5641 36 36 * @param paramCount the count of parameters this command takes 37 37 */ 38 ShellCommand::ShellCommand(const char* commandName, const char* className, Executor*executor)38 ShellCommand::ShellCommand(const char* commandName, const char* className, const Executor& executor) 39 39 { 40 40 this->setClassID(CL_SHELL_COMMAND, "ShellCommand"); … … 54 54 this->defaultValue = new MultiType[paramCount]; 55 55 56 this->executor = executor ;56 this->executor = executor.clone(); 57 57 } 58 58 … … 69 69 delete this->alias; 70 70 } 71 delete this->executor; 71 72 } 72 73 … … 74 75 * registers a new ShellCommand 75 76 */ 76 ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, Executor*executor)77 ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, const Executor& executor) 77 78 { 78 79 if (ShellCommand::isRegistered(commandName, className, executor)) … … 132 133 * This is checked in the registerCommand-function. 133 134 */ 134 bool ShellCommand::isRegistered(const char* commandName, const char* className, Executor*executor)135 bool ShellCommand::isRegistered(const char* commandName, const char* className, const Executor& executor) 135 136 { 136 137 if (ShellCommandClass::commandClassList == NULL) -
trunk/src/lib/shell/shell_command.h
r5640 r5641 41 41 // ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function) 42 42 #define SHELL_COMMAND(command, class, function) \ 43 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, newExecutorObjective<class>(&class::function))43 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function)) 44 44 45 45 /** … … 57 57 */ 58 58 #define SHELL_COMMAND_STATIC(command, class, function) \ 59 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, newExecutorStatic<class>(function))59 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function)) 60 60 61 61 … … 72 72 ShellCommand* defaultValues(unsigned int count, ...); 73 73 74 static ShellCommand* registerCommand(const char* commandName, const char* className, Executor*executor);74 static ShellCommand* registerCommand(const char* commandName, const char* className, const Executor& executor); 75 75 76 76 static void unregisterCommand(const char* commandName, const char* className); … … 79 79 80 80 protected: 81 ShellCommand(const char* commandName, const char* className, Executor*executor);81 ShellCommand(const char* commandName, const char* className, const Executor& executor); 82 82 ~ShellCommand(); 83 83 84 static bool isRegistered(const char* commandName, const char* className, Executor*executor);84 static bool isRegistered(const char* commandName, const char* className, const Executor& executor); 85 85 static const char* paramToString(long parameter); 86 86 87 87 protected: 88 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )89 88 unsigned int paramCount; //!< the count of parameters. 90 89 unsigned int* parameters; //!< Parameters the function of this Command takes. -
trunk/src/lib/shell/shell_command_class.cc
r5639 r5641 217 217 { 218 218 ShellCommandClass::commandClassList = new tList<ShellCommandClass>; 219 ShellCommand::registerCommand("debug", "ShellCommand", newExecutorStatic<ShellCommand>(ShellCommand::debug));219 ShellCommand::registerCommand("debug", "ShellCommand", ExecutorStatic<ShellCommand>(ShellCommand::debug)); 220 220 } 221 221 } -
trunk/src/lib/util/executor/executor.cc
r5636 r5641 32 32 // SHELL COMMAND BASE // 33 33 //////////////////////// 34 // empty constructor 35 Executor::Executor() 36 { 37 this->defaultValue = NULL; 38 } 39 34 40 /** 35 41 * constructs and registers a new Command … … 63 69 delete[] this->defaultValue; 64 70 } 71 72 /** 73 * clones this element into executor. 74 */ 75 void Executor::cloning(Executor* executor) const 76 { 77 executor->functorType = this->functorType; 78 executor->paramCount = this->paramCount; 79 executor->defaultValue = new MultiType[this->paramCount]; 80 for (unsigned int i = 0; i < this->paramCount; i++) 81 executor->defaultValue[i] = this->defaultValue[i]; 82 } 83 84 65 85 66 86 /** -
trunk/src/lib/util/executor/executor.h
r5636 r5641 22 22 typedef enum { 23 23 Executor_Objective = 1, 24 Executor_Static = 2,24 Executor_Static = 2, 25 25 } Executor_Type; 26 26 … … 32 32 { 33 33 public: 34 virtual ~Executor(); 35 36 virtual Executor* clone () const = 0; 37 34 38 Executor* defaultValues(unsigned int count, ...); 35 39 Executor* defaultValues(unsigned int count, va_list values); … … 38 42 virtual void execute (BaseObject* object, const char* parameters) = 0; 39 43 44 /** @returns the Type of this Function (either static or objective) */ 45 inline Executor_Type getType() const { return this->functorType; }; 46 40 47 static void debug(); 41 48 42 49 protected: 50 Executor(); 43 51 Executor(unsigned int paramCount, ...); 44 ~Executor(); 45 46 /** @returns the Type of this Function (either static or objective) */ 47 inline Executor_Type getType() { return this->functorType; }; 52 53 void cloning(Executor* executor) const; 48 54 49 55 protected: … … 51 57 unsigned int paramCount; //!< the count of parameters. 52 58 MultiType* defaultValue; //!< Default Values. 53 54 private:55 59 }; 56 60 … … 226 230 template<class T> class ExecutorObjective : public Executor 227 231 { 228 229 232 public: 233 ExecutorObjective() : Executor() { }; 234 // COPY constuctor (virtual version) 235 virtual Executor* clone () const 236 { 237 ExecutorObjective<T>* executor = new ExecutorObjective<T>(); 238 this->cloning(executor); 239 executor->fp = this->fp; 240 return executor; 241 } 242 230 243 //! FUNCTOR_LIST is the List of CommandConstructors 231 244 #define FUNCTOR_LIST(x) ExecutorConstructor ## x … … 279 292 { 280 293 public: 294 ExecutorStatic() : Executor() { }; 295 // COPY constuctor 296 virtual Executor* clone () const 297 { 298 ExecutorStatic<T>* executor = new ExecutorStatic<T>(); 299 this->cloning(executor); 300 executor->fp = this->fp; 301 return executor; 302 } 303 281 304 //! FUNCTOR_LIST is the List of CommandConstructors 282 305 #define FUNCTOR_LIST(x) ExecutorConstructor ## x … … 303 326 }; 304 327 305 //! A Class, that handles aliases.306 class ExecutorAlias307 {308 friend class ExecutorBase;309 public:310 /** @returns the Name of the Alias. */311 const char* getName() const { return this->aliasName; };312 /** @returns the Command, this Alias is asociated with */313 ExecutorBase* getCommand() const { return this->command; };314 315 private:316 /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */317 ExecutorAlias(const char* aliasName, ExecutorBase* command) { this->aliasName = aliasName; this->command = command; };318 319 private:320 const char* aliasName; //!< the name of the Alias321 ExecutorBase* command; //!< a pointer to the command, this alias executes.322 };323 324 328 #endif /* _EXECUTOR_H */ -
trunk/src/lib/util/multi_type.cc
r5638 r5641 101 101 this->value = mt.value; 102 102 103 if (mt.type == MT_STRING )103 if (mt.type == MT_STRING && mt.storedString != NULL) 104 104 { 105 105 this->storedString = new char[strlen (mt.storedString)+1]; … … 107 107 this->value.String = this->storedString; 108 108 } 109 else 110 this->storedString = NULL; 109 111 } 110 112 … … 290 292 { 291 293 if (this->type & MT_BOOL) return (this->value.Bool)? "true" : "false"; 292 else if (this->type & MT_CHAR) &this->value.Char;293 294 294 char tmpString[128]; 295 295 if (this->storedString != NULL) … … 298 298 this->storedString = NULL; 299 299 } 300 301 if (this->type & MT_INT) 300 if (this->type & MT_CHAR) 301 { 302 this->storedString = new char[2]; 303 this->storedString[0] = this->value.Char; 304 this->storedString[1] = '\0'; 305 return this->storedString; 306 } 307 else if (this->type & MT_INT) 302 308 { 303 309 sprintf(tmpString, "%d", this->value.Int);
Note: See TracChangeset
for help on using the changeset viewer.