Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 26, 2010, 2:56:06 PM (14 years ago)
Author:
rgrieder
Message:

Moved the port() function of XMLPortObjectContainer from the template to the base class and reduced the indentation levels in the code a little bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/libraries/core/XMLPort.h

    r7148 r7160  
    495495            virtual ~XMLPortObjectContainer() {}
    496496
     497            XMLPortObjectContainer& port(BaseObject* object, Element& xmlelement, XMLPort::Mode mode);
     498
     499            virtual void callLoadExecutor(BaseObject* object, BaseObject* newObject) = 0;
     500
    497501            inline const std::string& getName() const
    498502                { return this->sectionname_; }
     
    508512            bool bLoadBefore_;
    509513            Identifier* identifier_;
     514            Identifier* objectIdentifier_;
    510515    };
    511516
     
    518523                this->sectionname_ = sectionname;
    519524                this->identifier_ = identifier;
     525                assert(identifier->isA(ClassIdentifier<T>::getIdentifier()));
     526                this->objectIdentifier_ = ClassIdentifier<O>::getIdentifier();
    520527                this->loadexecutor_ = loadexecutor;
    521528                this->saveexecutor_ = saveexecutor;
     
    532539            }
    533540
    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);
    636549            }
    637550
Note: See TracChangeset for help on using the changeset viewer.