[Orxonox-commit 2509] r7216 - in code/branches/consolecommands3/src/libraries/core: . command
landauf at orxonox.net
landauf at orxonox.net
Wed Aug 25 19:07:08 CEST 2010
Author: landauf
Date: 2010-08-25 19:07:08 +0200 (Wed, 25 Aug 2010)
New Revision: 7216
Modified:
code/branches/consolecommands3/src/libraries/core/Identifier.cc
code/branches/consolecommands3/src/libraries/core/Identifier.h
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
Log:
removed old console command implementation (doesn't compile)
Modified: code/branches/consolecommands3/src/libraries/core/Identifier.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Identifier.cc 2010-08-25 15:35:37 UTC (rev 7215)
+++ code/branches/consolecommands3/src/libraries/core/Identifier.cc 2010-08-25 17:07:08 UTC (rev 7216)
@@ -39,7 +39,6 @@
#include "ConfigValueContainer.h"
#include "ClassFactory.h"
#include "XMLPort.h"
-#include "command/ConsoleCommand.h"
namespace orxonox
{
@@ -63,7 +62,6 @@
this->bLoadable_ = false;
this->bHasConfigValues_ = false;
- this->bHasConsoleCommands_ = false;
// Default network ID is the class ID
this->networkID_ = this->classID_;
@@ -79,8 +77,6 @@
if (this->factory_)
delete this->factory_;
- for (std::map<std::string, ConsoleCommand*>::iterator it = this->consoleCommands_.begin(); it != this->consoleCommands_.end(); ++it)
- delete (it->second);
for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)
delete (it->second);
for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it)
@@ -432,59 +428,6 @@
}
/**
- @brief Adds a new console command of this class.
- @param executor The executor of the command
- @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command
- @return The executor of the command
- */
- ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut)
- {
- std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName());
- if (it != this->consoleCommands_.end())
- {
- COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << '.' << std::endl;
- delete (it->second);
- }
-
- this->bHasConsoleCommands_ = true;
- this->consoleCommands_[command->getName()] = command;
- this->consoleCommands_LC_[getLowercase(command->getName())] = command;
-
- if (bCreateShortcut)
- CommandExecutor::addConsoleCommandShortcut(command);
-
- return (*command);
- }
-
- /**
- @brief Returns the executor of a console command with given name.
- @brief name The name of the requested console command
- @return The executor of the requested console command
- */
- ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const
- {
- std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name);
- if (it != this->consoleCommands_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
- @brief Returns the executor of a console command with given name in lowercase.
- @brief name The name of the requested console command in lowercae
- @return The executor of the requested console command
- */
- ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const
- {
- std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name);
- if (it != this->consoleCommands_LC_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
@brief Returns a XMLPortParamContainer that loads a parameter of this class.
@param paramname The name of the parameter
@return The container
Modified: code/branches/consolecommands3/src/libraries/core/Identifier.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Identifier.h 2010-08-25 15:35:37 UTC (rev 7215)
+++ code/branches/consolecommands3/src/libraries/core/Identifier.h 2010-08-25 17:07:08 UTC (rev 7216)
@@ -203,31 +203,6 @@
ConfigValueContainer* getConfigValueContainer(const std::string& varname);
- ////////////////////////////
- ///// Console Commands /////
- ////////////////////////////
- /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */
- inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }
-
- /** @brief Returns the map that stores all console commands. @return The const_iterator */
- inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandMap() const { return this->consoleCommands_; }
- /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
- inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
- inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }
-
- /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
- inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }
- /** @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 */
- inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.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 */
- inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
-
- ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
- ConsoleCommand* getConsoleCommand(const std::string& name) const;
- ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
-
-
///////////////////
///// XMLPort /////
///////////////////
@@ -305,10 +280,6 @@
bool bHasConfigValues_; //!< True if this class has at least one assigned config value
std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
- bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command
- std::map<std::string, ConsoleCommand*> consoleCommands_; //!< All console commands of this class
- std::map<std::string, ConsoleCommand*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase
-
std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters
std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects
};
Modified: code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc 2010-08-25 15:35:37 UTC (rev 7215)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc 2010-08-25 17:07:08 UTC (rev 7216)
@@ -53,53 +53,6 @@
return CommandExecutor::getInstance().evaluation_;
}
- ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit)
- {
- std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName());
- if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
- {
- COUT(2) << "Warning: Overwriting console-command shortcut with name " << command->getName() << '.' << std::endl;
- }
-
- // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier
- if (command && bDeleteAtExit)
- {
- CommandExecutor::getInstance().consoleCommandExternals_.insert(command);
- }
-
- CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
- CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(command->getName())] = command;
- return (*command);
- }
-
- /**
- @brief Returns the executor of a console command shortcut with given name.
- @brief name The name of the requested console command shortcut
- @return The executor of the requested console command shortcut
- */
- ConsoleCommand* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
- {
- std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
- if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
- @brief Returns the executor of a console command shortcut with given name in lowercase.
- @brief name The name of the requested console command shortcut in lowercase
- @return The executor of the requested console command shortcut
- */
- ConsoleCommand* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
- {
- std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
- if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end())
- return it->second;
- else
- return 0;
- }
-
bool CommandExecutor::execute(const std::string& command, bool useTcl)
{
if (useTcl)
Modified: code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h 2010-08-25 15:35:37 UTC (rev 7215)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h 2010-08-25 17:07:08 UTC (rev 7216)
@@ -56,26 +56,6 @@
static CommandEvaluation evaluate(const std::string& command);
static const CommandEvaluation& getLastEvaluation();
- static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false);
- static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
- static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
-
- /** @brief Returns the map that stores all console commands. @return The const_iterator */
- static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
- /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
- static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.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<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
-
- /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
- static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
- /** @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<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.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<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
-
- static void destroyExternalCommands();
-
private:
CommandExecutor() {}
CommandExecutor(const CommandExecutor& other);
@@ -106,9 +86,6 @@
static std::string getCommonBegin(const ArgumentCompletionList& list);
CommandEvaluation evaluation_;
- std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
- std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
- std::set<ConsoleCommand*> consoleCommandExternals_;
}; // tolua_export
} // tolua_export
Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc 2010-08-25 15:35:37 UTC (rev 7215)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc 2010-08-25 17:07:08 UTC (rev 7216)
@@ -27,96 +27,9 @@
*/
#include "ConsoleCommand.h"
-#include <cassert>
#include "util/Convert.h"
#include "core/Language.h"
-
-namespace orxonox
-{
- ConsoleCommand::ConsoleCommand(const FunctorPtr& functor, const std::string& name) : Executor(functor, name)
- {
- this->accessLevel_ = AccessLevel::None;
- this->argumentCompleter_[0] = 0;
- this->argumentCompleter_[1] = 0;
- this->argumentCompleter_[2] = 0;
- this->argumentCompleter_[3] = 0;
- this->argumentCompleter_[4] = 0;
-
- this->keybindMode_ = KeybindMode::OnPress;
- this->inputConfiguredParam_ = -1;
- }
-
- ConsoleCommand& ConsoleCommand::argumentCompleter(unsigned int param, ArgumentCompleter* completer)
- {
- if (param < 5)
- this->argumentCompleter_[param] = completer;
- else
- {
- COUT(2) << "Warning: Couldn't add autocompletion-function for param " << param << ": index out of bound." << std::endl;
- }
- return (*this);
- }
-
- ArgumentCompleter* ConsoleCommand::getArgumentCompleter(unsigned int param) const
- {
- if (param < 5)
- return this->argumentCompleter_[param];
- else
- return 0;
- }
-
- void ConsoleCommand::createArgumentCompletionList(unsigned int param, const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)
- {
- if (param < 5 && this->argumentCompleter_[param])
- this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5);
- else
- this->argumentList_.clear();
- }
-
- ConsoleCommand& ConsoleCommand::description(const std::string& description)
- {
- this->description_ = std::string("ConsoleCommandDescription::" + this->name_ + "::function");
- AddLanguageEntry(this->description_, description);
- return (*this);
- }
-
- const std::string& ConsoleCommand::getDescription() const
- {
- return GetLocalisation_noerror(this->description_);
- }
-
- ConsoleCommand& ConsoleCommand::descriptionParam(unsigned int param, const std::string& description)
- {
- if (param < MAX_FUNCTOR_ARGUMENTS)
- {
- this->descriptionParam_[param] = std::string("ConsoleCommandDescription::" + this->name_ + "::param" + multi_cast<std::string>(param));
- AddLanguageEntry(this->descriptionParam_[param], description);
- }
- return (*this);
- }
-
- const std::string& ConsoleCommand::getDescriptionParam(unsigned int param) const
- {
- if (param < MAX_FUNCTOR_ARGUMENTS)
- return GetLocalisation_noerror(this->descriptionParam_[param]);
-
- return this->descriptionParam_[0];
- }
-
- ConsoleCommand& ConsoleCommand::descriptionReturnvalue(const std::string& description)
- {
- this->descriptionReturnvalue_ = std::string("ConsoleCommandDescription::" + this->name_ + "::returnvalue");
- AddLanguageEntry(this->descriptionReturnvalue_, description);
- return (*this);
- }
-
- const std::string& ConsoleCommand::getDescriptionReturnvalue(int param) const
- {
- return GetLocalisation_noerror(this->descriptionReturnvalue_);
- }
-}
-
#include "core/BaseObject.h" // remove this
namespace orxonox
@@ -536,4 +449,10 @@
++it_group;
}
}
+
+ /* static */ void _ConsoleCommand::destroyAll()
+ {
+ while (!_ConsoleCommand::getCommandMap().empty() && !_ConsoleCommand::getCommandMap().begin().empty())
+ _ConsoleCommand::getCommandMap().begin().erase(_ConsoleCommand::getCommandMap().begin().begin());
+ }
}
Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h 2010-08-25 15:35:37 UTC (rev 7215)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h 2010-08-25 17:07:08 UTC (rev 7216)
@@ -36,135 +36,10 @@
#include <boost/preprocessor/facilities/expand.hpp>
#include "util/VA_NARGS.h"
-#include "core/Identifier.h"
#include "ArgumentCompletionFunctions.h"
-#include "CommandExecutor.h"
#include "Executor.h"
-#define SetConsoleCommand(classname, function, bCreateShortcut) \
- SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut)
-#define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \
- SetConsoleCommandGeneric(classname, function, name, bCreateShortcut)
-
-#define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \
- orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
-
-
-#define SetConsoleCommandShortcut(classname, function) \
- SetConsoleCommandShortcutAliasGeneric(classname, function, #function)
-#define SetConsoleCommandShortcutAlias(classname, function, name) \
- SetConsoleCommandShortcutAliasGeneric(classname, function, name)
-#define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \
- SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
-
-#define SetConsoleCommandShortcutExtern(function) \
- SetConsoleCommandShortcutExternAliasGeneric(function, #function)
-#define SetConsoleCommandShortcutExternAlias(function, name) \
- SetConsoleCommandShortcutExternAliasGeneric(function, name)
-#define SetConsoleCommandShortcutExternAliasGeneric(function, name) \
- SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
-
-#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
- orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)
-
-
-namespace orxonox
-{
- namespace AccessLevel
- {
- enum Value
- {
- None,
- User,
- Admin,
- Offline,
- Debug,
- Disabled
- };
- }
-
- class _CoreExport ConsoleCommand : public Executor
- {
- public:
- ConsoleCommand(const FunctorPtr& functor, const std::string& name = "");
-
- ConsoleCommand& description(const std::string& description);
- const std::string& getDescription() const;
-
- ConsoleCommand& descriptionParam(unsigned int param, const std::string& description);
- const std::string& getDescriptionParam(unsigned int param) const;
-
- ConsoleCommand& descriptionReturnvalue(const std::string& description);
- const std::string& getDescriptionReturnvalue(int param) const;
-
- inline ConsoleCommand& defaultValues(const MultiType& param1)
- { this->Executor::setDefaultValues(param1); return (*this); }
- inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2)
- { this->Executor::setDefaultValues(param1, param2); return (*this); }
- inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
- { this->Executor::setDefaultValues(param1, param2, param3); return (*this); }
- inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
- { this->Executor::setDefaultValues(param1, param2, param3, param4); return (*this); }
- inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
- { this->Executor::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
- inline ConsoleCommand& defaultValue(unsigned int index, const MultiType& param)
- { this->Executor::setDefaultValue(index, param); return (*this); }
-
- inline ConsoleCommand& accessLevel(AccessLevel::Value level)
- { this->accessLevel_ = level; return (*this); }
- inline AccessLevel::Value getAccessLevel() const
- { return this->accessLevel_; }
-
- ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer);
- ArgumentCompleter* getArgumentCompleter(unsigned int param) const;
-
- void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "");
- const ArgumentCompletionList& getArgumentCompletionList() const
- { return this->argumentList_; }
- ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
- { return this->argumentList_.begin(); }
- ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
- { return this->argumentList_.end(); }
-
- inline ConsoleCommand& setAsInputCommand()
- {
- this->keybindMode(KeybindMode::OnHold);
- this->defaultValue(0, Vector2(0.0f, 0.0f));
- this->inputConfiguredParam(0);
- return *this;
- }
-
- inline ConsoleCommand& keybindMode(KeybindMode::Value mode)
- { this->keybindMode_ = mode; return *this; }
- inline KeybindMode::Value getKeybindMode() const
- { return this->keybindMode_; }
-
- inline ConsoleCommand& inputConfiguredParam(int index)
- { this->inputConfiguredParam_ = index; return *this; }
- inline int getInputConfiguredParam_() const
- { return this->inputConfiguredParam_; }
-
- private:
- AccessLevel::Value accessLevel_;
- ArgumentCompleter* argumentCompleter_[5];
- ArgumentCompletionList argumentList_;
-
- KeybindMode::Value keybindMode_;
- int inputConfiguredParam_;
-
- LanguageEntryLabel description_;
- LanguageEntryLabel descriptionReturnvalue_;
- LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
- };
-
- inline ConsoleCommand* createConsoleCommand(const FunctorPtr& functor, const std::string& name = "")
- {
- return new ConsoleCommand(functor, name);
- }
-}
-
-
#define _SetConsoleCommand(...) \
BOOST_PP_EXPAND(BOOST_PP_CAT(_SetConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__))
#define _SetConsoleCommand2(name, functionpointer) \
@@ -451,6 +326,8 @@
{ return _ConsoleCommand::getCommand("", name, bPrintError); }
static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
+ static void destroyAll();
+
private:
static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
More information about the Orxonox-commit
mailing list