/* * ORXONOX - the hottest 3D action shooter ever to exist * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * */ #ifndef _CommandExecutor_H__ #define _CommandExecutor_H__ #include #include #include #include "CorePrereqs.h" class SubString; namespace orxonox { class _CoreExport CommandExecutor { enum CommandState { CS_Empty, CS_FunctionClass_Or_Shortcut_Or_Keyword, CS_Shortcut_Params, CS_Shortcut_Finished, CS_Function, CS_Function_Params, CS_Function_Finished, CS_ConfigValueClass, CS_ConfigValue, CS_ConfigValueType, CS_ConfigValueFinished, CS_KeybindKey, CS_KeybindCommand, CS_KeybindFinished, CS_Error }; public: static bool execute(const std::string& command); static std::string complete(const std::string& command); static std::string hint(const std::string& command); static bool addConsoleCommandShortcut(ExecutorStatic* executor); static ExecutorStatic* getConsoleCommandShortcut(const std::string& name); static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name); /** @brief Returns the map that stores all console commands. @return The const_iterator */ static inline const std::map& getConsoleCommandShortcutMap() { return CommandExecutor::consoleCommandShortcuts_s; } /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ static inline std::map::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::consoleCommandShortcuts_s.begin(); } /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ static inline std::map::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::consoleCommandShortcuts_s.end(); } /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ static inline const std::map& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::consoleCommandShortcuts_LC_s; } /** @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 */ static inline std::map::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::consoleCommandShortcuts_LC_s.begin(); } /** @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 */ static inline std::map::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::consoleCommandShortcuts_LC_s.end(); } private: static void parse(const std::string& command, bool bInitialize = true); static void initialize(); static bool argumentsGiven(unsigned int num); static unsigned int argumentsGiven(); static std::string getToken(unsigned int index); static bool enoughParametersGiven(unsigned int head, Executor* executor); static void createListOfPossibleShortcuts(const std::string& fragment); static void createListOfPossibleFunctionClasses(const std::string& fragment); static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier); static void createListOfPossibleConfigValueClasses(const std::string& fragment); static void createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier); static void createListOfPossibleKeys(const std::string& fragment); static bool compareStringsInList(const std::string* first, const std::string* second); static std::string dump(const std::list& list); static std::string dump(const ExecutorStatic* executor); static std::string dump(const ConfigValueContainer* container); static std::string getCommonBegin(const std::list& list); static Identifier* getIdentifierOfPossibleFunctionClass(const std::string& name); static ExecutorStatic* getExecutorOfPossibleShortcut(const std::string& name); static ExecutorStatic* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier); static Identifier* getIdentifierOfPossibleConfigValueClass(const std::string& name); static ConfigValueContainer* getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier); static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name); static const char cursor_s = '$'; static std::string lastProcessedCommand_s; static SubString tokens_s; static std::list listOfPossibleFunctionClasses_s; static std::list listOfPossibleShortcuts_s; static std::list listOfPossibleFunctions_s; static std::list listOfPossibleConfigValueClasses_s; static std::list listOfPossibleConfigValues_s; static std::list listOfPossibleKeys_s; static Identifier* functionclass_s; static Identifier* configvalueclass_s; static ExecutorStatic* shortcut_s; static ExecutorStatic* function_s; static ConfigValueContainer* configvalue_s; static ConfigValueContainer* key_s; static std::string errorMessage_s; static CommandState state_s; static std::map consoleCommandShortcuts_s; static std::map consoleCommandShortcuts_LC_s; }; } #endif /* _CommandExecutor_H__ */