Changeset 7186 for code/branches/consolecommands3
- Timestamp:
- Aug 19, 2010, 2:14:54 AM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries/core
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
r7185 r7186 29 29 #include "ConsoleCommand.h" 30 30 #include <cassert> 31 32 #include "Language.h" 31 33 32 34 namespace orxonox … … 71 73 this->argumentList_.clear(); 72 74 } 75 76 ConsoleCommand& ConsoleCommand::description(const std::string& description) 77 { 78 this->description_ = std::string("ConsoleCommandDescription::" + this->name_ + "::function"); 79 AddLanguageEntry(this->description_, description); 80 return (*this); 81 } 82 83 const std::string& ConsoleCommand::getDescription() const 84 { 85 return GetLocalisation_noerror(this->description_); 86 } 87 88 ConsoleCommand& ConsoleCommand::descriptionParam(unsigned int param, const std::string& description) 89 { 90 if (param < MAX_FUNCTOR_ARGUMENTS) 91 { 92 this->descriptionParam_[param] = std::string("ConsoleCommandDescription::" + this->name_ + "::param" + multi_cast<std::string>(param)); 93 AddLanguageEntry(this->descriptionParam_[param], description); 94 } 95 return (*this); 96 } 97 98 const std::string& ConsoleCommand::getDescriptionParam(unsigned int param) const 99 { 100 if (param < MAX_FUNCTOR_ARGUMENTS) 101 return GetLocalisation_noerror(this->descriptionParam_[param]); 102 103 return this->descriptionParam_[0]; 104 } 105 106 ConsoleCommand& ConsoleCommand::descriptionReturnvalue(const std::string& description) 107 { 108 this->descriptionReturnvalue_ = std::string("ConsoleCommandDescription::" + this->name_ + "::returnvalue"); 109 AddLanguageEntry(this->descriptionReturnvalue_, description); 110 return (*this); 111 } 112 113 const std::string& ConsoleCommand::getDescriptionReturnvalue(int param) const 114 { 115 return GetLocalisation_noerror(this->descriptionReturnvalue_); 116 } 73 117 } 74 118 -
code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
r7185 r7186 90 90 ConsoleCommand(Functor* functor, const std::string& name = ""); 91 91 92 inline ConsoleCommand& description(const std::string& description) 93 { this->Executor::setDescription(description); return (*this); } 94 inline ConsoleCommand& descriptionParam(int param, const std::string& description) 95 { this->Executor::setDescriptionParam(param, description); return (*this); } 96 inline ConsoleCommand& descriptionReturnvalue(const std::string& description) 97 { this->Executor::setDescriptionReturnvalue(description); return (*this); } 92 ConsoleCommand& description(const std::string& description); 93 const std::string& getDescription() const; 94 95 ConsoleCommand& descriptionParam(unsigned int param, const std::string& description); 96 const std::string& getDescriptionParam(unsigned int param) const; 97 98 ConsoleCommand& descriptionReturnvalue(const std::string& description); 99 const std::string& getDescriptionReturnvalue(int param) const; 100 98 101 inline ConsoleCommand& defaultValues(const MultiType& param1) 99 102 { this->Executor::setDefaultValues(param1); return (*this); } … … 150 153 KeybindMode::Value keybindMode_; 151 154 int inputConfiguredParam_; 155 156 LanguageEntryLabel description_; 157 LanguageEntryLabel descriptionReturnvalue_; 158 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 152 159 }; 153 160 -
code/branches/consolecommands3/src/libraries/core/Executor.cc
r7163 r7186 36 36 #include "util/StringUtils.h" 37 37 #include "util/SubString.h" 38 #include "Language.h"39 38 40 39 namespace orxonox … … 44 43 this->functor_ = functor; 45 44 this->name_ = name; 46 47 this->bAddedDescription_ = false;48 this->bAddedDescriptionReturnvalue_ = false;49 50 this->bAddedDescriptionParam_[0] = false;51 this->bAddedDescriptionParam_[1] = false;52 this->bAddedDescriptionParam_[2] = false;53 this->bAddedDescriptionParam_[3] = false;54 this->bAddedDescriptionParam_[4] = false;55 45 56 46 this->bAddedDefaultValue_[0] = false; … … 69 59 { 70 60 unsigned int paramCount = this->functor_->getParamCount(); 71 61 72 62 if (paramCount == 0) 73 63 { … … 97 87 { 98 88 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); 99 89 100 90 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 101 91 { … … 106 96 } 107 97 } 108 98 109 99 MultiType param[MAX_FUNCTOR_ARGUMENTS]; 110 100 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; … … 129 119 } 130 120 COUT(5) << ")." << std::endl; 131 121 132 122 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) 133 123 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); 134 124 135 125 switch(paramCount) 136 126 { … … 198 188 return true; 199 189 } 200 }201 202 Executor& Executor::setDescription(const std::string& description)203 {204 if (!this->bAddedDescription_)205 {206 this->description_ = std::string("ExecutorDescription::" + this->name_ + "::function");207 AddLanguageEntry(this->description_, description);208 this->bAddedDescription_ = true;209 }210 return (*this);211 }212 213 const std::string& Executor::getDescription() const214 {215 return GetLocalisation(this->description_);216 }217 218 Executor& Executor::setDescriptionParam(unsigned int param, const std::string& description)219 {220 if (param < MAX_FUNCTOR_ARGUMENTS)221 {222 if (!this->bAddedDescriptionParam_[param])223 {224 std::string paramnumber;225 if (!convertValue(¶mnumber, param))226 return (*this);227 228 this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber);229 AddLanguageEntry(this->descriptionParam_[param], description);230 this->bAddedDescriptionParam_[param] = true;231 }232 }233 return (*this);234 }235 236 const std::string& Executor::getDescriptionParam(unsigned int param) const237 {238 if (param < MAX_FUNCTOR_ARGUMENTS)239 return GetLocalisation(this->descriptionParam_[param]);240 241 return this->descriptionParam_[0];242 }243 244 Executor& Executor::setDescriptionReturnvalue(const std::string& description)245 {246 if (!this->bAddedDescriptionReturnvalue_)247 {248 this->descriptionReturnvalue_ = std::string("ExecutorDescription::" + this->name_ + "::returnvalue");249 AddLanguageEntry(this->descriptionReturnvalue_, description);250 this->bAddedDescriptionReturnvalue_ = true;251 }252 return (*this);253 }254 255 const std::string& Executor::getDescriptionReturnvalue(int param) const256 {257 return GetLocalisation(this->descriptionReturnvalue_);258 190 } 259 191 -
code/branches/consolecommands3/src/libraries/core/Executor.h
r7177 r7186 61 61 62 62 bool evaluate(const std::string& params, MultiType param[5], const std::string& delimiter = " ") const; 63 64 Executor& setDescription(const std::string& description);65 const std::string& getDescription() const;66 67 Executor& setDescriptionParam(unsigned int param, const std::string& description);68 const std::string& getDescriptionParam(unsigned int param) const;69 70 Executor& setDescriptionReturnvalue(const std::string& description);71 const std::string& getDescriptionReturnvalue(int param) const;72 63 73 64 inline Functor* getFunctor() const … … 120 111 MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS]; 121 112 bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS]; 122 123 private:124 LanguageEntryLabel description_;125 LanguageEntryLabel descriptionReturnvalue_;126 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];127 128 bool bAddedDescription_;129 bool bAddedDescriptionReturnvalue_;130 bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS];131 113 }; 132 114 -
code/branches/consolecommands3/src/libraries/core/Language.cc
r6417 r7186 36 36 #include <fstream> 37 37 #include "util/Debug.h" 38 #include "util/StringUtils.h" 38 39 #include "Core.h" 39 40 #include "PathConfig.h" … … 169 170 @return The localisation 170 171 */ 171 const std::string& Language::getLocalisation(const LanguageEntryLabel& label ) const172 const std::string& Language::getLocalisation(const LanguageEntryLabel& label, bool bError) const 172 173 { 173 174 std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label); 174 175 if (it != this->languageEntries_.end()) 175 176 return it->second->getLocalisation(); 176 else 177 else if (bError) 177 178 { 178 179 // Uh, oh, an undefined entry was requested: return the default string … … 180 181 return this->defaultLocalisation_; 181 182 } 183 else 184 return BLANKSTRING; 182 185 } 183 186 -
code/branches/consolecommands3/src/libraries/core/Language.h
r6536 r7186 116 116 117 117 void addEntry(const LanguageEntryLabel& label, const std::string& entry); 118 const std::string& getLocalisation(const LanguageEntryLabel& label ) const;118 const std::string& getLocalisation(const LanguageEntryLabel& label, bool bError = true) const; 119 119 120 120 private: … … 145 145 return Language::getInstance().getLocalisation(label); 146 146 } 147 148 //! Shortcut function for Language::getLocalisation without printing an error in case the label doesn't exist 149 inline const std::string& GetLocalisation_noerror(const LanguageEntryLabel& label) 150 { 151 return Language::getInstance().getLocalisation(label, false); 152 } 147 153 } 148 154 -
code/branches/consolecommands3/src/libraries/core/XMLPort.h
r7163 r7186 317 317 { return this->paramname_; } 318 318 319 virtual XMLPortParamContainer& description(const std::string& description) = 0; 320 virtual const std::string& getDescription() = 0; 319 inline XMLPortParamContainer& description(const std::string& description) 320 { this->description_ = description; return *this; } 321 inline const std::string& getDescription() const 322 { return this->description_; } 321 323 322 324 virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiType& param) = 0; … … 332 334 Identifier* identifier_; 333 335 BaseObject* owner_; 336 std::string description_; 334 337 }; 335 338 … … 436 439 } 437 440 438 virtual XMLPortParamContainer& description(const std::string& description)439 { this->loadexecutor_->setDescription(description); return (*this); }440 virtual const std::string& getDescription()441 { return this->loadexecutor_->getDescription(); }442 443 441 virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiType& param) 444 442 { … … 502 500 { return this->sectionname_; } 503 501 504 virtual XMLPortObjectContainer& description(const std::string& description) = 0; 505 virtual const std::string& getDescription() = 0; 502 inline XMLPortObjectContainer& description(const std::string& description) 503 { this->description_ = description; return *this; } 504 const std::string& getDescription() const 505 { return this->description_; } 506 506 507 507 bool identifierIsIncludedInLoaderMask(const Identifier* identifier); … … 513 513 Identifier* identifier_; 514 514 Identifier* objectIdentifier_; 515 std::string description_; 515 516 }; 516 517 … … 548 549 (*this->loadexecutor_)(castedObject, castedNewObject); 549 550 } 550 551 virtual XMLPortObjectContainer& description(const std::string& description)552 { this->loadexecutor_->setDescription(description); return (*this); }553 virtual const std::string& getDescription()554 { return this->loadexecutor_->getDescription(); }555 551 556 552 private:
Note: See TracChangeset
for help on using the changeset viewer.