Changeset 1052
- Timestamp:
- Apr 14, 2008, 3:42:49 AM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 3 deleted
- 66 edited
- 16 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/bin/levels/sample.oxw
r1032 r1052 1 <Namespace name="test" /> 2 <Namespace name="blub" /> 3 <Namespace name="rofl" /> 4 5 <Namespace name="ns1"> 6 <Namespace name="ns11"> 7 <Namespace name="ns111"> 8 </Namespace> 9 <Namespace name="ns112"> 10 </Namespace> 11 </Namespace> 12 <Namespace name="ns12"> 13 <Namespace name="ns121"> 14 </Namespace> 15 <Namespace name="ns122"> 16 </Namespace> 17 </Namespace> 18 </Namespace> 19 20 <Namespace name="ns1::ns12::ns121"> 21 <Namespace name="ns1211"> 22 </Namespace> 23 </Namespace> 24 <Namespace name="ns1::ns12::ns122::ns1221" /> 25 1 26 <!-- 2 27 <audio> … … 40 65 <Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" /> 41 66 67 68 <Namespace name="test" /> 69 <Namespace name="blub"> 70 </Namespace> 71 <Namespace name="rofl"> 72 <Namespace name="lol"> 73 </Namespace> 74 </Namespace> 75 76 <Namespace name="ns1"> 77 <Namespace name="ns11"> 78 <Namespace name="ns111"> 79 <Namespace name="ns1111"> 80 </Namespace> 81 </Namespace> 82 </Namespace> 83 <Namespace name="ns13"> 84 </Namespace> 85 </Namespace> 86 87 <Namespace name="ns1 ns2"> 88 <Namespace name="abc" /> 89 </Namespace> 90 91 <Namespace name="ns1::ns11 ns1::ns12 ns1::ns12::ns121"> 92 <Namespace name="muhahaha" /> 93 </Namespace> 94 95 <Namespace name="test"> 96 <Namespace name="test" /> 97 </Namespace> 98 99 <Namespace name="ns1::ns13"> 100 <Namespace name="..::ns14" /> 101 <Namespace name="..::..::ns3" /> 102 </Namespace> 103 104 <Namespace name="AAA::BBB::..::CCC::..::DDD::..::BBB::BBBBBB::..::BBBBBBBBBBBBBBBBBBB::..::..::EEE" /> 105 106 <Namespace name="..::justatest" /> 107 108 <Namespace name="@file.oxw::anothertest" /> 109 110 <Namespace name="justonemoretest::@file.oxw::gagagaga" /> 111 112 <Namespace name="AAA::BBB, AAA::CCC; AAA::DDD,AAA::EEE"> 113 <Namespace name="hax" /> 114 </Namespace> 115 42 116 <?lua 43 117 for i = 1, 226, 1 -
code/trunk/src/CMakeLists.txt
r1024 r1052 4 4 ADD_SUBDIRECTORY(util) 5 5 ADD_SUBDIRECTORY(orxonox/core) 6 ADD_SUBDIRECTORY(audio)7 ADD_SUBDIRECTORY(network)6 #ADD_SUBDIRECTORY(audio) 7 #ADD_SUBDIRECTORY(network) 8 8 ADD_SUBDIRECTORY(orxonox) -
code/trunk/src/asylum/orxonox/objects/Fighter.cc
r1032 r1052 38 38 #include "util/String2Number.h" 39 39 #include "core/CoreIncludes.h" 40 #include "core/ConfigValueIncludes.h" 40 41 #include "GraphicsEngine.h" 41 42 #include "core/InputManager.h" -
code/trunk/src/asylum/orxonox/objects/Test.h
r1024 r1052 30 30 31 31 #include "core/BaseObject.h" 32 #include "core/CoreIncludes.h" 32 33 33 34 namespace orxonox -
code/trunk/src/asylum/orxonox/objects/test2.cc
r1024 r1052 30 30 #include "test3.h" 31 31 #include "core/CoreIncludes.h" 32 #include "core/Executor.h" 32 33 33 34 namespace orxonox … … 43 44 this->usefullClass3_ = Class(Test3); 44 45 45 timer1.setTimer(1, true, this, &Test2::timerFunction1);46 timer2.setTimer(5, true, this, &Test2::timerFunction2);47 timer3.setTimer(10, false, this, &Test2::timerFunction3);46 timer1.setTimer(1, true, this, createExecutor(createFunctor(&Test2::timerFunction1))); 47 timer2.setTimer(5, true, this, createExecutor(createFunctor(&Test2::timerFunction2))); 48 timer3.setTimer(10, false, this, createExecutor(createFunctor(&Test2::timerFunction3))); 48 49 } 49 50 -
code/trunk/src/asylum/orxonox/objects/test3.cc
r1024 r1052 30 30 #include "test3.h" 31 31 #include "core/CoreIncludes.h" 32 #include "core/ConfigValueIncludes.h" 32 33 33 34 namespace orxonox … … 56 57 SetConfigValue(value_vector3_, Vector3(13, 26, 39)); 57 58 SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887)); 59 SetConfigValueVector(vector_int_, std::vector<int>(1, 13)); 60 SetConfigValueVector(vector_string_, std::vector<std::string>(3, "nothing")); 61 SetConfigValueVector(vector_vector3_, std::vector<Vector3>(1, Vector3(3, 2, 1))); 58 62 } 59 63 … … 64 68 void Test3::configOutput() 65 69 { 66 std::cout << "int: " << this->value_int_ << std::endl; 67 std::cout << "uint: " << this->value_uint_ << std::endl; 68 std::cout << "char: " << (int)this->value_char_ << std::endl; 69 std::cout << "uchar: " << (int)this->value_uchar_ << std::endl; 70 std::cout << "float: " << this->value_float_ << std::endl; 71 std::cout << "double: " << this->value_double_ << std::endl; 72 std::cout << "bool: " << this->value_bool_ << std::endl; 73 std::cout << "string: " << this->value_string_ << std::endl; 74 std::cout << "constchar: " << this->value_constchar_ << std::endl; 75 std::cout << "vector2: " << this->value_vector2_ << std::endl; 76 std::cout << "vector3: " << this->value_vector3_ << std::endl; 77 std::cout << "colourvalue: " << this->value_colourvalue_ << std::endl; 70 std::cout << "int: " << this->value_int_ << std::endl; 71 std::cout << "uint: " << this->value_uint_ << std::endl; 72 std::cout << "char: " << (int)this->value_char_ << std::endl; 73 std::cout << "uchar: " << (int)this->value_uchar_ << std::endl; 74 std::cout << "float: " << this->value_float_ << std::endl; 75 std::cout << "double: " << this->value_double_ << std::endl; 76 std::cout << "bool: " << this->value_bool_ << std::endl; 77 std::cout << "string: >" << this->value_string_ << "<" << std::endl; 78 std::cout << "constchar: >" << this->value_constchar_ << "<" << std::endl; 79 std::cout << "vector2: " << this->value_vector2_ << std::endl; 80 std::cout << "vector3: " << this->value_vector3_ << std::endl; 81 std::cout << "colourvalue: " << this->value_colourvalue_ << std::endl; 82 std::cout << std::endl; 83 for (unsigned int i = 0; i < this->vector_int_.size(); i++) 84 std::cout << "vector<int>: " << i << ": " << this->vector_int_[i] << std::endl; 85 for (unsigned int i = 0; i < this->vector_string_.size(); i++) 86 std::cout << "vector<string>: " << i << ":>" << this->vector_string_[i] << "<" << std::endl; 87 for (unsigned int i = 0; i < this->vector_vector3_.size(); i++) 88 std::cout << "vector<vector3>: " << i << ": " << this->vector_vector3_[i] << std::endl; 89 90 ModifyConfigValue(value_int_, tset, "100"); 91 std::cout << std::endl; 92 std::cout << "int: " << this->value_int_ << std::endl; 93 94 ModifyConfigValue(value_int_, update); 95 std::cout << std::endl; 96 std::cout << "int: " << this->value_int_ << std::endl; 78 97 } 79 98 -
code/trunk/src/asylum/orxonox/objects/test3.h
r1024 r1052 1 1 #ifndef _Test3_H__ 2 2 #define _Test3_H__ 3 4 #include <vector> 3 5 4 6 #include "core/BaseObject.h" … … 36 38 Vector3 value_vector3_; 37 39 ColourValue value_colourvalue_; 40 41 std::vector<int> vector_int_; 42 std::vector<std::string> vector_string_; 43 std::vector<Vector3> vector_vector3_; 38 44 }; 39 45 } -
code/trunk/src/orxonox/GraphicsEngine.cc
r1042 r1052 42 42 43 43 #include "core/CoreIncludes.h" 44 #include "core/ConfigValueIncludes.h" 44 45 #include "core/Debug.h" 45 46 46 47 47 48 namespace orxonox { 48 49 using namespace Ogre;50 49 51 50 /** … … 96 95 this->renderWindow_ = 0; 97 96 // delete the ogre log and the logManager (since we have created it). 98 if ( LogManager::getSingletonPtr() != 0)99 { 100 LogManager::getSingleton().getDefaultLog()->removeListener(this);101 LogManager::getSingleton().destroyLog(LogManager::getSingleton().getDefaultLog());102 delete LogManager::getSingletonPtr();97 if (Ogre::LogManager::getSingletonPtr() != 0) 98 { 99 Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this); 100 Ogre::LogManager::getSingleton().destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 101 delete Ogre::LogManager::getSingletonPtr(); 103 102 } 104 103 COUT(4) << "*** GraphicsEngine: Destroying objects done" << std::endl; … … 121 120 //TODO: Check if file exists (maybe not here) 122 121 /*#ifndef OGRE_STATIC_LIB 123 root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg",122 root_ = new Ogre::Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg", 124 123 configPath_ + "Ogre.log"); 125 124 #else 126 root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");125 root_ = new Ogre::Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); 127 126 #endif*/ 128 127 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) … … 153 152 // Root will detect that we've already created a Log 154 153 COUT(4) << "*** GraphicsEngine: Creating Ogre Root..." << std::endl; 155 root_ = new Root(plugin_filename);154 root_ = new Ogre::Root(plugin_filename); 156 155 COUT(4) << "*** GraphicsEngine: Creating Ogre Root done" << std::endl; 157 156 } … … 160 159 * @return scene manager 161 160 */ 162 SceneManager* GraphicsEngine::getSceneManager()161 Ogre::SceneManager* GraphicsEngine::getSceneManager() 163 162 { 164 163 if(!scene_) 165 164 { 166 scene_ = root_->createSceneManager( ST_GENERIC, "Default SceneManager");165 scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 167 166 COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl; 168 167 } … … 184 183 { 185 184 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 186 TextureManager::getSingleton().setDefaultNumMipmaps(5);185 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 187 186 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 188 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();187 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 189 188 } 190 189 … … 194 193 //TODO: Work with ressource groups (should be generated by a special loader) 195 194 // Load resource paths from data file using configfile ressource type 196 ConfigFile cf;195 Ogre::ConfigFile cf; 197 196 cf.load(dataPath + "resources.cfg"); 198 197 199 198 // Go through all sections & settings in the file 200 ConfigFile::SectionIterator seci = cf.getSectionIterator();199 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 201 200 202 201 std::string secName, typeName, archName; … … 204 203 { 205 204 secName = seci.peekNextKey(); 206 ConfigFile::SettingsMultiMap *settings = seci.getNext();207 ConfigFile::SettingsMultiMap::iterator i;205 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 206 Ogre::ConfigFile::SettingsMultiMap::iterator i; 208 207 for (i = settings->begin(); i != settings->end(); ++i) 209 208 { … … 211 210 archName = i->second; // name (and location) of archive 212 211 213 ResourceGroupManager::getSingleton().addResourceLocation(212 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 214 213 std::string(dataPath + archName), 215 214 typeName, secName); … … 269 268 */ 270 269 void GraphicsEngine::messageLogged(const std::string& message, 271 LogMessageLevel lml, bool maskDebug, const std::string &logName)270 Ogre::LogMessageLevel lml, bool maskDebug, const std::string &logName) 272 271 { 273 272 int orxonoxLevel; 274 273 switch (lml) 275 274 { 276 case LML_TRIVIAL:275 case Ogre::LML_TRIVIAL: 277 276 orxonoxLevel = this->ogreLogLevelTrivial_; 278 277 break; 279 case LML_NORMAL:278 case Ogre::LML_NORMAL: 280 279 orxonoxLevel = this->ogreLogLevelNormal_; 281 280 break; 282 case LML_CRITICAL:281 case Ogre::LML_CRITICAL: 283 282 orxonoxLevel = this->ogreLogLevelCritical_; 284 283 break; -
code/trunk/src/orxonox/Orxonox.cc
r1039 r1052 55 55 56 56 // core 57 #include "core/ConsoleCommand.h" 57 58 #include "core/Debug.h" 58 59 #include "core/Factory.h" 59 60 #include "core/Loader.h" 60 61 #include "core/Tickable.h" 62 #include "core/InputBuffer.h" 61 63 #include "core/InputManager.h" 62 64 … … 80 82 namespace orxonox 81 83 { 84 ConsoleCommand(Orxonox, exit, AccessLevel::None, true); 85 ConsoleCommand(Orxonox, slomo, AccessLevel::Offline, true).setDefaultValue(0, 1.0); 86 ConsoleCommand(Orxonox, setTimeFactor, AccessLevel::Offline, false).setDefaultValue(0, 1.0); 87 88 class Testconsole : public InputBufferListener 89 { 90 public: 91 Testconsole(InputBuffer* ib) : ib_(ib) {} 92 void listen() const 93 { 94 std::cout << "> " << this->ib_->get() << std::endl; 95 } 96 void execute() const 97 { 98 std::cout << ">> " << this->ib_->get() << std::endl; 99 if (!CommandExecutor::execute(this->ib_->get())) 100 std::cout << "Error" << std::endl; 101 this->ib_->clear(); 102 } 103 void hintandcomplete() const 104 { 105 std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl; 106 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 107 } 108 void clear() const 109 { 110 this->ib_->clear(); 111 } 112 void removeLast() const 113 { 114 this->ib_->removeLast(); 115 } 116 117 private: 118 InputBuffer* ib_; 119 }; 120 82 121 /** 83 122 @brief Reference to the only instance of the class. … … 198 237 { 199 238 COUT(2) << "initialising server" << std::endl; 200 239 201 240 ogre_->setConfigPath(path); 202 241 ogre_->setup(); 203 242 //root_ = ogre_->getRoot(); 204 243 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 205 244 206 245 server_g = new network::Server(); 207 246 } … … 210 249 { 211 250 COUT(2) << "initialising client" << std::endl;\ 212 251 213 252 ogre_->setConfigPath(path); 214 253 ogre_->setup(); … … 219 258 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 220 259 } 221 260 222 261 void Orxonox::standaloneInit(std::string path) 223 262 { 224 263 COUT(2) << "initialising standalone mode" << std::endl; 225 264 226 265 ogre_->setConfigPath(path); 227 266 ogre_->setup(); … … 229 268 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 230 269 } 231 270 232 271 /** 233 272 * start modules … … 246 285 } 247 286 } 248 287 249 288 void Orxonox::clientStart(){ 250 289 ogre_->initialise(); 251 290 Factory::createClassHierarchy(); 252 253 291 292 254 293 auMan_ = new audio::AudioManager(); 255 294 256 295 //bulletMgr_ = new BulletManager(); 257 296 258 297 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 259 298 HUD* orxonoxHud; … … 262 301 orxonoxHud->setEnergyDistr(20,20,60); 263 302 hudOverlay->show(); 264 303 265 304 client_g->establishConnection(); 266 305 client_g->tick(0); 267 268 306 307 269 308 //setupInputSystem(); 270 309 271 310 startRenderLoop(); 272 311 } 273 312 274 313 void Orxonox::serverStart(){ 275 314 //TODO: start modules … … 279 318 createScene(); 280 319 setupInputSystem(); 281 320 282 321 server_g->open(); 283 322 284 323 startRenderLoop(); 285 324 } 286 325 287 326 void Orxonox::standaloneStart(){ 288 327 //TODO: start modules … … 292 331 createScene(); 293 332 setupInputSystem(); 294 333 295 334 startRenderLoop(); 296 335 } … … 351 390 void Orxonox::startRenderLoop() 352 391 { 392 InputBuffer* ib = new InputBuffer(); 393 Testconsole* console = new Testconsole(ib); 394 ib->registerListener(console, &Testconsole::listen, true); 395 ib->registerListener(console, &Testconsole::execute, '\r', false); 396 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true); 397 ib->registerListener(console, &Testconsole::clear, '§', true); 398 ib->registerListener(console, &Testconsole::removeLast, '\b', true); 399 353 400 // first check whether ogre root object has been created 354 401 if (Ogre::Root::getSingletonPtr() == 0) … … 395 442 // Iterate through all Tickables and call their tick(dt) function 396 443 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) 397 (it++)->tick((float)evt.timeSinceLastFrame );444 (it++)->tick((float)evt.timeSinceLastFrame * this->timefactor_); 398 445 399 446 // don't forget to call _fireFrameStarted in ogre to make sure -
code/trunk/src/orxonox/Orxonox.h
r1039 r1052 41 41 static void destroySingleton(); 42 42 43 static inline void slomo(float factor) { Orxonox::getSingleton()->timefactor_ = factor; } 44 static inline void setTimeFactor(float factor = 1.0) { Orxonox::getSingleton()->timefactor_ = factor; } 45 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 46 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } 47 43 48 private: 44 49 // don't mess with singletons … … 75 80 HUD* orxonoxHUD_; 76 81 bool bAbort_; //!< aborts the render loop if true 82 float timefactor_; //!< A factor to change the gamespeed 77 83 78 84 // this is used to identify the mode (server/client/...) we're in -
code/trunk/src/orxonox/OrxonoxStableHeaders.h
r1032 r1052 97 97 98 98 #include "util/Math.h" 99 #include "util/Convert.h"100 99 #include "util/Sleep.h" 101 100 #include "util/String2Number.h" -
code/trunk/src/orxonox/core/BaseObject.cc
r1021 r1052 52 52 this->bVisible_ = true; 53 53 this->level_ = 0; 54 this->namespace_ = 0; 54 55 } 55 56 … … 78 79 @return The XML-element 79 80 */ 80 void BaseObject::XMLPort(Element& xmlelement, bool loading)81 void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode) 81 82 { 82 XMLPortParam(BaseObject, "name", setName, getName, xmlelement, loading);83 XMLPortParam(BaseObject, "name", setName, getName, xmlelement, mode); 83 84 } 84 85 -
code/trunk/src/orxonox/core/BaseObject.h
r871 r1052 50 50 virtual ~BaseObject(); 51 51 virtual void loadParams(TiXmlElement* xmlElem); 52 virtual void XMLPort(Element& xmlelement, bool loading);52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 53 53 54 54 /** @brief Sets the name of the object. @param name The name */ … … 79 79 const std::string& getLevelfile() const; 80 80 81 virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; } 82 inline Namespace* getNamespace() const { return this->namespace_; } 83 81 84 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ 82 85 inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } … … 90 93 const Level* level_; //!< The level that loaded this object 91 94 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 95 Namespace* namespace_; 92 96 }; 93 97 } -
code/trunk/src/orxonox/core/CMakeLists.txt
r1048 r1052 9 9 InputEventListener.cc 10 10 MetaObjectList.cc 11 ConfigFileManager.cc 11 12 ConfigValueContainer.cc 12 13 Error.cc 13 14 SignalHandler.cc 14 DebugLevel.cc15 CoreSettings.cc 15 16 OutputHandler.cc 16 17 Language.cc … … 19 20 Executor.cc 20 21 XMLPort.cc 22 Namespace.cc 23 NamespaceNode.cc 24 CommandExecutor.cc 25 InputBuffer.cc 21 26 Tickable.cc 22 27 Script.cc -
code/trunk/src/orxonox/core/ClassTreeMask.cc
r1021 r1052 327 327 { 328 328 // No it's not: Search for classes inheriting from the given class and add the rules for them 329 for (std:: list<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it)329 for (std::set<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it) 330 330 if ((*it)->isA(this->root_->getClass())) 331 331 if (overwrite || (!this->nodeExists(*it))) // If we don't want to overwrite, only add nodes that don't already exist … … 422 422 void ClassTreeMask::addSingle(const Identifier* subclass, bool bInclude, bool clean) 423 423 { 424 for (std:: list<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it)424 for (std::set<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it) 425 425 this->add(*it, this->isIncluded(*it), false, false); 426 426 … … 561 561 562 562 /** 563 @brief Compares the mask with another mask and returns true if they represent the same logic. 564 @param other The other mask 565 @return True if both masks represent the same logic 566 */ 567 bool ClassTreeMask::operator==(const ClassTreeMask& other) const 568 { 569 ClassTreeMask temp1 = other; 570 ClassTreeMask temp2 = (*this); 571 572 temp1.clean(); 573 temp2.clean(); 574 575 ClassTreeMaskIterator it1 = temp1.root_; 576 ClassTreeMaskIterator it2 = temp2.root_; 577 578 for ( ; it1 && it2; ++it1, ++it2) 579 if (it1->getClass() != it2->getClass()) 580 return false; 581 582 return true; 583 } 584 585 /** 586 @brief Compares the mask with another mask and returns true if they represent different logics. 587 @param other The other mask 588 @return True if the masks represent different logics 589 */ 590 bool ClassTreeMask::operator!=(const ClassTreeMask& other) const 591 { 592 return (!((*this) == other)); 593 } 594 595 /** 563 596 @brief Prefix operator + does nothing. 564 597 @return A reference to the mask itself -
code/trunk/src/orxonox/core/ClassTreeMask.h
r871 r1052 179 179 ClassTreeMask& operator=(const ClassTreeMask& other); 180 180 181 bool operator==(const ClassTreeMask& other) const; 182 bool operator!=(const ClassTreeMask& other) const; 183 181 184 ClassTreeMask& operator+(); 182 185 ClassTreeMask operator-() const; -
code/trunk/src/orxonox/core/ConfigValueContainer.cc
r871 r1052 34 34 35 35 #include "ConfigValueContainer.h" 36 #include "util/Tokenizer.h" 36 #include "Language.h" 37 #include "Identifier.h" 38 #include "util/SubString.h" 37 39 #include "util/Convert.h" 38 #include "Language.h" 39 40 #define CONFIGFILEPATH "orxonox.ini" 40 41 #define MAX_VECTOR_INDEX 255 // to avoid up to 4*10^9 vector entries in the config file after accidentally using a wrong argument 42 41 43 42 44 namespace orxonox … … 44 46 /** 45 47 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 46 @param value This is only needed to determine the right type.47 @param classname The nameof the class the variable belongs to48 @param type The type of the corresponding config-file 49 @param identifier The identifier of the class the variable belongs to 48 50 @param varname The name of the variable 49 51 @param defvalue The default-value 50 52 */ 51 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue) 52 { 53 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue) 54 { 55 this->type_ = type; 56 this->identifier_ = identifier; 57 this->sectionname_ = identifier->getName(); 58 this->varname_ = varname; 59 60 this->value_ = defvalue; 53 61 this->bAddedDescription_ = false; 54 this->classname_ = classname; 62 this->bIsVector_ = false; 63 64 this->defvalueString_ = defvalue.toString(); 65 this->update(); 66 } 67 68 /** 69 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 70 @param type The type of the corresponding config-file 71 @param identifier The identifier of the class the variable belongs to 72 @param varname The name of the variable 73 @param defvalue The default-value 74 */ 75 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue) 76 { 77 this->type_ = type; 78 this->identifier_ = identifier; 79 this->sectionname_ = identifier->getName(); 55 80 this->varname_ = varname; 56 81 57 this->valueToString(&this->defvalueString_, defvalue); // Try to convert the default-value to a string 58 this->searchConfigFileLine(); // Search the entry in the config-file 59 60 std::string valueString = this->parseValueString(!(defvalue.isA(MT_string) || defvalue.isA(MT_constchar))); // Parses the value string from the config-file-entry 61 if (!this->parseString(valueString, defvalue)) // Try to convert the string to a value 62 this->resetConfigFileEntry(); // The conversion failed 63 } 64 65 /** 66 @brief Converts a value to a string. 67 @param output The string to write to 68 @param input The value to convert 69 @return True if the converson was successful 70 */ 71 bool ConfigValueContainer::valueToString(std::string* output, MultiTypeMath& input) 72 { 73 if (input.getType() == MT_int) 74 return ConvertValue(output, input.getInt(), std::string("0")); 75 else if (input.getType() == MT_uint) 76 return ConvertValue(output, input.getUnsignedInt(), std::string("0")); 77 else if (input.getType() == MT_char) 78 return ConvertValue(output, (int)input.getChar(), std::string("0")); 79 else if (input.getType() == MT_uchar) 80 return ConvertValue(output, (unsigned int)input.getUnsignedChar(), std::string("0")); 81 else if (input.getType() == MT_short) 82 return ConvertValue(output, input.getShort(), std::string("0")); 83 else if (input.getType() == MT_ushort) 84 return ConvertValue(output, input.getUnsignedShort(), std::string("0")); 85 else if (input.getType() == MT_long) 86 return ConvertValue(output, input.getLong(), std::string("0")); 87 else if (input.getType() == MT_ulong) 88 return ConvertValue(output, input.getUnsignedLong(), std::string("0")); 89 else if (input.getType() == MT_float) 90 return ConvertValue(output, input.getFloat(), std::string("0.000000")); 91 else if (input.getType() == MT_double) 92 return ConvertValue(output, input.getDouble(), std::string("0.000000")); 93 else if (input.getType() == MT_longdouble) 94 return ConvertValue(output, input.getChar(), std::string("0.000000")); 95 else if (input.getType() == MT_bool) 96 { 97 if (input.getBool()) 98 (*output) = "true"; 82 this->valueVector_ = defvalue; 83 this->bAddedDescription_ = false; 84 this->bIsVector_ = true; 85 86 if (defvalue.size() > 0) 87 this->value_ = defvalue[0]; 88 89 for (unsigned int i = 0; i < defvalue.size(); i++) 90 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 91 92 for (unsigned int i = 0; i < defvalue.size(); i++) 93 this->defvalueStringVector_.push_back(defvalue[i].toString()); 94 95 this->update(); 96 } 97 98 /** 99 @brief Adds a new entry to the end of the vector. 100 @param input The new entry 101 @return True if the new entry was successfully added 102 */ 103 bool ConfigValueContainer::add(const std::string& input) 104 { 105 if (this->bIsVector_) 106 return this->set(this->valueVector_.size(), input); 107 108 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 109 return false; 110 } 111 112 /** 113 @brief Removes an existing entry from the vector. 114 @param index The index of the entry 115 @return True if the entry was removed 116 */ 117 bool ConfigValueContainer::remove(unsigned int index) 118 { 119 if (this->bIsVector_) 120 { 121 if (index < this->valueVector_.size()) 122 { 123 this->valueVector_.erase(this->valueVector_.begin() + index); 124 for (unsigned int i = index; i < this->valueVector_.size(); i++) 125 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string)); 126 ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size()); 127 128 return true; 129 } 130 COUT(1) << "Error: Invalid vector-index." << std::endl; 131 } 132 133 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 134 return false; 135 } 136 137 /** 138 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 139 @param input The new value 140 @return True if the new value was successfully assigned 141 */ 142 bool ConfigValueContainer::set(const std::string& input) 143 { 144 if (this->bIsVector_) 145 { 146 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 147 int index = -1; 148 bool success = false; 149 150 if (token.size() > 0) 151 success = ConvertValue(&index, token[0]); 152 153 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 154 { 155 if (!success) 156 { 157 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 158 } 159 else 160 { 161 COUT(1) << "Error: Invalid vector-index." << std::endl; 162 } 163 return false; 164 } 165 166 if (token.size() >= 2) 167 return this->set(index, token.subSet(1).join()); 99 168 else 100 (*output) = "false"; 101 102 return true; 103 } 104 else if (input.getType() == MT_constchar) 105 { 106 (*output) = "\"" + input.getString() + "\""; 107 return true; 108 } 109 else if (input.getType() == MT_string) 110 { 111 (*output) = "\"" + input.getString() + "\""; 112 return true; 113 } 114 else if (input.getType() == MT_vector2) 115 { 116 std::ostringstream ostream; 117 if (ostream << "(" << input.getVector2().x << "," << input.getVector2().y << ")") 118 { 119 (*output) = ostream.str(); 120 return true; 121 } 122 else 123 { 124 (*output) = "(0,0)"; 125 return false; 126 } 127 } 128 else if (input.getType() == MT_vector3) 129 { 130 std::ostringstream ostream; 131 if (ostream << "(" << input.getVector3().x << "," << input.getVector3().y << "," << input.getVector3().z << ")") 132 { 133 (*output) = ostream.str(); 134 return true; 135 } 136 else 137 { 138 (*output) = "(0,0,0)"; 139 return false; 140 } 141 } 142 else if (input.getType() == MT_colourvalue) 143 { 144 std::ostringstream ostream; 145 if (ostream << "(" << input.getColourValue().r << "," << input.getColourValue().g << "," << input.getColourValue().b << "," << input.getColourValue().a << ")") 146 { 147 (*output) = ostream.str(); 148 return true; 149 } 150 else 151 { 152 (*output) = "(0,0,0,0)"; 153 return false; 154 } 155 } 156 else if (input.getType() == MT_quaternion) 157 { 158 std::ostringstream ostream; 159 if (ostream << "(" << input.getQuaternion().w << "," << input.getQuaternion().x << "," << input.getQuaternion().y << "," << input.getQuaternion().z << ")") 160 { 161 (*output) = ostream.str(); 162 return true; 163 } 164 else 165 { 166 (*output) = "(0,0,0,0)"; 167 return false; 168 } 169 } 170 else if (input.getType() == MT_radian) 171 return ConvertValue(output, input.getRadian(), std::string("0.000000")); 172 else if (input.getType() == MT_degree) 173 return ConvertValue(output, input.getDegree(), std::string("0.000000")); 174 175 return false; 169 return this->set(index, ""); 170 } 171 172 bool success = this->tset(input); 173 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isA(MT_string)); 174 return success; 175 } 176 177 /** 178 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 179 @param index The index in the vector 180 @param input The new value 181 @return True if the new value was successfully assigned 182 */ 183 bool ConfigValueContainer::set(unsigned int index, const std::string& input) 184 { 185 if (this->bIsVector_) 186 { 187 bool success = this->tset(index, input); 188 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isA(MT_string)); 189 return success; 190 } 191 192 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 193 return false; 194 } 195 196 /** 197 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 198 @param input The new value 199 @return True if the new value was successfully assigned 200 */ 201 bool ConfigValueContainer::tset(const std::string& input) 202 { 203 bool success = this->parse(input); 204 if (this->identifier_) 205 this->identifier_->updateConfigValues(); 206 return success; 207 } 208 209 /** 210 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 211 @param index The index in the vector 212 @param input The new value 213 @return True if the new value was successfully assigned 214 */ 215 bool ConfigValueContainer::tset(unsigned int index, const std::string& input) 216 { 217 if (this->bIsVector_) 218 { 219 bool success = this->parse(index, input); 220 if (this->identifier_) 221 this->identifier_->updateConfigValues(); 222 return success; 223 } 224 225 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 226 return false; 227 } 228 229 /** 230 @brief Sets the value of the variable back to the default value and resets the config-file entry. 231 */ 232 bool ConfigValueContainer::reset() 233 { 234 if (!this->bIsVector_) 235 return this->set(this->defvalueString_); 236 else 237 { 238 bool success = true; 239 for (unsigned int i = 0; i < this->defvalueStringVector_.size(); i++) 240 if (!this->set(i, this->defvalueStringVector_[i])) 241 success = false; 242 ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size()); 243 return success; 244 } 245 } 246 247 /** 248 @brief Retrieves the configured value from the currently loaded config-file. 249 */ 250 void ConfigValueContainer::update() 251 { 252 if (!this->bIsVector_) 253 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isA(MT_string))); 254 else 255 { 256 this->valueVector_.clear(); 257 for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 258 { 259 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 260 this->valueVector_.push_back(this->value_); 261 } 262 } 176 263 } 177 264 … … 181 268 @return True if the string was successfully parsed 182 269 */ 183 bool ConfigValueContainer::parseString(const std::string& input, MultiTypeMath& defvalue) 184 { 185 if (defvalue.getType() == MT_int) 186 return this->parseString(input, defvalue.getInt()); 187 else if (defvalue.getType() == MT_uint) 188 return this->parseString(input, defvalue.getUnsignedInt()); 189 else if (defvalue.getType() == MT_char) 190 return this->parseString(input, defvalue.getChar()); 191 else if (defvalue.getType() == MT_uchar) 192 return this->parseString(input, defvalue.getUnsignedChar()); 193 else if (defvalue.getType() == MT_short) 194 return this->parseString(input, defvalue.getShort()); 195 else if (defvalue.getType() == MT_ushort) 196 return this->parseString(input, defvalue.getUnsignedShort()); 197 else if (defvalue.getType() == MT_long) 198 return this->parseString(input, defvalue.getLong()); 199 else if (defvalue.getType() == MT_ulong) 200 return this->parseString(input, defvalue.getUnsignedLong()); 201 else if (defvalue.getType() == MT_float) 202 return this->parseString(input, defvalue.getFloat()); 203 else if (defvalue.getType() == MT_double) 204 return this->parseString(input, defvalue.getDouble()); 205 else if (defvalue.getType() == MT_longdouble) 206 return this->parseString(input, defvalue.getLongDouble()); 207 else if (defvalue.getType() == MT_bool) 208 return this->parseString(input, defvalue.getBool()); 209 else if (defvalue.getType() == MT_constchar) 210 return this->parseString(input, defvalue.getString()); 211 else if (defvalue.getType() == MT_string) 212 return this->parseString(input, defvalue.getString()); 213 else if (defvalue.getType() == MT_vector2) 214 return this->parseString(input, defvalue.getVector2()); 215 else if (defvalue.getType() == MT_vector3) 216 return this->parseString(input, defvalue.getVector3()); 217 else if (defvalue.getType() == MT_colourvalue) 218 return this->parseString(input, defvalue.getColourValue()); 219 else if (defvalue.getType() == MT_quaternion) 220 return this->parseString(input, defvalue.getQuaternion()); 221 else if (defvalue.getType() == MT_radian) 222 return this->parseString(input, defvalue.getRadian()); 223 else if (defvalue.getType() == MT_degree) 224 return this->parseString(input, defvalue.getDegree()); 225 226 return false; 227 } 228 229 /** 230 @brief Parses a given std::string into a value of the type int and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 231 @param input The string to convert 232 @param defvalue The default-value 233 @return True if the string was successfully parsed 234 */ 235 bool ConfigValueContainer::parseString(const std::string& input, int defvalue) 236 { 237 int temp; 238 bool success = ConvertValue(&temp, input, defvalue); 239 this->value_.setValue(temp); 240 return success; 241 } 242 243 /** 244 @brief Parses a given std::string into a value of the type unsigned int and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 245 @param input The string to convert 246 @param defvalue The default-value 247 @return True if the string was successfully parsed 248 */ 249 bool ConfigValueContainer::parseString(const std::string& input, unsigned int defvalue) 250 { 251 unsigned int temp; 252 bool success = ConvertValue(&temp, input, defvalue); 253 this->value_.setValue(temp); 254 return success; 255 } 256 257 /** 258 @brief Parses a given std::string into a value of the type char and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 259 @param input The string to convert 260 @param defvalue The default-value 261 @return True if the string was successfully parsed 262 */ 263 bool ConfigValueContainer::parseString(const std::string& input, char defvalue) 264 { 265 // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file 266 int temp; 267 bool success = ConvertValue(&temp, input, (int)defvalue); 268 this->value_.setValue((char)temp); 269 return success; 270 } 271 272 /** 273 @brief Parses a given std::string into a value of the type unsigned char and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 274 @param input The string to convert 275 @param defvalue The default-value 276 @return True if the string was successfully parsed 277 */ 278 bool ConfigValueContainer::parseString(const std::string& input, unsigned char defvalue) 279 { 280 // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file 281 unsigned int temp; 282 bool success = ConvertValue(&temp, input, (unsigned int)defvalue); 283 this->value_.setValue((unsigned char)temp); 284 return success; 285 } 286 287 /** 288 @brief Parses a given std::string into a value of the type short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 289 @param input The string to convert 290 @param defvalue The default-value 291 @return True if the string was successfully parsed 292 */ 293 bool ConfigValueContainer::parseString(const std::string& input, short defvalue) 294 { 295 short temp; 296 bool success = ConvertValue(&temp, input, defvalue); 297 this->value_.setValue(temp); 298 return success; 299 } 300 301 /** 302 @brief Parses a given std::string into a value of the type unsigned short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 303 @param input The string to convert 304 @param defvalue The default-value 305 @return True if the string was successfully parsed 306 */ 307 bool ConfigValueContainer::parseString(const std::string& input, unsigned short defvalue) 308 { 309 unsigned short temp; 310 bool success = ConvertValue(&temp, input, defvalue); 311 this->value_.setValue(temp); 312 return success; 313 } 314 315 /** 316 @brief Parses a given std::string into a value of the type long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 317 @param input The string to convert 318 @param defvalue The default-value 319 @return True if the string was successfully parsed 320 */ 321 bool ConfigValueContainer::parseString(const std::string& input, long defvalue) 322 { 323 long temp; 324 bool success = ConvertValue(&temp, input, defvalue); 325 this->value_.setValue(temp); 326 return success; 327 } 328 329 /** 330 @brief Parses a given std::string into a value of the type unsigned long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 331 @param input The string to convert 332 @param defvalue The default-value 333 @return True if the string was successfully parsed 334 */ 335 bool ConfigValueContainer::parseString(const std::string& input, unsigned long defvalue) 336 { 337 unsigned long temp; 338 bool success = ConvertValue(&temp, input, defvalue); 339 this->value_.setValue(temp); 340 return success; 341 } 342 343 /** 344 @brief Parses a given std::string into a value of the type float and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 345 @param input The string to convert 346 @param defvalue The default-value 347 @return True if the string was successfully parsed 348 */ 349 bool ConfigValueContainer::parseString(const std::string& input, float defvalue) 350 { 351 float temp; 352 bool success = ConvertValue(&temp, input, defvalue); 353 this->value_.setValue(temp); 354 return success; 355 } 356 357 /** 358 @brief Parses a given std::string into a value of the type double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 359 @param input The string to convert 360 @param defvalue The default-value 361 @return True if the string was successfully parsed 362 */ 363 bool ConfigValueContainer::parseString(const std::string& input, double defvalue) 364 { 365 double temp; 366 bool success = ConvertValue(&temp, input, defvalue); 367 this->value_.setValue(temp); 368 return success; 369 } 370 371 /** 372 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 373 @param input The string to convert 374 @param defvalue The default-value 375 @return True if the string was successfully parsed 376 */ 377 bool ConfigValueContainer::parseString(const std::string& input, long double defvalue) 378 { 379 long double temp; 380 bool success = ConvertValue(&temp, input, defvalue); 381 this->value_.setValue(temp); 382 return success; 383 } 384 385 /** 386 @brief Parses a given std::string into a value of the type bool and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 387 @param input The string to convert 388 @param defvalue The default-value 389 @return True if the string was successfully parsed 390 */ 391 bool ConfigValueContainer::parseString(const std::string& input, bool defvalue) 392 { 393 // Try to parse the value-string - is it a word? 394 if (input.find("true") < input.size() 395 || input.find("True") < input.size() 396 || input.find("yes") < input.size() 397 || input.find("Yes") < input.size()) 398 this->value_.setValue(true); 399 else if (input.find("false") < input.size() 400 || input.find("False") < input.size() 401 || input.find("no") < input.size() 402 || input.find("No") < input.size()) 403 this->value_.setValue(false); 404 else 405 { 406 // Its not a known word - is it a number? 407 bool temp; 408 bool success = ConvertValue(&temp, input, defvalue); 409 this->value_.setValue(temp); 410 return success; 411 } 412 413 return true; 414 } 415 416 /** 417 @brief Parses a given std::string into a value of the type std::string and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 418 @param input The string to convert 419 @param defvalue The default-value 420 @return True if the string was successfully parsed 421 */ 422 bool ConfigValueContainer::parseString(const std::string& input, const std::string& defvalue) 423 { 424 // Strip the quotes 425 unsigned int pos1 = input.find("\"") + 1; 426 unsigned int pos2 = input.find("\"", pos1); 427 428 // Check if the entry was correctly quoted 429 if (pos1 < input.length() && pos2 < input.length() && !(input.find("\"", pos2 + 1) < input.length())) 430 { 431 // It was - get the string between the quotes 432 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 433 return true; 434 } 435 436 // It wasn't - use the default-value and restore the entry in the config-file. 437 this->value_.setValue(defvalue); 438 return false; 439 } 440 441 /** 442 @brief Parses a given std::string into a value of the type const char* and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 443 @param input The string to convert 444 @param defvalue The default-value 445 @return True if the string was successfully parsed 446 */ 447 bool ConfigValueContainer::parseString(const std::string& input, const char* defvalue) 448 { 449 // Strip the quotes 450 unsigned int pos1 = input.find("\"") + 1; 451 unsigned int pos2 = input.find("\"", pos1); 452 453 // Check if the entry was correctly quoted 454 if (pos1 < input.length() && pos2 < input.length() && !(input.find("\"", pos2 + 1) < input.length())) 455 { 456 // It was - get the string between the quotes 457 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 458 return true; 459 } 460 461 // It wasn't - use the default-value and restore the entry in the config-file. 462 this->value_.setValue(defvalue); 463 return false; 464 } 465 466 /** 467 @brief Parses a given std::string into a value of the type _Vector2 and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 468 @param input The string to convert 469 @param defvalue The default-value 470 @return True if the string was successfully parsed 471 */ 472 bool ConfigValueContainer::parseString(const std::string& input, const Vector2& defvalue) 473 { 474 // Strip the value-string 475 unsigned int pos1 = input.find("(") + 1; 476 unsigned int pos2 = input.find(")", pos1); 477 478 // Try to convert the stripped value-string to Vector2 479 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 480 { 481 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 482 if (!ConvertValue(&this->value_.getVector2().x, tokens[0])) 483 { 484 this->value_.setValue(defvalue); 485 return false; 486 } 487 if (!ConvertValue(&this->value_.getVector2().y, tokens[1])) 488 { 489 this->value_.setValue(defvalue); 490 return false; 491 } 492 493 return true; 494 } 495 496 this->value_.setValue(defvalue); 497 return false; 498 } 499 500 /** 501 @brief Parses a given std::string into a value of the type Vector3 and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 502 @param input The string to convert 503 @param defvalue The default-value 504 @return True if the string was successfully parsed 505 */ 506 bool ConfigValueContainer::parseString(const std::string& input, const Vector3& defvalue) 507 { 508 // Strip the value-string 509 unsigned int pos1 = input.find("(") + 1; 510 unsigned int pos2 = input.find(")", pos1); 511 512 // Try to convert the stripped value-string to Vector3 513 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 514 { 515 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 516 if (!ConvertValue(&this->value_.getVector3().x, tokens[0])) 517 { 518 this->value_.setValue(defvalue); 519 return false; 520 } 521 if (!ConvertValue(&this->value_.getVector3().y, tokens[1])) 522 { 523 this->value_.setValue(defvalue); 524 return false; 525 } 526 if (!ConvertValue(&this->value_.getVector3().z, tokens[2])) 527 { 528 this->value_.setValue(defvalue); 529 return false; 530 } 531 532 return true; 533 } 534 535 this->value_.setValue(defvalue); 536 return false; 537 } 538 539 /** 540 @brief Parses a given std::string into a value of the type ColourValue and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 541 @param input The string to convert 542 @param defvalue The default-value 543 @return True if the string was successfully parsed 544 */ 545 bool ConfigValueContainer::parseString(const std::string& input, const ColourValue& defvalue) 546 { 547 // Strip the value-string 548 unsigned int pos1 = input.find("(") + 1; 549 unsigned int pos2 = input.find(")", pos1); 550 551 // Try to convert the stripped value-string to Vector3 552 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 553 { 554 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 555 if (!ConvertValue(&this->value_.getColourValue().r, tokens[0])) 556 { 557 this->value_.setValue(defvalue); 558 return false; 559 } 560 if (!ConvertValue(&this->value_.getColourValue().g, tokens[1])) 561 { 562 this->value_.setValue(defvalue); 563 return false; 564 } 565 if (!ConvertValue(&this->value_.getColourValue().b, tokens[2])) 566 { 567 this->value_.setValue(defvalue); 568 return false; 569 } 570 if (!ConvertValue(&this->value_.getColourValue().a, tokens[3])) 571 { 572 this->value_.setValue(defvalue); 573 return false; 574 } 575 576 return true; 577 } 578 579 this->value_.setValue(defvalue); 580 return false; 581 } 582 583 /** 584 @brief Parses a given std::string into a value of the type Quaternion and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 585 @param input The string to convert 586 @param defvalue The default-value 587 @return True if the string was successfully parsed 588 */ 589 bool ConfigValueContainer::parseString(const std::string& input, const Quaternion& defvalue) 590 { 591 // Strip the value-string 592 unsigned int pos1 = input.find("(") + 1; 593 unsigned int pos2 = input.find(")", pos1); 594 595 // Try to convert the stripped value-string to Vector3 596 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 597 { 598 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 599 if (!ConvertValue(&this->value_.getQuaternion().w, tokens[0])) 600 { 601 this->value_.setValue(defvalue); 602 return false; 603 } 604 if (!ConvertValue(&this->value_.getQuaternion().x, tokens[1])) 605 { 606 this->value_.setValue(defvalue); 607 return false; 608 } 609 if (!ConvertValue(&this->value_.getQuaternion().y, tokens[2])) 610 { 611 this->value_.setValue(defvalue); 612 return false; 613 } 614 if (!ConvertValue(&this->value_.getQuaternion().z, tokens[3])) 615 { 616 this->value_.setValue(defvalue); 617 return false; 618 } 619 620 return true; 621 } 622 623 this->value_.setValue(defvalue); 624 return false; 625 } 626 627 /** 628 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 629 @param input The string to convert 630 @param defvalue The default-value 631 @return True if the string was successfully parsed 632 */ 633 bool ConfigValueContainer::parseString(const std::string& input, const Radian& defvalue) 634 { 635 return ConvertValue(&this->value_.getRadian(), input, defvalue); 636 } 637 638 /** 639 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 640 @param input The string to convert 641 @param defvalue The default-value 642 @return True if the string was successfully parsed 643 */ 644 bool ConfigValueContainer::parseString(const std::string& input, const Degree& defvalue) 645 { 646 return ConvertValue(&this->value_.getDegree(), input, defvalue); 647 } 648 649 /** 650 @brief Sets the corresponding entry in the config-file back to the default value. 651 */ 652 void ConfigValueContainer::resetConfigFileEntry() 653 { 654 (*this->configFileLine_) = this->varname_ + "=" + this->defvalueString_; 655 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 656 } 657 658 /** 659 @brief Sets the value of the variable back to the default value and resets the config-file entry. 660 */ 661 void ConfigValueContainer::resetConfigValue() 662 { 663 this->parseString(this->defvalueString_, this->value_); 664 this->resetConfigFileEntry(); 665 } 666 667 /** 668 @brief Searches the corresponding entry in the config-file and creates it, if there is no entry. 669 */ 670 void ConfigValueContainer::searchConfigFileLine() 671 { 672 // Read the file if needed 673 if (!ConfigValueContainer::finishedReadingConfigFile()) 674 ConfigValueContainer::readConfigFile(CONFIGFILEPATH); 675 676 // The string of the section we're searching 677 std::string section = ""; 678 section.append("["); 679 section.append(this->classname_); 680 section.append("]"); 681 682 // Iterate through all config-file-lines 683 bool success = false; 684 std::list<std::string>::iterator it1; 685 for(it1 = ConfigValueContainer::getConfigFileLines().begin(); it1 != ConfigValueContainer::getConfigFileLines().end(); ++it1) 686 { 687 // Don't try to parse comments 688 if (this->isComment(*it1)) 689 continue; 690 691 if ((*it1).find(section) < (*it1).length()) 692 { 693 // We found the right section 694 bool bLineIsEmpty = false; 695 std::list<std::string>::iterator positionToPutNewLineAt; 696 697 // Iterate through all lines in the section 698 std::list<std::string>::iterator it2; 699 for(it2 = ++it1; it2 != ConfigValueContainer::getConfigFileLines().end(); ++it2) 700 { 701 // Don't try to parse comments 702 if (this->isComment(*it2)) 703 continue; 704 705 // This if-else block is used to write a new line right after the last line of the 706 // section but in front of the following empty lines before the next section. 707 // (So this helps to keep a nice formatting with empty-lines between sections in the config-file) 708 if (this->isEmpty(*it2)) 709 { 710 if (!bLineIsEmpty) 711 { 712 bLineIsEmpty = true; 713 positionToPutNewLineAt = it2; 714 } 715 } 716 else 717 { 718 if (!bLineIsEmpty) 719 positionToPutNewLineAt = it2; 720 721 bLineIsEmpty = false; 722 } 723 724 // Look out for the beginning of the next section 725 unsigned int open = (*it2).find("["); 726 unsigned int close = (*it2).find("]"); 727 if ((open < (*it2).length()) && (close < (*it2).length()) && (open < close)) 728 { 729 // The next section startet, so our line isn't yet in the file - now we add it and safe the file 730 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 731 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 732 success = true; 733 break; 734 } 735 736 // Look out for the variable-name 737 if ((*it2).find(this->varname_) < (*it2).length()) 738 { 739 // We found the right line - safe it and return 740 this->configFileLine_ = it2; 741 success = true; 742 break; 743 } 744 } 745 746 // Check if we succeeded 270 bool ConfigValueContainer::parse(const std::string& input) 271 { 272 if (this->bIsVector_) 273 { 274 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 275 int index = -1; 276 bool success = false; 277 278 if (token.size() > 0) 279 success = ConvertValue(&index, token[0]); 280 281 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 282 { 747 283 if (!success) 748 284 { 749 // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file 750 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 751 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 752 success = true; 285 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 753 286 } 754 break; 755 } 756 } 757 758 // Check if we succeeded 759 if (!success) 760 { 761 // We obviously didn't found the right section, so we'll create it 762 this->getConfigFileLines().push_back("[" + this->classname_ + "]"); // Create the section 763 this->getConfigFileLines().push_back(this->varname_ + "=" + this->defvalueString_); // Create the line 764 this->configFileLine_ = --this->getConfigFileLines().end(); // Set the pointer to the last element 765 success = true; 766 this->getConfigFileLines().push_back(""); // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function 767 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); // Save the changed config-file 768 } 769 } 770 771 /** 772 @brief Determines if a line in the config-file is a comment. 773 @param line The line to check 774 @return True = it's a comment 775 */ 776 bool ConfigValueContainer::isComment(const std::string& line) 777 { 778 // Strip the line, whitespaces are disturbing 779 std::string teststring = getStrippedLine(line); 780 781 // There are four possible comment-symbols: 782 // 1) #comment in script-language style 783 // 2) %comment in matlab style 784 // 3) ;comment in unreal tournament config-file style 785 // 4) //comment in code style 786 if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[0] == '/')) 287 else 288 { 289 COUT(1) << "Error: Invalid vector-index." << std::endl; 290 } 291 return false; 292 } 293 294 if (token.size() >= 2) 295 return this->parse(index, token.subSet(1).join()); 296 else 297 return this->parse(index, ""); 298 } 299 300 MultiTypeMath temp = this->value_; 301 if (temp.fromString(input)) 302 { 303 this->value_ = temp; 787 304 return true; 788 789 return false; 790 } 791 792 /** 793 @brief Determines if a line in the config-file is empty (contains only whitespaces). 794 @param line The line to check 795 @return True = it's empty 796 */ 797 bool ConfigValueContainer::isEmpty(const std::string& line) 798 { 799 return getStrippedLine(line) == ""; 800 } 801 802 /** 803 @brief Removes all whitespaces from a line. 804 @param line The line to strip 805 @return The stripped line 806 */ 807 std::string ConfigValueContainer::getStrippedLine(const std::string& line) 808 { 809 std::string output = line; 810 unsigned int pos; 811 while ((pos = output.find(" ")) < output.length()) 812 output.erase(pos, 1); 813 while ((pos = output.find("\t")) < output.length()) 814 output.erase(pos, 1); 815 816 return output; 817 } 818 819 /** 820 @brief Returns the part in the corresponding config-file-entry of the container that defines the value. 821 @param bStripped True = strip the value-string 822 @return The value-string 823 */ 824 std::string ConfigValueContainer::parseValueString(bool bStripped) 825 { 826 std::string output; 827 if (bStripped) 828 output = this->getStrippedLine(*this->configFileLine_); 829 else 830 output = *this->configFileLine_; 831 832 return output.substr(output.find("=") + 1); 833 } 834 835 /** 836 @brief Rreturns a list, containing all entrys in the config-file. 837 @return The list 838 */ 839 std::list<std::string>& ConfigValueContainer::getConfigFileLines() 840 { 841 // This is done to avoid problems while executing this code before main() 842 static std::list<std::string> configFileLinesStaticReference = std::list<std::string>(); 843 return configFileLinesStaticReference; 844 } 845 846 /** 847 @brief Returns true if the ConfigFile is read and stored into the ConfigFile-lines-list. 848 @param finished This is used to change the state 849 @return True if the ConfigFile is read and stored into the ConfigFile-lines-list 850 */ 851 bool ConfigValueContainer::finishedReadingConfigFile(bool finished) 852 { 853 // This is done to avoid problems while executing this code before main() 854 static bool finishedReadingConfigFileStaticVariable = false; 855 856 if (finished) 857 finishedReadingConfigFileStaticVariable = true; 858 859 return finishedReadingConfigFileStaticVariable; 860 } 861 862 /** 863 @brief Reads the config-file and stores the lines in a list. 864 @param filename The name of the config-file 865 */ 866 void ConfigValueContainer::readConfigFile(const std::string& filename) 867 { 868 // This creates the file if it's not existing 869 std::ofstream createFile; 870 createFile.open(filename.c_str(), std::fstream::app); 871 createFile.close(); 872 873 // Open the file 874 std::ifstream file; 875 file.open(filename.c_str(), std::fstream::in); 876 877 if (!file.is_open()) 878 { 879 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 880 COUT(1) << "Error: Couldn't open config-file " << filename << " to read the config values!" << std::endl; 881 return; 882 } 883 884 char line[1024]; 885 886 // Iterate through the file and add the lines into the list 887 while (file.good() && !file.eof()) 888 { 889 file.getline(line, 1024); 890 ConfigValueContainer::getConfigFileLines().push_back(line); 891 // std::cout << "### ->" << line << "<- : empty: " << isEmpty(line) << " comment: " << isComment(line) << std::endl; 892 } 893 894 // The last line is useless 895 ConfigValueContainer::getConfigFileLines().pop_back(); 896 897 // Add an empty line to the end of the file if needed 898 // this is needed for the algorithm in the searchConfigFileLine-function 899 if ((ConfigValueContainer::getConfigFileLines().size() > 0) && !isEmpty(*ConfigValueContainer::getConfigFileLines().rbegin())) 900 { 901 // std::cout << "### newline added" << std::endl; 902 ConfigValueContainer::getConfigFileLines().push_back(""); 903 } 904 905 file.close(); 906 907 ConfigValueContainer::finishedReadingConfigFile(true); 908 } 909 910 /** 911 @brief Writes the content of the list, containing all lines of the config-file, into the config-file. 912 @param filename The name of the config-file 913 */ 914 void ConfigValueContainer::writeConfigFile(const std::string& filename) 915 { 916 // Make sure we stored the config-file in the list 917 if (!ConfigValueContainer::finishedReadingConfigFile()) 918 ConfigValueContainer::readConfigFile(filename); 919 920 // Open the file 921 std::ofstream file; 922 file.open(filename.c_str(), std::fstream::out); 923 924 if (!file.is_open()) 925 { 926 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 927 COUT(1) << "Error: Couldn't open config-file " << filename << " to write the config values!" << std::endl; 928 return; 929 } 930 931 // Iterate through the list an write the lines into the file 932 std::list<std::string>::iterator it; 933 for (it = ConfigValueContainer::getConfigFileLines().begin(); it != ConfigValueContainer::getConfigFileLines().end(); ++it) 934 { 935 file << (*it) << std::endl; 936 } 937 938 file.close(); 305 } 306 return false; 307 } 308 309 /** 310 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 311 @param index The index in the vector 312 @param input The string to convert 313 @return True if the string was successfully parsed 314 */ 315 bool ConfigValueContainer::parse(unsigned int index, const std::string& input) 316 { 317 if (this->bIsVector_) 318 { 319 if (index >= this->valueVector_.size()) 320 { 321 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 322 { 323 this->valueVector_.push_back(MultiTypeMath()); 324 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string)); 325 } 326 } 327 328 MultiTypeMath temp = this->value_; 329 if (temp.fromString(input)) 330 { 331 this->valueVector_[index] = temp; 332 return true; 333 } 334 return false; 335 } 336 337 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 338 return false; 339 } 340 341 /** 342 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 343 @param input The string to convert 344 @param defvalue The default value to assign if the parsing fails 345 @return True if the string was successfully parsed 346 */ 347 bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue) 348 { 349 if (this->parse(input)) 350 return true; 351 352 this->value_ = defvalue; 353 return false; 354 } 355 356 /** 357 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 358 @param index The index in the vector 359 @param input The string to convert 360 @param defvalue The default value to assign if the parsing fails 361 @return True if the string was successfully parsed 362 */ 363 bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue) 364 { 365 if (this->bIsVector_) 366 { 367 if (this->parse(index, input)) 368 return true; 369 370 this->valueVector_[index] = defvalue; 371 return false; 372 } 373 374 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 375 return false; 939 376 } 940 377 … … 947 384 if (!this->bAddedDescription_) 948 385 { 949 this->description_ = std::string("ConfigValueDescription::" + this-> classname_+ "::" + this->varname_);386 this->description_ = std::string("ConfigValueDescription::" + this->identifier_->getName() + "::" + this->varname_); 950 387 AddLanguageEntry(this->description_, description); 951 388 this->bAddedDescription_ = true; -
code/trunk/src/orxonox/core/ConfigValueContainer.h
r871 r1052 43 43 #define _ConfigValueContainer_H__ 44 44 45 #include <list>46 45 #include <string> 46 #include <vector> 47 47 48 48 #include "CorePrereqs.h" … … 50 50 #include "util/Math.h" 51 51 #include "util/MultiTypeMath.h" 52 #include "ConfigFileManager.h" 52 53 53 54 namespace orxonox … … 72 73 { 73 74 public: 74 ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue); 75 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue); 76 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue); 75 77 76 78 /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */ 77 /* template <typename T> 78 inline ConfigValueContainer& getValue(T& value) { this->value_.getValue(value); return *this; } 79 */ 80 inline ConfigValueContainer& getValue(int* value) { this->value_.getValue(value); return *this; } 81 inline ConfigValueContainer& getValue(unsigned int* value) { this->value_.getValue(value); return *this; } 82 inline ConfigValueContainer& getValue(char* value) { this->value_.getValue(value); return *this; } 83 inline ConfigValueContainer& getValue(unsigned char* value) { this->value_.getValue(value); return *this; } 84 inline ConfigValueContainer& getValue(short* value) { this->value_.getValue(value); return *this; } 85 inline ConfigValueContainer& getValue(unsigned short* value) { this->value_.getValue(value); return *this; } 86 inline ConfigValueContainer& getValue(long* value) { this->value_.getValue(value); return *this; } 87 inline ConfigValueContainer& getValue(unsigned long* value) { this->value_.getValue(value); return *this; } 88 inline ConfigValueContainer& getValue(float* value) { this->value_.getValue(value); return *this; } 89 inline ConfigValueContainer& getValue(double* value) { this->value_.getValue(value); return *this; } 90 inline ConfigValueContainer& getValue(long double* value) { this->value_.getValue(value); return *this; } 91 inline ConfigValueContainer& getValue(bool* value) { this->value_.getValue(value); return *this; } 92 inline ConfigValueContainer& getValue(std::string* value) { this->value_.getValue(value); return *this; } 93 inline ConfigValueContainer& getValue(const char** value) { this->value_.getValue(value); return *this; } 94 inline ConfigValueContainer& getValue(Vector2* value) { this->value_.getValue(value); return *this; } 95 inline ConfigValueContainer& getValue(Vector3* value) { this->value_.getValue(value); return *this; } 96 inline ConfigValueContainer& getValue(ColourValue* value) { this->value_.getValue(value); return *this; } 97 inline ConfigValueContainer& getValue(Quaternion* value) { this->value_.getValue(value); return *this; } 98 inline ConfigValueContainer& getValue(Radian* value) { this->value_.getValue(value); return *this; } 99 inline ConfigValueContainer& getValue(Degree* value) { this->value_.getValue(value); return *this; } 79 template <typename T> 80 inline ConfigValueContainer& getValue(T* value) 81 { this->value_.getValue(value); return *this; } 82 template <typename T> 83 inline ConfigValueContainer& getValue(std::vector<T>* value) 84 { 85 value->clear(); 86 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 87 value->push_back(this->valueVector_[i]); 88 return *this; 89 } 90 91 inline const std::string& getName() const 92 { return this->varname_; } 93 inline bool isVector() const 94 { return this->bIsVector_; } 95 inline unsigned int getVectorSize() const 96 { return this->valueVector_.size(); } 100 97 101 98 void description(const std::string& description); 102 99 const std::string& getDescription() const; 103 100 104 bool parseString(const std::string& input, MultiTypeMath& defvalue); 105 bool valueToString(std::string* output, MultiTypeMath& input); 106 void resetConfigFileEntry(); 107 void resetConfigValue(); 101 bool add(const std::string& input); 102 bool remove(unsigned int index); 103 bool set(const std::string& input); 104 bool tset(const std::string& input); 105 bool reset(); 106 void update(); 108 107 109 static std::string getStrippedLine(const std::string& line); 110 static bool isEmpty(const std::string& line); 111 static bool isComment(const std::string& line); 108 /** @brief Converts the config-value to a string. @return The string */ 109 inline std::string toString() const 110 { return this->value_.toString(); } 111 /** @brief Returns the typename of the assigned config-value. @return The typename */ 112 inline std::string getTypename() const 113 { return this->value_.getTypename(); } 112 114 113 115 private: 114 bool parseString(const std::string& input, int defvalue); 115 bool parseString(const std::string& input, unsigned int defvalue); 116 bool parseString(const std::string& input, char defvalue); 117 bool parseString(const std::string& input, unsigned char defvalue); 118 bool parseString(const std::string& input, short defvalue); 119 bool parseString(const std::string& input, unsigned short defvalue); 120 bool parseString(const std::string& input, long defvalue); 121 bool parseString(const std::string& input, unsigned long defvalue); 122 bool parseString(const std::string& input, float defvalue); 123 bool parseString(const std::string& input, double defvalue); 124 bool parseString(const std::string& input, long double defvalue); 125 bool parseString(const std::string& input, bool defvalue); 126 bool parseString(const std::string& input, const std::string& defvalue); 127 bool parseString(const std::string& input, const char* defvalue); 128 bool parseString(const std::string& input, const Vector2& defvalue); 129 bool parseString(const std::string& input, const Vector3& defvalue); 130 bool parseString(const std::string& input, const ColourValue& defvalue); 131 bool parseString(const std::string& input, const Quaternion& defvalue); 132 bool parseString(const std::string& input, const Radian& defvalue); 133 bool parseString(const std::string& input, const Degree& defvalue); 116 bool parse(const std::string& input); 117 bool parse(const std::string& input, const MultiTypeMath& defvalue); 134 118 135 static std::list<std::string>& getConfigFileLines();136 static bool finishedReadingConfigFile(bool finished = false);137 void searchConfigFileLine();138 std::string parseValueString(bool bStripped = true);119 bool set(unsigned int index, const std::string& input); 120 bool tset(unsigned int index, const std::string& input); 121 bool parse(unsigned int index, const std::string& input); 122 bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue); 139 123 140 static void readConfigFile(const std::string& filename); 141 static void writeConfigFile(const std::string& filename); 124 bool bIsVector_; //!< True if the container contains a std::vector 142 125 143 std::string classname_; //!< The name of the class the variable belongs to 144 std::string varname_; //!< The name of the variable 145 std::string defvalueString_; //!< The string of the default-variable 126 ConfigFileType type_; //!< The type of the corresponding config-file 127 Identifier* identifier_; //!< The identifier of the class 128 std::string sectionname_; //!< The name of the class the variable belongs to 129 std::string varname_; //!< The name of the variable 130 std::string defvalueString_; //!< The string of the default-value 131 std::vector<std::string> defvalueStringVector_; //!< A vector, containg the strings of the default-values in case we're storing a vector 146 132 147 MultiTypeMath value_; //!< The value 133 MultiTypeMath value_; //!< The value 134 std::vector<MultiTypeMath> valueVector_; //!< A vector, containg the values in case we're storing a vector 148 135 149 std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file 150 151 bool bAddedDescription_; //!< True if a description was added 152 LanguageEntryLabel description_; //!< The description 136 bool bAddedDescription_; //!< True if a description was added 137 LanguageEntryLabel description_; //!< The description 153 138 }; 154 139 } -
code/trunk/src/orxonox/core/CoreIncludes.h
r871 r1052 28 28 /** 29 29 @file CoreIncludes.h 30 @brief Definition of macros and typedefs.30 @brief Definition of macros for Identifier and Factory. 31 31 32 32 Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface … … 40 40 #define _CoreIncludes_H__ 41 41 42 #include "CorePrereqs.h"43 44 // All needed header-files45 42 #include "Identifier.h" 46 43 #include "ClassManager.h" 47 44 #include "Factory.h" 48 45 #include "ClassFactory.h" 49 #include "Iterator.h"50 #include "OrxonoxClass.h"51 #include "ConfigValueContainer.h"52 46 #include "Debug.h" 53 47 54 48 55 // All needed macros56 49 /** 57 50 @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. … … 111 104 orxonox::Factory::getIdentifier(StringOrInt) 112 105 113 /**114 @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).115 @param varname The name of the variable116 @param defvalue The default-value of the variable117 */118 #define SetConfigValue(varname, defvalue) \119 orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \120 if (!container##varname) \121 { \122 container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, varname = defvalue); \123 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \124 } \125 container##varname->getValue(&varname)126 127 /**128 @brief Sets the variable and the config-file entry back to the previously defined default-value.129 @param varname The name of the variable130 */131 #define ResetConfigValue(varname) \132 orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \133 if (container##varname##reset) \134 { \135 container##varname##reset->resetConfigValue(); \136 container##varname##reset->getValue(&varname); \137 } \138 else \139 COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl140 141 106 #endif /* _CoreIncludes_H__ */ -
code/trunk/src/orxonox/core/CorePrereqs.h
r1024 r1052 65 65 namespace orxonox 66 66 { 67 #ifndef _XMLPort_Mode__ 68 #define _XMLPort_Mode__ 69 namespace XMLPort 70 { 71 enum Mode 72 { 73 LoadObject, 74 SaveObject 75 }; 76 } 77 #endif 78 67 79 typedef std::string LanguageEntryLabel; 68 80 … … 79 91 class ClassTreeMaskIterator; 80 92 class ClassTreeMaskNode; 93 class CommandEvaluation; 94 class CommandExecutor; 95 class ConfigFile; 96 class ConfigFileEntry; 97 class ConfigFileEntryComment; 98 class ConfigFileEntryValue; 99 class ConfigFileManager; 100 class ConfigFileSection; 81 101 class ConfigValueContainer; 82 class DebugLevel;102 class CoreSettings; 83 103 class Error; 84 104 class Executor; 105 template <class T> 106 class ExecutorMember; 107 class ExecutorStatic; 85 108 class Factory; 109 class Functor; 110 template <class T> 111 class FunctorMember; 112 class FunctorStatic; 86 113 class Identifier; 87 114 class IdentifierDistributor; 115 class InputBuffer; 116 class InputBufferListener; 88 117 class InputHandlerGame; 89 118 class InputHandlerGUI; … … 98 127 template <class T> 99 128 class MetaObjectListElement; 129 class Namespace; 130 class NamespaceNode; 100 131 template <class T> 101 132 class ObjectList; … … 104 135 class OrxonoxClass; 105 136 class OutputHandler; 137 class Shell; 106 138 template <class T> 107 139 class SubclassIdentifier; -
code/trunk/src/orxonox/core/Executor.cc
r871 r1052 29 29 #include "Executor.h" 30 30 #include "Language.h" 31 #include "util/ String.h"31 #include "util/Math.h" 32 32 33 33 namespace orxonox 34 34 { 35 Executor::Executor(Functor* functor, const std::string& name )35 Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level) 36 36 { 37 37 this->functor_ = functor; 38 38 this->name_ = name; 39 this->accessLevel_ = level; 40 39 41 this->bAddedDescription_ = false; 40 42 this->bAddedDescriptionReturnvalue_ = false; 43 41 44 this->bAddedDescriptionParam_[0] = false; 42 45 this->bAddedDescriptionParam_[1] = false; … … 44 47 this->bAddedDescriptionParam_[3] = false; 45 48 this->bAddedDescriptionParam_[4] = false; 49 50 this->bAddedDefaultValue_[0] = false; 51 this->bAddedDefaultValue_[1] = false; 52 this->bAddedDefaultValue_[2] = false; 53 this->bAddedDefaultValue_[3] = false; 54 this->bAddedDefaultValue_[4] = false; 46 55 } 47 56 48 57 Executor::~Executor() 49 58 { 50 } 51 52 void Executor::setName(const std::string name) 53 { 54 this->name_ = name; 55 } 56 57 const std::string& Executor::getName() const 58 { 59 return this->name_; 60 } 61 62 void Executor::description(const std::string& description) 59 delete this->functor_; 60 } 61 62 bool Executor::parse(const std::string& params, const std::string& delimiter) const 63 { 64 EXECUTOR_PARSE(normal); 65 } 66 67 bool Executor::evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter) const 68 { 69 unsigned int paramCount = this->functor_->getParamCount(); 70 71 if (paramCount == 1) 72 { 73 // only one param: check if there are params given, otherwise try to use default values 74 std::string temp = getStripped(params); 75 if ((temp != "") && (temp.size() != 0)) 76 { 77 param[0] = params; 78 this->functor_->evaluateParam(0, param[0]); 79 return true; 80 } 81 else if (this->bAddedDefaultValue_[0]) 82 { 83 param[0] = this->defaultValue_[0]; 84 this->functor_->evaluateParam(0, param[0]); 85 return true; 86 } 87 return false; 88 } 89 else 90 { 91 // more than one param 92 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); 93 94 // if there are not enough params given, check if there are default values 95 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 96 if (!this->bAddedDefaultValue_[i]) 97 return false; 98 99 // assign all given arguments to the multitypes 100 for (unsigned int i = 0; i < min(tokens.size(), (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 101 param[i] = tokens[i]; 102 103 // fill the remaining multitypes with default values 104 for (unsigned int i = tokens.size(); i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 105 param[i] = this->defaultValue_[i]; 106 107 // evaluate the param types through the functor 108 for (unsigned int i = 0; i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 109 this->functor_->evaluateParam(i, param[i]); 110 111 return true; 112 } 113 } 114 115 Executor& Executor::setDescription(const std::string& description) 63 116 { 64 117 if (!this->bAddedDescription_) … … 68 121 this->bAddedDescription_ = true; 69 122 } 123 return (*this); 70 124 } 71 125 … … 75 129 } 76 130 77 void Executor::descriptionParam(int param, const std::string& description)78 { 79 if (param > 0 && param <= 5)131 Executor& Executor::setDescriptionParam(int param, const std::string& description) 132 { 133 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 80 134 { 81 135 if (!this->bAddedDescriptionParam_[param]) … … 83 137 std::string paramnumber; 84 138 if (!Convert::ToString(¶mnumber, param)) 85 return ;139 return (*this); 86 140 87 141 this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber); … … 90 144 } 91 145 } 146 return (*this); 92 147 } 93 148 94 149 const std::string& Executor::getDescriptionParam(int param) const 95 150 { 96 if (param > 0 && param <= 5) 97 { 151 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 98 152 return GetLocalisation(this->descriptionParam_[param]); 99 }100 153 101 154 return this->descriptionParam_[0]; 102 155 } 103 156 104 void Executor::descriptionReturnvalue(const std::string& description)157 Executor& Executor::setDescriptionReturnvalue(const std::string& description) 105 158 { 106 159 if (!this->bAddedDescriptionReturnvalue_) … … 110 163 this->bAddedDescriptionReturnvalue_ = true; 111 164 } 165 return (*this); 112 166 } 113 167 … … 116 170 return GetLocalisation(this->descriptionReturnvalue_); 117 171 } 172 173 Executor& Executor::setDefaultValues(const MultiTypeMath& param1) 174 { 175 this->defaultValue_[0] = param1; 176 this->bAddedDefaultValue_[0] = true; 177 178 return (*this); 179 } 180 181 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) 182 { 183 this->defaultValue_[0] = param1; 184 this->bAddedDefaultValue_[0] = true; 185 this->defaultValue_[1] = param2; 186 this->bAddedDefaultValue_[1] = true; 187 188 return (*this); 189 } 190 191 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) 192 { 193 this->defaultValue_[0] = param1; 194 this->bAddedDefaultValue_[0] = true; 195 this->defaultValue_[1] = param2; 196 this->bAddedDefaultValue_[1] = true; 197 this->defaultValue_[2] = param3; 198 this->bAddedDefaultValue_[2] = true; 199 200 return (*this); 201 } 202 203 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) 204 { 205 this->defaultValue_[0] = param1; 206 this->bAddedDefaultValue_[0] = true; 207 this->defaultValue_[1] = param2; 208 this->bAddedDefaultValue_[1] = true; 209 this->defaultValue_[2] = param3; 210 this->bAddedDefaultValue_[2] = true; 211 this->defaultValue_[3] = param4; 212 this->bAddedDefaultValue_[3] = true; 213 214 return (*this); 215 } 216 217 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) 218 { 219 this->defaultValue_[0] = param1; 220 this->bAddedDefaultValue_[0] = true; 221 this->defaultValue_[1] = param2; 222 this->bAddedDefaultValue_[1] = true; 223 this->defaultValue_[2] = param3; 224 this->bAddedDefaultValue_[2] = true; 225 this->defaultValue_[3] = param4; 226 this->bAddedDefaultValue_[3] = true; 227 this->defaultValue_[4] = param5; 228 this->bAddedDefaultValue_[4] = true; 229 230 return (*this); 231 } 232 233 Executor& Executor::setDefaultValue(unsigned int index, const MultiTypeMath& param) 234 { 235 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 236 { 237 this->defaultValue_[index] = param; 238 this->bAddedDefaultValue_[index] = true; 239 } 240 return (*this); 241 } 242 243 bool Executor::allDefaultValuesSet() const 244 { 245 for (unsigned int i = 0; i < this->functor_->getParamCount(); i++) 246 if (!this->bAddedDefaultValue_[i]) 247 return false; 248 249 return true; 250 } 118 251 } -
code/trunk/src/orxonox/core/Executor.h
r871 r1052 32 32 #include "CorePrereqs.h" 33 33 #include "Functor.h" 34 #include "Debug.h" 35 #include "util/SubString.h" 36 #include "util/String.h" 37 38 39 #define EXECUTOR_PARSE_FUNCTORCALL(mode) EXECUTOR_PARSE_FUNCTORCALL##mode 40 #define EXECUTOR_PARSE_FUNCTORCALLnormal (*this->functor_) 41 #define EXECUTOR_PARSE_FUNCTORCALLobject (*((FunctorMember<T>*)this->functor_)) 42 43 #define EXECUTOR_PARSE_OBJECT(mode, comma) EXECUTOR_PARSE_OBJECT##mode##comma 44 #define EXECUTOR_PARSE_OBJECTnormal0 45 #define EXECUTOR_PARSE_OBJECTnormal1 46 #define EXECUTOR_PARSE_OBJECTobject0 object 47 #define EXECUTOR_PARSE_OBJECTobject1 object, 48 49 #define EXECUTOR_PARSE(mode) \ 50 unsigned int paramCount = this->functor_->getParamCount(); \ 51 \ 52 if (paramCount == 0) \ 53 { \ 54 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; \ 55 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 0)); \ 56 } \ 57 else if (paramCount == 1) \ 58 { \ 59 std::string temp = getStripped(params); \ 60 if ((temp != "") && (temp.size() != 0)) \ 61 { \ 62 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; \ 63 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) MultiTypeMath(params)); \ 64 } \ 65 else if (this->bAddedDefaultValue_[0]) \ 66 { \ 67 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; \ 68 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) this->defaultValue_[0]); \ 69 } \ 70 else \ 71 { \ 72 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; \ 73 return false; \ 74 } \ 75 } \ 76 else \ 77 { \ 78 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \ 79 \ 80 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \ 81 { \ 82 if (!this->bAddedDefaultValue_[i]) \ 83 { \ 84 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; \ 85 return false; \ 86 } \ 87 } \ 88 \ 89 MultiTypeMath param[MAX_FUNCTOR_ARGUMENTS]; \ 90 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \ 91 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \ 92 { \ 93 param[i] = tokens[i]; \ 94 if (i != 0) \ 95 { \ 96 COUT(5) << ", "; \ 97 } \ 98 COUT(5) << tokens[i]; \ 99 } \ 100 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; \ 101 for (unsigned int i = tokens.size(); i < paramCount; i++) \ 102 { \ 103 param[i] = this->defaultValue_[i]; \ 104 if (i != 0) \ 105 { \ 106 COUT(5) << ", "; \ 107 } \ 108 COUT(5) << this->defaultValue_[i]; \ 109 } \ 110 COUT(5) << ")." << std::endl; \ 111 \ 112 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \ 113 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \ 114 \ 115 switch(paramCount) \ 116 { \ 117 case 2: \ 118 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1]); \ 119 break; \ 120 case 3: \ 121 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2]); \ 122 break; \ 123 case 4: \ 124 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3]); \ 125 break; \ 126 case 5: \ 127 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3], param[4]); \ 128 break; \ 129 } \ 130 } \ 131 \ 132 return true 133 134 namespace AccessLevel 135 { 136 enum Level 137 { 138 None, 139 User, 140 Admin, 141 Offline, 142 Debug, 143 Disabled 144 }; 145 } 34 146 35 147 namespace orxonox … … 38 150 { 39 151 public: 40 Executor(Functor* functor, const std::string& name = "" );152 Executor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None); 41 153 virtual ~Executor(); 42 154 43 inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 155 inline void operator()() const 156 { (*this->functor_)(this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 157 inline void operator()(const MultiTypeMath& param1) const 158 { (*this->functor_)(param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 159 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2) const 160 { (*this->functor_)(param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 161 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const 162 { (*this->functor_)(param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 163 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const 164 { (*this->functor_)(param1, param2, param3, param4, this->defaultValue_[4]); } 165 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const 44 166 { (*this->functor_)(param1, param2, param3, param4, param5); } 45 167 46 void setName(const std::string name); 47 const std::string& getName() const; 48 49 void description(const std::string& description); 168 bool parse(const std::string& params, const std::string& delimiter = " ") const; 169 170 bool evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter = " ") const; 171 172 Executor& setDescription(const std::string& description); 50 173 const std::string& getDescription() const; 51 174 52 void descriptionParam(int param, const std::string& description);175 Executor& setDescriptionParam(int param, const std::string& description); 53 176 const std::string& getDescriptionParam(int param) const; 54 177 55 void descriptionReturnvalue(const std::string& description);178 Executor& setDescriptionReturnvalue(const std::string& description); 56 179 const std::string& getDescriptionReturnvalue(int param) const; 57 180 58 inline int getParamCount() const181 inline unsigned int getParamCount() const 59 182 { return this->functor_->getParamCount(); } 60 183 inline bool hasReturnvalue() const … … 64 187 inline MultiTypeMath getReturnvalue() const 65 188 { return this->functor_->getReturnvalue(); } 66 inline std::string getTypenameParam( int param) const189 inline std::string getTypenameParam(unsigned int param) const 67 190 { return this->functor_->getTypenameParam(param); } 68 191 inline std::string getTypenameReturnvalue() const 69 192 { return this->functor_->getTypenameReturnvalue(); } 70 193 194 inline void setName(const std::string name) 195 { this->name_ = name; } 196 inline const std::string& getName() const 197 { return this->name_; } 198 199 inline void setAccessLevel(AccessLevel::Level level) 200 { this->accessLevel_ = level; } 201 inline AccessLevel::Level getAccessLevel() const 202 { return this->accessLevel_; } 203 204 Executor& setDefaultValues(const MultiTypeMath& param1); 205 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2); 206 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3); 207 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4); 208 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5); 209 Executor& setDefaultValue(unsigned int index, const MultiTypeMath& param); 210 211 inline MultiTypeMath getDefaultValue(unsigned int index) const 212 { 213 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 214 return this->defaultValue_[index]; 215 216 return MT_null; 217 } 218 219 bool allDefaultValuesSet() const; 220 inline bool defaultValueSet(unsigned int index) const 221 { 222 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 223 return this->bAddedDefaultValue_[index]; 224 225 return false; 226 } 227 71 228 protected: 72 229 Functor* functor_; 230 std::string name_; 231 MultiTypeMath defaultValue_[MAX_FUNCTOR_ARGUMENTS]; 232 bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS]; 73 233 74 234 private: 75 std::string name_;76 77 235 LanguageEntryLabel description_; 78 236 LanguageEntryLabel descriptionReturnvalue_; 79 LanguageEntryLabel descriptionParam_[ 5];237 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 80 238 81 239 bool bAddedDescription_; 82 240 bool bAddedDescriptionReturnvalue_; 83 bool bAddedDescriptionParam_[5]; 241 bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 242 243 AccessLevel::Level accessLevel_; 84 244 }; 85 245 … … 87 247 { 88 248 public: 89 ExecutorStatic(FunctorStatic* functor, const std::string& name = "" ) : Executor(functor, name) {}249 ExecutorStatic(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {} 90 250 virtual ~ExecutorStatic() {} 91 92 inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)93 { (*this->functor_)(param1, param2, param3, param4, param5); }94 251 }; 95 252 … … 98 255 { 99 256 public: 100 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "" ) : Executor(functor, name) {}257 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {} 101 258 virtual ~ExecutorMember() {} 102 259 103 inline virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 104 { (*this->functor_)(object, param1, param2, param3, param4, param5); } 105 inline virtual void operator()(const T* object, const MultiTypeMath param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 106 { (*this->functor_)(object, param1, param2, param3, param4, param5); } 107 inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 108 { (*this->functor_)(param1, param2, param3, param4, param5); } 109 110 inline void setObject(T* object) 111 { this->functor_->setObject(object); } 112 inline void setObject(const T* object) 113 { this->functor_->setObject(object); } 260 inline void operator()(T* object) const 261 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 262 inline void operator()(T* object, const MultiTypeMath& param1) const 263 { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 264 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2) const 265 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 266 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const 267 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 268 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const 269 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); } 270 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const 271 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); } 272 273 274 inline void operator()(const T* object) const 275 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 276 inline void operator()(const T* object, const MultiTypeMath& param1) const 277 { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 278 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2) const 279 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 280 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const 281 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 282 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const 283 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); } 284 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const 285 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); } 286 287 inline void setObject(T* object) const 288 { ((FunctorMember<T>*)this->functor_)->setObject(object); } 289 inline void setObject(const T* object) const 290 { ((FunctorMember<T>*)this->functor_)->setObject(object); } 291 292 bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const 293 { 294 EXECUTOR_PARSE(object); 295 } 296 297 bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const 298 { 299 EXECUTOR_PARSE(object); 300 } 114 301 }; 302 303 inline Executor* createExecutor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) 304 { 305 return new Executor(functor, name, level); 306 } 307 308 template <class T> 309 inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) 310 { 311 return new ExecutorMember<T>(functor, name, level); 312 } 313 314 inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) 315 { 316 return new ExecutorStatic(functor, name, level); 317 } 115 318 } 116 319 -
code/trunk/src/orxonox/core/Functor.h
r871 r1052 35 35 #include "CorePrereqs.h" 36 36 37 38 enum FunctionType 37 #define MAX_FUNCTOR_ARGUMENTS 5 38 39 namespace orxonox 39 40 { 40 FT_MEMBER, 41 FT_CONSTMEMBER, 42 FT_STATIC 43 }; 44 45 46 template <class T> 47 inline std::string typeToString(); 41 enum FunctionType 42 { 43 FT_MEMBER, 44 FT_CONSTMEMBER, 45 FT_STATIC 46 }; 47 48 49 template <class T> 50 inline std::string typeToString() { return "unknown"; } 48 51 49 52 #define CreateTypeToStringTemplate(type) \ 50 53 template <> \ 51 inline std::string typeToString<type>() { return #type; } 52 53 CreateTypeToStringTemplate(int); 54 CreateTypeToStringTemplate(unsigned int); 55 CreateTypeToStringTemplate(char); 56 CreateTypeToStringTemplate(unsigned char); 57 CreateTypeToStringTemplate(short); 58 CreateTypeToStringTemplate(unsigned short); 59 CreateTypeToStringTemplate(long); 60 CreateTypeToStringTemplate(unsigned long); 61 CreateTypeToStringTemplate(float); 62 CreateTypeToStringTemplate(double); 63 CreateTypeToStringTemplate(long double); 64 CreateTypeToStringTemplate(bool); 65 CreateTypeToStringTemplate(std::string); 66 CreateTypeToStringTemplate(orxonox::Vector2); 67 CreateTypeToStringTemplate(orxonox::Vector3); 68 CreateTypeToStringTemplate(orxonox::Quaternion); 69 CreateTypeToStringTemplate(orxonox::ColourValue); 70 CreateTypeToStringTemplate(orxonox::Radian); 71 CreateTypeToStringTemplate(orxonox::Degree); 72 73 74 class _CoreExport Functor 75 { 76 public: 77 Functor() {} 78 virtual ~Functor() {} 79 80 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 81 82 inline int getParamCount() const { return this->numParams_; } 83 inline bool hasReturnvalue() const { return this->hasReturnValue_; } 84 inline FunctionType getType() const { return this->type_; } 85 inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; } 86 87 std::string getTypenameParam(int param) const { return (param > 0 && param <= 5) ? this->typeParam_[param-1] : ""; } 88 std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } 89 90 protected: 91 int numParams_; 92 bool hasReturnValue_; 93 FunctionType type_; 94 MultiTypeMath returnedValue_; 95 96 std::string typeReturnvalue_; 97 std::string typeParam_[5]; 98 }; 99 100 class _CoreExport FunctorStatic : public Functor 101 { 102 public: 103 virtual ~FunctorStatic() {} 104 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 105 }; 106 107 template <class T> 108 class FunctorMember : public Functor 109 { 110 public: 111 FunctorMember() 112 { 113 constObject_ = 0; 114 object_ = 0; 115 bConstObject_ = false; 116 } 117 virtual ~FunctorMember() {} 118 119 virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 120 virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 121 122 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 123 { 124 if (this->bConstObject_) 54 inline std::string typeToString<type>() { return #type; } \ 55 template <> \ 56 inline std::string typeToString<type&>() { return #type; } \ 57 template <> \ 58 inline std::string typeToString<const type>() { return #type; } \ 59 template <> \ 60 inline std::string typeToString<const type&>() { return #type; } 61 62 CreateTypeToStringTemplate(int); 63 CreateTypeToStringTemplate(unsigned int); 64 CreateTypeToStringTemplate(char); 65 CreateTypeToStringTemplate(unsigned char); 66 CreateTypeToStringTemplate(short); 67 CreateTypeToStringTemplate(unsigned short); 68 CreateTypeToStringTemplate(long); 69 CreateTypeToStringTemplate(unsigned long); 70 CreateTypeToStringTemplate(float); 71 CreateTypeToStringTemplate(double); 72 CreateTypeToStringTemplate(long double); 73 CreateTypeToStringTemplate(bool); 74 CreateTypeToStringTemplate(Vector2); 75 CreateTypeToStringTemplate(Vector3); 76 CreateTypeToStringTemplate(Quaternion); 77 CreateTypeToStringTemplate(ColourValue); 78 CreateTypeToStringTemplate(Radian); 79 CreateTypeToStringTemplate(Degree); 80 81 template <> \ 82 inline std::string typeToString<std::string>() { return "string"; } \ 83 template <> \ 84 inline std::string typeToString<std::string&>() { return "string"; } \ 85 template <> \ 86 inline std::string typeToString<const std::string>() { return "string"; } \ 87 template <> \ 88 inline std::string typeToString<const std::string&>() { return "string"; } 89 90 class _CoreExport Functor 91 { 92 public: 93 Functor() {} 94 virtual ~Functor() {} 95 96 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 97 98 inline unsigned int getParamCount() const { return this->numParams_; } 99 inline bool hasReturnvalue() const { return this->hasReturnValue_; } 100 inline FunctionType getType() const { return this->type_; } 101 inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; } 102 103 std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; } 104 std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } 105 106 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0; 107 108 protected: 109 unsigned int numParams_; 110 bool hasReturnValue_; 111 FunctionType type_; 112 MultiTypeMath returnedValue_; 113 114 std::string typeReturnvalue_; 115 std::string typeParam_[MAX_FUNCTOR_ARGUMENTS]; 116 }; 117 118 class _CoreExport FunctorStatic : public Functor 119 { 120 public: 121 virtual ~FunctorStatic() {} 122 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 123 }; 124 125 template <class T> 126 class FunctorMember : public Functor 127 { 128 public: 129 FunctorMember() 125 130 { 126 if (this->constObject_) 127 (*this)(this->constObject_, param1, param2, param3, param4, param5); 131 constObject_ = 0; 132 object_ = 0; 133 bConstObject_ = false; 134 } 135 virtual ~FunctorMember() {} 136 137 virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 138 virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 139 140 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 141 { 142 if (this->bConstObject_) 143 { 144 if (this->constObject_) 145 (*this)(this->constObject_, param1, param2, param3, param4, param5); 146 else 147 { 148 COUT(1) << "An error occurred in Functor.h:" << std::endl; 149 COUT(1) << "Error: No const object set." << std::endl; 150 } 151 } 128 152 else 129 153 { 130 COUT(1) << "An error occurred in Functor.h:" << std::endl; 131 COUT(1) << "Error: No const object set." << std::endl; 154 if (this->object_) 155 (*this)(this->object_, param1, param2, param3, param4, param5); 156 else 157 { 158 COUT(1) << "An error occurred in Functor.h:" << std::endl; 159 COUT(1) << "Error: No object set." << std::endl; 160 } 132 161 } 133 162 } 134 else 163 164 void setObject(T* object) 135 165 { 136 if (this->object_) 137 (*this)(this->object_, param1, param2, param3, param4, param5); 138 else 139 { 140 COUT(1) << "An error occurred in Functor.h:" << std::endl; 141 COUT(1) << "Error: No object set." << std::endl; 142 } 166 this->bConstObject_ = false; 167 this->object_ = object; 143 168 } 144 } 145 146 void setObject(T* object) 147 { 148 this->bConstObject_ = false; 149 this->object_ = object; 150 } 151 152 void setObject(const T* object) 153 { 154 this->bConstObject_ = true; 155 this->constObject_ = object; 156 } 157 158 private: 159 const T* constObject_; 160 T* object_; 161 bool bConstObject_; 162 }; 163 164 165 166 #define MAKE_COMMA(x) MAKE_COMMA##x 167 #define MAKE_COMMA0 168 #define MAKE_COMMA1 , 169 #define MAKE_COMMA2 , 170 #define MAKE_COMMA3 , 171 #define MAKE_COMMA4 , 172 #define MAKE_COMMA5 , 169 170 void setObject(const T* object) 171 { 172 this->bConstObject_ = true; 173 this->constObject_ = object; 174 } 175 176 private: 177 const T* constObject_; 178 T* object_; 179 bool bConstObject_; 180 }; 173 181 174 182 … … 272 280 273 281 282 #define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams 283 #define FUNCTOR_EVALUATE_PARAM0 284 #define FUNCTOR_EVALUATE_PARAM1 \ 285 if (index == 0) param = (P1)param 286 #define FUNCTOR_EVALUATE_PARAM2 \ 287 if (index == 0) param = (P1)param; \ 288 else if (index == 1) param = (P2)param 289 #define FUNCTOR_EVALUATE_PARAM3 \ 290 if (index == 0) param = (P1)param; \ 291 else if (index == 1) param = (P2)param; \ 292 else if (index == 2) param = (P3)param 293 #define FUNCTOR_EVALUATE_PARAM4 \ 294 if (index == 0) param = (P1)param; \ 295 else if (index == 1) param = (P2)param; \ 296 else if (index == 2) param = (P3)param; \ 297 else if (index == 3) param = (P4)param 298 #define FUNCTOR_EVALUATE_PARAM5 \ 299 if (index == 0) param = (P1)param; \ 300 else if (index == 1) param = (P2)param; \ 301 else if (index == 2) param = (P3)param; \ 302 else if (index == 3) param = (P4)param; \ 303 else if (index == 4) param = (P5)param 304 305 306 274 307 275 308 … … 295 328 } \ 296 329 \ 330 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 331 { \ 332 FUNCTOR_EVALUATE_PARAM(numparams); \ 333 } \ 334 \ 297 335 private: \ 298 336 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ … … 334 372 } \ 335 373 \ 374 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 375 { \ 376 FUNCTOR_EVALUATE_PARAM(numparams); \ 377 } \ 378 \ 336 379 private: \ 337 380 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ … … 359 402 { \ 360 403 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 404 } \ 405 \ 406 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 407 { \ 408 FUNCTOR_EVALUATE_PARAM(numparams); \ 361 409 } \ 362 410 \ … … 412 460 413 461 414 CREATE_ALL_STATIC_FUNCTORS(); 415 CREATE_ALL_MEMBER_FUNCTORS(); 462 CREATE_ALL_STATIC_FUNCTORS(); 463 CREATE_ALL_MEMBER_FUNCTORS(); 464 } 416 465 417 466 #endif /* _Functor_H__ */ -
code/trunk/src/orxonox/core/Identifier.cc
r871 r1052 35 35 #include "Identifier.h" 36 36 #include "Factory.h" 37 #include "Executor.h" 38 #include "CommandExecutor.h" 37 39 38 40 namespace orxonox … … 51 53 this->factory_ = 0; 52 54 53 this->children_ = new std::list<const Identifier*>(); 54 this->directChildren_ = new std::list<const Identifier*>(); 55 this->bHasConfigValues_ = false; 56 this->bHasConsoleCommands_ = false; 57 58 this->children_ = new std::set<const Identifier*>(); 59 this->directChildren_ = new std::set<const Identifier*>(); 55 60 56 61 // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables … … 72 77 @param parents A list containing all parents 73 78 */ 74 void Identifier::initialize(std:: list<const Identifier*>* parents)79 void Identifier::initialize(std::set<const Identifier*>* parents) 75 80 { 76 81 COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl; … … 83 88 84 89 // Iterate through all parents 85 for (std:: list<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)90 for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it) 86 91 { 87 92 // Tell the parent we're one of it's children … … 89 94 90 95 // Erase all parents of our parent from our direct-parent-list 91 for (std:: list<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)96 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1) 92 97 { 93 98 // Search for the parent's parent in our direct-parent-list 94 for (std:: list<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)99 for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2) 95 100 { 96 101 if ((*it1) == (*it2)) … … 105 110 106 111 // Now iterate through all direct parents 107 for (std:: list<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)112 for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 108 113 { 109 114 // Tell the parent we're one of it's direct children … … 149 154 bool Identifier::isA(const Identifier* identifier) const 150 155 { 151 return (identifier == this || this->identifierIsInList(identifier, this->parents_));156 return (identifier == this || (this->parents_.find(identifier) != this->children_->end())); 152 157 } 153 158 … … 167 172 bool Identifier::isChildOf(const Identifier* identifier) const 168 173 { 169 return this->identifierIsInList(identifier, this->parents_);174 return (this->parents_.find(identifier) != this->children_->end()); 170 175 } 171 176 … … 176 181 bool Identifier::isDirectChildOf(const Identifier* identifier) const 177 182 { 178 return this->identifierIsInList(identifier, this->directParents_);183 return (this->directParents_.find(identifier) != this->children_->end()); 179 184 } 180 185 … … 185 190 bool Identifier::isParentOf(const Identifier* identifier) const 186 191 { 187 return this->identifierIsInList(identifier, *this->children_);192 return (this->children_->find(identifier) != this->children_->end()); 188 193 } 189 194 … … 194 199 bool Identifier::isDirectParentOf(const Identifier* identifier) const 195 200 { 196 return this->identifierIsInList(identifier, *this->directChildren_); 201 return (this->directChildren_->find(identifier) != this->children_->end()); 202 } 203 204 /** 205 @brief Returns the map that stores all Identifiers. 206 @return The map 207 */ 208 std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern() 209 { 210 static std::map<std::string, Identifier*> identifierMap; 211 return identifierMap; 212 } 213 214 /** 215 @brief Returns the map that stores all Identifiers. 216 @return The map 217 */ 218 std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern() 219 { 220 static std::map<std::string, Identifier*> lowercaseIdentifierMap; 221 return lowercaseIdentifierMap; 222 } 223 224 /** 225 @brief Adds the ConfigValueContainer of a variable, given by the string of its name. 226 @param varname The name of the variablee 227 @param container The container 228 */ 229 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 230 { 231 this->bHasConfigValues_ = true; 232 this->configValues_[varname] = container; 233 this->configValues_LC_[getLowercase(varname)] = container; 197 234 } 198 235 … … 212 249 213 250 /** 214 @brief Adds the ConfigValueContainer of a variable, given by the string of its name. 215 @param varname The name of the variablee 216 @param container The container 217 */ 218 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 219 { 220 this->configValues_[varname] = container; 221 } 222 223 /** 224 @brief Searches for a given identifier in a list and returns whether the identifier is in the list or not. 225 @param identifier The identifier to look for 226 @param list The list 227 @return True = the identifier is in the list 228 */ 229 bool Identifier::identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list) 230 { 231 for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 232 if (identifier == (*it)) 233 return true; 234 235 return false; 236 } 237 238 std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list) 239 { 240 for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 251 @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase. 252 @param varname The name of the variable in lowercase 253 @return The ConfigValueContainer 254 */ 255 ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname) 256 { 257 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname); 258 if (it != configValues_LC_.end()) 259 return ((*it).second); 260 else 261 return 0; 262 } 263 264 /** 265 @brief Adds a new console command of this class. 266 @param executor The executor of the command 267 @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command 268 @return The executor of the command 269 */ 270 ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut) 271 { 272 this->bHasConsoleCommands_ = true; 273 this->consoleCommands_[executor->getName()] = executor; 274 this->consoleCommands_LC_[getLowercase(executor->getName())] = executor; 275 276 if (bCreateShortcut) 277 CommandExecutor::addConsoleCommandShortcut(executor); 278 279 return (*executor); 280 } 281 282 /** 283 @brief Returns the executor of a console command with given name. 284 @brief name The name of the requested console command 285 @return The executor of the requested console command 286 */ 287 ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const 288 { 289 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name); 290 if (it != this->consoleCommands_.end()) 291 return (*it).second; 292 else 293 return 0; 294 } 295 296 /** 297 @brief Returns the executor of a console command with given name in lowercase. 298 @brief name The name of the requested console command in lowercae 299 @return The executor of the requested console command 300 */ 301 ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const 302 { 303 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name); 304 if (it != this->consoleCommands_LC_.end()) 305 return (*it).second; 306 else 307 return 0; 308 } 309 310 /** 311 @brief Lists the names of all Identifiers in a std::set<const Identifier*>. 312 @param out The outstream 313 @param list The list (or set) of Identifiers 314 @return The outstream 315 */ 316 std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list) 317 { 318 for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 241 319 out << (*it)->getName() << " "; 242 320 -
code/trunk/src/orxonox/core/Identifier.h
r1024 r1052 52 52 #define _Identifier_H__ 53 53 54 #include < list>54 #include <set> 55 55 #include <map> 56 56 #include <string> … … 62 62 #include "Debug.h" 63 63 #include "Iterator.h" 64 #include "util/String.h" 64 65 65 66 namespace orxonox … … 105 106 bool isDirectParentOf(const Identifier* identifier) const; 106 107 107 /** @brief Removes all objects of the corresponding class. */ 108 virtual void removeObjects() const = 0; 108 virtual const ObjectList<BaseObject>* getObjectList() const = 0; 109 110 virtual void updateConfigValues() const = 0; 109 111 110 112 /** @brief Returns the name of the class the Identifier belongs to. @return The name */ 111 113 inline const std::string& getName() const { return this->name_; } 112 114 115 113 116 /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */ 114 inline const std:: list<const Identifier*>& getParents() const { return this->parents_; }117 inline const std::set<const Identifier*>& getParents() const { return this->parents_; } 115 118 /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */ 116 inline std:: list<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }119 inline std::set<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); } 117 120 /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */ 118 inline std:: list<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }121 inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); } 119 122 120 123 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 121 inline const std:: list<const Identifier*>& getChildren() const { return (*this->children_); }124 inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); } 122 125 /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */ 123 inline std:: list<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }126 inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); } 124 127 /** @brief Returns the end-iterator of the children-list. @return The end-iterator */ 125 inline std:: list<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }128 inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); } 126 129 127 130 /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */ 128 inline const std:: list<const Identifier*>& getDirectParents() const { return this->directParents_; }131 inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; } 129 132 /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */ 130 inline std:: list<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }133 inline std::set<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); } 131 134 /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */ 132 inline std:: list<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }135 inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); } 133 136 134 137 /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */ 135 inline const std:: list<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }138 inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); } 136 139 /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */ 137 inline std:: list<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }140 inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); } 138 141 /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */ 139 inline std::list<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); } 142 inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); } 143 144 145 /** @brief Returns the map that stores all Identifiers. @return The map */ 146 static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); } 147 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */ 148 static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); } 149 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */ 150 static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); } 151 152 /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */ 153 static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); } 154 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */ 155 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); } 156 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */ 157 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); } 158 159 160 /** @brief Returns the map that stores all config values. @return The const_iterator */ 161 inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; } 162 /** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */ 163 inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapBegin() const { return this->configValues_.begin(); } 164 /** @brief Returns a const_iterator to the end of the map that stores all config values. @return The const_iterator */ 165 inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapEnd() const { return this->configValues_.end(); } 166 167 /** @brief Returns the map that stores all config values with their names in lowercase. @return The const_iterator */ 168 inline const std::map<std::string, ConfigValueContainer*>& getLowercaseConfigValueMap() const { return this->configValues_LC_; } 169 /** @brief Returns a const_iterator to the beginning of the map that stores all config values with their names in lowercase. @return The const_iterator */ 170 inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapBegin() const { return this->configValues_LC_.begin(); } 171 /** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */ 172 inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); } 173 174 175 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 176 inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; } 177 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 178 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); } 179 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 180 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); } 181 182 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 183 inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; } 184 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 185 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); } 186 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 187 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); } 188 189 190 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 191 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 192 /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */ 193 inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; } 140 194 141 195 /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */ … … 148 202 void setNetworkID(unsigned int id); 149 203 204 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container); 150 205 ConfigValueContainer* getConfigValueContainer(const std::string& varname); 151 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container); 152 206 ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname); 207 208 virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0; 153 209 virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0; 154 virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0; 155 210 211 virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0; 156 212 virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0; 157 virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0; 158 159 static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list); 213 214 ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut); 215 ExecutorStatic* getConsoleCommand(const std::string& name) const; 216 ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const; 217 218 protected: 219 /** @brief Returns the map that stores all Identifiers. @return The map */ 220 static std::map<std::string, Identifier*>& getIdentifierMapIntern(); 221 /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */ 222 static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern(); 160 223 161 224 private: … … 163 226 Identifier(const Identifier& identifier) {} // don't copy 164 227 virtual ~Identifier(); 165 void initialize(std:: list<const Identifier*>* parents);228 void initialize(std::set<const Identifier*>* parents); 166 229 167 230 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 168 inline std:: list<const Identifier*>& getChildrenIntern() const { return (*this->children_); }231 inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); } 169 232 /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */ 170 inline std:: list<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }233 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); } 171 234 172 235 /** … … 188 251 } 189 252 190 std::list<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 191 std::list<const Identifier*>* children_; //!< The children of the class the Identifier belongs to 192 193 std::list<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to 194 std::list<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to 195 196 std::string name_; //!< The name of the class the Identifier belongs to 197 198 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 199 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 200 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 201 unsigned int classID_; //!< The network ID to identify a class through the network 202 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 253 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 254 std::set<const Identifier*>* children_; //!< The children of the class the Identifier belongs to 255 256 std::set<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to 257 std::set<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to 258 259 std::string name_; //!< The name of the class the Identifier belongs to 260 261 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 262 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 263 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 264 unsigned int classID_; //!< The network ID to identify a class through the network 265 266 bool bHasConfigValues_; //!< True if this class has at least one assigned config value 267 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 268 std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer 269 270 bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command 271 std::map<std::string, ExecutorStatic*> consoleCommands_; //!< All console commands of this class 272 std::map<std::string, ExecutorStatic*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase 203 273 }; 204 274 205 _CoreExport std::ostream& operator<<(std::ostream& out, const std:: list<const Identifier*>& list);275 _CoreExport std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list); 206 276 207 277 … … 228 298 229 299 public: 230 ClassIdentifier<T>* registerClass(std:: list<const Identifier*>* parents, const std::string& name, bool bRootClass);300 ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass); 231 301 void addObject(T* object); 232 void removeObjects() const;233 302 void setName(const std::string& name); 303 /** @brief Returns the list of all existing objects of this class. @return The list */ 234 304 inline const ObjectList<T>* getObjects() const { return this->objects_; } 305 /** @brief Returns a list of all existing objects of this class. @return The list */ 306 inline const ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; } 307 308 void updateConfigValues() const; 235 309 236 310 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); … … 245 319 ~ClassIdentifier() {} // don't delete 246 320 247 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T248 bool bSetName_; //!< True if the name is set249 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; 250 std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_; 321 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T 322 bool bSetName_; //!< True if the name is set 323 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; //!< All loadable parameters 324 std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_; //!< All attachable objects 251 325 }; 252 326 … … 270 344 */ 271 345 template <class T> 272 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std:: list<const Identifier*>* parents, const std::string& name, bool bRootClass)273 { 274 COUT(5) << "*** ClassIdentifier: Register Class in " << name << "-Singleton." << std::endl;346 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass) 347 { 348 this->setName(name); 275 349 276 350 // Check if at least one object of the given type was created 277 if (!this->bCreatedOneObject_ )351 if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy()) 278 352 { 279 353 // If no: We have to store the informations and initialize the Identifier 280 this->setName(name);281 282 354 COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl; 283 355 if (bRootClass) … … 301 373 this->name_ = name; 302 374 this->bSetName_ = true; 375 Identifier::getIdentifierMapIntern()[name] = this; 376 Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this; 303 377 } 304 378 } … … 316 390 317 391 /** 318 @brief Removes all objects of the corresponding class. 319 */ 320 template <class T> 321 void ClassIdentifier<T>::removeObjects() const 322 { 323 for (Iterator<T> it = this->objects_->start(); it;) 324 delete *(it++); 325 } 326 392 @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function. 393 */ 394 template <class T> 395 void ClassIdentifier<T>::updateConfigValues() const 396 { 397 for (Iterator<T> it = this->objects_->start(); it; ++it) 398 ((T*)*it)->setConfigValues(); 399 } 400 401 /** 402 @brief Returns a XMLPortParamContainer that loads a parameter of this class. 403 @param paramname The name of the parameter 404 @return The container 405 */ 327 406 template <class T> 328 407 XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname) … … 335 414 } 336 415 416 /** 417 @brief Adds a new XMLPortParamContainer that loads a parameter of this class. 418 @param paramname The name of the parameter 419 @param container The container 420 */ 337 421 template <class T> 338 422 void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) … … 341 425 } 342 426 427 /** 428 @brief Returns a XMLPortObjectContainer that attaches an object to this class. 429 @param sectionname The name of the section that contains the attachable objects 430 @return The container 431 */ 343 432 template <class T> 344 433 XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname) … … 351 440 } 352 441 442 /** 443 @brief Adds a new XMLPortObjectContainer that attaches an object to this class. 444 @param sectionname The name of the section that contains the attachable objects 445 @param container The container 446 */ 353 447 template <class T> 354 448 void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) -
code/trunk/src/orxonox/core/InputBuffer.cc
r1051 r1052 29 29 30 30 #include "InputBuffer.h" 31 #include "InputManager.h" 31 32 #include "util/Clipboard.h" 32 33 33 34 namespace orxonox 34 35 { 35 InputBuffer::InputBuffer( OIS::Keyboard* keyboard)36 InputBuffer::InputBuffer() 36 37 { 37 38 this->bActivated_ = false; 38 39 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"().:,;_-+*/=!?<>[|]"; 39 this->keyboard_ = keyboard;40 this->keyboard_ = InputManager::getSingleton().getKeyboard(); 40 41 this->buffer_ = ""; 41 42 -
code/trunk/src/orxonox/core/InputBuffer.h
r1051 r1052 58 58 59 59 public: 60 InputBuffer( OIS::Keyboard* keyboard);60 InputBuffer(); 61 61 62 62 template <class T> -
code/trunk/src/orxonox/core/InputHandler.cc
r1024 r1052 66 66 { 67 67 // simply write the key number (i) in the string 68 this->bindingsKeyPressed_[i] = ConvertValueAndReturn<int, std::string>(i);69 this->bindingsKeyReleased_[i] = ConvertValueAndReturn<int, std::string>(i);68 this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i); 69 this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i); 70 70 } 71 71 return true; -
code/trunk/src/orxonox/core/Language.cc
r871 r1052 28 28 /** 29 29 @file Language.cc 30 @brief Implementation of the Language and the LanguageEntry class .30 @brief Implementation of the Language and the LanguageEntry classes. 31 31 */ 32 32 33 33 #include <fstream> 34 34 35 #include "CoreIncludes.h"36 35 #include "Language.h" 36 #include "CoreSettings.h" 37 37 38 38 namespace orxonox … … 47 47 LanguageEntry::LanguageEntry(const std::string& fallbackEntry) 48 48 { 49 RegisterRootObject(LanguageEntry);50 51 49 this->fallbackEntry_ = fallbackEntry; 52 50 this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned … … 61 59 { 62 60 // Check if the translation is more than just an empty string 63 if ( localisation.compare("") != 0)61 if ((localisation != "") && (localisation.size() > 0)) 64 62 { 65 63 this->localisedEntry_ = localisation; … … 91 89 Language::Language() 92 90 { 93 RegisterRootObject(Language);94 95 91 this->defaultLanguage_ = "default"; 96 92 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; … … 101 97 102 98 /** 103 @brief Function to collect the SetConfigValue-macro calls.104 */105 void Language::setConfigValues()106 {107 SetConfigValue(language_, this->defaultLanguage_).description("The language of the ingame text");108 109 // Read the translation file after the language was configured110 this->readTranslatedLanguageFile();111 }112 113 /**114 99 @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function. 115 100 @return The reference to the only existing instance … … 117 102 Language& Language::getLanguage() 118 103 { 119 // Use static variables to avoid conflicts while executing this code before main() 120 static Language theOnlyLanguageObject = Language(); 121 static bool bCreatingTheOnlyLanguageObject = true; 122 123 // This workaround is used to set a description of the own config value without creating an infinite recursion 124 if (bCreatingTheOnlyLanguageObject) 125 { 126 bCreatingTheOnlyLanguageObject = false; 127 theOnlyLanguageObject.setConfigValues(); 128 } 129 130 return theOnlyLanguageObject; 104 static Language instance = Language(); 105 return instance; 131 106 } 132 107 … … 244 219 245 220 // Check if the line is empty 246 if ( lineString.compare("") != 0)221 if ((lineString != "") && (lineString.size() > 0)) 247 222 { 248 223 unsigned int pos = lineString.find('='); … … 252 227 this->createEntry(lineString.substr(0, pos), lineString.substr(pos + 1)); 253 228 else 229 { 254 230 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->defaultLanguage_) << std::endl; 231 } 255 232 } 256 233 } … … 264 241 void Language::readTranslatedLanguageFile() 265 242 { 266 COUT(4) << "Read translated language file (" << this->language_<< ")." << std::endl;243 COUT(4) << "Read translated language file (" << CoreSettings::getLanguage() << ")." << std::endl; 267 244 268 245 // Open the file 269 246 std::ifstream file; 270 file.open(getFileName( this->language_).c_str(), std::fstream::in);247 file.open(getFileName(CoreSettings::getLanguage()).c_str(), std::fstream::in); 271 248 272 249 if (!file.is_open()) 273 250 { 274 251 COUT(1) << "An error occurred in Language.cc:" << std::endl; 275 COUT(1) << "Error: Couldn't open file " << getFileName( this->language_) << " to read the translated language entries!" << std::endl;276 ResetConfigValue(language_);252 COUT(1) << "Error: Couldn't open file " << getFileName(CoreSettings::getLanguage()) << " to read the translated language entries!" << std::endl; 253 CoreSettings::resetLanguage(); 277 254 COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl; 278 255 return; … … 288 265 289 266 // Check if the line is empty 290 if ( lineString.compare("") != 0)267 if ((lineString != "") && (lineString.size() > 0)) 291 268 { 292 269 unsigned int pos = lineString.find('='); … … 304 281 } 305 282 else 306 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->language_) << std::endl; 283 { 284 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(CoreSettings::getLanguage()) << std::endl; 285 } 307 286 } 308 287 } … … 330 309 331 310 // Iterate through the list an write the lines into the file 332 for ( Iterator<LanguageEntry> it = ObjectList<LanguageEntry>::start(); it; ++it)333 { 334 file << it->getLabel() << "=" << it->getDefault() << std::endl;311 for (std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it) 312 { 313 file << (*it).second->getLabel() << "=" << (*it).second->getDefault() << std::endl; 335 314 } 336 315 -
code/trunk/src/orxonox/core/Language.h
r871 r1052 49 49 50 50 #include "CorePrereqs.h" 51 #include "OrxonoxClass.h"52 51 53 52 … … 65 64 // ############################### 66 65 //! The LanguageEntry class stores the default- and the translated string of a given entry in the language file. 67 class _CoreExport LanguageEntry : public OrxonoxClass66 class _CoreExport LanguageEntry 68 67 { 69 68 public: … … 112 111 // ############################### 113 112 //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map. 114 class _CoreExport Language : public OrxonoxClass113 class _CoreExport Language 115 114 { 116 template <class T> 117 friend class ClassIdentifier; // forward declaration because of the private destructor 115 friend class CoreSettings; 118 116 119 117 public: 120 118 static Language& getLanguage(); 121 void setConfigValues();122 119 void addEntry(const LanguageEntryLabel& label, const std::string& entry); 123 120 const std::string& getLocalisation(const LanguageEntryLabel& label) const; … … 134 131 LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry); 135 132 136 std::string language_; //!< The configured language137 133 std::string defaultLanguage_; //!< The default language 138 134 std::string defaultLocalisation_; //!< The returned string, if an entry unavailable entry is requested -
code/trunk/src/orxonox/core/Loader.cc
r1021 r1052 34 34 #include "CoreIncludes.h" 35 35 #include "Script.h" 36 #include "Namespace.h" 36 37 37 38 #include "util/tinyxml/ticpp.h" … … 129 130 xmlfile.Parse(lua->getLuaOutput(), true); 130 131 131 for ( ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++ ) 132 { 133 Identifier* identifier = ID(child->Value()); 134 if (identifier) 135 { 136 if (Loader::currentMask_s.isIncluded(identifier)) 137 { 138 COUT(4) << " fabricating " << child->Value() << "..." << std::endl; 139 BaseObject* newObject = identifier->fabricate(); 140 newObject->setLoaderIndentation(" "); 141 newObject->setLevel(level); 142 newObject->XMLPort(*child, true); 143 COUT(5) << " ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 144 } 145 } 146 else 147 { 148 COUT(2) << " Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 149 } 150 } 132 ticpp::Element rootElement; 133 rootElement.SetAttribute("name", "root"); 134 rootElement.SetAttribute("bAutogenerated", true); 135 136 for (ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++) 137 rootElement.InsertEndChild(*child); 138 139 COUT(4) << " creating root-namespace..." << std::endl; 140 Namespace* rootNamespace = new Namespace(); 141 rootNamespace->setLoaderIndentation(" "); 142 rootNamespace->setLevel(level); 143 rootNamespace->setNamespace(rootNamespace); 144 rootNamespace->setRoot(true); 145 rootNamespace->XMLPort(rootElement, XMLPort::LoadObject); 151 146 152 147 COUT(0) << "Finished loading " << level->getFile() << "." << std::endl; 148 149 COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString(" ") << std::endl; 153 150 154 151 return true; -
code/trunk/src/orxonox/core/MetaObjectList.h
r1024 r1052 99 99 100 100 101 COUT(5) << "*** MetaObjectList: Removing Object from " << this->element_->object_->getIdentifier()->getName() << "-list." << std::endl;101 COUT(5) << "*** MetaObjectList: Removing Object from " << ClassManager<T>::getIdentifier()->getName() << "-list." << std::endl; 102 102 delete this->element_; 103 103 } -
code/trunk/src/orxonox/core/OrxonoxClass.h
r871 r1052 37 37 #define _OrxonoxClass_H__ 38 38 39 #include < list>39 #include <set> 40 40 #include <string> 41 41 … … 67 67 68 68 /** @brief Returns the list of all parents of the object. @return The list */ 69 inline std:: list<const Identifier*>* getParents() const { return this->parents_; }69 inline std::set<const Identifier*>* getParents() const { return this->parents_; } 70 70 71 71 /** @brief Creates the parents-list. */ 72 inline void createParents() { this->parents_ = new std:: list<const Identifier*>(); }72 inline void createParents() { this->parents_ = new std::set<const Identifier*>(); } 73 73 74 74 /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */ … … 157 157 private: 158 158 Identifier* identifier_; //!< The Identifier of the object 159 std:: list<const Identifier*>* parents_; //!< List of all parents of the object159 std::set<const Identifier*>* parents_; //!< List of all parents of the object 160 160 MetaObjectList metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 161 161 }; -
code/trunk/src/orxonox/core/OutputHandler.cc
r871 r1052 31 31 */ 32 32 33 #include " DebugLevel.h"33 #include "CoreSettings.h" 34 34 #include "OutputHandler.h" 35 #include "ConsoleCommand.h" 35 36 36 37 namespace orxonox 37 38 { 39 ConsoleCommandShortcutGeneric(log, createExecutor(createFunctor(&OutputHandler::log), "log", AccessLevel::None)); 40 38 41 /** 39 42 @brief Constructor: Opens the logfile and writes the first line. … … 44 47 this->logfilename_ = logfilename; 45 48 this->logfile_.open(this->logfilename_.c_str(), std::fstream::out); 46 this->logfile_ << "Started log " << std::endl;49 this->logfile_ << "Started log at yyyy/mm/dd hh:mm:ss" << std::endl; 47 50 this->logfile_.flush(); 48 51 } … … 74 77 int OutputHandler::getSoftDebugLevel(OutputHandler::OutputDevice device) 75 78 { 76 return DebugLevel::getSoftDebugLevel(device);79 return CoreSettings::getSoftDebugLevel(device); 77 80 } 78 81 -
code/trunk/src/orxonox/core/OutputHandler.h
r871 r1052 58 58 59 59 static OutputHandler& getOutStream(); 60 61 /** @brief Puts some text on the outstream. @param text The text */ 62 static inline std::string log(const std::string& text) 63 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; } 60 64 61 65 /** @brief Returns a reference to the logfile. @return The logfile */ -
code/trunk/src/orxonox/core/Tickable.cc
r1021 r1052 27 27 28 28 #include "core/CoreIncludes.h" 29 #include "core/ConsoleCommand.h" 29 30 #include "Tickable.h" 30 31 -
code/trunk/src/orxonox/core/XMLPort.cc
r871 r1052 29 29 #include "Language.h" 30 30 #include "Loader.h" 31 #include "Namespace.h" 32 #include "CoreIncludes.h" 31 33 32 34 namespace orxonox 33 35 { 34 // ###############################35 // ### XMLPortParamContainer ###36 // ###############################37 XMLPortParamContainer::XMLPortParamContainer()38 {39 this->bAddedDescription_ = false;40 this->bAddedDefaultValues_ = false;41 }42 43 XMLPortParamContainer& XMLPortParamContainer::description(const std::string description)44 {45 if (!this->bAddedDescription_)46 {47 this->description_ = std::string("XMLPortParamContainer::" + this->classname_ + "::" + this->paramname_);48 AddLanguageEntry(this->description_, description);49 this->bAddedDescription_ = true;50 }51 52 return (*this);53 }54 55 const std::string& XMLPortParamContainer::getDescription()56 {57 return GetLocalisation(this->description_);58 }59 60 61 36 // ################################ 62 37 // ### XMLPortObjectContainer ### 63 38 // ################################ 64 XMLPortObjectContainer::XMLPortObjectContainer()65 {66 this->bAddedDescription_ = false;67 }68 69 XMLPortObjectContainer& XMLPortObjectContainer::description(const std::string description)70 {71 if (!this->bAddedDescription_)72 {73 this->description_ = std::string("XMLPortObjectContainer::" + this->classname_ + "::" + this->sectionname_);74 AddLanguageEntry(this->description_, description);75 this->bAddedDescription_ = true;76 }77 78 return (*this);79 }80 81 const std::string& XMLPortObjectContainer::getDescription()82 {83 return GetLocalisation(this->description_);84 }85 86 39 bool XMLPortObjectContainer::identifierIsIncludedInLoaderMask(const Identifier* identifier) 87 40 { 88 return Loader::currentMask_s.isIncluded(identifier);41 return ((!this->bApplyLoaderMask_) || identifier->isA(Class(Namespace)) || Loader::currentMask_s.isIncluded(identifier)); 89 42 } 90 43 } -
code/trunk/src/orxonox/core/XMLPort.h
r871 r1052 32 32 #include "util/MultiTypeMath.h" 33 33 #include "util/tinyxml/ticpp.h" 34 #include "util/SubString.h" 35 #include "Functor.h" 34 #include "Executor.h" 36 35 #include "Debug.h" 37 36 #include "CoreIncludes.h" … … 41 40 42 41 43 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, loading) \ 44 orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 45 if (!xmlcontainer##loadfunction##savefunction) \ 42 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, mode) \ 43 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), #savefunction), xmlelement, mode) 44 #define XMLPortParam_Template(classname, paramname, loadtemplate, loadfunction, savetemplate, savefunction, xmlelement, mode) \ 45 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, paramname, orxonox::createExecutor(orxonox::createFunctor loadtemplate (&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor savetemplate (&classname::savefunction), #savefunction), xmlelement, mode) 46 47 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, mode) \ 48 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), #loadfunction), 0, xmlelement, mode) 49 #define XMLPortParamLoadOnly_Template(classname, paramname, loadtemplate, loadfunction, xmlelement, mode) \ 50 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, paramname, orxonox::createExecutor(orxonox::createFunctor loadtemplate (&classname::loadfunction), #loadfunction), 0, xmlelement, mode) 51 52 #define XMLPortParamGeneric(containername, classname, paramname, loadexecutor, saveexecutor, xmlelement, mode) \ 53 orxonox::XMLPortClassParamContainer<classname>* containername = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 54 if (!containername) \ 46 55 { \ 47 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), createFunctor(&classname::savefunction)); \48 this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \56 containername = new orxonox::XMLPortClassParamContainer<classname>(std::string(paramname), loadexecutor, saveexecutor); \ 57 this->getIdentifier()->addXMLPortParamContainer(paramname, containername); \ 49 58 } \ 50 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 51 52 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, loading) \ 53 orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 54 if (!xmlcontainer##loadfunction##savefunction) \ 59 containername->port(this, xmlelement, mode) 60 61 62 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 63 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 64 #define XMLPortObject_Template(classname, objectclass, sectionname, loadtemplate, loadfunction, savetemplate, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 65 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor loadtemplate (&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor savetemplate (&classname::savefunction), #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 66 67 #define XMLPortObjectGeneric(containername, classname, objectclass, sectionname, loadexecutor, saveexecutor, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 68 orxonox::XMLPortClassObjectContainer<classname, objectclass>* containername = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(this->getIdentifier()->getXMLPortObjectContainer(sectionname)); \ 69 if (!containername) \ 55 70 { \ 56 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), 0); \57 this->getIdentifier()->addXMLPort ParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \71 containername = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(std::string(sectionname), loadexecutor, saveexecutor, bApplyLoaderMask, bLoadBefore); \ 72 this->getIdentifier()->addXMLPortObjectContainer(sectionname, containername); \ 58 73 } \ 59 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 60 61 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading) \ 62 orxonox::XMLPortClassObjectContainer<classname, objectclass>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(this->getIdentifier()->getXMLPortObjectContainer(sectionname)); \ 63 if (!xmlcontainer##loadfunction##savefunction) \ 64 { \ 65 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(this->getIdentifier()->getName(), std::string(sectionname), &classname::loadfunction, &classname::savefunction); \ 66 this->getIdentifier()->addXMLPortObjectContainer(sectionname, xmlcontainer##loadfunction##savefunction); \ 67 } \ 68 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 74 containername->port(this, xmlelement, mode) 69 75 70 76 71 77 namespace orxonox 72 78 { 79 80 #ifndef _XMLPort_Mode__ 81 #define _XMLPort_Mode__ 82 namespace XMLPort 83 { 84 enum Mode 85 { 86 LoadObject, 87 SaveObject 88 }; 89 } 90 #endif 91 73 92 // ############################### 74 93 // ### XMLPortParamContainer ### … … 76 95 class _CoreExport XMLPortParamContainer 77 96 { 97 enum ParseResult 98 { 99 PR_not_started, 100 PR_finished, 101 PR_waiting_for_default_values 102 }; 103 78 104 public: 79 XMLPortParamContainer(); 105 XMLPortParamContainer() 106 { this->parseResult_ = PR_not_started; } 107 virtual ~XMLPortParamContainer() {} 80 108 81 109 inline const std::string& getName() const 82 110 { return this->paramname_; } 83 111 84 XMLPortParamContainer& description(const std::string description); 85 const std::string& getDescription(); 86 87 XMLPortParamContainer& defaultValues(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 88 { 89 this->defaultValues_[0] = param1; 90 this->defaultValues_[1] = param2; 91 this->defaultValues_[2] = param3; 92 this->defaultValues_[3] = param4; 93 this->defaultValues_[4] = param5; 94 95 return (*this); 96 } 112 virtual XMLPortParamContainer& description(const std::string description) = 0; 113 virtual const std::string& getDescription() = 0; 114 115 virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiTypeMath& param) = 0; 116 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1) = 0; 117 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) = 0; 118 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) = 0; 119 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) = 0; 120 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) = 0; 97 121 98 122 protected: 99 std::string classname_;100 123 std::string paramname_; 101 MultiTypeMath defaultValues_[5]; 102 103 private: 104 LanguageEntryLabel description_; 105 bool bAddedDescription_; 106 bool bAddedDefaultValues_; 124 ParseResult parseResult_; 125 107 126 }; 108 127 … … 110 129 class XMLPortClassParamContainer : public XMLPortParamContainer 111 130 { 131 struct ParseParams 132 { 133 T* object; 134 Element* xmlelement; 135 XMLPort::Mode mode; 136 }; 137 112 138 public: 113 XMLPortClassParamContainer(const std::string classname, const std::string paramname, FunctorMember<T>* loadfunction, FunctorMember<T>* savefunction) 114 { 115 this->classname_ = classname; 139 XMLPortClassParamContainer(const std::string paramname, ExecutorMember<T>* loadexecutor, ExecutorMember<T>* saveexecutor) 140 { 116 141 this->paramname_ = paramname; 117 this->loadfunction_ = loadfunction; 118 this->savefunction_ = savefunction; 119 } 120 121 XMLPortParamContainer& port(T* object, Element& xmlelement, bool loading) 122 { 123 if (loading) 142 this->loadexecutor_ = loadexecutor; 143 this->saveexecutor_ = saveexecutor; 144 } 145 146 XMLPortParamContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode) 147 { 148 this->parseParams_.object = object; 149 this->parseParams_.xmlelement = &xmlelement; 150 this->parseParams_.mode = mode; 151 152 if (mode == XMLPort::LoadObject) 124 153 { 125 154 try 126 155 { 127 156 std::string attribute = xmlelement.GetAttribute(this->paramname_); 128 if ( attribute.size() > 0)157 if ((attribute.size() > 0) || (this->loadexecutor_->allDefaultValuesSet())) 129 158 { 130 SubString tokens(attribute, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 131 if ((unsigned int)tokens.size() >= (unsigned int)this->loadfunction_->getParamCount()) 132 { 133 COUT(5) << object->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->classname_ << " (objectname " << object->getName() << ") with "; 134 if (this->loadfunction_->getParamCount() == 1) 135 { 136 COUT(5) << "1 parameter (using whole string):" << std::endl; 137 COUT(5) << object->getLoaderIndentation() << " " << attribute << std::endl; 138 (*this->loadfunction_)(object, MultiTypeMath(attribute)); 139 } 140 else 141 { 142 COUT(5) << tokens.size() << " parameter (using MultiTypeMath)." << std::endl; 143 MultiTypeMath param1 = MT_null, param2 = MT_null, param3 = MT_null, param4 = MT_null, param5 = MT_null; 144 if (tokens.size() >= 1) param1 = tokens[0]; 145 if (tokens.size() >= 2) param2 = tokens[1]; 146 if (tokens.size() >= 3) param3 = tokens[2]; 147 if (tokens.size() >= 4) param4 = tokens[3]; 148 if (tokens.size() >= 5) param5 = tokens[4]; 149 COUT(5) << object->getLoaderIndentation() << " " << attribute << std::endl; 150 COUT(5) << object->getLoaderIndentation() << " " << param1 << ", " << param2 << ", " << param3 << ", " << param4 << ", " << param5 << std::endl; 151 152 (*this->loadfunction_)(object, param1, param2, param3, param4, param5); 153 } 154 } 159 COUT(5) << object->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << object->getIdentifier()->getName() << " (objectname " << object->getName() << ")." << std::endl << object->getLoaderIndentation(); 160 if (this->loadexecutor_->parse(object, attribute, ",")) 161 this->parseResult_ = PR_finished; 155 162 else 156 { 157 COUT(2) << object->getLoaderIndentation() << "Warning: Parameter \"" << this->paramname_ << "\" in \"" << this->classname_ << "\" (objectname: " << object->getName() << ") is incomplete and couln't be loaded." << std::endl; 158 } 163 this->parseResult_ = PR_waiting_for_default_values; 159 164 } 160 165 } … … 162 167 { 163 168 COUT(1) << std::endl; 164 COUT(1) << "An error occurred in XMLPort.h while loading attribute '" << this->paramname_ << "' of '" << this->classname_<< "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl;169 COUT(1) << "An error occurred in XMLPort.h while loading attribute '" << this->paramname_ << "' of '" << object->getIdentifier()->getName() << "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl; 165 170 COUT(1) << ex.what() << std::endl; 166 171 } … … 168 173 else 169 174 { 170 if (this->save function_)175 if (this->saveexecutor_) 171 176 { 172 177 // xmlelement.SetAttribute(this->paramname_, "..."); … … 177 182 } 178 183 184 XMLPortParamContainer& port(const ParseParams& parseParams) 185 { 186 return this->port(parseParams.object, *parseParams.xmlelement, parseParams.mode); 187 } 188 189 XMLPortParamContainer& portIfWaitingForDefaultValues(const ParseResult& result, const ParseParams& params) 190 { 191 if (result == PR_waiting_for_default_values) 192 return this->port(params); 193 else 194 return (*this); 195 } 196 197 virtual XMLPortParamContainer& description(const std::string description) 198 { this->loadexecutor_->setDescription(description); return (*this); } 199 virtual const std::string& getDescription() 200 { return this->loadexecutor_->getDescription(); } 201 202 virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiTypeMath& param) 203 { 204 if (!this->loadexecutor_->defaultValueSet(index)) 205 this->loadexecutor_->setDefaultValue(index, param); 206 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 207 } 208 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1) 209 { 210 if (!this->loadexecutor_->defaultValueSet(0)) 211 this->loadexecutor_->setDefaultValues(param1); 212 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 213 } 214 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) 215 { 216 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1))) 217 this->loadexecutor_->setDefaultValues(param1, param2); 218 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 219 } 220 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) 221 { 222 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1)) || (!this->loadexecutor_->defaultValueSet(2))) 223 this->loadexecutor_->setDefaultValues(param1, param2, param3); 224 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 225 } 226 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) 227 { 228 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1)) || (!this->loadexecutor_->defaultValueSet(2)) || (!this->loadexecutor_->defaultValueSet(3))) 229 this->loadexecutor_->setDefaultValues(param1, param2, param3, param4); 230 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 231 } 232 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) 233 { 234 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1)) || (!this->loadexecutor_->defaultValueSet(2)) || (!this->loadexecutor_->defaultValueSet(3)) || (!this->loadexecutor_->defaultValueSet(4))) 235 this->loadexecutor_->setDefaultValues(param1, param2, param3, param4, param5); 236 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 237 } 238 179 239 private: 180 FunctorMember<T>* loadfunction_; 181 FunctorMember<T>* savefunction_; 240 ExecutorMember<T>* loadexecutor_; 241 ExecutorMember<T>* saveexecutor_; 242 ParseParams parseParams_; 182 243 }; 183 244 … … 189 250 { 190 251 public: 191 XMLPortObjectContainer(); 252 XMLPortObjectContainer() 253 { this->bApplyLoaderMask_ = false; } 254 virtual ~XMLPortObjectContainer() {} 192 255 193 256 inline const std::string& getName() const 194 257 { return this->sectionname_; } 195 258 196 XMLPortObjectContainer& description(const std::string description); 197 const std::string& getDescription(); 198 static bool identifierIsIncludedInLoaderMask(const Identifier* identifier); 259 virtual XMLPortObjectContainer& description(const std::string description) = 0; 260 virtual const std::string& getDescription() = 0; 261 262 bool identifierIsIncludedInLoaderMask(const Identifier* identifier); 199 263 200 264 protected: 201 std::string classname_;202 265 std::string sectionname_; 203 204 private: 205 LanguageEntryLabel description_; 206 bool bAddedDescription_; 266 bool bApplyLoaderMask_; 267 bool bLoadBefore_; 207 268 }; 208 269 … … 211 272 { 212 273 public: 213 XMLPortClassObjectContainer(const std::string classname, const std::string sectionname, void (T::*loadfunction)(O*), const O* (T::*savefunction)(unsigned int)) 214 { 215 this->classname_ = classname; 274 XMLPortClassObjectContainer(const std::string sectionname, ExecutorMember<T>* loadexecutor, ExecutorMember<T>* saveexecutor, bool bApplyLoaderMask, bool bLoadBefore) 275 { 216 276 this->sectionname_ = sectionname; 217 this->loadfunction_ = loadfunction; 218 this->savefunction_ = savefunction; 219 } 220 221 XMLPortObjectContainer& port(T* object, Element& xmlelement, bool loading) 222 { 223 if (loading) 277 this->loadexecutor_ = loadexecutor; 278 this->saveexecutor_ = saveexecutor; 279 this->bApplyLoaderMask_ = bApplyLoaderMask; 280 this->bLoadBefore_ = bLoadBefore; 281 } 282 283 XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode) 284 { 285 if (mode == XMLPort::LoadObject) 224 286 { 225 287 try 226 288 { 227 Element* xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 289 Element* xmlsubelement; 290 if ((this->sectionname_ != "") && (this->sectionname_.size() > 0)) 291 xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 292 else 293 xmlsubelement = &xmlelement; 228 294 229 295 if (xmlsubelement) 230 296 { 231 for ( ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)297 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 232 298 { 233 299 Identifier* identifier = ID(child->Value()); … … 239 305 { 240 306 COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl; 307 241 308 O* newObject = (O*)identifier->fabricate(); 242 309 newObject->setLoaderIndentation(object->getLoaderIndentation() + " "); 243 310 newObject->setLevel(object->getLevel()); 244 newObject->XMLPort(*child, true); 245 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl; 246 (*object.*this->loadfunction_)(newObject); 247 COUT(5) << " ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 311 newObject->setNamespace(object->getNamespace()); 312 313 if (this->bLoadBefore_) 314 { 315 newObject->XMLPort(*child, XMLPort::LoadObject); 316 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << object->getIdentifier()->getName() << " (objectname " << object->getName() << ")" << std::endl; 317 } 318 else 319 { 320 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << object->getIdentifier()->getName() << " (objectname " << object->getName() << ")" << std::endl; 321 } 322 323 COUT(5) << object->getLoaderIndentation(); 324 (*this->loadexecutor_)(object, newObject); 325 326 if (!this->bLoadBefore_) 327 newObject->XMLPort(*child, XMLPort::LoadObject); 328 329 COUT(5) << object->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 248 330 } 249 331 } … … 263 345 { 264 346 COUT(1) << std::endl; 265 COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << this->classname_<< "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl;347 COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << object->getIdentifier()->getName() << "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl; 266 348 COUT(1) << ex.what() << std::endl; 267 349 } … … 274 356 } 275 357 358 virtual XMLPortObjectContainer& description(const std::string description) 359 { this->loadexecutor_->setDescription(description); return (*this); } 360 virtual const std::string& getDescription() 361 { return this->loadexecutor_->getDescription(); } 362 276 363 private: 277 void (T::*loadfunction_)(O*);278 const O* (T::*savefunction_)(unsigned int);364 ExecutorMember<T>* loadexecutor_; 365 ExecutorMember<T>* saveexecutor_; 279 366 }; 280 367 } -
code/trunk/src/orxonox/objects/Ambient.cc
r1039 r1052 42 42 #include "GraphicsEngine.h" 43 43 #include "core/XMLPort.h" 44 #include "core/ConsoleCommand.h" 44 45 45 46 namespace orxonox 46 47 { 48 ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1)); 49 47 50 CreateFactory(Ambient); 51 52 Ambient* Ambient::instance_s; 48 53 49 54 Ambient::Ambient() 50 55 { 51 56 RegisterObject(Ambient); 57 Ambient::instance_s = this; 52 58 } 53 59 … … 84 90 @return The XML-element 85 91 */ 86 void Ambient::XMLPort(Element& xmlelement, bool loading)92 void Ambient::XMLPort(Element& xmlelement, XMLPort::Mode mode) 87 93 { 88 BaseObject::XMLPort(xmlelement, loading);94 BaseObject::XMLPort(xmlelement, mode); 89 95 90 XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, loading);96 XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode); 91 97 } 92 98 } -
code/trunk/src/orxonox/objects/Ambient.h
r1040 r1052 43 43 44 44 void loadParams(TiXmlElement* xmlElem); 45 virtual void XMLPort(Element& xmlelement, bool loading);45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 46 void setAmbientLight(const ColourValue& colour); 47 47 48 static void setAmbientLightTest(const ColourValue& colour) 49 { Ambient::instance_s->setAmbientLight(colour); } 50 48 51 private: 49 52 static Ambient* instance_s; 50 53 51 54 }; -
code/trunk/src/orxonox/objects/Explosion.cc
r1039 r1052 34 34 35 35 #include "core/CoreIncludes.h" 36 #include "core/Executor.h" 37 36 38 #include "util/Math.h" 37 39 #include "GraphicsEngine.h" … … 51 53 if (owner) 52 54 { 53 this->destroyTimer_.setTimer(this->lifetime_, false, this, &Explosion::destroyObject);55 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Explosion::destroyObject))); 54 56 55 57 Vector3 position = owner->getNode()->getWorldPosition(); -
code/trunk/src/orxonox/objects/Model.cc
r1039 r1052 68 68 @return The XML-element 69 69 */ 70 void Model::XMLPort(Element& xmlelement, bool loading)70 void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode) 71 71 { 72 WorldEntity::XMLPort(xmlelement, loading);72 WorldEntity::XMLPort(xmlelement, mode); 73 73 74 XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, loading);74 XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, mode); 75 75 76 76 create(); … … 84 84 bool Model::create(){ 85 85 WorldEntity::create(); 86 if(meshSrc_.compare("")!=0){ 86 if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0)) 87 { 87 88 this->mesh_.setMesh(meshSrc_); 88 89 this->attachObject(this->mesh_.getEntity()); -
code/trunk/src/orxonox/objects/Model.h
r1039 r1052 43 43 virtual ~Model(); 44 44 virtual void loadParams(TiXmlElement* xmlElem); 45 virtual void XMLPort(Element& xmlelement, bool loading);45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 46 void setMesh(const std::string& meshname); 47 47 bool create(); -
code/trunk/src/orxonox/objects/Projectile.cc
r1039 r1052 29 29 #include "Projectile.h" 30 30 31 #include "../core/CoreIncludes.h" 31 #include "core/CoreIncludes.h" 32 #include "core/Executor.h" 33 #include "core/ConfigValueIncludes.h" 34 32 35 #include "SpaceShip.h" 33 36 #include "Explosion.h" … … 59 62 } 60 63 61 this->destroyTimer_.setTimer(this->lifetime_, false, this, &Projectile::destroyObject);64 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 62 65 } 63 66 … … 70 73 SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive"); 71 74 SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second"); 75 76 this->setVelocity(Vector3(1, 0, 0) * this->speed_); 72 77 } 73 78 -
code/trunk/src/orxonox/objects/Skybox.cc
r1039 r1052 76 76 @return The XML-element 77 77 */ 78 void Skybox::XMLPort(Element& xmlelement, bool loading)78 void Skybox::XMLPort(Element& xmlelement, XMLPort::Mode mode) 79 79 { 80 BaseObject::XMLPort(xmlelement, loading);80 BaseObject::XMLPort(xmlelement, mode); 81 81 82 XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, loading);82 XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode); 83 83 } 84 84 } -
code/trunk/src/orxonox/objects/Skybox.h
r1039 r1052 15 15 16 16 void loadParams(TiXmlElement* xmlElem); 17 virtual void XMLPort(Element& xmlelement, bool loading);17 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 18 18 void setSkybox(const std::string& skyboxname); 19 19 -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1039 r1052 41 41 #include "util/Math.h" 42 42 #include "core/CoreIncludes.h" 43 #include "core/ConfigValueIncludes.h" 43 44 #include "core/Debug.h" 44 45 #include "GraphicsEngine.h" … … 47 48 #include "Projectile.h" 48 49 #include "core/XMLPort.h" 50 #include "core/ConsoleCommand.h" 49 51 50 52 namespace orxonox 51 53 { 54 ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false); 55 ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false); 56 ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false); 57 ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false); 58 52 59 CreateFactory(SpaceShip); 60 61 SpaceShip* SpaceShip::instance_s; 53 62 54 63 SpaceShip::SpaceShip() … … 56 65 RegisterObject(SpaceShip); 57 66 this->registerAllVariables(); 67 68 SpaceShip::instance_s = this; 58 69 59 70 this->setConfigValues(); … … 309 320 @return The XML-element 310 321 */ 311 void SpaceShip::XMLPort(Element& xmlelement, bool loading)312 { 313 Model::XMLPort(xmlelement, loading);314 315 XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, loading);316 XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, loading);317 XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, loading);318 XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, loading);319 XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, loading);320 XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, loading);321 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, loading);322 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, loading);322 void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) 323 { 324 Model::XMLPort(xmlelement, mode); 325 326 XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode); 327 XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode); 328 XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode); 329 XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode); 330 XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode); 331 XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode); 332 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 333 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 323 334 } 324 335 -
code/trunk/src/orxonox/objects/SpaceShip.h
r1039 r1052 49 49 void setConfigValues(); 50 50 virtual void loadParams(TiXmlElement* xmlElem); 51 virtual void XMLPort(Element& xmlelement, bool loading);51 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 52 52 virtual void tick(float dt); 53 53 … … 61 61 void setRotDamp(float value); 62 62 63 static void setMaxSpeedTest(float value) 64 { SpaceShip::instance_s->setMaxSpeed(value); } 65 63 66 bool mouseMoved(const OIS::MouseEvent &e); 64 67 bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id); … … 67 70 68 71 private: 72 static SpaceShip* instance_s; 73 69 74 Vector3 testvector_; 70 75 bool bInvertYAxis_; -
code/trunk/src/orxonox/objects/WorldEntity.cc
r1039 r1052 176 176 @return The XML-element 177 177 */ 178 void WorldEntity::XMLPort(Element& xmlelement, bool loading)179 { 180 BaseObject::XMLPort(xmlelement, loading);181 182 XMLPortParam(WorldEntity, "position", setPositionLoader2, getPosition, xmlelement, loading);183 XMLPortParamLoadOnly(WorldEntity, "direction", setDirectionLoader, xmlelement, loading);184 XMLPortParamLoadOnly(WorldEntity, "yawpitchroll", setYawPitchRoll, xmlelement, loading);185 XMLPortParam(WorldEntity, "scale", setTotalScale, getScale, xmlelement, loading);186 XMLPortParam(WorldEntity, "rotationAxis", setRotationAxisLoader, getRotationAxis, xmlelement, loading);187 XMLPortParam(WorldEntity, "rotationRate", setRotationRate, getRotationRate, xmlelement, loading);188 189 XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, loading);178 void WorldEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode) 179 { 180 BaseObject::XMLPort(xmlelement, mode); 181 182 XMLPortParam(WorldEntity, "position", setPositionLoader2, getPosition, xmlelement, mode); 183 XMLPortParamLoadOnly(WorldEntity, "direction", setDirectionLoader, xmlelement, mode); 184 XMLPortParamLoadOnly(WorldEntity, "yawpitchroll", setYawPitchRoll, xmlelement, mode); 185 XMLPortParam(WorldEntity, "scale", setTotalScale, getScale, xmlelement, mode); 186 XMLPortParam(WorldEntity, "rotationAxis", setRotationAxisLoader, getRotationAxis, xmlelement, mode); 187 XMLPortParam(WorldEntity, "rotationRate", setRotationRate, getRotationRate, xmlelement, mode); 188 189 XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true); 190 190 } 191 191 … … 219 219 } 220 220 221 const WorldEntity* WorldEntity::getAttachedWorldEntity(unsigned int index) 221 const WorldEntity* WorldEntity::getAttachedWorldEntity(unsigned int index) const 222 222 { 223 223 if (index < this->attachedWorldEntities_.size()) -
code/trunk/src/orxonox/objects/WorldEntity.h
r1039 r1052 51 51 virtual void tick(float dt); 52 52 virtual void loadParams(TiXmlElement* xmlElem); 53 virtual void XMLPort(Element& xmlelement, bool loading);53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 54 inline bool create(){ return true; } 55 55 56 56 void attachWorldEntity(WorldEntity* entity); 57 const WorldEntity* getAttachedWorldEntity(unsigned int index) ;57 const WorldEntity* getAttachedWorldEntity(unsigned int index) const; 58 58 59 59 inline Ogre::SceneNode* getNode() -
code/trunk/src/orxonox/tools/Timer.cc
r1039 r1052 27 27 28 28 #include "OrxonoxStableHeaders.h" 29 #include "core/Executor.h" 30 #include "core/CoreIncludes.h" 31 #include "core/ConsoleCommand.h" 32 #include "core/CommandExecutor.h" 29 33 #include "Timer.h" 30 31 #include "core/CoreIncludes.h"32 34 33 35 namespace orxonox 34 36 { 37 ConsoleCommandShortcutExtern(delay, AccessLevel::None); 38 39 /** 40 @brief Calls a console command after 'delay' seconds. 41 @param delay The delay in seconds 42 @param command The console command 43 */ 44 void delay(float delay, const std::string& command) 45 { 46 StaticTimer *delaytimer = new StaticTimer(); 47 ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand)); 48 delayexecutor->setDefaultValues(delaytimer, command); 49 delaytimer->setTimer(delay, false, delayexecutor); 50 } 51 52 /** 53 @brief Executes the command. 54 @param timer The timer to destroy after the command-execution 55 @param command The command to execute 56 */ 57 void executeDelayedCommand(StaticTimer* timer, const std::string& command) 58 { 59 CommandExecutor::execute(command); 60 delete timer; 61 } 62 35 63 /** 36 64 @brief Constructor: Sets the default-values. … … 40 68 RegisterRootObject(TimerBase); 41 69 70 this->executor_ = 0; 42 71 this->interval_ = 0; 43 72 this->bLoop_ = false; … … 45 74 46 75 this->time_ = 0; 76 } 77 78 /** 79 @brief Deletes the executor. 80 */ 81 TimerBase::~TimerBase() 82 { 83 delete this->executor_; 84 } 85 86 /** 87 @brief Executes the executor. 88 */ 89 void TimerBase::run() const 90 { 91 (*this->executor_)(); 47 92 } 48 93 -
code/trunk/src/orxonox/tools/Timer.h
r1039 r1052 43 43 44 44 source.cc: 45 include "core/Executor.h" 46 45 47 ClassName::ClassName() 46 48 { 47 myTimer.setTimer(interval_in_seconds, bLoop, this, &ClassName::functionName);49 myTimer.setTimer(interval_in_seconds, bLoop, this, createExecutor(createFunctor(&ClassName::functionName))); 48 50 } 49 51 … … 59 61 60 62 #include "OrxonoxPrereqs.h" 61 63 #include "core/CorePrereqs.h" 62 64 #include "core/Tickable.h" 63 65 64 66 namespace orxonox 65 67 { 68 class StaticTimer; 69 void delay(float delay, const std::string& command); 70 void executeDelayedCommand(StaticTimer* timer, const std::string& command); 71 66 72 //! TimerBase is the parent of the Timer class. 67 73 class _OrxonoxExport TimerBase : public Tickable 68 74 { 69 75 public: 70 TimerBase();76 ~TimerBase(); 71 77 72 v irtual void run() const = 0;78 void run() const; 73 79 74 80 /** @brief Starts the Timer: Function-call after 'interval' seconds. */ 75 inline void startTimer() { this->bActive_ = true; this->time_ = this->interval_; } 81 inline void startTimer() 82 { this->bActive_ = true; this->time_ = this->interval_; } 76 83 /** @brief Stops the Timer. */ 77 inline void stopTimer() { this->bActive_ = false; this->time_ = this->interval_; } 84 inline void stopTimer() 85 { this->bActive_ = false; this->time_ = this->interval_; } 78 86 /** @brief Pauses the Timer - it will continue with the actual state if you unpause it. */ 79 inline void pauseTimer() { this->bActive_ = false; } 87 inline void pauseTimer() 88 { this->bActive_ = false; } 80 89 /** @brief Unpauses the Timer - continues with the given state. */ 81 inline void unpauseTimer() { this->bActive_ = true; } 90 inline void unpauseTimer() 91 { this->bActive_ = true; } 82 92 /** @brief Returns true if the Timer is active (= not stoped, not paused). @return True = Time is active */ 83 inline bool isActive() const { return this->bActive_; } 93 inline bool isActive() const 94 { return this->bActive_; } 95 /** @brief Gives the Timer some extra time. @param time The amount of extra time in seconds */ 96 inline void addTime(float time) 97 { this->time_ += time; } 98 /** @brief Decreases the remaining time of the Timer. @param time The amount of time to remove */ 99 inline void removeTime(float time) 100 { this->time_ -= time; } 101 /** @brief Sets the interval of the Timer. @param interval The interval */ 102 inline void setInterval(float interval) 103 { this->interval_ = interval; } 104 /** @brief Sets bLoop to a given value. @param bLoop True = loop */ 105 inline void setLoop(bool bLoop) 106 { this->bLoop_ = bLoop; } 84 107 85 108 void tick(float dt); 86 109 87 110 protected: 88 float interval_; //!< The time-interval in seconds 89 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 90 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 111 TimerBase(); 91 112 92 float time_; //!< Internal variable, counting the time till the next function-call 113 Executor* executor_; //!< The executor of the function that should be called when the time expires 114 115 float interval_; //!< The time-interval in seconds 116 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 117 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 118 119 float time_; //!< Internal variable, counting the time till the next function-call 93 120 }; 94 121 … … 98 125 { 99 126 public: 100 /** @brief Constructor: Sets the default-values. */ 101 Timer() 102 { 103 this->timerFunction_ = 0; 104 this->object_ = 0; 105 } 127 Timer() {} 106 128 107 129 /** … … 110 132 @param bLoop If true, the function gets called every 'interval' seconds 111 133 @param object The object owning the timer and the function 112 @param timerFunction A function pointer tothe function to call134 @param exeuctor A executor of the function to call 113 135 */ 114 Timer(float interval, bool bLoop, T* object, void (T::*timerFunction)())136 Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor) 115 137 { 116 this->setTimer(interval, bLoop, timerFunction, object);138 this->setTimer(interval, bLoop, object, exeuctor); 117 139 } 118 140 … … 122 144 @param bLoop If true, the function gets called every 'interval' seconds 123 145 @param object The object owning the timer and the function 124 @param timerFunction A function pointer tothe function to call146 @param exeuctor A executor of the function to call 125 147 */ 126 void setTimer(float interval, bool bLoop, T* object, void (T::*timerFunction)())148 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor) 127 149 { 128 150 this->interval_ = interval; 129 151 this->bLoop_ = bLoop; 130 this->timerFunction_ = timerFunction;131 this-> object_ = object;152 executor->setObject(object); 153 this->executor_ = (Executor*)executor; 132 154 this->bActive_ = true; 133 155 134 156 this->time_ = interval; 135 157 } 158 }; 136 159 137 /** @brief Calls the given function of the given object. */ 138 void run() const 160 //! The StaticTimer is a callback-object, calling a static function after a given time-interval. 161 class StaticTimer : public TimerBase 162 { 163 public: 164 StaticTimer() {} 165 166 /** 167 @brief Constructor: Initializes the Timer with given values. 168 @param interval The timer-interval in seconds 169 @param bLoop If true, the function gets called every 'interval' seconds 170 @param exeuctor A executor of the function to call 171 */ 172 StaticTimer(float interval, bool bLoop, ExecutorStatic* executor) 139 173 { 140 ((*this->object_).*timerFunction_)();174 this->setTimer(interval, bLoop, executor); 141 175 } 142 176 143 private: 144 void (T::*timerFunction_)(); 145 T* object_; 177 /** 178 @brief Initializes the Timer with given values. 179 @param interval The timer-interval in seconds 180 @param bLoop If true, the function gets called every 'interval' seconds 181 @param object The object owning the timer and the function 182 @param executor A executor of the function to call 183 */ 184 void setTimer(float interval, bool bLoop, ExecutorStatic* executor) 185 { 186 this->interval_ = interval; 187 this->bLoop_ = bLoop; 188 this->executor_ = (Executor*)executor; 189 this->bActive_ = true; 190 191 this->time_ = interval; 192 } 146 193 }; 147 194 -
code/trunk/src/util/CMakeLists.txt
r1051 r1052 8 8 Math.cc 9 9 String.cc 10 Clipboard.cc 10 11 SubString.cc 11 12 MultiTypePrimitive.cc -
code/trunk/src/util/Convert.h
r871 r1052 21 21 * Author: 22 22 * Benjamin Grauer 23 * Fabian 'x3n' Landau 23 24 * Co-authors: 24 * Fabian 'x3n' Landau25 * ... 25 26 */ 26 27 … … 42 43 43 44 44 // DEFAULT CLASS 45 template <typename FromType, typename ToType> 46 class Converter 47 { 48 public: 49 bool operator()(ToType* output, const FromType& input) const 50 { 51 return false; 52 } 53 }; 54 55 // PARTIAL SPECIALIZATION TO CONVERT TO STRINGS 56 template<typename FromType> 57 class Converter<FromType, std::string> 58 { 59 public: 60 bool operator()(std::string* output, const FromType& input) const 61 { 62 std::ostringstream oss; 63 if (oss << input) 64 { 65 (*output) = oss.str(); 45 ////////// 46 // MAIN // 47 ////////// 48 49 // Enum to declare the wanted conversion preference in case of equal type-levels 50 enum ConversionPreference 51 { 52 CP_PreferToType, 53 CP_PreferFromType, 54 }; 55 56 // Helper classes to determine the preferred partial template specialization 57 class _ToType_ {}; 58 class _FromType_ {}; 59 class _Explicit_ {}; 60 61 62 // The default convert functions 63 template <class FromType, class ToType, class Type> 64 struct ConverterSpecialized 65 { 66 enum { specialized = false }; 67 static bool convert(ToType* output, const FromType& input) 68 { return false; } 69 }; 70 71 72 // The default convert function if both types are the same 73 template <class BothTypes> 74 struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_> 75 { 76 enum { specialized = true }; 77 static bool convert(BothTypes* output, const BothTypes& input) 78 { (*output) = input; return true; } 79 }; 80 81 82 // The possible levels 83 #define __low__ 0 // Everything that is or behaves like a primitive type (an can be converted with a typecast to every other low-level type) 84 #define __mid__ 1 // Everything that has overloaded << and >> operators to operate on a std::stream 85 #define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions 86 87 // Defines the levels of all types: Default is __high__ so you don't have to define every high-level type 88 template <class T> struct ConverterLevel { enum { level = __high__ }; }; 89 template <> struct ConverterLevel<std::string> { enum { level = __mid__ }; }; 90 template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; }; 91 template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; }; 92 template <> struct ConverterLevel<int> { enum { level = __low__ }; }; 93 template <> struct ConverterLevel<unsigned int> { enum { level = __low__ }; }; 94 template <> struct ConverterLevel<char> { enum { level = __low__ }; }; 95 template <> struct ConverterLevel<unsigned char> { enum { level = __low__ }; }; 96 template <> struct ConverterLevel<short> { enum { level = __low__ }; }; 97 template <> struct ConverterLevel<unsigned short> { enum { level = __low__ }; }; 98 template <> struct ConverterLevel<long> { enum { level = __low__ }; }; 99 template <> struct ConverterLevel<unsigned long> { enum { level = __low__ }; }; 100 template <> struct ConverterLevel<float> { enum { level = __low__ }; }; 101 template <> struct ConverterLevel<double> { enum { level = __low__ }; }; 102 template <> struct ConverterLevel<long double> { enum { level = __low__ }; }; 103 template <> struct ConverterLevel<bool> { enum { level = __low__ }; }; 104 105 106 // Calculates the preference based on the levels of FromType and ToType 107 template <int from, int to> 108 struct ConverterPreference 109 { 110 enum 111 { 112 // The maximum of both levels: element of {0, 1, 2} 113 // max 0: Both types are primitives or have a similar behaviour 114 // max 1: At least one type is not a primitive, but both can be put on a std::stream 115 // max 2: There is at least one generic type that needs specialized conversions 116 max = (from > to) ? from : to, 117 118 // The difference between both levels limited to +-1: element of {-1, 0, 1} 119 // diff -1: The FromType has higher level than the ToType 120 // diff 0: Both types have the same level 121 // diff 1: The ToType has higher level than the FromType 122 diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from) 123 }; 124 }; 125 126 127 // The default conversion: This usually does nothing 128 template <int max, class FromType, class ToType> 129 struct ConverterDefault 130 { 131 static bool convert(ToType* output, const FromType& input) 132 { 133 return false; 134 } 135 }; 136 // The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes) template <int max, class FromType, class ToType> 137 template <class FromType, class ToType> 138 struct ConverterDefault<0, FromType, ToType> 139 { 140 static bool convert(ToType* output, const FromType& input) 141 { 142 (*output) = (ToType)input; 66 143 return true; 67 } 68 else 69 return false; 70 } 71 }; 72 73 // PARTIAL SPECIALIZATION TO CONVERT FROM STRING 74 template<typename ToType> 75 class Converter<std::string, ToType> 76 { 77 public: 78 bool operator()(ToType* output, const std::string& input) const 79 { 80 std::istringstream iss(input); 81 if (iss >> (*output)) 144 } 145 }; 146 147 148 // Converter: Converts input of FromType into output of ToType 149 template <int diff, int max, class FromType, class ToType, ConversionPreference pref> 150 struct Converter 151 { 152 static bool convert(ToType* output, const FromType& input) 153 { 154 return false; 155 } 156 }; 157 // Converter: level{FromType} > level{ToType} 158 template <int max, class FromType, class ToType, ConversionPreference pref> 159 struct Converter<-1, max, FromType, ToType, pref> 160 { static bool convert(ToType* output, const FromType& input) 161 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 162 // Converter: level{FromType} < level{ToType} 163 template <int max, class FromType, class ToType, ConversionPreference pref> 164 struct Converter<1, max, FromType, ToType, pref> 165 { static bool convert(ToType* output, const FromType& input) 166 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 167 // Converter: level{FromType} = level{ToType} 168 // CP_PreferToType 169 template <int max, class FromType, class ToType> 170 struct Converter<0, max, FromType, ToType, CP_PreferToType> 171 { static bool convert(ToType* output, const FromType& input) 172 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 173 // CP_PreferFromType 174 template <int max, class FromType, class ToType> 175 struct Converter<0, max, FromType, ToType, CP_PreferFromType> 176 { static bool convert(ToType* output, const FromType& input) 177 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 178 179 180 // Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference 181 template <class FromType, class ToType> 182 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 183 { 184 return (preference == CP_PreferToType) ? 185 Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 186 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 187 FromType, 188 ToType, 189 CP_PreferToType>::convert(output, input) 190 : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 191 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 192 FromType, 193 ToType, 194 CP_PreferFromType>::convert(output, input); 195 } 196 197 198 ////////////////////// 199 // HELPER FUNCTIONS // 200 ////////////////////// 201 202 // Helper function: Calls convertValue with and without default value and returns true if the conversion was successful 203 template<class FromType, class ToType> 204 static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 205 { 206 return convertValue(output, input, preference); 207 } 208 template<class FromType, class ToType> 209 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 210 { 211 if (convertValue(output, input, preference)) 82 212 return true; 83 else 84 return false; 85 } 86 }; 87 88 // FUNCTION SO WE DO NOT HAVE TO TELL THE COMPILER ABOUT THE TYPE 89 template<typename FromType, typename ToType> 90 static bool ConvertValue(ToType* output, const FromType& input) 91 { 92 Converter<FromType, ToType> converter; 93 return converter(output, input); 213 214 (*output) = fallback; 215 return false; 94 216 } 95 217 96 // THE SAME, BUT WITH DEFAULT VALUE 97 template<typename FromType, typename ToType> 98 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback) 99 { 100 Converter<FromType, ToType> converter; 101 if (converter(output, input)) 102 return true; 103 104 (*output) = fallback; 105 return false; 218 // Helper function: Calls convertValue with and without default value and returns the converted value 219 template<class FromType, class ToType> 220 static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType) 221 { 222 ToType output = ToType(); 223 ConvertValue(&output, input, preference); 224 return output; 106 225 } 107 108 // THE SAME LIKE BEFORE, BUT NEEDS NO POINTER TO THE OUTPUT 109 template<typename FromType, typename ToType> 110 static ToType ConvertValueAndReturn(const FromType& input) 111 { 112 ToType output; 113 ConvertValue(&output, input); 114 return output; 226 template<class FromType, class ToType> 227 static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 228 { 229 ToType output = fallback; 230 ConvertValue(&output, input, fallback, preference); 231 return output; 115 232 } 116 233 117 // THE SAME, BUT WITH DEFAULT VALUE 118 template<typename FromType, typename ToType> 119 static ToType ConvertValueAndReturn(const FromType& input, const FromType& fallback) 120 { 121 ToType output; 122 ConvertValue(&output, input, fallback); 123 return output; 124 } 125 126 ////////////////////////// 127 // MORE SPECIALISATIONS // 128 ////////////////////////// 129 130 // STRING TO STRING 131 template<> 132 class Converter<std::string, std::string> 133 { 134 public: 135 bool operator()(std::string* output, const std::string& input) const 136 { 137 (*output) = std::string(input); 138 return true; 139 } 140 }; 234 235 ///////////////////// 236 // SPECIALIZATIONS // 237 ///////////////////// 238 239 ///////////// 240 // SAMPLES // 241 ///////////// 242 /* 243 // convert everything to xyz 244 template <class FromType> 245 struct ConverterSpecialized<FromType, xyz, _ToType_> 246 { 247 enum { specialized = true }; 248 static bool convert(xyz* output, const FromType& input) 249 { return ...; } 250 }; 251 252 // convert xyz to everything 253 template <class ToType> 254 struct ConverterSpecialized<xyz, ToType, _FromType_> 255 { 256 enum { specialized = true }; 257 static bool convert(ToType* output, const xyz& input) 258 { return ...; } 259 }; 260 261 // convert abc to xyz 262 template <> 263 struct ConverterSpecialized<abc, xyz, _Explicit_> 264 { 265 enum { specialized = true }; 266 static bool convert(xyz* output, const abc& input) 267 { return ...; } 268 }; 269 */ 270 271 //////////// 272 // STRING // 273 //////////// 274 275 // convert to string 276 template <class FromType> 277 struct ConverterSpecialized<FromType, std::string, _ToType_> 278 { 279 enum { specialized = true }; 280 static bool convert(std::string* output, const FromType& input) 281 { 282 std::ostringstream oss; 283 if (oss << input) 284 { 285 (*output) = oss.str(); 286 return true; 287 } 288 else 289 return false; 290 } 291 }; 292 293 // convert from string 294 template <class ToType> 295 struct ConverterSpecialized<std::string, ToType, _FromType_> 296 { 297 enum { specialized = true }; 298 static bool convert(ToType* output, const std::string& input) 299 { 300 std::istringstream iss(input); 301 if (iss >> (*output)) 302 return true; 303 else 304 return false; 305 } 306 }; 307 141 308 142 309 //////////////// … … 144 311 //////////////// 145 312 146 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEPRIMITIVE 147 template<typename ToType> 148 class Converter<MultiTypePrimitive, ToType> 149 { 150 public: 151 bool operator()(ToType* output, const MultiTypePrimitive& input) const 152 { 153 if (input.getType() == MT_int) 154 return ConvertValue(output, input.getInt()); 155 else if (input.getType() == MT_uint) 156 return ConvertValue(output, input.getUnsignedInt()); 157 else if (input.getType() == MT_char) 158 return ConvertValue(output, input.getChar()); 159 else if (input.getType() == MT_uchar) 160 return ConvertValue(output, input.getUnsignedChar()); 161 else if (input.getType() == MT_short) 162 return ConvertValue(output, input.getShort()); 163 else if (input.getType() == MT_ushort) 164 return ConvertValue(output, input.getUnsignedShort()); 165 else if (input.getType() == MT_long) 166 return ConvertValue(output, input.getLong()); 167 else if (input.getType() == MT_ulong) 168 return ConvertValue(output, input.getUnsignedLong()); 169 else if (input.getType() == MT_float) 170 return ConvertValue(output, input.getFloat()); 171 else if (input.getType() == MT_double) 172 return ConvertValue(output, input.getDouble()); 173 else if (input.getType() == MT_longdouble) 174 return ConvertValue(output, input.getLongDouble()); 175 else if (input.getType() == MT_bool) 176 return ConvertValue(output, input.getBool()); 177 else 178 return false; 179 } 180 }; 181 template<> 182 class Converter<MultiTypePrimitive, std::string> 183 { 184 public: 185 bool operator()(std::string* output, const MultiTypePrimitive& input) const 186 { 187 if (input.getType() == MT_int) 188 return ConvertValue(output, input.getInt()); 189 else if (input.getType() == MT_uint) 190 return ConvertValue(output, input.getUnsignedInt()); 191 else if (input.getType() == MT_char) 192 return ConvertValue(output, input.getChar()); 193 else if (input.getType() == MT_uchar) 194 return ConvertValue(output, input.getUnsignedChar()); 195 else if (input.getType() == MT_short) 196 return ConvertValue(output, input.getShort()); 197 else if (input.getType() == MT_ushort) 198 return ConvertValue(output, input.getUnsignedShort()); 199 else if (input.getType() == MT_long) 200 return ConvertValue(output, input.getLong()); 201 else if (input.getType() == MT_ulong) 202 return ConvertValue(output, input.getUnsignedLong()); 203 else if (input.getType() == MT_float) 204 return ConvertValue(output, input.getFloat()); 205 else if (input.getType() == MT_double) 206 return ConvertValue(output, input.getDouble()); 207 else if (input.getType() == MT_longdouble) 208 return ConvertValue(output, input.getLongDouble()); 209 else if (input.getType() == MT_bool) 210 return ConvertValue(output, input.getBool()); 211 else 212 return false; 213 } 214 }; 215 216 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPESTRING 217 template<typename ToType> 218 class Converter<MultiTypeString, ToType> 219 { 220 public: 221 bool operator()(ToType* output, const MultiTypeString& input) const 222 { 223 if (input.getType() == MT_constchar) 224 return ConvertValue(output, input.getConstChar()); 225 else if (input.getType() == MT_string) 226 return ConvertValue(output, input.getString()); 227 else 228 return ConvertValue(output, (MultiTypePrimitive)input); 229 } 230 }; 231 template<> 232 class Converter<MultiTypeString, std::string> 233 { 234 public: 235 bool operator()(std::string* output, const MultiTypeString& input) const 236 { 237 if (input.getType() == MT_constchar) 238 return ConvertValue(output, input.getConstChar()); 239 else if (input.getType() == MT_string) 240 return ConvertValue(output, input.getString()); 241 else 242 return ConvertValue(output, (MultiTypePrimitive)input); 243 } 244 }; 245 246 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEMATH 247 template<typename ToType> 248 class Converter<MultiTypeMath, ToType> 249 { 250 public: 251 bool operator()(ToType* output, const MultiTypeMath& input) const 252 { 253 if (input.getType() == MT_vector2) 254 return ConvertValue(output, input.getVector2()); 255 else if (input.getType() == MT_vector3) 256 return ConvertValue(output, input.getVector3()); 257 else if (input.getType() == MT_quaternion) 258 return ConvertValue(output, input.getQuaternion()); 259 else if (input.getType() == MT_colourvalue) 260 return ConvertValue(output, input.getColourValue()); 261 else if (input.getType() == MT_radian) 262 return ConvertValue(output, input.getRadian()); 263 else if (input.getType() == MT_degree) 264 return ConvertValue(output, input.getDegree()); 265 else 266 return ConvertValue(output, (MultiTypeString)input); 267 } 268 }; 269 template<> 270 class Converter<MultiTypeMath, std::string> 271 { 272 public: 273 bool operator()(std::string* output, const MultiTypeMath& input) const 274 { 275 if (input.getType() == MT_vector2) 276 return ConvertValue(output, input.getVector2()); 277 else if (input.getType() == MT_vector3) 278 return ConvertValue(output, input.getVector3()); 279 else if (input.getType() == MT_quaternion) 280 return ConvertValue(output, input.getQuaternion()); 281 else if (input.getType() == MT_colourvalue) 282 return ConvertValue(output, input.getColourValue()); 283 else if (input.getType() == MT_radian) 284 return ConvertValue(output, input.getRadian()); 285 else if (input.getType() == MT_degree) 286 return ConvertValue(output, input.getDegree()); 287 else 288 return ConvertValue(output, (MultiTypeString)input); 313 // convert from MultiTypePrimitive 314 template <class ToType> 315 struct ConverterSpecialized<MultiTypePrimitive, ToType, _FromType_> 316 { 317 enum { specialized = true }; 318 static bool convert(ToType* output, const MultiTypePrimitive& input) 319 { 320 if (input.getType() == MT_void) 321 return ConvertValue(output, input.getVoid()); 322 else if (input.getType() == MT_int) 323 return ConvertValue(output, input.getInt()); 324 else if (input.getType() == MT_uint) 325 return ConvertValue(output, input.getUnsignedInt()); 326 else if (input.getType() == MT_char) 327 return ConvertValue(output, input.getChar()); 328 else if (input.getType() == MT_uchar) 329 return ConvertValue(output, input.getUnsignedChar()); 330 else if (input.getType() == MT_short) 331 return ConvertValue(output, input.getShort()); 332 else if (input.getType() == MT_ushort) 333 return ConvertValue(output, input.getUnsignedShort()); 334 else if (input.getType() == MT_long) 335 return ConvertValue(output, input.getLong()); 336 else if (input.getType() == MT_ulong) 337 return ConvertValue(output, input.getUnsignedLong()); 338 else if (input.getType() == MT_float) 339 return ConvertValue(output, input.getFloat()); 340 else if (input.getType() == MT_double) 341 return ConvertValue(output, input.getDouble()); 342 else if (input.getType() == MT_longdouble) 343 return ConvertValue(output, input.getLongDouble()); 344 else if (input.getType() == MT_bool) 345 return ConvertValue(output, input.getBool()); 346 else 347 return false; 348 } 349 }; 350 351 // convert from MultiTypeString 352 template <class ToType> 353 struct ConverterSpecialized<MultiTypeString, ToType, _FromType_> 354 { 355 enum { specialized = true }; 356 static bool convert(ToType* output, const MultiTypeString& input) 357 { 358 if (input.getType() == MT_constchar) 359 return ConvertValue(output, input.getConstChar()); 360 else if (input.getType() == MT_string) 361 return ConvertValue(output, input.getString()); 362 else 363 return ConvertValue(output, (MultiTypePrimitive)input); 364 } 365 }; 366 367 // convert from MultiTypeMath 368 template <class ToType> 369 struct ConverterSpecialized<MultiTypeMath, ToType, _FromType_> 370 { 371 enum { specialized = true }; 372 static bool convert(ToType* output, const MultiTypeMath& input) 373 { 374 if (input.getType() == MT_vector2) 375 return ConvertValue(output, input.getVector2()); 376 else if (input.getType() == MT_vector3) 377 return ConvertValue(output, input.getVector3()); 378 else if (input.getType() == MT_quaternion) 379 return ConvertValue(output, input.getQuaternion()); 380 else if (input.getType() == MT_colourvalue) 381 return ConvertValue(output, input.getColourValue()); 382 else if (input.getType() == MT_radian) 383 return ConvertValue(output, input.getRadian()); 384 else if (input.getType() == MT_degree) 385 return ConvertValue(output, input.getDegree()); 386 else 387 return ConvertValue(output, (MultiTypeString)input); 289 388 } 290 389 }; … … 297 396 // Vector2 to std::string 298 397 template <> 299 class Converter<orxonox::Vector2, std::string> 300 { 301 public: 302 bool operator()(std::string* output, const orxonox::Vector2& input) const 303 { 304 std::ostringstream ostream; 305 if (ostream << input.x << "," << input.y) 306 { 307 (*output) = ostream.str(); 308 return true; 309 } 310 311 return false; 398 struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_> 399 { 400 enum { specialized = true }; 401 static bool convert(std::string* output, const orxonox::Vector2& input) 402 { 403 std::ostringstream ostream; 404 if (ostream << input.x << "," << input.y) 405 { 406 (*output) = ostream.str(); 407 return true; 408 } 409 return false; 312 410 } 313 411 }; … … 315 413 // Vector3 to std::string 316 414 template <> 317 class Converter<orxonox::Vector3, std::string> 318 { 319 public: 320 bool operator()(std::string* output, const orxonox::Vector3& input) const 321 { 322 std::ostringstream ostream; 323 if (ostream << input.x << "," << input.y << "," << input.z) 324 { 325 (*output) = ostream.str(); 326 return true; 327 } 328 329 return false; 415 struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_> 416 { 417 enum { specialized = true }; 418 static bool convert(std::string* output, const orxonox::Vector3& input) 419 { 420 std::ostringstream ostream; 421 if (ostream << input.x << "," << input.y << "," << input.z) 422 { 423 (*output) = ostream.str(); 424 return true; 425 } 426 return false; 330 427 } 331 428 }; … … 333 430 // Vector4 to std::string 334 431 template <> 335 class Converter<orxonox::Vector4, std::string> 336 { 337 public: 338 bool operator()(std::string* output, const orxonox::Vector4& input) const 339 { 340 std::ostringstream ostream; 341 if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w) 342 { 343 (*output) = ostream.str(); 344 return true; 345 } 346 347 return false; 432 struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_> 433 { 434 enum { specialized = true }; 435 static bool convert(std::string* output, const orxonox::Vector4& input) 436 { 437 std::ostringstream ostream; 438 if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w) 439 { 440 (*output) = ostream.str(); 441 return true; 442 } 443 return false; 348 444 } 349 445 }; … … 351 447 // Quaternion to std::string 352 448 template <> 353 class Converter<orxonox::Quaternion, std::string> 354 { 355 public: 356 bool operator()(std::string* output, const orxonox::Quaternion& input) const 357 { 358 std::ostringstream ostream; 359 if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z) 360 { 361 (*output) = ostream.str(); 362 return true; 363 } 364 365 return false; 449 struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_> 450 { 451 enum { specialized = true }; 452 static bool convert(std::string* output, const orxonox::Quaternion& input) 453 { 454 std::ostringstream ostream; 455 if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z) 456 { 457 (*output) = ostream.str(); 458 return true; 459 } 460 return false; 366 461 } 367 462 }; … … 369 464 // ColourValue to std::string 370 465 template <> 371 class Converter<orxonox::ColourValue, std::string> 372 { 373 public: 374 bool operator()(std::string* output, const orxonox::ColourValue& input) const 375 { 376 std::ostringstream ostream; 377 if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a) 378 { 379 (*output) = ostream.str(); 380 return true; 381 } 382 383 return false; 466 struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_> 467 { 468 enum { specialized = true }; 469 static bool convert(std::string* output, const orxonox::ColourValue& input) 470 { 471 std::ostringstream ostream; 472 if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a) 473 { 474 (*output) = ostream.str(); 475 return true; 476 } 477 return false; 384 478 } 385 479 }; … … 392 486 // std::string to Vector2 393 487 template <> 394 class Converter<std::string, orxonox::Vector2> 395 { 396 public: 397 bool operator()(orxonox::Vector2* output, const std::string& input) const 398 { 399 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 400 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 401 402 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0'); 403 404 if (tokens.size() >= 2) 405 { 406 if (!ConvertValue(&(output->x), tokens[0])) 407 return false; 408 if (!ConvertValue(&(output->y), tokens[1])) 409 return false; 410 411 return true; 412 } 413 414 return false; 488 struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_> 489 { 490 enum { specialized = true }; 491 static bool convert(orxonox::Vector2* output, const std::string& input) 492 { 493 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 494 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 495 496 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 497 if (tokens.size() >= 2) 498 { 499 if (!ConvertValue(&(output->x), tokens[0])) 500 return false; 501 if (!ConvertValue(&(output->y), tokens[1])) 502 return false; 503 504 return true; 505 } 506 return false; 415 507 } 416 508 }; … … 418 510 // std::string to Vector3 419 511 template <> 420 class Converter<std::string, orxonox::Vector3> 421 { 422 public: 423 bool operator()(orxonox::Vector3* output, const std::string& input) const 424 { 425 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 426 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 427 428 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0'); 429 430 if (tokens.size() >= 3) 431 { 432 if (!ConvertValue(&(output->x), tokens[0])) 433 return false; 434 if (!ConvertValue(&(output->y), tokens[1])) 435 return false; 436 if (!ConvertValue(&(output->z), tokens[2])) 437 return false; 438 439 return true; 440 } 441 442 return false; 512 struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_> 513 { 514 enum { specialized = true }; 515 static bool convert(orxonox::Vector3* output, const std::string& input) 516 { 517 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 518 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 519 520 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 521 if (tokens.size() >= 3) 522 { 523 if (!ConvertValue(&(output->x), tokens[0])) 524 return false; 525 if (!ConvertValue(&(output->y), tokens[1])) 526 return false; 527 if (!ConvertValue(&(output->z), tokens[2])) 528 return false; 529 530 return true; 531 } 532 return false; 443 533 } 444 534 }; … … 446 536 // std::string to Vector4 447 537 template <> 448 class Converter<std::string, orxonox::Vector4> 449 { 450 public: 451 bool operator()(orxonox::Vector4* output, const std::string& input) const 452 { 453 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 454 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 455 456 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0'); 457 458 if (tokens.size() >= 4) 459 { 460 if (!ConvertValue(&(output->x), tokens[0])) 461 return false; 462 if (!ConvertValue(&(output->y), tokens[1])) 463 return false; 464 if (!ConvertValue(&(output->z), tokens[2])) 465 return false; 466 if (!ConvertValue(&(output->w), tokens[3])) 467 return false; 468 469 return true; 470 } 471 472 return false; 538 struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_> 539 { 540 enum { specialized = true }; 541 static bool convert(orxonox::Vector4* output, const std::string& input) 542 { 543 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 544 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 545 546 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 547 if (tokens.size() >= 4) 548 { 549 if (!ConvertValue(&(output->x), tokens[0])) 550 return false; 551 if (!ConvertValue(&(output->y), tokens[1])) 552 return false; 553 if (!ConvertValue(&(output->z), tokens[2])) 554 return false; 555 if (!ConvertValue(&(output->w), tokens[3])) 556 return false; 557 558 return true; 559 } 560 return false; 473 561 } 474 562 }; … … 476 564 // std::string to Quaternion 477 565 template <> 478 class Converter<std::string, orxonox::Quaternion> 479 { 480 public: 481 bool operator()(orxonox::Quaternion* output, const std::string& input) const 482 { 483 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 484 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 485 486 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0'); 487 488 if (tokens.size() >= 4) 489 { 490 if (!ConvertValue(&(output->w), tokens[0])) 491 return false; 492 if (!ConvertValue(&(output->x), tokens[1])) 493 return false; 494 if (!ConvertValue(&(output->y), tokens[2])) 495 return false; 496 if (!ConvertValue(&(output->z), tokens[3])) 497 return false; 498 499 return true; 500 } 501 502 return false; 566 struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_> 567 { 568 enum { specialized = true }; 569 static bool convert(orxonox::Quaternion* output, const std::string& input) 570 { 571 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 572 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 573 574 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 575 if (tokens.size() >= 4) 576 { 577 if (!ConvertValue(&(output->w), tokens[0])) 578 return false; 579 if (!ConvertValue(&(output->x), tokens[1])) 580 return false; 581 if (!ConvertValue(&(output->y), tokens[2])) 582 return false; 583 if (!ConvertValue(&(output->z), tokens[3])) 584 return false; 585 586 return true; 587 } 588 return false; 503 589 } 504 590 }; … … 506 592 // std::string to ColourValue 507 593 template <> 508 class Converter<std::string, orxonox::ColourValue> 509 { 510 public: 511 bool operator()(orxonox::ColourValue* output, const std::string& input) const 512 { 513 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 514 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 515 516 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0'); 517 518 if (tokens.size() >= 4) 519 { 520 if (!ConvertValue(&(output->r), tokens[0])) 521 return false; 522 if (!ConvertValue(&(output->g), tokens[1])) 523 return false; 524 if (!ConvertValue(&(output->b), tokens[2])) 525 return false; 526 if (!ConvertValue(&(output->a), tokens[3])) 527 return false; 528 529 return true; 530 } 531 532 return false; 594 struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_> 595 { 596 enum { specialized = true }; 597 static bool convert(orxonox::ColourValue* output, const std::string& input) 598 { 599 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 600 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 601 602 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 603 if (tokens.size() >= 4) 604 { 605 if (!ConvertValue(&(output->r), tokens[0])) 606 return false; 607 if (!ConvertValue(&(output->g), tokens[1])) 608 return false; 609 if (!ConvertValue(&(output->b), tokens[2])) 610 return false; 611 if (!ConvertValue(&(output->a), tokens[3])) 612 return false; 613 614 return true; 615 } 616 return false; 533 617 } 534 618 }; -
code/trunk/src/util/Math.h
r892 r1052 26 26 */ 27 27 28 #ifndef _ Math_H__29 #define _ Math_H__28 #ifndef _Util_Math_H__ 29 #define _Util_Math_H__ 30 30 31 31 #include <ostream> … … 146 146 } 147 147 148 #endif /* _Math_H__ */ 149 148 #endif /* _Util_Math_H__ */ -
code/trunk/src/util/MultiType.h
r871 r1052 35 35 { 36 36 MT_null, 37 MT_void, 37 38 MT_int, 38 39 MT_uint, … … 49 50 MT_constchar, 50 51 MT_string, 52 MT_xmlelement, 51 53 MT_vector2, 52 54 MT_vector3, … … 59 61 union _UtilExport MultiTypeValue 60 62 { 63 void* void_; 61 64 int int_; 62 65 unsigned int uint_; -
code/trunk/src/util/MultiTypeMath.cc
r871 r1052 88 88 } 89 89 90 MultiTypeMath::operator void*() const 91 { return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeMath, void*>(*this, 0); } 90 92 MultiTypeMath::operator int() const 91 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this); }93 { return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeMath, int>(*this, 0); } 92 94 MultiTypeMath::operator unsigned int() const 93 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeMath, unsigned int>(*this); }95 { return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeMath, unsigned int>(*this, 0); } 94 96 MultiTypeMath::operator char() const 95 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeMath, char>(*this); }97 { return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeMath, char>(*this, 0); } 96 98 MultiTypeMath::operator unsigned char() const 97 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeMath, unsigned char>(*this); }99 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeMath, unsigned char>(*this, 0); } 98 100 MultiTypeMath::operator short() const 99 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeMath, short>(*this); }101 { return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeMath, short>(*this, 0); } 100 102 MultiTypeMath::operator unsigned short() const 101 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeMath, unsigned short>(*this); }103 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeMath, unsigned short>(*this, 0); } 102 104 MultiTypeMath::operator long() const 103 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeMath, long>(*this); }105 { return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeMath, long>(*this, 0); } 104 106 MultiTypeMath::operator unsigned long() const 105 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeMath, unsigned long>(*this); }107 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeMath, unsigned long>(*this, 0); } 106 108 MultiTypeMath::operator float() const 107 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeMath, float>(*this); }109 { return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeMath, float>(*this, 0); } 108 110 MultiTypeMath::operator double() const 109 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeMath, double>(*this); }111 { return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeMath, double>(*this, 0); } 110 112 MultiTypeMath::operator long double() const 111 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeMath, long double>(*this); }113 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeMath, long double>(*this, 0); } 112 114 MultiTypeMath::operator bool() const 113 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeMath, bool>(*this); }115 { return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeMath, bool>(*this, 0); } 114 116 MultiTypeMath::operator std::string() const 115 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this); }117 { return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this); } 116 118 MultiTypeMath::operator const char*() const 117 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this)).c_str(); }119 { return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this)).c_str(); } 118 120 MultiTypeMath::operator orxonox::Vector2() const 119 { return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector2>(*this); }121 { return (this->type_ == MT_vector2) ? this->vector2_ : getConvertedValue<MultiTypeMath, orxonox::Vector2>(*this); } 120 122 MultiTypeMath::operator orxonox::Vector3() const 121 { return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector3>(*this); }123 { return (this->type_ == MT_vector3) ? this->vector3_ : getConvertedValue<MultiTypeMath, orxonox::Vector3>(*this); } 122 124 MultiTypeMath::operator orxonox::Quaternion() const 123 { return (this->type_ == MT_quaternion) ? this->quaternion_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Quaternion>(*this); }125 { return (this->type_ == MT_quaternion) ? this->quaternion_ : getConvertedValue<MultiTypeMath, orxonox::Quaternion>(*this); } 124 126 MultiTypeMath::operator orxonox::ColourValue() const 125 { return (this->type_ == MT_colourvalue) ? this->colourvalue_ : ConvertValueAndReturn<MultiTypeMath, orxonox::ColourValue>(*this); }127 { return (this->type_ == MT_colourvalue) ? this->colourvalue_ : getConvertedValue<MultiTypeMath, orxonox::ColourValue>(*this); } 126 128 MultiTypeMath::operator orxonox::Radian() const 127 { return (this->type_ == MT_radian) ? this->radian_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Radian>(*this); }129 { return (this->type_ == MT_radian) ? this->radian_ : getConvertedValue<MultiTypeMath, orxonox::Radian>(*this); } 128 130 MultiTypeMath::operator orxonox::Degree() const 129 { return (this->type_ == MT_degree) ? this->degree_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Degree>(*this); }131 { return (this->type_ == MT_degree) ? this->degree_ : getConvertedValue<MultiTypeMath, orxonox::Degree>(*this); } 130 132 131 133 void MultiTypeMath::setValue(const MultiTypeMath& mtm) … … 138 140 this->radian_ = mtm.radian_; 139 141 this->degree_ = mtm.degree_; 142 } 143 144 std::string MultiTypeMath::getTypename() const 145 { 146 if (this->type_ == MT_vector2) 147 return "Vector2"; 148 else if (this->type_ == MT_vector3) 149 return "Vector3"; 150 else if (this->type_ == MT_colourvalue) 151 return "ColourValue"; 152 else if (this->type_ == MT_quaternion) 153 return "Quaternion"; 154 else if (this->type_ == MT_radian) 155 return "Radian"; 156 else if (this->type_ == MT_degree) 157 return "Degree"; 158 else 159 return MultiTypeString::getTypename(); 140 160 } 141 161 -
code/trunk/src/util/MultiTypeMath.h
r890 r1052 38 38 { 39 39 public: 40 MultiTypeMath(MultiType type = MT_null); 40 MultiTypeMath(MultiType type = MT_null); 41 inline MultiTypeMath(void* value) : MultiTypeString(value) {} 41 42 inline MultiTypeMath(int value) : MultiTypeString(value) {} 42 43 inline MultiTypeMath(unsigned int value) : MultiTypeString(value) {} … … 51 52 inline MultiTypeMath(long double value) : MultiTypeString(value) {} 52 53 inline MultiTypeMath(bool value) : MultiTypeString(value) {} 53 inline MultiTypeMath(const char* value) : MultiTypeString(value) {}54 inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {}54 inline MultiTypeMath(const char* value) : MultiTypeString(value) {} 55 inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {} 55 56 inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } 56 57 inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } … … 89 90 bool operator!=(const MultiTypeMath& mtm) const; 90 91 92 virtual operator void*() const; 91 93 virtual operator int() const; 92 94 virtual operator unsigned int() const; … … 141 143 inline void getValue(orxonox::Degree* variable) const { (*variable) = orxonox::Degree (this->degree_); } 142 144 145 virtual std::string getTypename() const; 146 143 147 virtual std::string toString() const; 144 148 virtual bool fromString(const std::string value); -
code/trunk/src/util/MultiTypePrimitive.cc
r871 r1052 34 34 this->type_ = type; 35 35 36 if (type == MT_int) 36 if (type == MT_void) 37 this->value_.void_ = 0; 38 else if (type == MT_int) 37 39 this->value_.int_ = 0; 38 40 else if (type == MT_uint) … … 59 61 this->value_.bool_ = false; 60 62 else 61 this->value_. int_ = 0;63 this->value_.void_ = 0; 62 64 } 63 65 … … 66 68 if (this->type_ == mtp.type_) 67 69 { 68 if (this->type_ == MT_int) 70 if (this->type_ == MT_void) 71 return (this->value_.void_ == mtp.value_.void_); 72 else if (this->type_ == MT_int) 69 73 return (this->value_.int_ == mtp.value_.int_); 70 74 else if (this->type_ == MT_uint) … … 99 103 if (this->type_ == mtp.type_) 100 104 { 101 if (this->type_ == MT_int) 105 if (this->type_ == MT_void) 106 return (this->value_.void_ != mtp.value_.void_); 107 else if (this->type_ == MT_int) 102 108 return (this->value_.int_ != mtp.value_.int_); 103 109 else if (this->type_ == MT_uint) … … 128 134 } 129 135 136 MultiTypePrimitive::operator void*() const 137 { return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypePrimitive, void*>(*this, 0); } 130 138 MultiTypePrimitive::operator int() const 131 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this); }139 { return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypePrimitive, int>(*this, 0); } 132 140 MultiTypePrimitive::operator unsigned int() const 133 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this); }141 { return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypePrimitive, unsigned int>(*this, 0); } 134 142 MultiTypePrimitive::operator char() const 135 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this); }143 { return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypePrimitive, char>(*this, 0); } 136 144 MultiTypePrimitive::operator unsigned char() const 137 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this); }145 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypePrimitive, unsigned char>(*this, 0); } 138 146 MultiTypePrimitive::operator short() const 139 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this); }147 { return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypePrimitive, short>(*this, 0); } 140 148 MultiTypePrimitive::operator unsigned short() const 141 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this); }149 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypePrimitive, unsigned short>(*this, 0); } 142 150 MultiTypePrimitive::operator long() const 143 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this); }151 { return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypePrimitive, long>(*this, 0); } 144 152 MultiTypePrimitive::operator unsigned long() const 145 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this); }153 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypePrimitive, unsigned long>(*this, 0); } 146 154 MultiTypePrimitive::operator float() const 147 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this); }155 { return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypePrimitive, float>(*this, 0); } 148 156 MultiTypePrimitive::operator double() const 149 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this); }157 { return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypePrimitive, double>(*this, 0); } 150 158 MultiTypePrimitive::operator long double() const 151 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this); }159 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypePrimitive, long double>(*this, 0); } 152 160 MultiTypePrimitive::operator bool() const 153 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this); }161 { return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypePrimitive, bool>(*this, 0); } 154 162 155 163 void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp) … … 159 167 } 160 168 169 std::string MultiTypePrimitive::getTypename() const 170 { 171 if (this->type_ == MT_void) 172 return "pointer"; 173 else if (this->type_ == MT_int) 174 return "int"; 175 else if (this->type_ == MT_uint) 176 return "unsigned int"; 177 else if (this->type_ == MT_char) 178 return "char"; 179 else if (this->type_ == MT_uchar) 180 return "unsigned char"; 181 else if (this->type_ == MT_short) 182 return "short"; 183 else if (this->type_ == MT_ushort) 184 return "unsigned short"; 185 else if (this->type_ == MT_long) 186 return "long"; 187 else if (this->type_ == MT_ulong) 188 return "unsigned long"; 189 else if (this->type_ == MT_float) 190 return "float"; 191 else if (this->type_ == MT_double) 192 return "double"; 193 else if (this->type_ == MT_longdouble) 194 return "long double"; 195 else if (this->type_ == MT_bool) 196 return "bool"; 197 else 198 return "unknown"; 199 } 200 161 201 std::string MultiTypePrimitive::toString() const 162 202 { 163 203 std::string output; 164 204 165 if (this->type_ == MT_int) 205 if (this->type_ == MT_void) 206 ConvertValue(&output, this->value_.void_); 207 else if (this->type_ == MT_int) 166 208 ConvertValue(&output, this->value_.int_); 167 209 else if (this->type_ == MT_uint) … … 193 235 bool MultiTypePrimitive::fromString(const std::string value) 194 236 { 195 if (this->type_ == MT_int) 237 if (this->type_ == MT_void) 238 return ConvertValue(&this->value_.void_, value, (void*)0); 239 else if (this->type_ == MT_int) 196 240 return ConvertValue(&this->value_.int_, value, (int)0); 197 241 else if (this->type_ == MT_uint) -
code/trunk/src/util/MultiTypePrimitive.h
r890 r1052 36 36 #include "MultiType.h" 37 37 38 namespace orxonox 39 { 40 class BaseObject; 41 } 38 42 class _UtilExport MultiTypePrimitive 39 43 { 40 44 public: 41 MultiTypePrimitive(MultiType type = MT_null); 45 MultiTypePrimitive(MultiType type = MT_null); 46 inline MultiTypePrimitive(void* value) { this->setValue(value); } 42 47 inline MultiTypePrimitive(int value) { this->setValue(value); } 43 48 inline MultiTypePrimitive(unsigned int value) { this->setValue(value); } … … 56 61 57 62 inline MultiTypePrimitive& operator=(MultiType value) { this->type_ = MT_null; return *this; } 63 inline MultiTypePrimitive& operator=(void* value) { this->setValue(value); return *this; } 58 64 inline MultiTypePrimitive& operator=(int value) { this->setValue(value); return *this; } 59 65 inline MultiTypePrimitive& operator=(unsigned int value) { this->setValue(value); return *this; } … … 70 76 inline MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; } 71 77 78 inline bool operator==(void* value) const { return (this->value_.void_ == value); } 72 79 inline bool operator==(int value) const { return (this->value_.int_ == value); } 73 80 inline bool operator==(unsigned int value) const { return (this->value_.uint_ == value); } … … 84 91 bool operator==(const MultiTypePrimitive& mtp) const; 85 92 86 inline bool operator!=( int value) const { return (this->value_.int_!= value); }93 inline bool operator!=(void* value) const { return (this->value_.void_ != value); } 87 94 inline bool operator!=(unsigned int value) const { return (this->value_.uint_ != value); } 88 95 inline bool operator!=(char value) const { return (this->value_.char_ != value); } … … 98 105 bool operator!=(const MultiTypePrimitive& mtp) const; 99 106 107 template <class T> 108 operator T*() const 109 { return ((T*)this->value_.void_); } 110 virtual operator void*() const; 100 111 virtual operator int() const; 101 112 virtual operator unsigned int() const; … … 111 122 virtual operator bool() const; 112 123 124 inline void setValue(void* value) { this->type_ = MT_void; this->value_.void_ = value; } 113 125 inline void setValue(int value) { this->type_ = MT_int; this->value_.int_ = value; } 114 126 inline void setValue(unsigned int value) { this->type_ = MT_uint; this->value_.uint_ = value; } … … 125 137 void setValue(const MultiTypePrimitive& mtp); 126 138 139 inline void* getVoid() const { return this->value_.void_; } 127 140 inline int getInt() const { return this->value_.int_; } 128 141 inline unsigned int getUnsignedInt() const { return this->value_.uint_; } … … 151 164 inline bool& getBool() { return this->value_.bool_; } 152 165 166 inline void getValue(void* variable) const { variable = this->value_.void_; } 153 167 inline void getValue(int* variable) const { (*variable) = this->value_.int_; } 154 168 inline void getValue(unsigned int* variable) const { (*variable) = this->value_.uint_; } … … 167 181 inline bool isA(MultiType type) const { return (this->type_ == type); } 168 182 183 virtual std::string getTypename() const; 184 169 185 virtual std::string toString() const; 170 186 virtual bool fromString(const std::string value); -
code/trunk/src/util/MultiTypeString.cc
r871 r1052 32 32 MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type) 33 33 { 34 if (type == MT_constchar) 35 this->string_ = std::string(""); 36 else if (type == MT_string) 37 this->string_ = std::string(""); 34 // Nothing to do for string and xml-element 38 35 } 39 36 … … 64 61 } 65 62 63 MultiTypeString::operator void*() const 64 { return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeString, void*>(*this, 0); } 66 65 MultiTypeString::operator int() const 67 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this); }66 { return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeString, int>(*this, 0); } 68 67 MultiTypeString::operator unsigned int() const 69 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeString, unsigned int>(*this); }68 { return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeString, unsigned int>(*this, 0); } 70 69 MultiTypeString::operator char() const 71 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeString, char>(*this); }70 { return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeString, char>(*this, 0); } 72 71 MultiTypeString::operator unsigned char() const 73 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeString, unsigned char>(*this); }72 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeString, unsigned char>(*this, 0); } 74 73 MultiTypeString::operator short() const 75 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeString, short>(*this); }74 { return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeString, short>(*this, 0); } 76 75 MultiTypeString::operator unsigned short() const 77 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeString, unsigned short>(*this); }76 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeString, unsigned short>(*this, 0); } 78 77 MultiTypeString::operator long() const 79 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeString, long>(*this); }78 { return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeString, long>(*this, 0); } 80 79 MultiTypeString::operator unsigned long() const 81 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeString, unsigned long>(*this); }80 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeString, unsigned long>(*this, 0); } 82 81 MultiTypeString::operator float() const 83 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeString, float>(*this); }82 { return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeString, float>(*this, 0); } 84 83 MultiTypeString::operator double() const 85 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeString, double>(*this); }84 { return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeString, double>(*this, 0); } 86 85 MultiTypeString::operator long double() const 87 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeString, long double>(*this); }86 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeString, long double>(*this, 0); } 88 87 MultiTypeString::operator bool() const 89 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeString, bool>(*this); }88 { return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeString, bool>(*this, 0); } 90 89 MultiTypeString::operator std::string() const 91 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this); }90 { return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this); } 92 91 MultiTypeString::operator const char*() const 93 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this)).c_str(); }92 { return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this)).c_str(); } 94 93 95 94 void MultiTypeString::setValue(const MultiTypeString& mts) … … 99 98 } 100 99 100 std::string MultiTypeString::getTypename() const 101 { 102 if (this->type_ == MT_constchar) 103 return "string"; 104 else if (this->type_ == MT_string) 105 return "string"; 106 else 107 return MultiTypePrimitive::getTypename(); 108 } 109 101 110 std::string MultiTypeString::toString() const 102 111 { 112 std::string output; 113 103 114 if (this->type_ == MT_constchar) 104 115 return this->string_; … … 107 118 else 108 119 return MultiTypePrimitive::toString(); 120 121 return output; 109 122 } 110 123 -
code/trunk/src/util/MultiTypeString.h
r890 r1052 39 39 { 40 40 public: 41 MultiTypeString(MultiType type = MT_null); 41 MultiTypeString(MultiType type = MT_null); 42 inline MultiTypeString(void* value) : MultiTypePrimitive(value) {} 42 43 inline MultiTypeString(int value) : MultiTypePrimitive(value) {} 43 44 inline MultiTypeString(unsigned int value) : MultiTypePrimitive(value) {} … … 52 53 inline MultiTypeString(long double value) : MultiTypePrimitive(value) {} 53 54 inline MultiTypeString(bool value) : MultiTypePrimitive(value) {} 54 inline MultiTypeString(const char* value) { this->setValue(value); }55 inline MultiTypeString(const std::string& value) { this->setValue(value); }56 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); }55 inline MultiTypeString(const char* value) { this->setValue(value); } 56 inline MultiTypeString(const std::string& value) { this->setValue(value); } 57 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } 57 58 virtual inline ~MultiTypeString() {} 58 59 59 60 using MultiTypePrimitive::operator=; 60 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; }61 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; }62 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; }61 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } 62 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } 63 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 63 64 64 65 using MultiTypePrimitive::operator==; 65 inline bool operator==(const char* value) const { return (this->string_== std::string(value)); }66 inline bool operator==(const std::string& value) const { return (this->string_== value); }66 inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } 67 inline bool operator==(const std::string& value) const { return (this->string_ == value); } 67 68 bool operator==(const MultiTypeString& mts) const; 68 69 69 70 using MultiTypePrimitive::operator!=; 70 inline bool operator!=(const char* value) const { return (this->string_!= std::string(value)); }71 inline bool operator!=(const std::string& value) const { return (this->string_!= value); }71 inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } 72 inline bool operator!=(const std::string& value) const { return (this->string_ != value); } 72 73 bool operator!=(const MultiTypeString& mts) const; 73 74 74 virtual operator int() const; 75 virtual operator unsigned int() const; 76 virtual operator char() const; 77 virtual operator unsigned char() const; 78 virtual operator short() const; 79 virtual operator unsigned short() const; 80 virtual operator long() const; 81 virtual operator unsigned long() const; 82 virtual operator float () const; 83 virtual operator double () const; 84 virtual operator long double() const; 85 virtual operator bool() const; 86 virtual operator std::string() const; 87 virtual operator const char*() const; 75 virtual operator void*() const; 76 virtual operator int() const; 77 virtual operator unsigned int() const; 78 virtual operator char() const; 79 virtual operator unsigned char() const; 80 virtual operator short() const; 81 virtual operator unsigned short() const; 82 virtual operator long() const; 83 virtual operator unsigned long() const; 84 virtual operator float () const; 85 virtual operator double () const; 86 virtual operator long double() const; 87 virtual operator bool() const; 88 virtual operator std::string() const; 89 virtual operator const char*() const; 88 90 89 91 using MultiTypePrimitive::setValue; 90 inline void setValue(const char* value) { this->type_ = MT_string; this->string_= std::string(value); }91 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_= value; }92 inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } 93 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } 92 94 void setValue(const MultiTypeString& mts); 93 95 94 inline const std::string getString()const { return this->string_; }95 inline const char* getConstChar() const { return this->string_.c_str(); }96 inline std::string getString() const { return this->string_; } 97 inline const char* getConstChar() const { return this->string_.c_str(); } 96 98 97 inline const std::string& getString(){ return this->string_; }98 inline const char* getConstChar() { return this->string_.c_str(); }99 inline std::string& getString() { return this->string_; } 100 inline const char* getConstChar() { return this->string_.c_str(); } 99 101 100 102 using MultiTypePrimitive::getValue; 101 inline void getValue(std::string* variable) const { (*variable) = this->string_; } 102 inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } 103 inline void getValue(std::string* variable) const { (*variable) = this->string_; } 104 inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } 105 106 virtual std::string getTypename() const; 103 107 104 108 virtual std::string toString() const; … … 106 110 107 111 protected: 108 std::string string_;112 std::string string_; 109 113 }; 110 114 -
code/trunk/src/util/String.cc
r871 r1052 26 26 */ 27 27 28 #include <cctype> 29 #include <iostream> 28 30 #include "String.h" 29 31 … … 54 56 55 57 /** 58 @brief Returns a copy of a string without trailing whitespaces. 59 @param str The string 60 @return The modified copy 61 */ 62 std::string removeTrailingWhitespaces(const std::string& str) 63 { 64 unsigned int pos1 = 0; 65 unsigned int pos2 = str.size() - 1; 66 for (; pos1 < str.size() && (str[pos1] == ' ' || str[pos1] == '\t' || str[pos1] == '\n'); pos1++); 67 for (; pos2 >= 0 && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--); 68 return str.substr(pos1, pos2 - pos1 + 1); 69 } 70 71 /** 72 @brief Returns the position of the next quote in the string, starting with start. 73 @param str The string 74 @param start The startposition 75 @return The position of the next quote (std::string::npos if there is no next quote) 76 */ 77 unsigned int getNextQuote(const std::string& str, unsigned int start) 78 { 79 unsigned int quote = start - 1; 80 81 while ((quote = str.find('\"', quote + 1)) != std::string::npos) 82 { 83 unsigned int backslash = quote; 84 unsigned int numbackslashes = 0; 85 for (; backslash > 0; backslash--, numbackslashes++) 86 if (str[backslash - 1] != '\\') 87 break; 88 89 if (numbackslashes % 2 == 0) 90 break; 91 } 92 93 return quote; 94 } 95 96 /** 97 @brief Returns true if pos is between two quotes. 98 @param str The string 99 @param pos The position to check 100 @return True if pos is between two quotes 101 */ 102 bool isBetweenQuotes(const std::string& str, unsigned int pos) 103 { 104 if (pos == std::string::npos) 105 return false; 106 107 unsigned int quotecount = 0; 108 unsigned int quote = 0; 109 while ((quote = getNextQuote(str, quote)) < pos) 110 { 111 quotecount++; 112 } 113 114 if (quote == std::string::npos) 115 return false; 116 117 return ((quotecount % 2) == 1); 118 } 119 120 /** 121 @brief Returns true if the string contains something like '..."between quotes"...' 122 @param The string 123 @return True if there is something between quotes 124 */ 125 bool hasStringBetweenQuotes(const std::string& str) 126 { 127 unsigned int pos1 = getNextQuote(str, 0); 128 unsigned int pos2 = getNextQuote(str, pos1 + 1); 129 return (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1); 130 } 131 132 /** 133 @brief If the string contains something like '..."between quotes"...' then 'between quotes' gets returned (without quotes). 134 @param The string 135 @param The string between the quotes 136 */ 137 std::string getStringBetweenQuotes(const std::string& str) 138 { 139 unsigned int pos1 = getNextQuote(str, 0); 140 unsigned int pos2 = getNextQuote(str, pos1 + 1); 141 if (pos1 != std::string::npos && pos2 != std::string::npos) 142 return str.substr(pos1, pos2 - pos1 + 1); 143 else 144 return ""; 145 } 146 147 /** 148 @brief Removes enclosing quotes if available. 149 @brief str The string to strip 150 @return The string with removed quotes 151 */ 152 std::string stripEnclosingQuotes(const std::string& str) 153 { 154 unsigned int start = std::string::npos; 155 unsigned int end = 0; 156 157 for (unsigned int pos = 0; (pos < str.size()) && (pos < std::string::npos); pos++) 158 { 159 if (str[pos] == '"') 160 { 161 start = pos; 162 break; 163 } 164 165 if ((str[pos] != ' ') && (str[pos] != '\t') && (str[pos] != '\n')) 166 return str; 167 } 168 169 for (unsigned int pos = str.size() - 1; pos < std::string::npos; pos--) 170 { 171 if (str[pos] == '"') 172 { 173 end = pos; 174 break; 175 } 176 177 if ((str[pos] != ' ') && (str[pos] != '\t') && (str[pos] != '\n')) 178 return str; 179 } 180 181 if ((start != std::string::npos) && (end != 0)) 182 return str.substr(start + 1, end - start - 1); 183 else 184 return str; 185 } 186 187 /** 56 188 @brief Determines if a string in is a comment. 57 189 @param str The string to check … … 70 202 // 3) ;comment in unreal tournament config-file style 71 203 // 4) //comment in code style 72 if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[0] == '/')) 73 return true; 204 if (teststring.size() >= 2) 205 { 206 if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[1] == '/')) 207 return true; 208 } 209 else if (teststring.size() == 1) 210 { 211 if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';') 212 return true; 213 } 74 214 75 215 return false; … … 83 223 bool isEmpty(const std::string& str) 84 224 { 85 return getStripped(str) == ""; 225 std::string temp = getStripped(str); 226 return ((temp == "") || (temp.size() == 0)); 86 227 } 87 228 … … 109 250 } 110 251 252 std::string addSlashes(const std::string& str) 253 { 254 std::string output = str; 255 256 for (unsigned int pos = 0; (pos = output.find('\\', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\\"); } 257 for (unsigned int pos = 0; (pos = output.find('\n', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\n"); } 258 for (unsigned int pos = 0; (pos = output.find('\t', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\t"); } 259 for (unsigned int pos = 0; (pos = output.find('\v', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\v"); } 260 for (unsigned int pos = 0; (pos = output.find('\b', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\b"); } 261 for (unsigned int pos = 0; (pos = output.find('\r', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\r"); } 262 for (unsigned int pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\f"); } 263 for (unsigned int pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\a"); } 264 for (unsigned int pos = 0; (pos = output.find('"', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); } 265 for (unsigned int pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\0"); } 266 267 return output; 268 } 269 270 std::string removeSlashes(const std::string& str) 271 { 272 if (str.size() == 0) 273 return str; 274 275 std::string output = ""; 276 for (unsigned int pos = 0; pos < str.size() - 1; ) 277 { 278 if (str[pos] == '\\') 279 { 280 if (str[pos + 1] == '\\') { output += '\\'; pos += 2; continue; } 281 else if (str[pos + 1] == 'n') { output += '\n'; pos += 2; continue; } 282 else if (str[pos + 1] == 't') { output += '\t'; pos += 2; continue; } 283 else if (str[pos + 1] == 'v') { output += '\v'; pos += 2; continue; } 284 else if (str[pos + 1] == 'b') { output += '\b'; pos += 2; continue; } 285 else if (str[pos + 1] == 'r') { output += '\r'; pos += 2; continue; } 286 else if (str[pos + 1] == 'f') { output += '\f'; pos += 2; continue; } 287 else if (str[pos + 1] == 'a') { output += '\a'; pos += 2; continue; } 288 else if (str[pos + 1] == '"') { output += '"'; pos += 2; continue; } 289 else if (str[pos + 1] == '0') { output += '\0'; pos += 2; continue; } 290 } 291 output += str[pos]; 292 pos++; 293 if (pos == str.size() - 1) 294 output += str[pos]; 295 } 296 297 return output; 298 } 299 111 300 /** 112 301 @brief Replaces each char between A and Z with its lowercase equivalent. … … 115 304 void lowercase(std::string* str) 116 305 { 117 static unsigned const char difference_between_A_and_a = 'A' - 'a'; 118 119 for (std::string::iterator it = (*str).begin(); it != (*str).end(); ++it) 120 if ((*it) >= 'A' && (*it) <= 'Z') 121 (*it) -= difference_between_A_and_a; 306 for (unsigned int i = 0; i < str->size(); ++i) 307 { 308 (*str)[i] = tolower((*str)[i]); 309 } 122 310 } 123 311 … … 140 328 void uppercase(std::string* str) 141 329 { 142 static unsigned const char difference_between_A_and_a = 'A' - 'a'; 143 144 for (std::string::iterator it = (*str).begin(); it != (*str).end(); ++it) 145 if ((*it) >= 'a' && (*it) <= 'z') 146 (*it) += difference_between_A_and_a; 330 for (unsigned int i = 0; i < str->size(); ++i) 331 { 332 (*str)[i] = toupper((*str)[i]); 333 } 147 334 } 148 335 … … 160 347 161 348 /** 162 *@brief compares two strings without ignoring the case163 *@param s1 first string164 *@param s2 second string165 349 @brief compares two strings without ignoring the case 350 @param s1 first string 351 @param s2 second string 352 */ 166 353 int nocaseCmp(const std::string& s1, const std::string& s2) 167 354 { … … 188 375 189 376 /** 190 *@brief compares two strings without ignoring the case191 *@param s1 first string192 *@param s2 second string193 *@param len how far from the beginning to start.194 377 @brief compares two strings without ignoring the case 378 @param s1 first string 379 @param s2 second string 380 @param len how far from the beginning to start. 381 */ 195 382 int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len) 196 383 { … … 212 399 return 0; 213 400 } 401 402 /** 403 @brief Returns true if the string contains a comment, introduced by #, %, ; or //. 404 @param str The string 405 @return True if the string contains a comment 406 */ 407 bool hasComment(const std::string& str) 408 { 409 return (getCommentPosition(str) != std::string::npos); 410 } 411 412 /** 413 @brief If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 414 @param str The string 415 @return The comment 416 */ 417 std::string getComment(const std::string& str) 418 { 419 return str.substr(getCommentPosition(str)); 420 } 421 422 /** 423 @brief If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise. 424 @param str The string 425 @return The position 426 */ 427 unsigned int getCommentPosition(const std::string& str) 428 { 429 return getNextCommentPosition(str, 0); 430 } 431 432 /** 433 @brief Returns the position of the next comment-symbol, starting with start. 434 @param str The string 435 @param start The startposition 436 @return The position 437 */ 438 unsigned int getNextCommentPosition(const std::string& str, unsigned int start) 439 { 440 for (unsigned int i = start; i < str.size(); i++) 441 if (isComment(str.substr(i))) 442 return i; 443 444 return std::string::npos; 445 } -
code/trunk/src/util/String.h
r871 r1052 26 26 */ 27 27 28 #ifndef _ String_H__29 #define _ String_H__28 #ifndef _Util_String_H__ 29 #define _Util_String_H__ 30 30 31 31 #include <string> … … 34 34 #include "UtilPrereqs.h" 35 35 36 _UtilExport void strip(std::string* str);37 _UtilExport std::string getStripped(const std::string& str);36 _UtilExport void strip(std::string* str); 37 _UtilExport std::string getStripped(const std::string& str); 38 38 39 _UtilExport bool isEmpty(const std::string& str); 40 _UtilExport bool isComment(const std::string& str); 41 _UtilExport bool isNumeric(const std::string& str); 39 _UtilExport std::string removeTrailingWhitespaces(const std::string& str); 42 40 43 _UtilExport void lowercase(std::string* str);44 _UtilExport std::string getLowercase(const std::string& str);41 _UtilExport unsigned int getNextQuote(const std::string& str, unsigned int start); 42 _UtilExport bool isBetweenQuotes(const std::string& str, unsigned int pos); 45 43 46 _UtilExport void uppercase(std::string*str);47 _UtilExport std::string getUppercase(const std::string& str);44 _UtilExport bool hasStringBetweenQuotes(const std::string& str); 45 _UtilExport std::string getStringBetweenQuotes(const std::string& str); 48 46 49 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2); 50 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len); 47 _UtilExport std::string stripEnclosingQuotes(const std::string& str); 48 49 _UtilExport bool isEmpty(const std::string& str); 50 _UtilExport bool isComment(const std::string& str); 51 _UtilExport bool isNumeric(const std::string& str); 52 53 _UtilExport std::string addSlashes(const std::string& str); 54 _UtilExport std::string removeSlashes(const std::string& str); 55 56 _UtilExport void lowercase(std::string* str); 57 _UtilExport std::string getLowercase(const std::string& str); 58 59 _UtilExport void uppercase(std::string* str); 60 _UtilExport std::string getUppercase(const std::string& str); 61 62 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2); 63 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len); 64 65 _UtilExport bool hasComment(const std::string& str); 66 _UtilExport std::string getComment(const std::string& str); 67 _UtilExport unsigned int getCommentPosition(const std::string& str); 68 _UtilExport unsigned int getNextCommentPosition(const std::string& str, unsigned int start = 0); 51 69 52 70 //! The Convert class has some static member functions to convert strings to values and values to strings. … … 144 162 }; 145 163 146 #endif /* _ String_H__ */164 #endif /* _Util_String_H__ */ -
code/trunk/src/util/SubString.cc
r871 r1052 66 66 SubString::SubString(const std::string& string, 67 67 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 68 char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char) 69 { 70 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char); 68 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 69 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 70 { 71 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 71 72 } 72 73 … … 79 80 { 80 81 for (unsigned int i = subSetBegin; i < subString.size(); i++) 82 { 81 83 this->strings.push_back(subString[i]); 84 this->bInSafemode.push_back(subString.isInSafemode(i)); 85 } 82 86 } 83 87 … … 91 95 SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd) 92 96 { 93 for (unsigned int i = subSetBegin; i < subString.size() || i < subSetEnd; i++) 97 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) 98 { 94 99 this->strings.push_back(subString[i]); 100 this->bInSafemode.push_back(subString.isInSafemode(i)); 101 } 95 102 } 96 103 … … 103 110 { 104 111 for(unsigned int i = 0; i < argc; ++i) 112 { 105 113 this->strings.push_back(std::string(argv[i])); 114 this->bInSafemode.push_back(false); 115 } 106 116 } 107 117 … … 129 139 { 130 140 this->strings = subString.strings; 141 this->bInSafemode = subString.bInSafemode; 131 142 return *this; 132 143 } … … 140 151 bool SubString::operator==(const SubString& subString) const 141 152 { 142 return ( this->strings == subString.strings);153 return ((this->strings == subString.strings) && (this->bInSafemode == subString.bInSafemode)); 143 154 } 144 155 … … 165 176 166 177 for (unsigned int i = 0; i < length; i++) 167 if ( this->strings[i] != subString.strings[i])178 if ((this->strings[i] != subString.strings[i]) || (this->bInSafemode[i] != subString.bInSafemode[i])) 168 179 return false; 169 180 return true; … … 190 201 { 191 202 for (unsigned int i = 0; i < subString.size(); i++) 203 { 192 204 this->strings.push_back(subString[i]); 205 this->bInSafemode.push_back(subString.isInSafemode(i)); 206 } 193 207 return *this; 194 208 } … … 203 217 { 204 218 this->strings.clear(); 219 this->bInSafemode.clear(); 205 220 char split[2]; 206 221 split[0] = splitter; 207 222 split[1] = '\0'; 208 SubString::splitLine(this->strings, string, split);223 SubString::splitLine(this->strings, this->bInSafemode, string, split); 209 224 return strings.size(); 210 225 } … … 223 238 unsigned int SubString::split(const std::string& string, 224 239 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 225 char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char) 240 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 241 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 226 242 { 227 243 this->strings.clear(); 228 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char); 244 this->bInSafemode.clear(); 245 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 229 246 return this->strings.size(); 230 247 } … … 292 309 * @param escape_char: Escape carater (escapes splitters) 293 310 * @param safemode_char: the beginning of the safemode is marked with this 311 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token 312 * @param openparenthesis_char the beginning of a safemode is marked with this 313 * @param closeparenthesis_char the ending of a safemode is marked with this 314 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 294 315 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 295 316 * @param start_state: the Initial state on how to parse the String. 296 * @return sSPLIT_LINE_STATE the parser was in when returning317 * @return SPLIT_LINE_STATE the parser was in when returning 297 318 * 298 319 * This is the Actual Splitting Algorithm from Clemens Wacha … … 302 323 SubString::SPLIT_LINE_STATE 303 324 SubString::splitLine(std::vector<std::string>& ret, 325 std::vector<bool>& bInSafemode, 304 326 const std::string& line, 305 327 const std::string& delimiters, … … 307 329 bool emptyEntries, 308 330 char escape_char, 331 bool removeExcapeChar, 309 332 char safemode_char, 333 bool removeSafemodeChar, 310 334 char openparenthesis_char, 311 335 char closeparenthesis_char, 336 bool removeParenthesisChars, 312 337 char comment_char, 313 338 SPLIT_LINE_STATE start_state) … … 318 343 319 344 std::string token; 345 bool inSafemode = false; 320 346 321 347 if(start_state != SL_NORMAL && ret.size() > 0) … … 323 349 token = ret[ret.size()-1]; 324 350 ret.pop_back(); 351 } 352 if(start_state != SL_NORMAL && bInSafemode.size() > 0) 353 { 354 inSafemode = bInSafemode[bInSafemode.size()-1]; 355 bInSafemode.pop_back(); 325 356 } 326 357 … … 333 364 { 334 365 state = SL_ESCAPE; 366 if (!removeExcapeChar) 367 token += line[i]; 335 368 } 336 369 else if(line[i] == safemode_char) 337 370 { 338 371 state = SL_SAFEMODE; 372 inSafemode = true; 373 if (!removeSafemodeChar) 374 token += line[i]; 339 375 } 340 376 else if(line[i] == openparenthesis_char) 341 377 { 342 378 state = SL_PARENTHESES; 379 inSafemode = true; 380 if (!removeParenthesisChars) 381 token += line[i]; 343 382 } 344 383 else if(line[i] == comment_char) … … 351 390 ret.push_back(token); 352 391 token.clear(); 392 bInSafemode.push_back(inSafemode); 393 inSafemode = false; 353 394 } 354 395 token += line[i]; // EAT … … 365 406 ret.push_back(token); 366 407 token.clear(); 408 bInSafemode.push_back(inSafemode); 409 inSafemode = false; 367 410 } 368 411 state = SL_NORMAL; … … 386 429 break; 387 430 case SL_ESCAPE: 388 if(line[i] == 'n') token += '\n'; 389 else if(line[i] == 't') token += '\t'; 390 else if(line[i] == 'v') token += '\v'; 391 else if(line[i] == 'b') token += '\b'; 392 else if(line[i] == 'r') token += '\r'; 393 else if(line[i] == 'f') token += '\f'; 394 else if(line[i] == 'a') token += '\a'; 395 else if(line[i] == '?') token += '\?'; 396 else token += line[i]; // EAT 431 if (!removeSafemodeChar) 432 token += line[i]; 433 else 434 { 435 if(line[i] == 'n') token += '\n'; 436 else if(line[i] == 't') token += '\t'; 437 else if(line[i] == 'v') token += '\v'; 438 else if(line[i] == 'b') token += '\b'; 439 else if(line[i] == 'r') token += '\r'; 440 else if(line[i] == 'f') token += '\f'; 441 else if(line[i] == 'a') token += '\a'; 442 else if(line[i] == '?') token += '\?'; 443 else token += line[i]; // EAT 444 } 397 445 state = SL_NORMAL; 398 446 break; … … 401 449 { 402 450 state = SL_NORMAL; 451 if (!removeSafemodeChar) 452 token += line[i]; 403 453 } 404 454 else if(line[i] == escape_char) … … 429 479 { 430 480 state = SL_NORMAL; 481 if (!removeParenthesisChars) 482 token += line[i]; 431 483 } 432 484 else if(line[i] == escape_char) … … 461 513 ret.push_back(token); 462 514 token.clear(); 515 bInSafemode.push_back(inSafemode); 516 inSafemode = false; 463 517 } 464 518 state = SL_NORMAL; … … 484 538 ret.push_back(token); 485 539 token.clear(); 540 bInSafemode.push_back(inSafemode); 541 inSafemode = false; 486 542 } 487 543 return(state); -
code/trunk/src/util/SubString.h
r871 r1052 88 88 SubString(const std::string& string, 89 89 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 90 char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0'); 90 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 91 char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 91 92 SubString(unsigned int argc, const char** argv); 92 93 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ … … 111 112 unsigned int split(const std::string& string, 112 113 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false, 113 char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0'); 114 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 115 char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 114 116 std::string join(const std::string& delimiter = " ") const; 115 117 //////////////////////////////////////// … … 120 122 121 123 // retrieve Information from within 122 /** @ returns true if the SubString is empty */124 /** @brief Returns true if the SubString is empty */ 123 125 inline bool empty() const { return this->strings.empty(); }; 124 /** @ returns the count of Strings stored in this substring */126 /** @brief Returns the count of Strings stored in this substring */ 125 127 inline unsigned int size() const { return this->strings.size(); }; 126 /** @ param i the i'th String @returns the i'th string from the subset of Strings*/128 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 127 129 inline const std::string& operator[](unsigned int i) const { return this->strings[i]; }; 128 /** @ param i the i'th String @returns the i'th string from the subset of Strings*/130 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 129 131 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; 130 /** @returns the front of the StringList. */ 132 /** @brief Returns true if the token is in safemode. @param i the i'th token */ 133 inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; } 134 /** @brief Returns the front of the StringList. */ 131 135 inline const std::string& front() const { return this->strings.front(); }; 132 /** @ returns the back of the StringList. */136 /** @brief Returns the back of the StringList. */ 133 137 inline const std::string& back() const { return this->strings.back(); }; 134 138 /** @brief removes the back of the strings list. */ 135 inline void pop_back() { this->strings.pop_back(); };139 inline void pop_back() { this->strings.pop_back(); this->bInSafemode.pop_back(); }; 136 140 137 141 // the almighty algorithm. 138 142 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret, 143 std::vector<bool>& bInSafemode, 139 144 const std::string& line, 140 145 const std::string& delimiters = SubString::WhiteSpaces, … … 142 147 bool emptyEntries = false, 143 148 char escape_char = '\\', 149 bool removeExcapeChar = true, 144 150 char safemode_char = '"', 151 bool removeSafemodeChar = true, 145 152 char openparenthesis_char = '(', 146 153 char closeparenthesis_char = ')', 154 bool removeParenthesisChars = true, 147 155 char comment_char = '\0', 148 156 SPLIT_LINE_STATE start_state = SL_NORMAL); … … 157 165 private: 158 166 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 167 std::vector<bool> bInSafemode; 159 168 }; 160 169 -
code/trunk/src/util/UtilPrereqs.h
r1024 r1052 61 61 class ArgReader; 62 62 class Convert; 63 template <typename FromType, typename ToType>64 class Converter;65 63 class MultiTypePrimitive; 66 64 class MultiTypeString; -
code/trunk/src/util/tinyxml/ticpp.h
r871 r1052 973 973 Stream output operator. 974 974 */ 975 friend std::ostream& operator <<( std::ostream& out, Node& base )975 friend std::ostream& operator <<( std::ostream& out, const Node& base ) 976 976 { 977 977 out << *base.GetTiXmlPointer();
Note: See TracChangeset
for help on using the changeset viewer.