Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more std::string

File size: 4.5 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
[5636]11#include "executor/executor.h"
[5068]12#include <stdarg.h>
13
[5166]14#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
[5130]15
[5127]16
[5130]17
[4838]18// FORWARD DECLARATION
[5639]19class ShellCommandClass;
20class ShellCommandAlias;
[3543]21
[5166]22/**
23 * an easy to use Macro to create a Command
24 * @param command the name of the command (without "" around the string)
25 * @param class the name of the class to apply this command to (without the "" around the string)
26 * @param function the function to call
[5179]27 *
28 * MEANING:
[5636]29 *  ShellCommand* someUniqueVarName =
[5179]30 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
31 *
32 * In the Shell you would call this Command using:
33 * $ ClassName [ObjectName] commandNameInShell [parameters]
[5166]34 */
[5636]35//#define SHELL_COMMAND(command, class, function) \
36//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
[5162]37#define SHELL_COMMAND(command, class, function) \
[5641]38           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
[5636]39
[5329]40/**
41 * an easy to use Macro to create a Command
42 * @param command the name of the command (without "" around the string)
43 * @param class the name of the class to apply this command to (without the "" around the string)
44 * @param function the function to call
45 *
46 * MEANING:
[5636]47 *  ShellCommand* someUniqueVarName =
[5329]48 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
49 *
50 * In the Shell you would call this Command using:
51 * $ ClassName [ObjectName] commandNameInShell [parameters]
52 */
53#define SHELL_COMMAND_STATIC(command, class, function) \
[5641]54           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
[5135]55
[5162]56
[5328]57
[5161]58//! a baseClass for all possible ShellCommands
[5636]59class ShellCommand : public BaseObject
[5161]60{
[5170]61  friend class ShellCommandClass;
[5161]62  public:
[7221]63    static bool execute (const std::string& executionString);
[5161]64
[7221]65    ShellCommand* describe(const std::string& description);
[7225]66    ShellCommand* setAlias(const std::string& alias);
[7198]67    ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
68                                const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
69                                const MultiType& value4 = MT_NULL);
[5164]70
[7225]71    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, const Executor& executor);
[5636]72
[7225]73    static void unregisterCommand(const std::string& commandName, const std::string& className);
[5161]74
75    static void debug();
76
77  protected:
[7225]78    ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor);
[5636]79    ~ShellCommand();
[5161]80
[7225]81    static bool isRegistered(const std::string& commandName, const std::string& className);
[5161]82    static const char* paramToString(long parameter);
83
84  protected:
[5552]85    MultiType*                       defaultValue;                         //!< Default Values.
[5161]86
87  private:
[5170]88    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
[5196]89    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
[5161]90
[7221]91    std::string                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
[5642]92    Executor*                        executor;                             //!< The Executor, that really executes the Function.
[5161]93
[5129]94};
[5113]95
[5197]96//! A Class, that handles aliases.
[5190]97class ShellCommandAlias
98{
[5636]99  friend class ShellCommand;
[5190]100  public:
[5197]101    /** @returns the Name of the Alias. */
[7221]102    const std::string& getName() const { return this->aliasName; };
[5197]103    /** @returns the Command, this Alias is asociated with */
[5636]104    ShellCommand* getCommand() const { return this->command; };
[5196]105
[5190]106  private:
[5197]107    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
[7221]108    ShellCommandAlias(const std::string& aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
[5196]109
110  private:
[7221]111    std::string     aliasName;       //!< the name of the Alias
[5636]112    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[5190]113};
114
[5129]115#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.