[790] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1505] | 3 | * > www.orxonox.net < |
---|
[790] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[871] | 29 | /** |
---|
[2171] | 30 | @file |
---|
[790] | 31 | @brief Implementation of the Identifier class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[1505] | 34 | #include "Identifier.h" |
---|
| 35 | |
---|
| 36 | #include <ostream> |
---|
| 37 | |
---|
[3280] | 38 | #include "util/StringUtils.h" |
---|
[9667] | 39 | #include "core/CoreIncludes.h" |
---|
[9563] | 40 | #include "core/config/ConfigValueContainer.h" |
---|
| 41 | #include "core/XMLPort.h" |
---|
| 42 | #include "core/object/ClassFactory.h" |
---|
[790] | 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
[10400] | 46 | bool Identifier::initConfigValues_s = true; |
---|
| 47 | |
---|
[790] | 48 | // ############################### |
---|
| 49 | // ### Identifier ### |
---|
| 50 | // ############################### |
---|
| 51 | /** |
---|
| 52 | @brief Constructor: No factory, no object created, new ObjectList and a unique networkID. |
---|
| 53 | */ |
---|
[10395] | 54 | Identifier::Identifier(const std::string& name, Factory* factory, bool bLoadable) |
---|
[9667] | 55 | : classID_(IdentifierManager::getInstance().getUniqueClassId()) |
---|
[790] | 56 | { |
---|
[10396] | 57 | orxout(verbose, context::identifier) << "Create identifier for " << name << endl; |
---|
| 58 | |
---|
[10395] | 59 | this->name_ = name; |
---|
| 60 | this->factory_ = factory; |
---|
| 61 | this->bLoadable_ = bLoadable; |
---|
[9667] | 62 | this->bInitialized_ = false; |
---|
[10374] | 63 | this->bIsVirtualBase_ = false; |
---|
[1505] | 64 | |
---|
| 65 | this->bHasConfigValues_ = false; |
---|
[790] | 66 | |
---|
[5781] | 67 | // Default network ID is the class ID |
---|
| 68 | this->networkID_ = this->classID_; |
---|
[790] | 69 | } |
---|
| 70 | |
---|
| 71 | /** |
---|
[871] | 72 | @brief Destructor: Deletes the list containing the children. |
---|
[790] | 73 | */ |
---|
| 74 | Identifier::~Identifier() |
---|
| 75 | { |
---|
[1747] | 76 | if (this->factory_) |
---|
| 77 | delete this->factory_; |
---|
| 78 | |
---|
| 79 | for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it) |
---|
| 80 | delete (it->second); |
---|
[5781] | 81 | for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it) |
---|
| 82 | delete (it->second); |
---|
| 83 | for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it) |
---|
| 84 | delete (it->second); |
---|
[790] | 85 | } |
---|
| 86 | |
---|
[1856] | 87 | |
---|
[1747] | 88 | /** |
---|
[790] | 89 | @brief Creates an object of the type the Identifier belongs to. |
---|
| 90 | @return The new object |
---|
| 91 | */ |
---|
[9667] | 92 | Identifiable* Identifier::fabricate(Context* context) |
---|
[790] | 93 | { |
---|
| 94 | if (this->factory_) |
---|
| 95 | { |
---|
[9667] | 96 | return this->factory_->fabricate(context); |
---|
[790] | 97 | } |
---|
| 98 | else |
---|
| 99 | { |
---|
[8858] | 100 | orxout(user_error) << "An error occurred in Identifier.cc:" << endl; |
---|
| 101 | orxout(user_error) << "Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << endl; |
---|
| 102 | orxout(user_error) << "Aborting..." << endl; |
---|
[790] | 103 | abort(); |
---|
[5929] | 104 | return 0; |
---|
[790] | 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | /** |
---|
[5929] | 109 | @brief Sets the network ID to a new value and changes the entry in the ID-Identifier-map. |
---|
[5781] | 110 | */ |
---|
| 111 | void Identifier::setNetworkID(uint32_t id) |
---|
| 112 | { |
---|
| 113 | this->networkID_ = id; |
---|
[10395] | 114 | IdentifierManager::getInstance().addIdentifier(this); |
---|
[5781] | 115 | } |
---|
| 116 | |
---|
| 117 | /** |
---|
[9667] | 118 | * @brief Used to define the direct parents of an Identifier of an abstract class. |
---|
| 119 | */ |
---|
| 120 | Identifier& Identifier::inheritsFrom(Identifier* directParent) |
---|
| 121 | { |
---|
| 122 | if (this->parents_.empty()) |
---|
[10372] | 123 | this->directParents_.push_back(directParent); |
---|
[9667] | 124 | else |
---|
| 125 | orxout(internal_error) << "Trying to add " << directParent->getName() << " as a direct parent of " << this->getName() << " after the latter was already initialized" << endl; |
---|
| 126 | |
---|
| 127 | return *this; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | * @brief Initializes the parents of this Identifier while creating the class hierarchy. |
---|
[10366] | 132 | * @param initializationTrace All identifiers that were recorded while creating an instance of this class (including nested classes and this identifier itself) |
---|
[9667] | 133 | */ |
---|
[10372] | 134 | void Identifier::initializeParents(const std::list<const Identifier*>& initializationTrace) |
---|
[9667] | 135 | { |
---|
| 136 | if (!IdentifierManager::getInstance().isCreatingHierarchy()) |
---|
| 137 | { |
---|
| 138 | orxout(internal_warning) << "Identifier::initializeParents() created outside of class hierarchy creation" << endl; |
---|
| 139 | return; |
---|
| 140 | } |
---|
| 141 | |
---|
[10371] | 142 | if (this->directParents_.empty()) |
---|
[9667] | 143 | { |
---|
[10372] | 144 | for (std::list<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it) |
---|
[10371] | 145 | if (*it != this) |
---|
[10372] | 146 | this->parents_.push_back(*it); |
---|
[9667] | 147 | } |
---|
[10371] | 148 | else |
---|
| 149 | orxout(internal_error) << "Trying to add parents to " << this->getName() << " after it was already initialized with manual calls to inheritsFrom<Class>()." << endl; |
---|
[9667] | 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | * @brief Finishes the initialization of this Identifier after creating the class hierarchy by wiring the (direct) parent/child references correctly. |
---|
| 154 | */ |
---|
| 155 | void Identifier::finishInitialization() |
---|
| 156 | { |
---|
| 157 | if (!IdentifierManager::getInstance().isCreatingHierarchy()) |
---|
| 158 | { |
---|
| 159 | orxout(internal_warning) << "Identifier::finishInitialization() created outside of class hierarchy creation" << endl; |
---|
| 160 | return; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | if (this->isInitialized()) |
---|
| 164 | return; |
---|
| 165 | |
---|
[10371] | 166 | if (!this->parents_.empty()) |
---|
| 167 | { |
---|
| 168 | // parents defined -> this class was initialized by creating a sample instance and recording the trace of identifiers |
---|
| 169 | |
---|
| 170 | // initialize all parents |
---|
[10372] | 171 | for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it) |
---|
[10371] | 172 | const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent |
---|
| 173 | |
---|
| 174 | // parents of parents are no direct parents of this identifier |
---|
[9667] | 175 | this->directParents_ = this->parents_; |
---|
[10372] | 176 | for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent) |
---|
| 177 | for (std::list<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) |
---|
| 178 | this->directParents_.remove(*it_parent_parent); |
---|
[10377] | 179 | |
---|
| 180 | this->verifyIdentifierTrace(); |
---|
[10371] | 181 | } |
---|
| 182 | else if (!this->directParents_.empty()) |
---|
| 183 | { |
---|
| 184 | // no parents defined -> this class was manually initialized by calling inheritsFrom<Class>() |
---|
[9667] | 185 | |
---|
[10371] | 186 | // initialize all direct parents |
---|
[10372] | 187 | for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) |
---|
[10371] | 188 | const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent |
---|
| 189 | |
---|
| 190 | // direct parents and their parents are also parents of this identifier (but only add them once) |
---|
[10372] | 191 | for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent) |
---|
[10375] | 192 | { |
---|
[10372] | 193 | for (std::list<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) |
---|
[10376] | 194 | this->addIfNotExists(this->parents_, *it_parent_parent); |
---|
| 195 | this->addIfNotExists(this->parents_, *it_parent); |
---|
[10375] | 196 | } |
---|
[10371] | 197 | } |
---|
| 198 | else if (!this->isExactlyA(Class(Identifiable))) |
---|
[9667] | 199 | { |
---|
[10371] | 200 | // only Identifiable is allowed to have no parents (even tough it's currently not abstract) |
---|
[10399] | 201 | orxout(internal_error) << "Identifier " << this->getName() << " / " << this->getTypeInfo().name() << " is marked as abstract but has no direct parents defined" << endl; |
---|
[10371] | 202 | orxout(internal_error) << " If this class is not abstract, use RegisterClass(ThisClass);" << endl; |
---|
| 203 | orxout(internal_error) << " If this class is abstract, use RegisterAbstractClass(ThisClass).inheritsFrom(Class(BaseClass));" << endl; |
---|
[9667] | 204 | } |
---|
| 205 | |
---|
| 206 | // tell all parents that this identifier is a child |
---|
[10372] | 207 | for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it) |
---|
[9667] | 208 | const_cast<Identifier*>(*it)->children_.insert(this); |
---|
| 209 | |
---|
| 210 | // tell all direct parents that this identifier is a direct child |
---|
[10372] | 211 | for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) |
---|
[9667] | 212 | { |
---|
| 213 | const_cast<Identifier*>(*it)->directChildren_.insert(this); |
---|
| 214 | |
---|
| 215 | // Create the super-function dependencies |
---|
| 216 | (*it)->createSuperFunctionCaller(); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | this->bInitialized_ = true; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | /** |
---|
[10403] | 223 | * Resets all information about the class hierarchy. The identifier is considered uninitialized afterwards. |
---|
| 224 | */ |
---|
| 225 | void Identifier::reset() |
---|
| 226 | { |
---|
[10405] | 227 | this->directParents_.clear(); |
---|
[10403] | 228 | this->parents_.clear(); |
---|
| 229 | this->directChildren_.clear(); |
---|
| 230 | this->children_.clear(); |
---|
| 231 | this->bInitialized_ = false; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | /** |
---|
[10377] | 235 | * Verifies if the recorded trace of parent identifiers matches the expected trace according to the class hierarchy. If it doesn't match, the class |
---|
| 236 | * hierarchy is likely wrong, e.g. due to wrong inheritsFrom<>() definitions in abstract classes. |
---|
| 237 | */ |
---|
| 238 | void Identifier::verifyIdentifierTrace() const |
---|
| 239 | { |
---|
| 240 | |
---|
| 241 | std::list<const Identifier*> expectedIdentifierTrace; |
---|
| 242 | |
---|
| 243 | // if any parent class is virtual, it will be instantiated first, so we need to add them first. |
---|
| 244 | for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent) |
---|
| 245 | { |
---|
| 246 | if ((*it_parent)->isVirtualBase()) |
---|
| 247 | { |
---|
| 248 | for (std::list<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) |
---|
| 249 | this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent); |
---|
| 250 | this->addIfNotExists(expectedIdentifierTrace, *it_parent); |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | // now all direct parents get created recursively. already added identifiers (e.g. virtual base classes) are not added again. |
---|
| 255 | for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent) |
---|
| 256 | { |
---|
| 257 | for (std::list<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) |
---|
| 258 | this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent); |
---|
| 259 | this->addIfNotExists(expectedIdentifierTrace, *it_parent); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | // check if the expected trace matches the actual trace (which was defined by creating a sample instance) |
---|
| 263 | if (expectedIdentifierTrace != this->parents_) |
---|
| 264 | { |
---|
| 265 | orxout(internal_warning) << this->getName() << " has an unexpected initialization trace:" << endl; |
---|
| 266 | |
---|
| 267 | orxout(internal_warning) << " Actual trace (after creating a sample instance):" << endl << " "; |
---|
| 268 | for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent) |
---|
| 269 | orxout(internal_warning) << " " << (*it_parent)->getName(); |
---|
| 270 | orxout(internal_warning) << endl; |
---|
| 271 | |
---|
| 272 | orxout(internal_warning) << " Expected trace (according to class hierarchy definitions):" << endl << " "; |
---|
| 273 | for (std::list<const Identifier*>::const_iterator it_parent = expectedIdentifierTrace.begin(); it_parent != expectedIdentifierTrace.end(); ++it_parent) |
---|
| 274 | orxout(internal_warning) << " " << (*it_parent)->getName(); |
---|
| 275 | orxout(internal_warning) << endl; |
---|
| 276 | |
---|
| 277 | orxout(internal_warning) << " Direct parents (according to class hierarchy definitions):" << endl << " "; |
---|
| 278 | for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent) |
---|
| 279 | orxout(internal_warning) << " " << (*it_parent)->getName(); |
---|
| 280 | orxout(internal_warning) << endl; |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /** |
---|
[10376] | 285 | * Adds @param identifierToAdd to @param list if this identifier is not already contained in the list. |
---|
| 286 | */ |
---|
| 287 | void Identifier::addIfNotExists(std::list<const Identifier*>& list, const Identifier* identifierToAdd) const |
---|
| 288 | { |
---|
| 289 | if (std::find(list.begin(), list.end(), identifierToAdd) == list.end()) |
---|
| 290 | list.push_back(identifierToAdd); |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | /** |
---|
[871] | 294 | @brief Returns true, if the Identifier is at least of the given type. |
---|
[790] | 295 | @param identifier The identifier to compare with |
---|
| 296 | */ |
---|
| 297 | bool Identifier::isA(const Identifier* identifier) const |
---|
| 298 | { |
---|
[10371] | 299 | return (identifier == this || (this->isChildOf(identifier))); |
---|
[790] | 300 | } |
---|
| 301 | |
---|
| 302 | /** |
---|
[871] | 303 | @brief Returns true, if the Identifier is exactly of the given type. |
---|
[790] | 304 | @param identifier The identifier to compare with |
---|
| 305 | */ |
---|
[871] | 306 | bool Identifier::isExactlyA(const Identifier* identifier) const |
---|
[790] | 307 | { |
---|
| 308 | return (identifier == this); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | /** |
---|
[871] | 312 | @brief Returns true, if the assigned identifier is a child of the given identifier. |
---|
[790] | 313 | @param identifier The identifier to compare with |
---|
| 314 | */ |
---|
| 315 | bool Identifier::isChildOf(const Identifier* identifier) const |
---|
| 316 | { |
---|
[10372] | 317 | return (std::find(this->parents_.begin(), this->parents_.end(), identifier) != this->parents_.end()); |
---|
[1505] | 318 | } |
---|
[790] | 319 | |
---|
| 320 | /** |
---|
[1505] | 321 | @brief Returns true, if the assigned identifier is a direct child of the given identifier. |
---|
| 322 | @param identifier The identifier to compare with |
---|
| 323 | */ |
---|
| 324 | bool Identifier::isDirectChildOf(const Identifier* identifier) const |
---|
| 325 | { |
---|
[10372] | 326 | return (std::find(this->directParents_.begin(), this->directParents_.end(), identifier) != this->directParents_.end()); |
---|
[1505] | 327 | } |
---|
| 328 | |
---|
| 329 | /** |
---|
[871] | 330 | @brief Returns true, if the assigned identifier is a parent of the given identifier. |
---|
[790] | 331 | @param identifier The identifier to compare with |
---|
| 332 | */ |
---|
| 333 | bool Identifier::isParentOf(const Identifier* identifier) const |
---|
| 334 | { |
---|
[5929] | 335 | return (this->children_.find(identifier) != this->children_.end()); |
---|
[1505] | 336 | } |
---|
| 337 | |
---|
| 338 | /** |
---|
| 339 | @brief Returns true, if the assigned identifier is a direct parent of the given identifier. |
---|
| 340 | @param identifier The identifier to compare with |
---|
| 341 | */ |
---|
| 342 | bool Identifier::isDirectParentOf(const Identifier* identifier) const |
---|
| 343 | { |
---|
[5929] | 344 | return (this->directChildren_.find(identifier) != this->directChildren_.end()); |
---|
[1505] | 345 | } |
---|
| 346 | |
---|
| 347 | /** |
---|
| 348 | @brief Adds the ConfigValueContainer of a variable, given by the string of its name. |
---|
| 349 | @param varname The name of the variablee |
---|
| 350 | @param container The container |
---|
| 351 | */ |
---|
| 352 | void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) |
---|
| 353 | { |
---|
| 354 | std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname); |
---|
| 355 | if (it != this->configValues_.end()) |
---|
| 356 | { |
---|
[8858] | 357 | orxout(internal_warning) << "Overwriting config-value with name " << varname << " in class " << this->getName() << '.' << endl; |
---|
[1747] | 358 | delete (it->second); |
---|
[1505] | 359 | } |
---|
| 360 | |
---|
| 361 | this->bHasConfigValues_ = true; |
---|
| 362 | this->configValues_[varname] = container; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | /** |
---|
| 366 | @brief Returns the ConfigValueContainer of a variable, given by the string of its name. |
---|
| 367 | @param varname The name of the variable |
---|
| 368 | @return The ConfigValueContainer |
---|
| 369 | */ |
---|
| 370 | ConfigValueContainer* Identifier::getConfigValueContainer(const std::string& varname) |
---|
| 371 | { |
---|
| 372 | std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname); |
---|
| 373 | if (it != configValues_.end()) |
---|
[5929] | 374 | return it->second; |
---|
[1505] | 375 | else |
---|
| 376 | return 0; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | /** |
---|
[5781] | 380 | @brief Returns a XMLPortParamContainer that loads a parameter of this class. |
---|
| 381 | @param paramname The name of the parameter |
---|
| 382 | @return The container |
---|
| 383 | */ |
---|
| 384 | XMLPortParamContainer* Identifier::getXMLPortParamContainer(const std::string& paramname) |
---|
| 385 | { |
---|
| 386 | std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); |
---|
| 387 | if (it != this->xmlportParamContainers_.end()) |
---|
[5929] | 388 | return it->second; |
---|
[5781] | 389 | else |
---|
| 390 | return 0; |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | /** |
---|
| 394 | @brief Adds a new XMLPortParamContainer that loads a parameter of this class. |
---|
| 395 | @param paramname The name of the parameter |
---|
| 396 | @param container The container |
---|
| 397 | */ |
---|
| 398 | void Identifier::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) |
---|
| 399 | { |
---|
| 400 | std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); |
---|
| 401 | if (it != this->xmlportParamContainers_.end()) |
---|
| 402 | { |
---|
[8858] | 403 | orxout(internal_warning) << "Overwriting XMLPortParamContainer in class " << this->getName() << '.' << endl; |
---|
[5781] | 404 | delete (it->second); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | this->xmlportParamContainers_[paramname] = container; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | /** |
---|
| 411 | @brief Returns a XMLPortObjectContainer that attaches an object to this class. |
---|
| 412 | @param sectionname The name of the section that contains the attachable objects |
---|
| 413 | @return The container |
---|
| 414 | */ |
---|
| 415 | XMLPortObjectContainer* Identifier::getXMLPortObjectContainer(const std::string& sectionname) |
---|
| 416 | { |
---|
| 417 | std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); |
---|
| 418 | if (it != this->xmlportObjectContainers_.end()) |
---|
[5929] | 419 | return it->second; |
---|
[5781] | 420 | else |
---|
| 421 | return 0; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | /** |
---|
| 425 | @brief Adds a new XMLPortObjectContainer that attaches an object to this class. |
---|
| 426 | @param sectionname The name of the section that contains the attachable objects |
---|
| 427 | @param container The container |
---|
| 428 | */ |
---|
| 429 | void Identifier::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) |
---|
| 430 | { |
---|
| 431 | std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); |
---|
| 432 | if (it != this->xmlportObjectContainers_.end()) |
---|
| 433 | { |
---|
[8858] | 434 | orxout(internal_warning) << "Overwriting XMLPortObjectContainer in class " << this->getName() << '.' << endl; |
---|
[5781] | 435 | delete (it->second); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | this->xmlportObjectContainers_[sectionname] = container; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | /** |
---|
[1505] | 442 | @brief Lists the names of all Identifiers in a std::set<const Identifier*>. |
---|
| 443 | @param out The outstream |
---|
| 444 | @param list The list (or set) of Identifiers |
---|
| 445 | @return The outstream |
---|
| 446 | */ |
---|
| 447 | std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list) |
---|
| 448 | { |
---|
| 449 | for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) |
---|
[5929] | 450 | { |
---|
| 451 | if (it != list.begin()) |
---|
[6417] | 452 | out << ' '; |
---|
[5929] | 453 | out << (*it)->getName(); |
---|
| 454 | } |
---|
[1505] | 455 | |
---|
| 456 | return out; |
---|
| 457 | } |
---|
[790] | 458 | } |
---|