Changeset 7163 for code/trunk/src/libraries/core/XMLPort.h
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/XMLPort.h
r6417 r7163 197 197 @param loadfunction The function to add a new object to the class 198 198 @param loadfunction The function to get all added objects from the class 199 @param xmlelement The XMLElement (rec ieved through the XMLPort function)199 @param xmlelement The XMLElement (received through the XMLPort function) 200 200 @param mode The mode (load/save) (received through the XMLPort function) 201 201 @param bApplyLoaderMask If this is true, an added sub-object gets loaded only if it's class is included in the Loaders ClassTreeMask (this is usually false) … … 495 495 virtual ~XMLPortObjectContainer() {} 496 496 497 XMLPortObjectContainer& port(BaseObject* object, Element& xmlelement, XMLPort::Mode mode); 498 499 virtual void callLoadExecutor(BaseObject* object, BaseObject* newObject) = 0; 500 497 501 inline const std::string& getName() const 498 502 { return this->sectionname_; } … … 508 512 bool bLoadBefore_; 509 513 Identifier* identifier_; 514 Identifier* objectIdentifier_; 510 515 }; 511 516 … … 518 523 this->sectionname_ = sectionname; 519 524 this->identifier_ = identifier; 525 assert(identifier->isA(ClassIdentifier<T>::getIdentifier())); 526 this->objectIdentifier_ = ClassIdentifier<O>::getIdentifier(); 520 527 this->loadexecutor_ = loadexecutor; 521 528 this->saveexecutor_ = saveexecutor; … … 532 539 } 533 540 534 XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode) 535 { 536 if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject)) 537 { 538 try 539 { 540 Element* xmlsubelement; 541 if (!this->sectionname_.empty()) 542 xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 543 else 544 xmlsubelement = &xmlelement; 545 546 if (xmlsubelement) 547 { 548 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 549 { 550 Identifier* identifier = Identifier::getIdentifierByString(child->Value()); 551 if (identifier) 552 { 553 if (identifier->isA(ClassIdentifier<O>::getIdentifier())) 554 { 555 if (identifier->isLoadable()) 556 { 557 if (this->identifierIsIncludedInLoaderMask(identifier)) 558 { 559 try 560 { 561 COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl; 562 563 BaseObject* newObject = identifier->fabricate(static_cast<BaseObject*>(object)); 564 assert(newObject); 565 newObject->setLoaderIndentation(object->getLoaderIndentation() + " "); 566 567 O* castedObject = orxonox_cast<O*>(newObject); 568 assert(castedObject); 569 570 if (this->bLoadBefore_) 571 { 572 newObject->XMLPort(*child, XMLPort::LoadObject); 573 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl; 574 } 575 else 576 { 577 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl; 578 } 579 580 COUT(5) << object->getLoaderIndentation(); 581 (*this->loadexecutor_)(object, castedObject); 582 583 if (!this->bLoadBefore_) 584 newObject->XMLPort(*child, XMLPort::LoadObject); 585 586 COUT(5) << object->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 587 } 588 catch (AbortLoadingException& ex) 589 { 590 COUT(1) << "An error occurred while loading object, abort loading..." << std::endl; 591 throw ex; 592 } 593 catch (...) 594 { 595 COUT(1) << "An error occurred while loading object:" << std::endl; 596 COUT(1) << Exception::handleMessage() << std::endl; 597 } 598 } 599 } 600 else 601 { 602 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl; 603 } 604 } 605 else 606 { 607 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a '" << ClassIdentifier<O>::getIdentifier()->getName() << "'." << std::endl; 608 } 609 } 610 else 611 { 612 if (!this->sectionname_.empty()) 613 { 614 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 615 } 616 else 617 { 618 // It's probably just another subsection 619 } 620 } 621 } 622 } 623 } 624 catch (ticpp::Exception& ex) 625 { 626 COUT(1) << std::endl; 627 COUT(1) << "An error occurred in XMLPort.h while loading a '" << ClassIdentifier<O>::getIdentifier()->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << object->getName() << ") in " << object->getFilename() << ':' << std::endl; 628 COUT(1) << ex.what() << std::endl; 629 } 630 } 631 else if (mode == XMLPort::SaveObject) 632 { 633 } 634 635 return (*this); 541 void callLoadExecutor(BaseObject* object, BaseObject* newObject) 542 { 543 T* castedObject = orxonox_cast<T*>(object); 544 assert(castedObject); 545 O* castedNewObject = orxonox_cast<O*>(newObject); 546 assert(castedNewObject); 547 548 (*this->loadexecutor_)(castedObject, castedNewObject); 636 549 } 637 550
Note: See TracChangeset
for help on using the changeset viewer.