Changeset 7163 for code/trunk/src/libraries/core
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/BaseObject.cc
r6800 r7163 75 75 this->setScene(this->creator_->getScene(), this->creator_->getSceneID()); 76 76 this->setGametype(this->creator_->getGametype()); 77 this->setLevel(this->creator_->getLevel()); 77 78 } 78 79 else … … 83 84 this->sceneID_ = OBJECTID_UNKNOWN; 84 85 this->gametype_ = 0; 86 this->level_ = 0; 85 87 } 86 88 } … … 103 105 } 104 106 } 105 107 106 108 /** @brief Adds an object which listens to the events of this object. */ 107 109 void BaseObject::registerEventListener(BaseObject* object) … … 123 125 XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode); 124 126 XMLPortParamTemplate(BaseObject, "template", addTemplate, getSingleTemplate, xmlelement, mode, const std::string&); 125 127 126 128 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 127 129 XMLPortObject(BaseObject, BaseObject, "eventlisteners", addEventListener, getEventListener, xmlelement, mode); … … 194 196 { 195 197 this->templates_.insert(temp); 198 if( temp->isLink() ) 199 { 200 this->networkTemplateNames_.insert(temp->getLink()); 201 assert( !Template::getTemplate(temp->getLink())->isLink() ); 202 } 203 else 204 this->networkTemplateNames_.insert(temp->getName()); 196 205 temp->applyOn(this); 197 206 } … … 363 372 { 364 373 this->registerEventStates(); 365 374 366 375 COUT(4) << this->getIdentifier()->getName() << " (&" << this << ") processing event. originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << "), activate: " << event.activate_ << ", name: " << event.name_ << ", statename: " << event.statename_ << "." << std::endl; 367 376 -
code/trunk/src/libraries/core/BaseObject.h
r6800 r7163 51 51 class Scene; 52 52 class Gametype; 53 class Level; 53 54 54 55 //! The BaseObject is the parent of all classes representing an instance in the game. … … 154 155 virtual void changedGametype() {} 155 156 157 inline void setLevel(const SmartPtr<Level>& level) 158 { 159 if (level != this->level_) 160 { 161 this->level_ = level; 162 this->changedLevel(); 163 } 164 } 165 inline const SmartPtr<Level>& getLevel() const { return this->level_; } 166 virtual void changedLevel() {} 167 156 168 void addEventSource(BaseObject* source, const std::string& state); 157 169 void removeEventSource(BaseObject* source); … … 179 191 EventState* getEventState(const std::string& name) const; 180 192 181 std::string name_; //!< The name of the object 182 std::string oldName_; //!< The old name of the object 183 mbool bActive_; //!< True = the object is active 184 mbool bVisible_; //!< True = the object is visible 185 std::string mainStateName_; 186 Functor* mainStateFunctor_; 193 std::string name_; //!< The name of the object 194 std::string oldName_; //!< The old name of the object 195 mbool bActive_; //!< True = the object is active 196 mbool bVisible_; //!< True = the object is visible 197 std::string mainStateName_; 198 Functor* mainStateFunctor_; 199 std::set<std::string> networkTemplateNames_; 187 200 188 201 private: … … 209 222 SmartPtr<Gametype> gametype_; 210 223 Gametype* oldGametype_; 224 SmartPtr<Level> level_; 211 225 std::set<Template*> templates_; 212 226 -
code/trunk/src/libraries/core/CMakeLists.txt
r6417 r7163 96 96 input/KeyBinder.h 97 97 input/KeyBinderManager.h 98 DEFINE_SYMBOL99 "CORE_SHARED_BUILD"100 98 PCH_FILE 101 99 CorePrecompiledHeaders.h … … 112 110 ogreceguirenderer_orxonox 113 111 ois_orxonox 114 tinyxml ++_orxonox115 tolua ++_orxonox112 tinyxml_orxonox 113 tolua_orxonox 116 114 util 117 115 SOURCE_FILES -
code/trunk/src/libraries/core/ConfigFileManager.cc
r6536 r7163 33 33 #include "util/Convert.h" 34 34 #include "util/Math.h" 35 #include "util/StringUtils.h" 35 36 #include "ConsoleCommand.h" 36 37 #include "ConfigValueContainer.h" -
code/trunk/src/libraries/core/ConfigFileManager.h
r6536 r7163 39 39 40 40 #include "util/Singleton.h" 41 #include "util/StringUtils.h"42 41 43 42 namespace orxonox // tolua_export -
code/trunk/src/libraries/core/Core.cc
r6746 r7163 79 79 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file"); 80 80 SetCommandLineSwitch(noIOConsole).information("Use this if you don't want to use the IOConsole (for instance for Lua debugging)"); 81 81 82 #ifdef ORXONOX_PLATFORM_WINDOWS 82 83 SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)"); -
code/trunk/src/libraries/core/Event.cc
r6859 r7163 60 60 61 61 COUT(4) << "Processing event (EventState) : originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << "), activate: " << event.activate_ << ", name: " << event.name_ << ", statename: " << event.statename_ << ", object: " << object->getIdentifier()->getName() << " (&" << object << ")" << "." << std::endl; 62 62 63 63 // check if the originator is an instance of the requested class 64 64 if (event.originator_->isA(this->subclass_)) -
code/trunk/src/libraries/core/EventIncludes.h
r6800 r7163 52 52 } \ 53 53 XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode) 54 54 55 55 #define XMLPortEventSink(classname, subclassname, statename, function, xmlelement, mode) \ 56 56 orxonox::EventState* containername##function = this->getEventState(statename); \ -
code/trunk/src/libraries/core/Executor.cc
r6417 r7163 30 30 #include "Executor.h" 31 31 32 #include <algorithm> 33 32 34 #include "util/Convert.h" 35 #include "util/Debug.h" 36 #include "util/StringUtils.h" 37 #include "util/SubString.h" 33 38 #include "Language.h" 34 39 … … 63 68 bool Executor::parse(const std::string& params, const std::string& delimiter) const 64 69 { 65 EXECUTOR_PARSE(normal); 70 unsigned int paramCount = this->functor_->getParamCount(); 71 72 if (paramCount == 0) 73 { 74 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; 75 (*this->functor_)(); 76 } 77 else if (paramCount == 1) 78 { 79 const std::string& temp = getStripped(params); 80 if (!temp.empty()) 81 { 82 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; 83 (*this->functor_)(MultiType(params)); 84 } 85 else if (this->bAddedDefaultValue_[0]) 86 { 87 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; 88 (*this->functor_)(this->defaultValue_[0]); 89 } 90 else 91 { 92 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; 93 return false; 94 } 95 } 96 else 97 { 98 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); 99 100 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 101 { 102 if (!this->bAddedDefaultValue_[i]) 103 { 104 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; 105 return false; 106 } 107 } 108 109 MultiType param[MAX_FUNCTOR_ARGUMENTS]; 110 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; 111 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) 112 { 113 param[i] = tokens[i]; 114 if (i != 0) 115 { 116 COUT(5) << ", "; 117 } 118 COUT(5) << tokens[i]; 119 } 120 COUT(5) << ") and " << std::max((int)paramCount - (int)tokens.size(), 0) << " default values ("; 121 for (unsigned int i = tokens.size(); i < paramCount; i++) 122 { 123 param[i] = this->defaultValue_[i]; 124 if (i != 0) 125 { 126 COUT(5) << ", "; 127 } 128 COUT(5) << this->defaultValue_[i]; 129 } 130 COUT(5) << ")." << std::endl; 131 132 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) 133 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); 134 135 switch(paramCount) 136 { 137 case 2: 138 (*this->functor_)(param[0], param[1]); 139 break; 140 case 3: 141 (*this->functor_)(param[0], param[1], param[2]); 142 break; 143 case 4: 144 (*this->functor_)(param[0], param[1], param[2], param[3]); 145 break; 146 case 5: 147 (*this->functor_)(param[0], param[1], param[2], param[3], param[4]); 148 break; 149 } 150 } 151 152 return true; 66 153 } 67 154 -
code/trunk/src/libraries/core/Executor.h
r6417 r7163 33 33 #include "CorePrereqs.h" 34 34 35 #include <algorithm>36 35 #include <string> 37 38 #include "util/Debug.h" 39 #include "util/Math.h" 40 #include "util/StringUtils.h" 41 #include "util/SubString.h" 36 #include "util/MultiType.h" 42 37 #include "Functor.h" 43 44 45 #define EXECUTOR_PARSE_FUNCTORCALL(mode) EXECUTOR_PARSE_FUNCTORCALL##mode46 #define EXECUTOR_PARSE_FUNCTORCALLnormal (*this->functor_)47 #define EXECUTOR_PARSE_FUNCTORCALLobject (*((FunctorMember<T>*)this->functor_))48 49 #define EXECUTOR_PARSE_OBJECT(mode, comma) EXECUTOR_PARSE_OBJECT##mode##comma50 #define EXECUTOR_PARSE_OBJECTnormal051 #define EXECUTOR_PARSE_OBJECTnormal152 #define EXECUTOR_PARSE_OBJECTobject0 object53 #define EXECUTOR_PARSE_OBJECTobject1 object,54 55 #define EXECUTOR_PARSE(mode) \56 unsigned int paramCount = this->functor_->getParamCount(); \57 \58 if (paramCount == 0) \59 { \60 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; \61 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 0)); \62 } \63 else if (paramCount == 1) \64 { \65 const std::string& temp = getStripped(params); \66 if (!temp.empty()) \67 { \68 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; \69 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) MultiType(params)); \70 } \71 else if (this->bAddedDefaultValue_[0]) \72 { \73 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; \74 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) this->defaultValue_[0]); \75 } \76 else \77 { \78 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; \79 return false; \80 } \81 } \82 else \83 { \84 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \85 \86 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \87 { \88 if (!this->bAddedDefaultValue_[i]) \89 { \90 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; \91 return false; \92 } \93 } \94 \95 MultiType param[MAX_FUNCTOR_ARGUMENTS]; \96 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \97 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \98 { \99 param[i] = tokens[i]; \100 if (i != 0) \101 { \102 COUT(5) << ", "; \103 } \104 COUT(5) << tokens[i]; \105 } \106 COUT(5) << ") and " << std::max(static_cast<int>(paramCount) - static_cast<int>(tokens.size()), 0) << " default values ("; \107 for (unsigned int i = tokens.size(); i < paramCount; i++) \108 { \109 param[i] = this->defaultValue_[i]; \110 if (i != 0) \111 { \112 COUT(5) << ", "; \113 } \114 COUT(5) << this->defaultValue_[i]; \115 } \116 COUT(5) << ")." << std::endl; \117 \118 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \119 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \120 \121 switch(paramCount) \122 { \123 case 2: \124 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1]); \125 break; \126 case 3: \127 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2]); \128 break; \129 case 4: \130 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3]); \131 break; \132 case 5: \133 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3], param[4]); \134 break; \135 } \136 } \137 \138 return true139 38 140 39 namespace orxonox … … 284 183 bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const 285 184 { 286 EXECUTOR_PARSE(object); 185 static_cast<FunctorMember<T>*>(this->functor_)->setObject(object); 186 if (Executor::parse(params, delimiter)) 187 return true; 188 else 189 { 190 static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL); 191 return false; 192 } 287 193 } 288 194 289 195 bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const 290 196 { 291 EXECUTOR_PARSE(object); 197 static_cast<FunctorMember<T>*>(this->functor_)->setObject(object); 198 if (Executor::parse(params, delimiter)) 199 return true; 200 else 201 { 202 static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL); 203 return false; 204 } 292 205 } 293 206 }; -
code/trunk/src/libraries/core/GUIManager.cc
r6763 r7163 321 321 } 322 322 323 void GUIManager:: keyPressed(const KeyEvent& evt)323 void GUIManager::buttonPressed(const KeyEvent& evt) 324 324 { 325 325 this->protectedCall(boost::bind(&CEGUI::System::injectKeyDown, _1, evt.getKeyCode())); … … 327 327 } 328 328 329 void GUIManager:: keyReleased(const KeyEvent& evt)329 void GUIManager::buttonReleased(const KeyEvent& evt) 330 330 { 331 331 this->protectedCall(boost::bind(&CEGUI::System::injectKeyUp, _1, evt.getKeyCode())); -
code/trunk/src/libraries/core/GUIManager.h
r6749 r7163 84 84 //! Creates a new InputState to be used with a GUI Sheet 85 85 const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export 86 LuaState* getLuaState(void) 87 { return this->luaState_.get(); } 86 88 87 89 //! Returns the root window for all menu sheets … … 95 97 inline void setPlayer(const std::string& guiname, PlayerInfo* player) 96 98 { this->players_[guiname] = player; } 97 inline PlayerInfo* getPlayer(const std::string& guiname) const 98 { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; } 99 inline orxonox::PlayerInfo* getPlayer(const std::string& guiname) const { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; } // tolua_export 99 100 100 101 // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work … … 105 106 private: 106 107 GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class) 108 void executeCode(const std::string& str); 107 109 108 void executeCode(const std::string& str);109 110 template <typename FunctionType> 110 111 bool protectedCall(FunctionType function); 111 112 112 113 // keyHandler functions 113 void keyPressed (const KeyEvent& evt);114 void keyReleased(const KeyEvent& evt);114 void buttonPressed (const KeyEvent& evt); 115 void buttonReleased(const KeyEvent& evt); 115 116 116 117 // mouseHandler functions -
code/trunk/src/libraries/core/OrxonoxClass.h
r6524 r7163 108 108 bool isParentOf(const OrxonoxClass* object); 109 109 bool isDirectParentOf(const OrxonoxClass* object); 110 110 111 111 virtual void clone(OrxonoxClass*& item) {} 112 112 … … 172 172 std::vector<std::pair<unsigned int, void*> > objectPointers_; 173 173 }; 174 175 SUPER_FUNCTION(11, OrxonoxClass, clone, true);176 174 175 SUPER_FUNCTION(11, OrxonoxClass, clone, false); 176 177 177 } 178 178 -
code/trunk/src/libraries/core/Super.h
r6524 r7163 267 267 #define SUPER_changedGametype(classname, functionname, ...) \ 268 268 SUPER_NOARGS(classname, functionname) 269 269 270 270 #define SUPER_changedUsed(classname, functionname, ...) \ 271 271 SUPER_NOARGS(classname, functionname) 272 272 273 273 #define SUPER_clone(classname, functionname, ...) \ 274 274 SUPER_ARGS(classname, functionname, __VA_ARGS__) 275 275 276 276 #define SUPER_changedCarrier(classname, functionname, ...) \ 277 277 SUPER_NOARGS(classname, functionname) 278 278 279 279 #define SUPER_changedPickedUp(classname, functionname, ...) \ 280 280 SUPER_NOARGS(classname, functionname) 281 281 282 282 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 283 283 … … 530 530 () 531 531 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 532 532 533 533 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedUsed, false) 534 534 () … … 538 538 (item) 539 539 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 540 540 541 541 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedCarrier, false) 542 542 () 543 543 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 544 544 545 545 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(13, changedPickedUp, false) 546 546 () -
code/trunk/src/libraries/core/Template.cc
r6746 r7163 99 99 } 100 100 101 const TiXmlElement& Template::getXMLElement() const101 const TiXmlElement& Template::getXMLElement() 102 102 { 103 103 if (this->bIsLink_) … … 106 106 if (temp) 107 107 { 108 this->bLoadDefaults_ = temp->bLoadDefaults_; 109 108 110 if (!temp->bIsReturningXMLElement_) 109 111 { -
code/trunk/src/libraries/core/Template.h
r6417 r7163 51 51 inline const std::string& getLink() const 52 52 { return this->link_; } 53 inline bool isLink() const 54 { return this->bIsLink_; } 53 55 54 56 inline void setLoadDefaults(bool bLoadDefaults) … … 58 60 59 61 void setXMLElement(const TiXmlElement& xmlelement); 60 const TiXmlElement& getXMLElement() const;62 const TiXmlElement& getXMLElement(); 61 63 62 64 void setBaseclass(const std::string& baseclass); -
code/trunk/src/libraries/core/XMLPort.cc
r5781 r7163 41 41 return ((!this->bApplyLoaderMask_) || identifier->isA(ClassIdentifier<Namespace>::getIdentifier()) || Loader::currentMask_s.isIncluded(identifier)); 42 42 } 43 44 XMLPortObjectContainer& XMLPortObjectContainer::port(BaseObject* object, Element& xmlelement, XMLPort::Mode mode) 45 { 46 if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject)) 47 { 48 try 49 { 50 Element* xmlsubelement; 51 if (!this->sectionname_.empty()) 52 xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 53 else 54 xmlsubelement = &xmlelement; 55 56 if (!xmlsubelement) 57 return (*this); 58 59 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 60 { 61 Identifier* identifier = Identifier::getIdentifierByString(child->Value()); 62 if (!identifier) 63 { 64 if (!this->sectionname_.empty()) 65 { 66 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 67 } 68 else 69 { 70 // It's probably just another subsection 71 } 72 continue; 73 } 74 if (!identifier->isA(objectIdentifier_)) 75 { 76 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a '" << objectIdentifier_->getName() << "'." << std::endl; 77 continue; 78 } 79 if (!identifier->isLoadable()) 80 { 81 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl; 82 continue; 83 } 84 if (!this->identifierIsIncludedInLoaderMask(identifier)) 85 continue; 86 87 try 88 { 89 COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl; 90 91 BaseObject* newObject = identifier->fabricate(object); 92 newObject->setLoaderIndentation(object->getLoaderIndentation() + " "); 93 94 if (this->bLoadBefore_) 95 { 96 newObject->XMLPort(*child, XMLPort::LoadObject); 97 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl; 98 } 99 else 100 { 101 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl; 102 } 103 104 COUT(5) << object->getLoaderIndentation(); 105 106 this->callLoadExecutor(object, newObject); 107 108 if (!this->bLoadBefore_) 109 newObject->XMLPort(*child, XMLPort::LoadObject); 110 111 COUT(5) << object->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 112 } 113 catch (AbortLoadingException& ex) 114 { 115 COUT(1) << "An error occurred while loading object, abort loading..." << std::endl; 116 throw ex; 117 } 118 catch (...) 119 { 120 COUT(1) << "An error occurred while loading object:" << std::endl; 121 COUT(1) << Exception::handleMessage() << std::endl; 122 } 123 } 124 } 125 catch (ticpp::Exception& ex) 126 { 127 COUT(1) << std::endl; 128 COUT(1) << "An error occurred in XMLPort.h while loading a '" << objectIdentifier_->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << object->getName() << ") in " << object->getFilename() << ':' << std::endl; 129 COUT(1) << ex.what() << std::endl; 130 } 131 } 132 else if (mode == XMLPort::SaveObject) 133 { 134 } 135 136 return (*this); 137 } 43 138 } -
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.