Changeset 876 for code/branches/core2/src/orxonox/core/Identifier.cc
- Timestamp:
- Mar 10, 2008, 12:27:30 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/Identifier.cc
r871 r876 51 51 this->factory_ = 0; 52 52 53 this->children_ = new std:: list<const Identifier*>();54 this->directChildren_ = new std:: list<const Identifier*>();53 this->children_ = new std::set<const Identifier*>(); 54 this->directChildren_ = new std::set<const Identifier*>(); 55 55 56 56 // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables … … 72 72 @param parents A list containing all parents 73 73 */ 74 void Identifier::initialize(std:: list<const Identifier*>* parents)74 void Identifier::initialize(std::set<const Identifier*>* parents) 75 75 { 76 76 COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl; … … 83 83 84 84 // Iterate through all parents 85 for (std:: list<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)85 for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it) 86 86 { 87 87 // Tell the parent we're one of it's children … … 89 89 90 90 // 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)91 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1) 92 92 { 93 93 // 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)94 for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2) 95 95 { 96 96 if ((*it1) == (*it2)) … … 105 105 106 106 // Now iterate through all direct parents 107 for (std:: list<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)107 for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 108 108 { 109 109 // Tell the parent we're one of it's direct children … … 149 149 bool Identifier::isA(const Identifier* identifier) const 150 150 { 151 return (identifier == this || this->identifierIsInList(identifier, this->parents_));151 return (identifier == this || (this->parents_.find(identifier) != this->children_->end())); 152 152 } 153 153 … … 167 167 bool Identifier::isChildOf(const Identifier* identifier) const 168 168 { 169 return this->identifierIsInList(identifier, this->parents_);169 return (this->parents_.find(identifier) != this->children_->end()); 170 170 } 171 171 … … 176 176 bool Identifier::isDirectChildOf(const Identifier* identifier) const 177 177 { 178 return this->identifierIsInList(identifier, this->directParents_);178 return (this->directParents_.find(identifier) != this->children_->end()); 179 179 } 180 180 … … 185 185 bool Identifier::isParentOf(const Identifier* identifier) const 186 186 { 187 return this->identifierIsInList(identifier, *this->children_);187 return (this->children_->find(identifier) != this->children_->end()); 188 188 } 189 189 … … 194 194 bool Identifier::isDirectParentOf(const Identifier* identifier) const 195 195 { 196 return this->identifierIsInList(identifier, *this->directChildren_);196 return (this->directChildren_->find(identifier) != this->children_->end()); 197 197 } 198 198 … … 221 221 } 222 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) 223 std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list) 224 { 225 for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 241 226 out << (*it)->getName() << " "; 242 227
Note: See TracChangeset
for help on using the changeset viewer.