[Orxonox-commit 2528] r7233 - in code/branches/consolecommands3/src: libraries/core/command libraries/tools orxonox/gamestates
landauf at orxonox.net
landauf at orxonox.net
Sat Aug 28 00:02:03 CEST 2010
Author: landauf
Date: 2010-08-28 00:02:03 +0200 (Sat, 28 Aug 2010)
New Revision: 7233
Modified:
code/branches/consolecommands3/src/libraries/core/command/ArgumentCompleter.h
code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc
code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
code/branches/consolecommands3/src/libraries/tools/Timer.cc
code/branches/consolecommands3/src/orxonox/gamestates/GSMainMenu.cc
code/branches/consolecommands3/src/orxonox/gamestates/GSRoot.cc
Log:
- console commands "setMMSoundPath" and "printObjects" are now hidden.
- added "unhide" command to show hidden commands
- extended auto-completion capability by allowing multi-word ArgumentCompleter and more
- added new auto-completion function that allows other commands as argument for a command (for example "delay [time] [command]")
Modified: code/branches/consolecommands3/src/libraries/core/command/ArgumentCompleter.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ArgumentCompleter.h 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/core/command/ArgumentCompleter.h 2010-08-27 22:02:03 UTC (rev 7233)
@@ -37,12 +37,12 @@
class _CoreExport ArgumentCompleter
{
public:
- ArgumentCompleter(ArgumentCompletionList (*function) (void)) : paramCount_(0), function_0_(function) {}
- ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1)) : paramCount_(1), function_1_(function) {}
- ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2)) : paramCount_(2), function_2_(function) {}
- ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3)) : paramCount_(3), function_3_(function) {}
- ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4)) : paramCount_(4), function_4_(function) {}
- ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)) : paramCount_(5), function_5_(function) {}
+ ArgumentCompleter(ArgumentCompletionList (*function) (void), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(0), function_0_(function) {}
+ ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(1), function_1_(function) {}
+ ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(2), function_2_(function) {}
+ ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(3), function_3_(function) {}
+ ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(4), function_4_(function) {}
+ ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(5), function_5_(function) {}
ArgumentCompletionList operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "")
{
@@ -65,7 +65,11 @@
}
}
+ inline bool useMultipleWords() const
+ { return this->bUseMultipleWords_; }
+
private:
+ bool bUseMultipleWords_;
unsigned char paramCount_;
ArgumentCompletionList (*function_0_) (void);
ArgumentCompletionList (*function_1_) (const std::string& param1);
Modified: code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc 2010-08-27 22:02:03 UTC (rev 7233)
@@ -37,8 +37,9 @@
#include "core/Identifier.h"
#include "core/ConfigFileManager.h"
#include "core/ConfigValueContainer.h"
+#include "CommandExecutor.h"
+#include "ConsoleCommand.h"
#include "TclThreadManager.h"
-#include "ConsoleCommand.h"
// Boost 1.36 has some issues with deprecated functions that have been omitted
#if (BOOST_VERSION == 103600)
@@ -56,56 +57,96 @@
return ArgumentCompletionList();
}
- bool groupIsVisible(const std::map<std::string, _ConsoleCommand*>& group)
+ namespace detail
{
- for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command)
- if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden())
- return true;
+ bool groupIsVisible(const std::map<std::string, _ConsoleCommand*>& group, bool bOnlyShowHidden)
+ {
+ for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command)
+ if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)
+ return true;
- return false;
- }
+ return false;
+ }
- ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)()
- {
- ArgumentCompletionList groupList;
+ ArgumentCompletionList _groupsandcommands(bool bOnlyShowHidden)
+ {
+ ArgumentCompletionList groupList;
- const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands();
- for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)
- if (groupIsVisible(it_group->second))
- groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first)));
+ const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands();
+ for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)
+ if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "")
+ groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first)));
- std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find("");
- if (it_group != commands.end())
+ std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find("");
+ if (it_group != commands.end())
+ {
+ groupList.push_back(ArgumentCompletionListElement("", "", "\n"));
+
+ for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
+ if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)
+ groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
+ }
+
+ return groupList;
+ }
+
+ ArgumentCompletionList _subcommands(const std::string& fragment, const std::string& group, bool bOnlyShowHidden)
{
- groupList.push_back(ArgumentCompletionListElement("\n"));
+ ArgumentCompletionList commandList;
- for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
- if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden())
- groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
+ std::string groupLC = getLowercase(group);
+
+ std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommands().begin();
+ for ( ; it_group != _ConsoleCommand::getCommands().end(); ++it_group)
+ if (getLowercase(it_group->first) == groupLC)
+ break;
+
+ if (it_group != _ConsoleCommand::getCommands().end())
+ {
+ for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
+ if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)
+ commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
+ }
+
+ return commandList;
}
+ }
- return groupList;
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)()
+ {
+ return detail::_groupsandcommands(false);
}
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group)
{
- ArgumentCompletionList commandList;
+ return detail::_subcommands(fragment, group, false);
+ }
- std::string groupLC = getLowercase(group);
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(hiddengroupsandcommands)()
+ {
+ return detail::_groupsandcommands(true);
+ }
- std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommands().begin();
- for ( ; it_group != _ConsoleCommand::getCommands().end(); ++it_group)
- if (getLowercase(it_group->first) == groupLC)
- break;
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(hiddensubcommands)(const std::string& fragment, const std::string& group)
+ {
+ return detail::_subcommands(fragment, group, true);
+ }
- if (it_group != _ConsoleCommand::getCommands().end())
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(command)(const std::string& fragment)
+ {
+ CommandEvaluation evaluation = CommandExecutor::evaluate(fragment);
+ const std::string& hint = evaluation.hint();
+
+ if (evaluation.getPossibleArguments().size() > 0)
{
- for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
- if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden())
- commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
+ return evaluation.getPossibleArguments();
}
-
- return commandList;
+ else
+ {
+ ArgumentCompletionList list;
+ list.push_back(ArgumentCompletionListElement("", "", hint));
+ return list;
+ }
}
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment)
Modified: code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h 2010-08-27 22:02:03 UTC (rev 7233)
@@ -38,9 +38,14 @@
_CoreExport ArgumentCompletionList acf_##functionname
#define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(functionname) \
+ _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, false)
+#define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(functionname) \
+ _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, true)
+
+#define _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, bUseMultipleWords) \
ArgumentCompleter* functionname() \
{ \
- static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname); \
+ static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname, bUseMultipleWords); \
return &completer; \
} \
\
@@ -54,6 +59,9 @@
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)();
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(groupsandcommands)();
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(subcommands)(const std::string& fragment, const std::string& group);
+ ARGUMENT_COMPLETION_FUNCTION_DECLARATION(hiddengroupsandcommands)();
+ ARGUMENT_COMPLETION_FUNCTION_DECLARATION(hiddensubcommands)(const std::string& fragment, const std::string& group);
+ ARGUMENT_COMPLETION_FUNCTION_DECLARATION(command)(const std::string& fragment);
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(files)(const std::string& fragment);
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingssections)();
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingsentries)(const std::string& fragment, const std::string& section);
Modified: code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc 2010-08-27 22:02:03 UTC (rev 7233)
@@ -176,14 +176,13 @@
if (!this->bPossibleArgumentsRetrieved_)
this->retrievePossibleArguments();
- if (this->possibleArguments_.empty())
+ if (CommandEvaluation::getSize(this->possibleArguments_) == 0)
{
return this->string_;
}
else
{
std::string output = this->string_.substr(0, this->string_.find_last_of(' ') + 1);
-
output += CommandEvaluation::getCommonBegin(this->possibleArguments_);
return output;
}
@@ -233,12 +232,28 @@
{
MultiType param[MAX_FUNCTOR_ARGUMENTS];
+ size_t max = this->hintArgumentsOffset_ + this->hintCommand_->getExecutor()->getParamCount();
+
for (size_t i = 0; i < argumentID; ++i)
- param[i] = this->getToken(this->getNumberOfArguments() - i - 1);
+ param[i] = this->getToken(std::min(this->getNumberOfArguments(), max) - i - 1);
- this->possibleArguments_ = (*ac)(param[0], param[1], param[2], param[3], param[4]);
+ if (this->getNumberOfArguments() > max)
+ {
+ if (ac->useMultipleWords())
+ {
+ std::string surplusArguments = this->tokens_.subSet(max - 1).join();
+ if (this->string_[this->string_.size() - 1] == ' ')
+ surplusArguments += ' ';
- CommandEvaluation::strip(this->possibleArguments_, param[0]);
+ this->possibleArguments_ = (*ac)(surplusArguments, param[1], param[2], param[3], param[4]);
+ CommandEvaluation::strip(this->possibleArguments_, this->getToken(this->getNumberOfArguments() - 1));
+ }
+ }
+ else
+ {
+ this->possibleArguments_ = (*ac)(param[0], param[1], param[2], param[3], param[4]);
+ CommandEvaluation::strip(this->possibleArguments_, param[0]);
+ }
}
}
@@ -250,6 +265,12 @@
{
const std::string& entry = it->getComparable();
+ if (entry == "")
+ {
+ ++it;
+ continue;
+ }
+
if (entry.size() < fragmentLC.size())
{
list.erase(it++);
@@ -274,15 +295,24 @@
}
}
+ /* static */ size_t CommandEvaluation::getSize(const ArgumentCompletionList& list)
+ {
+ size_t count = 0;
+ for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
+ if (it->getComparable() != "")
+ ++count;
+ return count;
+ }
+
/* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list)
{
std::string output;
for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
{
- if (it != list.begin())
+ output += it->getDisplay();
+
+ if (it->getComparable() != "")
output += ' ';
-
- output += it->getDisplay();
}
return output;
}
@@ -315,16 +345,24 @@
/* static */ std::string CommandEvaluation::getCommonBegin(const ArgumentCompletionList& list)
{
- if (list.size() == 0)
+ if (CommandEvaluation::getSize(list) == 0)
{
return "";
}
- else if (list.size() == 1)
+ else if (CommandEvaluation::getSize(list) == 1)
{
- if (list.begin()->hasDisplay())
- return (list.begin()->getString());
- else
- return (list.begin()->getString() + ' ');
+ for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
+ {
+ if (it->getComparable() != "")
+ {
+ if (it->hasDisplay())
+ return (it->getString());
+ else
+ return (it->getString() + ' ');
+ }
+ }
+
+ return "";
}
else
{
@@ -337,9 +375,13 @@
{
const std::string& argumentComparable = it->getComparable();
const std::string& argument = it->getString();
+
+ if (argumentComparable == "")
+ continue;
+
if (argument.size() > i)
{
- if (it == list.begin())
+ if (tempComparable == 0)
{
tempComparable = argumentComparable[i];
temp = argument[i];
Modified: code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h 2010-08-27 22:02:03 UTC (rev 7233)
@@ -64,6 +64,9 @@
void setEvaluatedParameter(unsigned int index, const MultiType& param);
MultiType getEvaluatedParameter(unsigned int index) const;
+ const ArgumentCompletionList& getPossibleArguments() const
+ { return this->possibleArguments_; }
+
private:
void initialize(const std::string& command);
@@ -74,6 +77,7 @@
void retrievePossibleArguments();
static void strip(ArgumentCompletionList& list, const std::string& fragment);
+ static size_t getSize(const ArgumentCompletionList& list);
static std::string dump(const ArgumentCompletionList& list);
static std::string dump(const _ConsoleCommand* command);
Modified: code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc 2010-08-27 22:02:03 UTC (rev 7233)
@@ -42,6 +42,12 @@
.argumentCompleter(0, autocompletion::groupsandcommands())
.argumentCompleter(1, autocompletion::subcommands());
+ _SetConsoleCommand("unhide", &CommandExecutor::unhide)
+ .argumentCompleter(0, autocompletion::hiddengroupsandcommands())
+ .argumentCompleter(1, autocompletion::hiddensubcommands())
+ .defaultValue(1, "")
+ .defaultValue(2, "");
+
/* static */ CommandExecutor& CommandExecutor::getInstance()
{
static CommandExecutor instance;
@@ -148,4 +154,9 @@
this->cachelist_.pop_back();
}
}
+
+ /* static */ MultiType CommandExecutor::unhide(const std::string& group, const std::string& name, const std::string& arguments)
+ {
+ return CommandExecutor::queryMT(group + " " + name + " " + arguments);
+ }
}
Modified: code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h 2010-08-27 22:02:03 UTC (rev 7233)
@@ -58,6 +58,7 @@
static const int Deactivated = 3;
static const int Denied = 4;
+ static MultiType unhide(const std::string& group, const std::string& name, const std::string& arguments);
static void _autocomplete(const std::string& group, const std::string& name) {}
private:
Modified: code/branches/consolecommands3/src/libraries/tools/Timer.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/tools/Timer.cc 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/libraries/tools/Timer.cc 2010-08-27 22:02:03 UTC (rev 7233)
@@ -38,7 +38,7 @@
namespace orxonox
{
- _SetConsoleCommand("delay", &delay);
+ _SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command());
_SetConsoleCommand("killdelays", &killdelays);
static std::set<Timer*> delaytimerset;
Modified: code/branches/consolecommands3/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/consolecommands3/src/orxonox/gamestates/GSMainMenu.cc 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/orxonox/gamestates/GSMainMenu.cc 2010-08-27 22:02:03 UTC (rev 7233)
@@ -59,7 +59,7 @@
_SetConsoleCommand(__CC_startClient_name, &GSMainMenu::startClient ).deactivate();
_SetConsoleCommand(__CC_startDedicated_name, &GSMainMenu::startDedicated ).deactivate();
_SetConsoleCommand(__CC_startMainMenu_name, &GSMainMenu::startMainMenu ).deactivate();
- _SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath);
+ _SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath).hide();
GSMainMenu::GSMainMenu(const GameStateInfo& info)
: GameState(info)
Modified: code/branches/consolecommands3/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/consolecommands3/src/orxonox/gamestates/GSRoot.cc 2010-08-27 18:41:22 UTC (rev 7232)
+++ code/branches/consolecommands3/src/orxonox/gamestates/GSRoot.cc 2010-08-27 22:02:03 UTC (rev 7233)
@@ -44,7 +44,7 @@
static const std::string __CC_setTimeFactor_name = "setTimeFactor";
static const std::string __CC_pause_name = "pause";
- _SetConsoleCommand("printObjects", &GSRoot::printObjects);
+ _SetConsoleCommand("printObjects", &GSRoot::printObjects).hide();
_SetConsoleCommand(__CC_setTimeFactor_name, &GSRoot::setTimeFactor).accessLevel(AccessLevel::Master).defaultValues(1.0);
_SetConsoleCommand(__CC_pause_name, &GSRoot::pause ).accessLevel(AccessLevel::Master);
More information about the Orxonox-commit
mailing list