Changeset 9667 for code/trunk/src/libraries/core/class/Identifier.cc
- Timestamp:
- Aug 25, 2013, 9:08:42 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core6 merged: 9552-9554,9556-9574,9577-9579,9585-9593,9596-9612,9626-9662
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/class/Identifier.cc
r9593 r9667 37 37 38 38 #include "util/StringUtils.h" 39 #include "core/CoreIncludes.h" 39 40 #include "core/config/ConfigValueContainer.h" 40 41 #include "core/XMLPort.h" … … 50 51 */ 51 52 Identifier::Identifier() 52 : classID_(IdentifierManager::classIDCounter_s++) 53 { 54 this->objects_ = new ObjectListBase(); 55 56 this->bCreatedOneObject_ = false; 57 this->bSetName_ = false; 53 : classID_(IdentifierManager::getInstance().getUniqueClassId()) 54 { 58 55 this->factory_ = 0; 56 this->bInitialized_ = false; 59 57 this->bLoadable_ = false; 60 58 … … 70 68 Identifier::~Identifier() 71 69 { 72 delete this->objects_;73 74 70 if (this->factory_) 75 71 delete this->factory_; … … 84 80 85 81 /** 86 @brief Registers a class, which means that the name and the parents get stored.87 @param parents A list, containing the Identifiers of all parents of the class88 @param bRootClass True if the class is either an Interface or the BaseObject itself89 */90 void Identifier::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)91 {92 // Check if at least one object of the given type was created93 if (!this->bCreatedOneObject_ && IdentifierManager::isCreatingHierarchy())94 {95 // If no: We have to store the information and initialize the Identifier96 orxout(verbose, context::identifier) << "Register Class in ClassIdentifier<" << this->getName() << ">-Singleton -> Initialize Singleton." << endl;97 if (bRootClass)98 this->initialize(0); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.99 else100 this->initialize(parents);101 }102 }103 104 /**105 @brief Initializes the Identifier with a list containing all parents of the class the Identifier belongs to.106 @param parents A list containing all parents107 */108 void Identifier::initialize(std::set<const Identifier*>* parents)109 {110 orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << this->name_ << ">-Singleton." << endl;111 this->bCreatedOneObject_ = true;112 113 if (parents)114 {115 this->parents_ = (*parents);116 this->directParents_ = (*parents);117 118 // Iterate through all parents119 for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)120 {121 // Tell the parent we're one of it's children122 (*it)->children_.insert((*it)->children_.end(), this);123 124 // Erase all parents of our parent from our direct-parent-list125 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)126 {127 // Search for the parent's parent in our direct-parent-list128 for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)129 {130 if ((*it1) == (*it2))131 {132 // We've found a non-direct parent in our list: Erase it133 this->directParents_.erase(it2);134 break;135 }136 }137 }138 }139 140 // Now iterate through all direct parents141 for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)142 {143 // Tell the parent we're one of it's direct children144 (*it)->directChildren_.insert((*it)->directChildren_.end(), this);145 146 // Create the super-function dependencies147 (*it)->createSuperFunctionCaller();148 }149 }150 }151 152 /**153 82 @brief Sets the name of the class. 154 83 */ 155 84 void Identifier::setName(const std::string& name) 156 85 { 157 if ( !this->bSetName_)86 if (name != this->name_) 158 87 { 159 88 this->name_ = name; 160 this->bSetName_ = true; 161 IdentifierManager::getStringIdentifierMapIntern()[name] = this; 162 IdentifierManager::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this; 163 IdentifierManager::getIDIdentifierMapIntern()[this->networkID_] = this; 164 } 165 } 89 IdentifierManager::getInstance().addIdentifierToLookupMaps(this); 90 } 91 } 92 93 void Identifier::setFactory(Factory* factory) 94 { 95 if (this->factory_) 96 delete this->factory_; 97 98 this->factory_ = factory; 99 } 100 166 101 167 102 /** … … 169 104 @return The new object 170 105 */ 171 OrxonoxClass* Identifier::fabricate(BaseObject* creator)106 Identifiable* Identifier::fabricate(Context* context) 172 107 { 173 108 if (this->factory_) 174 109 { 175 return this->factory_->fabricate(c reator);110 return this->factory_->fabricate(context); 176 111 } 177 112 else … … 190 125 void Identifier::setNetworkID(uint32_t id) 191 126 { 192 // Identifier::getIDIdentifierMapIntern().erase(this->networkID_);193 IdentifierManager::getIDIdentifierMapIntern()[id] = this;194 127 this->networkID_ = id; 128 IdentifierManager::getInstance().addIdentifierToLookupMaps(this); 129 } 130 131 /** 132 * @brief Used to define the direct parents of an Identifier of an abstract class. 133 */ 134 Identifier& Identifier::inheritsFrom(Identifier* directParent) 135 { 136 if (this->parents_.empty()) 137 this->directParents_.insert(directParent); 138 else 139 orxout(internal_error) << "Trying to add " << directParent->getName() << " as a direct parent of " << this->getName() << " after the latter was already initialized" << endl; 140 141 return *this; 142 } 143 144 /** 145 * @brief Initializes the parents of this Identifier while creating the class hierarchy. 146 * @param identifiers All identifiers that were used to create an instance of this class (including this identifier itself) 147 */ 148 void Identifier::initializeParents(const std::set<const Identifier*>& identifiers) 149 { 150 if (!IdentifierManager::getInstance().isCreatingHierarchy()) 151 { 152 orxout(internal_warning) << "Identifier::initializeParents() created outside of class hierarchy creation" << endl; 153 return; 154 } 155 156 for (std::set<const Identifier*>::const_iterator it = identifiers.begin(); it != identifiers.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. 163 */ 164 void Identifier::initializeDirectParentsOfAbstractClass() 165 { 166 if (!IdentifierManager::getInstance().isCreatingHierarchy()) 167 { 168 orxout(internal_warning) << "Identifier::initializeDirectParentsOfAbstractClass() created outside of class hierarchy creation" << endl; 169 return; 170 } 171 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 { 175 orxout(internal_error) << "Identifier " << this->getName() << " / " << this->getTypeidName() << " is marked as abstract but has no direct parents defined" << endl; 176 orxout(internal_error) << " If this class is not abstract, use RegisterClass(ThisClass);" << endl; 177 orxout(internal_error) << " If this class is abstract, use RegisterAbstractClass(ThisClass).inheritsFrom(Class(BaseClass));" << endl; 178 } 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 parents 196 if (this->directParents_.empty()) 197 this->directParents_ = this->parents_; 198 199 // initialize all parents before continuing to initialize this identifier 200 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 parent 204 this->parents_.insert(directParent); // direct parent is also a parent 205 this->parents_.insert(directParent->parents_.begin(), directParent->parents_.end()); // parents of direct parent are also parents 206 } 207 208 // parents of parents are no direct parents of this identifier 209 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 213 // tell all parents that this identifier is a child 214 for (std::set<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it) 215 const_cast<Identifier*>(*it)->children_.insert(this); 216 217 // tell all direct parents that this identifier is a direct child 218 for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 219 { 220 const_cast<Identifier*>(*it)->directChildren_.insert(this); 221 222 // Create the super-function dependencies 223 (*it)->createSuperFunctionCaller(); 224 } 225 226 this->bInitialized_ = true; 195 227 } 196 228
Note: See TracChangeset
for help on using the changeset viewer.