Changeset 10371 for code/branches/core7/src/libraries/core/class
- Timestamp:
- Apr 18, 2015, 12:46:57 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core/class
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/class/Identifier.cc
r10366 r10371 154 154 } 155 155 156 for (std::set<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it) 157 if (*it != this) 158 this->parents_.insert(*it); 159 } 160 161 /** 162 * @brief Initializes the direct parents of this Identifier while creating the class hierarchy. This is only intended for abstract classes. 156 if (this->directParents_.empty()) 157 { 158 for (std::set<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it) 159 if (*it != this) 160 this->parents_.insert(*it); 161 } 162 else 163 orxout(internal_error) << "Trying to add parents to " << this->getName() << " after it was already initialized with manual calls to inheritsFrom<Class>()." << endl; 164 } 165 166 /** 167 * @brief Finishes the initialization of this Identifier after creating the class hierarchy by wiring the (direct) parent/child references correctly. 163 168 */ 164 void Identifier:: initializeDirectParentsOfAbstractClass()169 void Identifier::finishInitialization() 165 170 { 166 171 if (!IdentifierManager::getInstance().isCreatingHierarchy()) 167 172 { 168 orxout(internal_warning) << "Identifier:: initializeDirectParentsOfAbstractClass() created outside of class hierarchy creation" << endl;173 orxout(internal_warning) << "Identifier::finishInitialization() created outside of class hierarchy creation" << endl; 169 174 return; 170 175 } 171 176 172 // only Identifiable is allowed to have no parents (even tough it's currently not abstract) 173 if (this->directParents_.empty() && !this->isExactlyA(Class(Identifiable))) 174 { 177 if (this->isInitialized()) 178 return; 179 180 if (!this->parents_.empty()) 181 { 182 // parents defined -> this class was initialized by creating a sample instance and recording the trace of identifiers 183 184 // initialize all parents 185 for (std::set<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it) 186 const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent 187 188 // parents of parents are no direct parents of this identifier 189 this->directParents_ = this->parents_; 190 for (std::set<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent) 191 for (std::set<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent) 192 this->directParents_.erase(*it_parent_parent); 193 } 194 else if (!this->directParents_.empty()) 195 { 196 // no parents defined -> this class was manually initialized by calling inheritsFrom<Class>() 197 198 // initialize all direct parents 199 for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 200 const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent 201 202 // direct parents and their parents are also parents of this identifier (but only add them once) 203 this->parents_ = this->directParents_; 204 for (std::set<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent) 205 for (std::set<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent) 206 if (std::find(this->parents_.begin(), this->parents_.end(), *it_parent_parent) == this->parents_.end()) 207 this->parents_.insert(*it_parent_parent); 208 } 209 else if (!this->isExactlyA(Class(Identifiable))) 210 { 211 // only Identifiable is allowed to have no parents (even tough it's currently not abstract) 175 212 orxout(internal_error) << "Identifier " << this->getName() << " / " << this->getTypeidName() << " is marked as abstract but has no direct parents defined" << endl; 176 213 orxout(internal_error) << " If this class is not abstract, use RegisterClass(ThisClass);" << endl; 177 214 orxout(internal_error) << " If this class is abstract, use RegisterAbstractClass(ThisClass).inheritsFrom(Class(BaseClass));" << endl; 178 215 } 179 }180 181 /**182 * @brief Finishes the initialization of this Identifier after creating the class hierarchy by wiring the (direct) parent/child references correctly.183 */184 void Identifier::finishInitialization()185 {186 if (!IdentifierManager::getInstance().isCreatingHierarchy())187 {188 orxout(internal_warning) << "Identifier::finishInitialization() created outside of class hierarchy creation" << endl;189 return;190 }191 192 if (this->isInitialized())193 return;194 195 // if no direct parents were defined, initialize them with the set of all parents196 if (this->directParents_.empty())197 this->directParents_ = this->parents_;198 199 // initialize all parents before continuing to initialize this identifier200 for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)201 {202 Identifier* directParent = const_cast<Identifier*>(*it);203 directParent->finishInitialization(); // initialize parent204 this->parents_.insert(directParent); // direct parent is also a parent205 this->parents_.insert(directParent->parents_.begin(), directParent->parents_.end()); // parents of direct parent are also parents206 }207 208 // parents of parents are no direct parents of this identifier209 for (std::set<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)210 for (std::set<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)211 this->directParents_.erase(*it_parent_parent);212 216 213 217 // tell all parents that this identifier is a child … … 233 237 bool Identifier::isA(const Identifier* identifier) const 234 238 { 235 return (identifier == this || (this-> parents_.find(identifier) != this->parents_.end()));239 return (identifier == this || (this->isChildOf(identifier))); 236 240 } 237 241 -
code/branches/core7/src/libraries/core/class/Identifier.h
r10367 r10371 149 149 150 150 void initializeParents(const std::set<const Identifier*>& initializationTrace); 151 void initializeDirectParentsOfAbstractClass();152 151 void finishInitialization(); 153 152 -
code/branches/core7/src/libraries/core/class/IdentifierManager.cc
r10370 r10371 133 133 delete temp; 134 134 } 135 else136 it->second->initializeDirectParentsOfAbstractClass();137 135 138 136 initializedIdentifiers.insert(it->second);
Note: See TracChangeset
for help on using the changeset viewer.