[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 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 | |
---|
| 29 | #include "XMLPort.h" |
---|
[3196] | 30 | |
---|
[9640] | 31 | #include "CoreIncludes.h" |
---|
[1505] | 32 | #include "Loader.h" |
---|
| 33 | #include "Namespace.h" |
---|
| 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
| 37 | // ################################ |
---|
| 38 | // ### XMLPortObjectContainer ### |
---|
| 39 | // ################################ |
---|
| 40 | bool XMLPortObjectContainer::identifierIsIncludedInLoaderMask(const Identifier* identifier) |
---|
| 41 | { |
---|
[3196] | 42 | return ((!this->bApplyLoaderMask_) || identifier->isA(ClassIdentifier<Namespace>::getIdentifier()) || Loader::currentMask_s.isIncluded(identifier)); |
---|
[1505] | 43 | } |
---|
[7163] | 44 | |
---|
| 45 | XMLPortObjectContainer& XMLPortObjectContainer::port(BaseObject* object, Element& xmlelement, XMLPort::Mode mode) |
---|
| 46 | { |
---|
| 47 | if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject)) |
---|
| 48 | { |
---|
| 49 | try |
---|
| 50 | { |
---|
| 51 | Element* xmlsubelement; |
---|
| 52 | if (!this->sectionname_.empty()) |
---|
| 53 | xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); |
---|
| 54 | else |
---|
| 55 | xmlsubelement = &xmlelement; |
---|
| 56 | |
---|
| 57 | if (!xmlsubelement) |
---|
| 58 | return (*this); |
---|
| 59 | |
---|
| 60 | for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) |
---|
| 61 | { |
---|
[9640] | 62 | Identifier* identifier = ClassByString(child->Value()); |
---|
[7163] | 63 | if (!identifier) |
---|
| 64 | { |
---|
| 65 | if (!this->sectionname_.empty()) |
---|
| 66 | { |
---|
[8858] | 67 | orxout(internal_warning, context::xml) << object->getLoaderIndentation() << "'" << child->Value() << "' is not a valid classname." << endl; |
---|
[7163] | 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | // It's probably just another subsection |
---|
| 72 | } |
---|
| 73 | continue; |
---|
| 74 | } |
---|
| 75 | if (!identifier->isA(objectIdentifier_)) |
---|
| 76 | { |
---|
[8858] | 77 | orxout(internal_warning, context::xml) << object->getLoaderIndentation() << "'" << child->Value() << "' is not a '" << objectIdentifier_->getName() << "'." << endl; |
---|
[7163] | 78 | continue; |
---|
| 79 | } |
---|
| 80 | if (!identifier->isLoadable()) |
---|
| 81 | { |
---|
[8858] | 82 | orxout(internal_warning, context::xml) << object->getLoaderIndentation() << "'" << child->Value() << "' is not loadable." << endl; |
---|
[7163] | 83 | continue; |
---|
| 84 | } |
---|
| 85 | if (!this->identifierIsIncludedInLoaderMask(identifier)) |
---|
| 86 | continue; |
---|
| 87 | |
---|
| 88 | try |
---|
| 89 | { |
---|
[8858] | 90 | orxout(verbose, context::xml) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << endl; |
---|
[7163] | 91 | |
---|
[9629] | 92 | BaseObject* newObject = orxonox_cast<BaseObject*>(identifier->fabricate(object->getContext())); |
---|
[7163] | 93 | newObject->setLoaderIndentation(object->getLoaderIndentation() + " "); |
---|
| 94 | |
---|
| 95 | if (this->bLoadBefore_) |
---|
| 96 | { |
---|
| 97 | newObject->XMLPort(*child, XMLPort::LoadObject); |
---|
[8858] | 98 | orxout(verbose, context::xml) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << endl; |
---|
[7163] | 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
[8858] | 102 | orxout(verbose, context::xml) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << endl; |
---|
[7163] | 103 | } |
---|
| 104 | |
---|
| 105 | this->callLoadExecutor(object, newObject); |
---|
| 106 | |
---|
| 107 | if (!this->bLoadBefore_) |
---|
| 108 | newObject->XMLPort(*child, XMLPort::LoadObject); |
---|
| 109 | |
---|
[8858] | 110 | orxout(verbose, context::xml) << object->getLoaderIndentation() << "fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << endl; |
---|
[7163] | 111 | } |
---|
| 112 | catch (AbortLoadingException& ex) |
---|
| 113 | { |
---|
[8858] | 114 | orxout(internal_error, context::xml) << "An error occurred while loading object, abort loading..." << endl; |
---|
[7163] | 115 | throw ex; |
---|
| 116 | } |
---|
| 117 | catch (...) |
---|
| 118 | { |
---|
[8858] | 119 | orxout(internal_error, context::xml) << "An error occurred while loading object:" << endl; |
---|
| 120 | orxout(internal_error, context::xml) << Exception::handleMessage() << endl; |
---|
[7163] | 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | catch (ticpp::Exception& ex) |
---|
| 125 | { |
---|
[8858] | 126 | orxout(internal_error, context::xml) << endl; |
---|
| 127 | orxout(internal_error, context::xml) << "An error occurred in XMLPort.h while loading a '" << objectIdentifier_->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << object->getName() << ") in " << object->getFilename() << ':' << endl; |
---|
| 128 | orxout(internal_error, context::xml) << ex.what() << endl; |
---|
[7163] | 129 | } |
---|
| 130 | } |
---|
| 131 | else if (mode == XMLPort::SaveObject) |
---|
| 132 | { |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | return (*this); |
---|
| 136 | } |
---|
[1505] | 137 | } |
---|