Changeset 1052 for code/trunk/src/orxonox/core/Identifier.cc
- Timestamp:
- Apr 14, 2008, 3:42:49 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/core/Identifier.cc
r871 r1052 35 35 #include "Identifier.h" 36 36 #include "Factory.h" 37 #include "Executor.h" 38 #include "CommandExecutor.h" 37 39 38 40 namespace orxonox … … 51 53 this->factory_ = 0; 52 54 53 this->children_ = new std::list<const Identifier*>(); 54 this->directChildren_ = new std::list<const Identifier*>(); 55 this->bHasConfigValues_ = false; 56 this->bHasConsoleCommands_ = false; 57 58 this->children_ = new std::set<const Identifier*>(); 59 this->directChildren_ = new std::set<const Identifier*>(); 55 60 56 61 // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables … … 72 77 @param parents A list containing all parents 73 78 */ 74 void Identifier::initialize(std:: list<const Identifier*>* parents)79 void Identifier::initialize(std::set<const Identifier*>* parents) 75 80 { 76 81 COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl; … … 83 88 84 89 // Iterate through all parents 85 for (std:: list<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)90 for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it) 86 91 { 87 92 // Tell the parent we're one of it's children … … 89 94 90 95 // Erase all parents of our parent from our direct-parent-list 91 for (std:: list<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)96 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1) 92 97 { 93 98 // Search for the parent's parent in our direct-parent-list 94 for (std:: list<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)99 for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2) 95 100 { 96 101 if ((*it1) == (*it2)) … … 105 110 106 111 // Now iterate through all direct parents 107 for (std:: list<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)112 for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 108 113 { 109 114 // Tell the parent we're one of it's direct children … … 149 154 bool Identifier::isA(const Identifier* identifier) const 150 155 { 151 return (identifier == this || this->identifierIsInList(identifier, this->parents_));156 return (identifier == this || (this->parents_.find(identifier) != this->children_->end())); 152 157 } 153 158 … … 167 172 bool Identifier::isChildOf(const Identifier* identifier) const 168 173 { 169 return this->identifierIsInList(identifier, this->parents_);174 return (this->parents_.find(identifier) != this->children_->end()); 170 175 } 171 176 … … 176 181 bool Identifier::isDirectChildOf(const Identifier* identifier) const 177 182 { 178 return this->identifierIsInList(identifier, this->directParents_);183 return (this->directParents_.find(identifier) != this->children_->end()); 179 184 } 180 185 … … 185 190 bool Identifier::isParentOf(const Identifier* identifier) const 186 191 { 187 return this->identifierIsInList(identifier, *this->children_);192 return (this->children_->find(identifier) != this->children_->end()); 188 193 } 189 194 … … 194 199 bool Identifier::isDirectParentOf(const Identifier* identifier) const 195 200 { 196 return this->identifierIsInList(identifier, *this->directChildren_); 201 return (this->directChildren_->find(identifier) != this->children_->end()); 202 } 203 204 /** 205 @brief Returns the map that stores all Identifiers. 206 @return The map 207 */ 208 std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern() 209 { 210 static std::map<std::string, Identifier*> identifierMap; 211 return identifierMap; 212 } 213 214 /** 215 @brief Returns the map that stores all Identifiers. 216 @return The map 217 */ 218 std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern() 219 { 220 static std::map<std::string, Identifier*> lowercaseIdentifierMap; 221 return lowercaseIdentifierMap; 222 } 223 224 /** 225 @brief Adds the ConfigValueContainer of a variable, given by the string of its name. 226 @param varname The name of the variablee 227 @param container The container 228 */ 229 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 230 { 231 this->bHasConfigValues_ = true; 232 this->configValues_[varname] = container; 233 this->configValues_LC_[getLowercase(varname)] = container; 197 234 } 198 235 … … 212 249 213 250 /** 214 @brief Adds the ConfigValueContainer of a variable, given by the string of its name. 215 @param varname The name of the variablee 216 @param container The container 217 */ 218 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 219 { 220 this->configValues_[varname] = container; 221 } 222 223 /** 224 @brief Searches for a given identifier in a list and returns whether the identifier is in the list or not. 225 @param identifier The identifier to look for 226 @param list The list 227 @return True = the identifier is in the list 228 */ 229 bool Identifier::identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list) 230 { 231 for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 232 if (identifier == (*it)) 233 return true; 234 235 return false; 236 } 237 238 std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list) 239 { 240 for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 251 @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase. 252 @param varname The name of the variable in lowercase 253 @return The ConfigValueContainer 254 */ 255 ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname) 256 { 257 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname); 258 if (it != configValues_LC_.end()) 259 return ((*it).second); 260 else 261 return 0; 262 } 263 264 /** 265 @brief Adds a new console command of this class. 266 @param executor The executor of the command 267 @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command 268 @return The executor of the command 269 */ 270 ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut) 271 { 272 this->bHasConsoleCommands_ = true; 273 this->consoleCommands_[executor->getName()] = executor; 274 this->consoleCommands_LC_[getLowercase(executor->getName())] = executor; 275 276 if (bCreateShortcut) 277 CommandExecutor::addConsoleCommandShortcut(executor); 278 279 return (*executor); 280 } 281 282 /** 283 @brief Returns the executor of a console command with given name. 284 @brief name The name of the requested console command 285 @return The executor of the requested console command 286 */ 287 ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const 288 { 289 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name); 290 if (it != this->consoleCommands_.end()) 291 return (*it).second; 292 else 293 return 0; 294 } 295 296 /** 297 @brief Returns the executor of a console command with given name in lowercase. 298 @brief name The name of the requested console command in lowercae 299 @return The executor of the requested console command 300 */ 301 ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const 302 { 303 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name); 304 if (it != this->consoleCommands_LC_.end()) 305 return (*it).second; 306 else 307 return 0; 308 } 309 310 /** 311 @brief Lists the names of all Identifiers in a std::set<const Identifier*>. 312 @param out The outstream 313 @param list The list (or set) of Identifiers 314 @return The outstream 315 */ 316 std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list) 317 { 318 for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 241 319 out << (*it)->getName() << " "; 242 320
Note: See TracChangeset
for help on using the changeset viewer.