Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell_command.h @ 5639

Last change on this file since 5639 was 5639, checked in by bensch, 19 years ago

orxonox/trunk: splitted shell_command into shell_command and shell_command_class

File size: 5.1 KB
RevLine 
[4838]1/*!
[5129]2 * @file shell_command.h
[5068]3 * Definition of a on-screen-shell
[5391]4 */
[1853]5
[5129]6#ifndef _SHELL_COMMAND_H
7#define _SHELL_COMMAND_H
[1853]8
[5129]9#include "base_object.h"
[1853]10
[5141]11#include "helper_functions.h"
[5552]12#include "multi_type.h"
[5155]13#include "substring.h"
[5143]14#include "functor_list.h"
[5636]15#include "executor/executor.h"
[5068]16#include <stdarg.h>
17
[5166]18#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
[5130]19
[5127]20
[5130]21
[4838]22// FORWARD DECLARATION
[5068]23template<class T> class tList;
[5639]24class ShellCommandClass;
25class ShellCommandAlias;
[3543]26
[5166]27/**
28 * an easy to use Macro to create a Command
29 * @param command the name of the command (without "" around the string)
30 * @param class the name of the class to apply this command to (without the "" around the string)
31 * @param function the function to call
[5179]32 *
33 * MEANING:
[5636]34 *  ShellCommand* someUniqueVarName =
[5179]35 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
36 *
37 * In the Shell you would call this Command using:
38 * $ ClassName [ObjectName] commandNameInShell [parameters]
[5166]39 */
[5636]40//#define SHELL_COMMAND(command, class, function) \
41//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
[5162]42#define SHELL_COMMAND(command, class, function) \
[5636]43           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function))
44
[5329]45/**
46 * an easy to use Macro to create a Command
47 * @param command the name of the command (without "" around the string)
48 * @param class the name of the class to apply this command to (without the "" around the string)
49 * @param function the function to call
50 *
51 * MEANING:
[5636]52 *  ShellCommand* someUniqueVarName =
[5329]53 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
54 *
55 * In the Shell you would call this Command using:
56 * $ ClassName [ObjectName] commandNameInShell [parameters]
57 */
58#define SHELL_COMMAND_STATIC(command, class, function) \
[5636]59           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function))
[5135]60
[5162]61
[5328]62//! an enumerator for the definition of the Type.
63typedef enum {
64  ShellCommand_Objective = 1,
65  ShellCommand_Static    = 2,
66} ShellCommand_Type;
67
[5161]68//! a baseClass for all possible ShellCommands
[5636]69class ShellCommand : public BaseObject
[5161]70{
[5170]71  friend class ShellCommandClass;
[5161]72  public:
73    static bool execute (const char* executionString);
74
[5636]75    ShellCommand* describe(const char* description);
76    ShellCommand* setAlias(const char* alias);
77    ShellCommand* defaultValues(unsigned int count, ...);
[5164]78
[5636]79    static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor);
80
[5166]81    static void unregisterCommand(const char* commandName, const char* className);
[5161]82
83    static void debug();
84
85  protected:
[5637]86    ShellCommand(const char* commandName, const char* className, Executor* executor);
[5636]87    ~ShellCommand();
[5161]88
[5328]89    /** @returns the Type of this Function (either static or objective) */
90    inline ShellCommand_Type getType() { return this->functorType; };
91
[5637]92    static bool isRegistered(const char* commandName, const char* className, Executor* executor);
[5161]93    static const char* paramToString(long parameter);
94
95  protected:
[5328]96    ShellCommand_Type                functorType;                          //!< The type of Function we've got (either static or objective).
[5163]97    void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
[5166]98    unsigned int                     paramCount;                           //!< the count of parameters.
99    unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
[5552]100    MultiType*                       defaultValue;                         //!< Default Values.
[5161]101
102  private:
[5170]103    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
[5196]104    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
[5161]105
[5166]106    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
[5636]107    Executor*                        executor;
[5161]108
[5129]109};
[5113]110
[5197]111//! A Class, that handles aliases.
[5190]112class ShellCommandAlias
113{
[5636]114  friend class ShellCommand;
[5190]115  public:
[5197]116    /** @returns the Name of the Alias. */
[5195]117    const char* getName() const { return this->aliasName; };
[5197]118    /** @returns the Command, this Alias is asociated with */
[5636]119    ShellCommand* getCommand() const { return this->command; };
[5196]120
[5190]121  private:
[5197]122    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
[5636]123    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
[5196]124
125  private:
[5197]126    const char*         aliasName;       //!< the name of the Alias
[5636]127    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[5190]128};
129
[5129]130#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.