Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some renamings, and GameWorldData now has lists for what EntityLists should be drawed/ticked/collided(not yet implemented).

File size: 4.4 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  private:
[5170]85    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
[5196]86    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
[5161]87
[7221]88    std::string                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
[5642]89    Executor*                        executor;                             //!< The Executor, that really executes the Function.
[5161]90
[5129]91};
[5113]92
[5197]93//! A Class, that handles aliases.
[5190]94class ShellCommandAlias
95{
[5636]96  friend class ShellCommand;
[5190]97  public:
[5197]98    /** @returns the Name of the Alias. */
[7221]99    const std::string& getName() const { return this->aliasName; };
[5197]100    /** @returns the Command, this Alias is asociated with */
[5636]101    ShellCommand* getCommand() const { return this->command; };
[5196]102
[5190]103  private:
[5197]104    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
[7221]105    ShellCommandAlias(const std::string& aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
[5196]106
107  private:
[7221]108    std::string     aliasName;       //!< the name of the Alias
[5636]109    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[5190]110};
111
[5129]112#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.