Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5641 in orxonox.OLD for trunk


Ignore:
Timestamp:
Nov 18, 2005, 9:22:23 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Passing Reference inastead of Pointer to create ShellCommand

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command.cc

    r5640 r5641  
    3636 * @param paramCount the count of parameters this command takes
    3737 */
    38 ShellCommand::ShellCommand(const char* commandName, const char* className, Executor* executor)
     38ShellCommand::ShellCommand(const char* commandName, const char* className, const Executor& executor)
    3939{
    4040  this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     
    5454  this->defaultValue = new MultiType[paramCount];
    5555
    56   this->executor = executor;
     56  this->executor = executor.clone();
    5757}
    5858
     
    6969    delete this->alias;
    7070  }
     71  delete this->executor;
    7172}
    7273
     
    7475 * registers a new ShellCommand
    7576 */
    76 ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, Executor* executor)
     77ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, const Executor& executor)
    7778{
    7879  if (ShellCommand::isRegistered(commandName, className, executor))
     
    132133 * This is checked in the registerCommand-function.
    133134 */
    134 bool ShellCommand::isRegistered(const char* commandName, const char* className, Executor* executor)
     135bool ShellCommand::isRegistered(const char* commandName, const char* className, const Executor& executor)
    135136{
    136137  if (ShellCommandClass::commandClassList == NULL)
  • trunk/src/lib/shell/shell_command.h

    r5640 r5641  
    4141//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
    4242#define SHELL_COMMAND(command, class, function) \
    43            ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function))
     43           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
    4444
    4545/**
     
    5757 */
    5858#define SHELL_COMMAND_STATIC(command, class, function) \
    59            ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function))
     59           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
    6060
    6161
     
    7272    ShellCommand* defaultValues(unsigned int count, ...);
    7373
    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);
    7575
    7676    static void unregisterCommand(const char* commandName, const char* className);
     
    7979
    8080  protected:
    81     ShellCommand(const char* commandName, const char* className, Executor* executor);
     81    ShellCommand(const char* commandName, const char* className, const Executor& executor);
    8282    ~ShellCommand();
    8383
    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);
    8585    static const char* paramToString(long parameter);
    8686
    8787  protected:
    88     void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    8988    unsigned int                     paramCount;                           //!< the count of parameters.
    9089    unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
  • trunk/src/lib/shell/shell_command_class.cc

    r5639 r5641  
    217217  {
    218218    ShellCommandClass::commandClassList = new tList<ShellCommandClass>;
    219     ShellCommand::registerCommand("debug", "ShellCommand", new ExecutorStatic<ShellCommand>(ShellCommand::debug));
     219    ShellCommand::registerCommand("debug", "ShellCommand", ExecutorStatic<ShellCommand>(ShellCommand::debug));
    220220  }
    221221}
  • trunk/src/lib/util/executor/executor.cc

    r5636 r5641  
    3232// SHELL COMMAND BASE //
    3333////////////////////////
     34// empty constructor
     35Executor::Executor()
     36{
     37  this->defaultValue = NULL;
     38}
     39
    3440/**
    3541 * constructs and registers a new Command
     
    6369  delete[] this->defaultValue;
    6470}
     71
     72/**
     73 * clones this element into executor.
     74 */
     75void 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
    6585
    6686/**
  • trunk/src/lib/util/executor/executor.h

    r5636 r5641  
    2222typedef enum {
    2323  Executor_Objective   = 1,
    24   Executor_Static    = 2,
     24  Executor_Static      = 2,
    2525} Executor_Type;
    2626
     
    3232{
    3333  public:
     34    virtual ~Executor();
     35
     36    virtual Executor* clone () const = 0;
     37
    3438    Executor* defaultValues(unsigned int count, ...);
    3539    Executor* defaultValues(unsigned int count, va_list values);
     
    3842    virtual void execute (BaseObject* object, const char* parameters) = 0;
    3943
     44    /** @returns the Type of this Function (either static or objective) */
     45    inline Executor_Type getType() const { return this->functorType; };
     46
    4047    static void debug();
    4148
    4249  protected:
     50    Executor();
    4351    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;
    4854
    4955  protected:
     
    5157    unsigned int                     paramCount;                           //!< the count of parameters.
    5258    MultiType*                       defaultValue;                         //!< Default Values.
    53 
    54   private:
    5559};
    5660
     
    226230template<class T> class ExecutorObjective : public Executor
    227231{
    228 
    229232  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
    230243//! FUNCTOR_LIST is the List of CommandConstructors
    231244#define FUNCTOR_LIST(x) ExecutorConstructor ## x
     
    279292{
    280293  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
    281304//! FUNCTOR_LIST is the List of CommandConstructors
    282305#define FUNCTOR_LIST(x) ExecutorConstructor ## x
     
    303326};
    304327
    305 //! A Class, that handles aliases.
    306 class ExecutorAlias
    307 {
    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 Alias
    321     ExecutorBase*       command;         //!< a pointer to the command, this alias executes.
    322 };
    323 
    324328#endif /* _EXECUTOR_H */
  • trunk/src/lib/util/multi_type.cc

    r5638 r5641  
    101101  this->value = mt.value;
    102102
    103   if (mt.type == MT_STRING)
     103  if (mt.type == MT_STRING && mt.storedString != NULL)
    104104  {
    105105    this->storedString = new char[strlen (mt.storedString)+1];
     
    107107    this->value.String = this->storedString;
    108108  }
     109  else
     110    this->storedString = NULL;
    109111}
    110112
     
    290292  {
    291293    if (this->type & MT_BOOL) return (this->value.Bool)? "true" : "false";
    292     else if (this->type & MT_CHAR) &this->value.Char;
    293 
    294294    char tmpString[128];
    295295    if (this->storedString != NULL)
     
    298298      this->storedString = NULL;
    299299    }
    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)
    302308    {
    303309      sprintf(tmpString, "%d", this->value.Int);
  • trunk/src/orxonox.cc

    r5546 r5641  
    4949
    5050#include "class_list.h"
     51#include "shell_command_class.h"
    5152#include "shell_command.h"
    5253#include "shell_buffer.h"
Note: See TracChangeset for help on using the changeset viewer.