Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9413 was 8145, checked in by bensch, 18 years ago

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

File size: 5.6 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"
[7407]12#include "shell_completion_plugin.h"
[5068]13
[5166]14#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
[5130]15
[7374]16namespace OrxShell
17{
18  // FORWARD DECLARATION
19  class ShellCommandClass;
20  class ShellCommandAlias;
[7407]21  class CompletorPlugin;
[3543]22
[7374]23  /**
[7398]24   * @brief an easy to use Macro to create a Command
[7374]25   * @param command the name of the command (without "" around the string)
26   * @param class the name of the class to apply this command to (without the "" around the string)
27   * @param function the function to call
28   *
29   * MEANING:
30   *  ShellCommand* someUniqueVarName =
31   *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
32   *
33   * In the Shell you would call this Command using:
34   * $ ClassName [ObjectName] commandNameInShell [parameters]
35   */
[5162]36#define SHELL_COMMAND(command, class, function) \
[7722]37           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class>(&class::function))
[5636]38
[7374]39  /**
[7398]40   * @brief an easy to use Macro to create a Command
[7374]41   * @param command the name of the command (without "" around the string)
42   * @param class the name of the class to apply this command to (without the "" around the string)
43   * @param function the function to call
44   *
45   * MEANING:
46   *  ShellCommand* someUniqueVarName =
47   *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
48   *
49   * In the Shell you would call this Command using:
50   * $ ClassName [ObjectName] commandNameInShell [parameters]
51   */
[5329]52#define SHELL_COMMAND_STATIC(command, class, function) \
[7722]53           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class>(function))
[5135]54
[5162]55
[5328]56
[7374]57  //! a baseClass for all possible ShellCommands
58  class ShellCommand : public BaseObject
59  {
60    friend class ShellCommandClass;
[5161]61  public:
[7221]62    static bool execute (const std::string& executionString);
[5161]63
[7221]64    ShellCommand* describe(const std::string& description);
[7225]65    ShellCommand* setAlias(const std::string& alias);
[7198]66    ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
67                                const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
68                                const MultiType& value4 = MT_NULL);
[7412]69    ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin);
[5164]70
[7722]71    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor* executor);
[7225]72    static void unregisterCommand(const std::string& commandName, const std::string& className);
[7408]73    static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className);
[7413]74    static const ShellCommand* const getCommand(const std::string& commandName, const ShellCommandClass* cmdClass);
[7403]75    static bool exists(const std::string& commandName, const std::string& className);
[7417]76    static const ShellCommand* const getCommandFromInput(const std::string& inputLine, unsigned int& paramBegin, std::vector<BaseObject*>* boList = NULL);
77    static const ShellCommand* const getCommandFromInput(const SubString& strings, unsigned int& paramBegin, std::vector<BaseObject*>* boList = NULL);
[5161]78
[7409]79    const ShellCommandClass* const getCommandClass() const { return this->shellClass; };
80    const ShellCommandAlias* const getAlias() const { return this->alias; }
[7407]81    unsigned int getParamCount() const { return this->executor->getParamCount(); }
82    const CompletorPlugin* const getCompletorPlugin(unsigned int i) const { return this->completors[i]; };
83
[7742]84    void help() const;
[5161]85
86  protected:
[7722]87    ShellCommand(const std::string& commandName, const std::string& className, Executor* executor);
[7386]88    virtual ~ShellCommand();
[5161]89
[7418]90    static bool fillObjectList(const std::string& objectDescriptor, const ShellCommand* cmd, std::vector<BaseObject*>* boList);
[7401]91    static const std::string& paramToString(long parameter);
[5161]92
93  private:
[7397]94    ShellCommandClass*               shellClass;            //!< A Pointer to the Shell-Class this Command belongs to.
95    ShellCommandAlias*               alias;                 //!< An Alias for the Class.
[5161]96
[7397]97    std::string                      description;           //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla");
[7407]98    std::vector<CompletorPlugin*>    completors;            //!< Completors for the Parameters
[7397]99    Executor*                        executor;              //!< The Executor, that really executes the Function.
[7374]100  };
[5113]101
[7374]102  //! A Class, that handles aliases.
103  class ShellCommandAlias
104  {
[5190]105  public:
[7397]106    ShellCommandAlias(const std::string& aliasName, ShellCommand* command);
107    ~ShellCommandAlias();
108
[5197]109    /** @returns the Name of the Alias. */
[7221]110    const std::string& getName() const { return this->aliasName; };
[5197]111    /** @returns the Command, this Alias is asociated with */
[5636]112    ShellCommand* getCommand() const { return this->command; };
[7389]113    static bool getCommandListOfAlias(std::list<std::string>& stringList);
[7397]114    static const std::vector<ShellCommandAlias*>& getAliases() { return ShellCommandAlias::aliasList; };
[5196]115
[5190]116  private:
[7221]117    std::string     aliasName;       //!< the name of the Alias
[5636]118    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[7389]119
120    static std::vector<ShellCommandAlias*> aliasList; //!< A list of Aliases to A Commands.
[7374]121  };
[5190]122
[7374]123}
124
[5129]125#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.