Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5639 in orxonox.OLD for trunk/src/lib/shell/shell_command_class.h


Ignore:
Timestamp:
Nov 18, 2005, 7:21:32 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: splitted shell_command into shell_command and shell_command_class

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command_class.h

    r5637 r5639  
    11/*!
    2  * @file shell_command.h
     2 * @file shell_command_class.h
    33 * Definition of a on-screen-shell
    44 */
    55
    6 #ifndef _SHELL_COMMAND_H
    7 #define _SHELL_COMMAND_H
     6#ifndef _SHELL_COMMAND_CLASS_H
     7#define _SHELL_COMMAND_CLASS_H
    88
    99#include "base_object.h"
    10 
    11 #include "helper_functions.h"
    12 #include "multi_type.h"
    13 #include "substring.h"
    14 #include "functor_list.h"
    15 #include "executor/executor.h"
    16 #include <stdarg.h>
    17 
    18 #define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
    19 
    2010
    2111
    2212// FORWARD DECLARATION
    2313template<class T> class tList;
    24 
    25 /**
    26  * an easy to use Macro to create a Command
    27  * @param command the name of the command (without "" around the string)
    28  * @param class the name of the class to apply this command to (without the "" around the string)
    29  * @param function the function to call
    30  *
    31  * MEANING:
    32  *  ShellCommand* someUniqueVarName =
    33  *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
    34  *
    35  * In the Shell you would call this Command using:
    36  * $ ClassName [ObjectName] commandNameInShell [parameters]
    37  */
    38 //#define SHELL_COMMAND(command, class, function) \
    39 //        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
    40 #define SHELL_COMMAND(command, class, function) \
    41            ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function))
    42 
    43 /**
    44  * an easy to use Macro to create a Command
    45  * @param command the name of the command (without "" around the string)
    46  * @param class the name of the class to apply this command to (without the "" around the string)
    47  * @param function the function to call
    48  *
    49  * MEANING:
    50  *  ShellCommand* someUniqueVarName =
    51  *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
    52  *
    53  * In the Shell you would call this Command using:
    54  * $ ClassName [ObjectName] commandNameInShell [parameters]
    55  */
    56 #define SHELL_COMMAND_STATIC(command, class, function) \
    57            ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function))
    58 
    59 
    60 //! an enumerator for the definition of the Type.
    61 typedef enum {
    62   ShellCommand_Objective = 1,
    63   ShellCommand_Static    = 2,
    64 } ShellCommand_Type;
    6514
    6615////////////////
     
    9645    const char*                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
    9746    long                             classID;                   //!< The classID of this Class
    98     tList<ShellCommand>*         commandList;               //!< A list of Commands from this Class
     47    tList<ShellCommand>*             commandList;               //!< A list of Commands from this Class
    9948    static tList<ShellCommandClass>* commandClassList;          //!< A list of Classes
    10049    static tList<ShellCommandAlias>* aliasList;                 //!< An Alias to A Command. (only for classes with one Instance)
    10150};
    10251
    103 
    104 //! a baseClass for all possible ShellCommands
    105 class ShellCommand : public BaseObject
    106 {
    107   friend class ShellCommandClass;
    108   public:
    109     static bool execute (const char* executionString);
    110 
    111     ShellCommand* describe(const char* description);
    112     ShellCommand* setAlias(const char* alias);
    113     ShellCommand* defaultValues(unsigned int count, ...);
    114 
    115     static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor);
    116 
    117     static void unregisterCommand(const char* commandName, const char* className);
    118 
    119     static void debug();
    120 
    121   protected:
    122     ShellCommand(const char* commandName, const char* className, Executor* executor);
    123     ~ShellCommand();
    124 
    125     /** @returns the Type of this Function (either static or objective) */
    126     inline ShellCommand_Type getType() { return this->functorType; };
    127 
    128     static bool isRegistered(const char* commandName, const char* className, Executor* executor);
    129     static const char* paramToString(long parameter);
    130 
    131   protected:
    132     ShellCommand_Type                functorType;                          //!< The type of Function we've got (either static or objective).
    133     void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    134     unsigned int                     paramCount;                           //!< the count of parameters.
    135     unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
    136     MultiType*                       defaultValue;                         //!< Default Values.
    137 
    138   private:
    139     ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
    140     ShellCommandAlias*               alias;                                //!< An Alias for the Class.
    141 
    142     const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
    143     Executor*                        executor;
    144 
    145 };
    146 
    147 //! A Class, that handles aliases.
    148 class ShellCommandAlias
    149 {
    150   friend class ShellCommand;
    151   public:
    152     /** @returns the Name of the Alias. */
    153     const char* getName() const { return this->aliasName; };
    154     /** @returns the Command, this Alias is asociated with */
    155     ShellCommand* getCommand() const { return this->command; };
    156 
    157   private:
    158     /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
    159     ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
    160 
    161   private:
    162     const char*         aliasName;       //!< the name of the Alias
    163     ShellCommand*   command;         //!< a pointer to the command, this alias executes.
    164 };
    165 
    16652#endif /* _SHELL_COMMAND_H */
Note: See TracChangeset for help on using the changeset viewer.