Changeset 10512 for code/branches/core7
- Timestamp:
- May 30, 2015, 10:59:13 PM (9 years ago)
- Location:
- code/branches/core7/src/libraries/core
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/CoreIncludes.h
r10481 r10512 218 218 class _CoreExport StaticallyInitializedIdentifier : public StaticallyInitializedInstance 219 219 { 220 struct InheritsFrom 220 template <class T> 221 struct InheritsFromClass : public Identifier::InheritsFrom 221 222 { 222 virtual ~InheritsFrom() {} 223 virtual Identifier* getParent() = 0; 224 }; 225 226 template <class T> 227 struct InheritsFromClass : public InheritsFrom 228 { 229 virtual Identifier* getParent() { return Class(T); } 223 virtual Identifier* getParent() const { return Class(T); } 230 224 }; 231 225 232 226 public: 233 227 StaticallyInitializedIdentifier(Identifier* identifier) : identifier_(identifier) {} 234 ~StaticallyInitializedIdentifier()235 {236 for (size_t i = 0; i < this->parents_.size(); ++i)237 delete parents_[i];238 }239 228 240 229 virtual void load() 241 230 { 242 231 IdentifierManager::getInstance().addIdentifier(this->identifier_); 243 for (size_t i = 0; i < this->parents_.size(); ++i)244 this->identifier_->inheritsFrom(this->parents_[i]->getParent());245 232 } 246 233 … … 255 242 template <class T> 256 243 inline StaticallyInitializedIdentifier& inheritsFrom() 257 { this-> parents_.push_back(new InheritsFromClass<T>()); return *this; }244 { this->identifier_->inheritsFrom(new InheritsFromClass<T>()); return *this; } 258 245 259 246 inline StaticallyInitializedIdentifier& virtualBase() … … 262 249 private: 263 250 Identifier* identifier_; 264 std::vector<InheritsFrom*> parents_;265 251 }; 266 252 -
code/branches/core7/src/libraries/core/class/Identifier.cc
r10483 r10512 79 79 delete this->factory_; 80 80 81 for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it) 82 delete (*it); 83 81 84 for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it) 82 85 delete (it->second); … … 121 124 * @brief Used to define the direct parents of an Identifier of an abstract class. 122 125 */ 123 Identifier& Identifier::inheritsFrom(I dentifier* directParent)124 { 125 if (this-> parents_.empty())126 this-> directParents_.push_back(directParent);127 else 128 orxout(internal_error) << "Trying to add " << directParent->getName() << " as adirect parent of " << this->getName() << " after the latter was already initialized" << endl;126 Identifier& Identifier::inheritsFrom(InheritsFrom* directParent) 127 { 128 if (this->directParents_.empty()) 129 this->manualDirectParents_.push_back(directParent); 130 else 131 orxout(internal_error) << "Trying to manually add direct parent of " << this->getName() << " after the latter was already initialized" << endl; 129 132 130 133 return *this; … … 183 186 this->verifyIdentifierTrace(); 184 187 } 185 else if (!this-> directParents_.empty())188 else if (!this->manualDirectParents_.empty()) 186 189 { 187 190 // no parents defined -> this class was manually initialized by calling inheritsFrom<Class>() 188 191 189 192 // initialize all direct parents 190 for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 191 const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent 193 for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it) 194 { 195 Identifier* directParent = (*it)->getParent(); 196 this->directParents_.push_back(directParent); 197 directParent->finishInitialization(); // initialize parent 198 } 192 199 193 200 // direct parents and their parents are also parents of this identifier (but only add them once) -
code/branches/core7/src/libraries/core/class/Identifier.h
r10483 r10512 112 112 { 113 113 public: 114 struct InheritsFrom //! helper class to manually define inheritance 115 { 116 virtual ~InheritsFrom() {} 117 virtual Identifier* getParent() const = 0; 118 }; 119 120 public: 114 121 Identifier(const std::string& name, Factory* factory, bool bLoadable); 115 122 Identifier(const Identifier& identifier); // don't copy … … 149 156 ////// Class Hierarchy ////// 150 157 ///////////////////////////// 151 Identifier& inheritsFrom(I dentifier* directParent);158 Identifier& inheritsFrom(InheritsFrom* directParent); 152 159 153 160 void initializeParents(const std::list<const Identifier*>& initializationTrace); … … 219 226 void addIfNotExists(std::list<const Identifier*>& list, const Identifier* identifierToAdd) const; 220 227 228 std::list<const InheritsFrom*> manualDirectParents_; //!< Manually defined direct parents 221 229 std::list<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to (sorted by their order of initialization) 222 230 std::list<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to (sorted by their order of initialization)
Note: See TracChangeset
for help on using the changeset viewer.