Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2008, 5:30:11 AM (16 years ago)
Author:
landauf
Message:

merged console branch into network branch

after several heavy troubles it compiles, but there is still a bug I couldn't fix: orxonox crashes as soon as one presses a key after opening the console… maybe someone else sees the problem?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/CommandExecutor.h

    r1349 r1446  
    3232#include "CorePrereqs.h"
    3333
    34 #include <string>
    3534#include <map>
    36 #include <list>
    3735
    38 #include "util/SubString.h"
    39 #include "util/MultiTypeMath.h"
    40 
    41 #define COMMAND_EXECUTOR_CURSOR "$"
     36#include "CommandEvaluation.h"
    4237
    4338namespace orxonox
    4439{
    45     enum CommandState
    46     {
    47         CS_Uninitialized,
    48         CS_Empty,
    49         CS_FunctionClass_Or_Shortcut_Or_Keyword,
    50         CS_Shortcut_Params,
    51         CS_Shortcut_Finished,
    52         CS_Function,
    53         CS_Function_Params,
    54         CS_Function_Finished,
    55         CS_ConfigValueClass,
    56         CS_ConfigValue,
    57         CS_ConfigValueType,
    58         CS_ConfigValueFinished,
    59         CS_KeybindKey,
    60         CS_KeybindCommand,
    61         CS_KeybindFinished,
    62         CS_Error
    63     };
    64 
    65     void exec(const std::string& filename);
    66     std::string echo(const std::string& text);
    67 
    68     void write(const std::string& filename, const std::string& text);
    69     void append(const std::string& filename, const std::string& text);
    70     std::string read(const std::string& filename);
    71 
    72     ///////////////////////
    73     // CommandEvaluation //
    74     ///////////////////////
    75     class _CoreExport CommandEvaluation
    76     {
    77         friend class CommandExecutor;
    78 
    79         public:
    80             CommandEvaluation();
    81 
    82             KeybindMode::Enum getKeybindMode();
    83             bool isValid() const;
    84 
    85             inline void setAdditionalParameter(const std::string& param)
    86                 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }
    87             inline std::string getAdditionalParameter() const
    88                 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }
    89             inline ExecutorStatic* getEvaluatedExecutor() { return evaluatedExecutor_; }
    90             inline std::string getCommandString() { return this->processedCommand_; }
    91 
    92             void setEvaluatedParameter(unsigned int index, MultiTypeMath param);
    93             MultiTypeMath getEvaluatedParameter(unsigned int index) const;
    94 
    95             void evaluateParams();
    96 
    97             bool hasReturnvalue() const;
    98             MultiTypeMath getReturnvalue() const;
    99 
    100         private:
    101             std::string processedCommand_;
    102             SubString tokens_;
    103             std::string additionalParameter_;
    104 
    105             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctionClasses_;
    106             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleShortcuts_;
    107             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;
    108             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValueClasses_;
    109             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValues_;
    110             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleKeys_;
    111 
    112             Identifier* functionclass_;
    113             Identifier* configvalueclass_;
    114             ExecutorStatic* shortcut_;
    115             ExecutorStatic* function_;
    116             ConfigValueContainer* configvalue_;
    117             ConfigValueContainer* key_;
    118 
    119             std::string errorMessage_;
    120             CommandState state_;
    121 
    122             bool bEvaluatedParams_;
    123             MultiTypeMath param_[5];
    124             ExecutorStatic* evaluatedExecutor_;
    125     };
    126 
    127     /////////////////////
    128     // CommandExecutor //
    129     /////////////////////
    13040    class _CoreExport CommandExecutor
    13141    {
    13242        public:
    13343            static bool execute(const std::string& command, bool useTcl = true);
    134             static bool execute(const CommandEvaluation& evaluation);
    135 
    13644            static std::string complete(const std::string& command);
    137             static std::string complete(const CommandEvaluation& evaluation);
    138 
    13945            static std::string hint(const std::string& command);
    140             static std::string hint(const CommandEvaluation& evaluation);
    14146
    14247            static CommandEvaluation evaluate(const std::string& command);
    143 
    14448            static const CommandEvaluation& getLastEvaluation();
    14549
    146             static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
    147             static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);
    148             static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);
     50            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command);
     51            static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
     52            static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
    14953
    15054            /** @brief Returns the map that stores all console commands. @return The const_iterator */
    151             static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
     55            static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
    15256            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
    153             static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
     57            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
    15458            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
    155             static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
     59            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
    15660
    15761            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
    158             static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
     62            static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
    15963            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    160             static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
     64            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
    16165            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    162             static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
     66            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
    16367
    16468        private:
     
    17074            static CommandEvaluation& getEvaluation();
    17175
     76            static void parseIfNeeded(const std::string& command);
    17277            static void parse(const std::string& command, bool bInitialize = true);
    173             static void initialize(const std::string& command);
    17478
    175             static bool argumentsGiven(unsigned int num);
     79            static unsigned int argumentsFinished();
    17680            static unsigned int argumentsGiven();
     81            static bool enoughArgumentsGiven(ConsoleCommand* command);
     82            static std::string getArgument(unsigned int index);
     83            static std::string getLastArgument();
    17784
    178             static std::string getToken(unsigned int index);
     85            static void createListOfPossibleIdentifiers(const std::string& fragment);
     86            static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0);
     87            static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param);
    17988
    180             static bool enoughParametersGiven(unsigned int head, Executor* executor);
     89            static Identifier* getPossibleIdentifier(const std::string& name);
     90            static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
     91            static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
    18192
    182             static void createListOfPossibleShortcuts(const std::string& fragment);
    183             static void createListOfPossibleFunctionClasses(const std::string& fragment);
    184             static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier);
    185             static void createListOfPossibleConfigValueClasses(const std::string& fragment);
    186             static void createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier);
    187             static void createListOfPossibleKeys(const std::string& fragment);
    188 
    189             static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second);
    190 
    191             static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
    192             static std::string dump(const ExecutorStatic* executor);
    193             static std::string dump(const ConfigValueContainer* container);
    194 
     93            static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
    19594            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
    196 
    197             static Identifier* getIdentifierOfPossibleFunctionClass(const std::string& name);
    198             static ExecutorStatic* getExecutorOfPossibleShortcut(const std::string& name);
    199             static ExecutorStatic* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier);
    200             static Identifier* getIdentifierOfPossibleConfigValueClass(const std::string& name);
    201             static ConfigValueContainer* getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier);
    202             static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name);
     95            static std::string getCommonBegin(const ArgumentCompletionList& list);
    20396
    20497            CommandEvaluation evaluation_;
    205 
    206             std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_;
    207             std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_;
     98            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
     99            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
    208100    };
    209101}
Note: See TracChangeset for help on using the changeset viewer.