- Timestamp:
- Aug 28, 2010, 1:51:04 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
r7228 r7236 36 36 namespace orxonox 37 37 { 38 _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized)38 ConsoleCommand::ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized) 39 39 { 40 40 this->bActive_ = true; … … 57 57 this->executor_ = executor; 58 58 59 _ConsoleCommand::registerCommand(group, name, this);60 } 61 62 _ConsoleCommand::~_ConsoleCommand()63 { 64 _ConsoleCommand::unregisterCommand(this);65 } 66 67 _ConsoleCommand& _ConsoleCommand::addShortcut()68 { 69 _ConsoleCommand::registerCommand("", this->baseName_, this);70 return *this; 71 } 72 73 _ConsoleCommand& _ConsoleCommand::addShortcut(const std::string& name)74 { 75 _ConsoleCommand::registerCommand("", name, this);76 return *this; 77 } 78 79 _ConsoleCommand& _ConsoleCommand::addGroup(const std::string& group)80 { 81 _ConsoleCommand::registerCommand(group, this->baseName_, this);82 return *this; 83 } 84 85 _ConsoleCommand& _ConsoleCommand::addGroup(const std::string& group, const std::string& name)86 { 87 _ConsoleCommand::registerCommand(group, name, this);88 return *this; 89 } 90 91 bool _ConsoleCommand::isActive() const59 ConsoleCommand::registerCommand(group, name, this); 60 } 61 62 ConsoleCommand::~ConsoleCommand() 63 { 64 ConsoleCommand::unregisterCommand(this); 65 } 66 67 ConsoleCommand& ConsoleCommand::addShortcut() 68 { 69 ConsoleCommand::registerCommand("", this->baseName_, this); 70 return *this; 71 } 72 73 ConsoleCommand& ConsoleCommand::addShortcut(const std::string& name) 74 { 75 ConsoleCommand::registerCommand("", name, this); 76 return *this; 77 } 78 79 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group) 80 { 81 ConsoleCommand::registerCommand(group, this->baseName_, this); 82 return *this; 83 } 84 85 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string& name) 86 { 87 ConsoleCommand::registerCommand(group, name, this); 88 return *this; 89 } 90 91 bool ConsoleCommand::isActive() const 92 92 { 93 93 return (this->bActive_ && this->executor_ && this->executor_->getFunctor() && (this->executor_->getFunctor()->getType() == Functor::Type::Static || this->executor_->getFunctor()->getRawObjectPointer())); 94 94 } 95 95 96 bool _ConsoleCommand::hasAccess() const96 bool ConsoleCommand::hasAccess() const 97 97 { 98 98 switch (this->accessLevel_) … … 110 110 } 111 111 112 bool _ConsoleCommand::headersMatch(const FunctorPtr& functor)112 bool ConsoleCommand::headersMatch(const FunctorPtr& functor) 113 113 { 114 114 unsigned int minparams = std::min(this->baseExecutor_->getParamCount(), functor->getParamCount()); … … 130 130 } 131 131 132 bool _ConsoleCommand::headersMatch(const ExecutorPtr& executor)132 bool ConsoleCommand::headersMatch(const ExecutorPtr& executor) 133 133 { 134 134 unsigned int minparams = std::min(this->baseExecutor_->getParamCount(), executor->getParamCount()); … … 148 148 } 149 149 150 bool _ConsoleCommand::setFunction(const ExecutorPtr& executor, bool bForce)150 bool ConsoleCommand::setFunction(const ExecutorPtr& executor, bool bForce) 151 151 { 152 152 if (!executor || !executor->getFunctor() || bForce || this->headersMatch(executor)) … … 162 162 } 163 163 164 bool _ConsoleCommand::setFunction(const FunctorPtr& functor, bool bForce)164 bool ConsoleCommand::setFunction(const FunctorPtr& functor, bool bForce) 165 165 { 166 166 if (!functor || bForce || this->headersMatch(functor)) … … 180 180 } 181 181 182 void _ConsoleCommand::pushFunction(const ExecutorPtr& executor, bool bForce)182 void ConsoleCommand::pushFunction(const ExecutorPtr& executor, bool bForce) 183 183 { 184 184 Command command; … … 191 191 } 192 192 193 void _ConsoleCommand::pushFunction(const FunctorPtr& functor, bool bForce)193 void ConsoleCommand::pushFunction(const FunctorPtr& functor, bool bForce) 194 194 { 195 195 Command command; … … 202 202 } 203 203 204 void _ConsoleCommand::pushFunction()204 void ConsoleCommand::pushFunction() 205 205 { 206 206 if (this->executor_) … … 210 210 } 211 211 212 void _ConsoleCommand::popFunction()212 void ConsoleCommand::popFunction() 213 213 { 214 214 Command command; … … 224 224 } 225 225 226 void _ConsoleCommand::resetFunction()226 void ConsoleCommand::resetFunction() 227 227 { 228 228 if (this->executor_) … … 230 230 } 231 231 232 const ExecutorPtr& _ConsoleCommand::getExecutor() const232 const ExecutorPtr& ConsoleCommand::getExecutor() const 233 233 { 234 234 return this->executor_; 235 235 } 236 236 237 bool _ConsoleCommand::setObject(void* object)237 bool ConsoleCommand::setObject(void* object) 238 238 { 239 239 if (this->executor_) … … 253 253 } 254 254 255 void _ConsoleCommand::pushObject(void* object)255 void ConsoleCommand::pushObject(void* object) 256 256 { 257 257 void* oldobject = this->getObject(); … … 260 260 } 261 261 262 void _ConsoleCommand::popObject()262 void ConsoleCommand::popObject() 263 263 { 264 264 void* newobject = 0; … … 271 271 } 272 272 273 void* _ConsoleCommand::getObject() const273 void* ConsoleCommand::getObject() const 274 274 { 275 275 if (this->executor_ && this->executor_->getFunctor()) … … 279 279 } 280 280 281 _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1)281 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1) 282 282 { 283 283 if (this->executor_) … … 289 289 } 290 290 291 _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2)291 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2) 292 292 { 293 293 if (this->executor_) … … 299 299 } 300 300 301 _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)301 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3) 302 302 { 303 303 if (this->executor_) … … 309 309 } 310 310 311 _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)311 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) 312 312 { 313 313 if (this->executor_) … … 319 319 } 320 320 321 _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)321 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) 322 322 { 323 323 if (this->executor_) … … 329 329 } 330 330 331 _ConsoleCommand& _ConsoleCommand::defaultValue(unsigned int index, const MultiType& param)331 ConsoleCommand& ConsoleCommand::defaultValue(unsigned int index, const MultiType& param) 332 332 { 333 333 if (this->executor_) … … 339 339 } 340 340 341 _ConsoleCommand& _ConsoleCommand::argumentCompleter(unsigned int param, ArgumentCompleter* completer)341 ConsoleCommand& ConsoleCommand::argumentCompleter(unsigned int param, ArgumentCompleter* completer) 342 342 { 343 343 if (param < 5) … … 349 349 } 350 350 351 ArgumentCompleter* _ConsoleCommand::getArgumentCompleter(unsigned int param) const351 ArgumentCompleter* ConsoleCommand::getArgumentCompleter(unsigned int param) const 352 352 { 353 353 if (param < 5) … … 357 357 } 358 358 359 _ConsoleCommand& _ConsoleCommand::description(const std::string& description)359 ConsoleCommand& ConsoleCommand::description(const std::string& description) 360 360 { 361 361 this->description_ = std::string("ConsoleCommandDescription::" + this->baseName_ + "::function"); … … 364 364 } 365 365 366 const std::string& _ConsoleCommand::getDescription() const366 const std::string& ConsoleCommand::getDescription() const 367 367 { 368 368 return GetLocalisation_noerror(this->description_); 369 369 } 370 370 371 _ConsoleCommand& _ConsoleCommand::descriptionParam(unsigned int param, const std::string& description)371 ConsoleCommand& ConsoleCommand::descriptionParam(unsigned int param, const std::string& description) 372 372 { 373 373 if (param < MAX_FUNCTOR_ARGUMENTS) … … 379 379 } 380 380 381 const std::string& _ConsoleCommand::getDescriptionParam(unsigned int param) const381 const std::string& ConsoleCommand::getDescriptionParam(unsigned int param) const 382 382 { 383 383 if (param < MAX_FUNCTOR_ARGUMENTS) … … 387 387 } 388 388 389 _ConsoleCommand& _ConsoleCommand::descriptionReturnvalue(const std::string& description)389 ConsoleCommand& ConsoleCommand::descriptionReturnvalue(const std::string& description) 390 390 { 391 391 this->descriptionReturnvalue_ = std::string("ConsoleCommandDescription::" + this->baseName_ + "::returnvalue"); … … 394 394 } 395 395 396 const std::string& _ConsoleCommand::getDescriptionReturnvalue(int param) const396 const std::string& ConsoleCommand::getDescriptionReturnvalue(int param) const 397 397 { 398 398 return GetLocalisation_noerror(this->descriptionReturnvalue_); 399 399 } 400 400 401 /* static */ _ConsoleCommand* _ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)402 { 403 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommandMap().find(group);404 if (it_group != _ConsoleCommand::getCommandMap().end())405 { 406 std::map<std::string, _ConsoleCommand*>::const_iterator it_name = it_group->second.find(name);401 /* static */ ConsoleCommand* ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError) 402 { 403 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMap().find(group); 404 if (it_group != ConsoleCommand::getCommandMap().end()) 405 { 406 std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(name); 407 407 if (it_name != it_group->second.end()) 408 408 { … … 420 420 } 421 421 422 /* static */ _ConsoleCommand* _ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError)422 /* static */ ConsoleCommand* ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError) 423 423 { 424 424 std::string groupLC = getLowercase(group); 425 425 std::string nameLC = getLowercase(name); 426 426 427 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommandMapLC().find(groupLC);428 if (it_group != _ConsoleCommand::getCommandMapLC().end())429 { 430 std::map<std::string, _ConsoleCommand*>::const_iterator it_name = it_group->second.find(nameLC);427 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMapLC().find(groupLC); 428 if (it_group != ConsoleCommand::getCommandMapLC().end()) 429 { 430 std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(nameLC); 431 431 if (it_name != it_group->second.end()) 432 432 { … … 444 444 } 445 445 446 /* static */ std::map<std::string, std::map<std::string, _ConsoleCommand*> >& _ConsoleCommand::getCommandMap()447 { 448 static std::map<std::string, std::map<std::string, _ConsoleCommand*> > commandMap;446 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMap() 447 { 448 static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMap; 449 449 return commandMap; 450 450 } 451 451 452 /* static */ std::map<std::string, std::map<std::string, _ConsoleCommand*> >& _ConsoleCommand::getCommandMapLC()453 { 454 static std::map<std::string, std::map<std::string, _ConsoleCommand*> > commandMapLC;452 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMapLC() 453 { 454 static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMapLC; 455 455 return commandMapLC; 456 456 } 457 457 458 /* static */ void _ConsoleCommand::registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command)458 /* static */ void ConsoleCommand::registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command) 459 459 { 460 460 if (name == "") 461 461 return; 462 462 463 if ( _ConsoleCommand::getCommand(group, name) != 0)463 if (ConsoleCommand::getCommand(group, name) != 0) 464 464 { 465 465 if (group == "") … … 470 470 else 471 471 { 472 _ConsoleCommand::getCommandMap()[group][name] = command;473 _ConsoleCommand::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command;474 } 475 } 476 477 /* static */ void _ConsoleCommand::unregisterCommand(_ConsoleCommand* command)478 { 479 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::iterator it_group = _ConsoleCommand::getCommandMap().begin(); it_group != _ConsoleCommand::getCommandMap().end(); )480 { 481 for (std::map<std::string, _ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )472 ConsoleCommand::getCommandMap()[group][name] = command; 473 ConsoleCommand::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command; 474 } 475 } 476 477 /* static */ void ConsoleCommand::unregisterCommand(ConsoleCommand* command) 478 { 479 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMap().begin(); it_group != ConsoleCommand::getCommandMap().end(); ) 480 { 481 for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ) 482 482 { 483 483 if (it_name->second == command) … … 488 488 489 489 if (it_group->second.empty()) 490 _ConsoleCommand::getCommandMap().erase(it_group++);490 ConsoleCommand::getCommandMap().erase(it_group++); 491 491 else 492 492 ++it_group; 493 493 } 494 494 495 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::iterator it_group = _ConsoleCommand::getCommandMapLC().begin(); it_group != _ConsoleCommand::getCommandMapLC().end(); )496 { 497 for (std::map<std::string, _ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )495 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMapLC().begin(); it_group != ConsoleCommand::getCommandMapLC().end(); ) 496 { 497 for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ) 498 498 { 499 499 if (it_name->second == command) … … 504 504 505 505 if (it_group->second.empty()) 506 _ConsoleCommand::getCommandMapLC().erase(it_group++);506 ConsoleCommand::getCommandMapLC().erase(it_group++); 507 507 else 508 508 ++it_group; … … 510 510 } 511 511 512 /* static */ void _ConsoleCommand::destroyAll()513 { 514 while (! _ConsoleCommand::getCommandMap().empty() && !_ConsoleCommand::getCommandMap().begin()->second.empty())515 delete _ConsoleCommand::getCommandMap().begin()->second.begin()->second;512 /* static */ void ConsoleCommand::destroyAll() 513 { 514 while (!ConsoleCommand::getCommandMap().empty() && !ConsoleCommand::getCommandMap().begin()->second.empty()) 515 delete ConsoleCommand::getCommandMap().begin()->second.begin()->second; 516 516 } 517 517 }
Note: See TracChangeset
for help on using the changeset viewer.