Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1052


Ignore:
Timestamp:
Apr 14, 2008, 3:42:49 AM (16 years ago)
Author:
landauf
Message:

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

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
    126<!--
    227 <audio>
     
    4065<Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" />
    4166
     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
    42116<?lua
    43117for i = 1, 226, 1
  • code/trunk/src/CMakeLists.txt

    r1024 r1052  
    44ADD_SUBDIRECTORY(util)
    55ADD_SUBDIRECTORY(orxonox/core)
    6 ADD_SUBDIRECTORY(audio)
    7 ADD_SUBDIRECTORY(network)
     6#ADD_SUBDIRECTORY(audio)
     7#ADD_SUBDIRECTORY(network)
    88ADD_SUBDIRECTORY(orxonox)
  • code/trunk/src/asylum/orxonox/objects/Fighter.cc

    r1032 r1052  
    3838#include "util/String2Number.h"
    3939#include "core/CoreIncludes.h"
     40#include "core/ConfigValueIncludes.h"
    4041#include "GraphicsEngine.h"
    4142#include "core/InputManager.h"
  • code/trunk/src/asylum/orxonox/objects/Test.h

    r1024 r1052  
    3030
    3131#include "core/BaseObject.h"
     32#include "core/CoreIncludes.h"
    3233
    3334namespace orxonox
  • code/trunk/src/asylum/orxonox/objects/test2.cc

    r1024 r1052  
    3030#include "test3.h"
    3131#include "core/CoreIncludes.h"
     32#include "core/Executor.h"
    3233
    3334namespace orxonox
     
    4344        this->usefullClass3_ = Class(Test3);
    4445
    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)));
    4849    }
    4950
  • code/trunk/src/asylum/orxonox/objects/test3.cc

    r1024 r1052  
    3030#include "test3.h"
    3131#include "core/CoreIncludes.h"
     32#include "core/ConfigValueIncludes.h"
    3233
    3334namespace orxonox
     
    5657        SetConfigValue(value_vector3_, Vector3(13, 26, 39));
    5758        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)));
    5862    }
    5963
     
    6468    void Test3::configOutput()
    6569    {
    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;
    7897    }
    7998
  • code/trunk/src/asylum/orxonox/objects/test3.h

    r1024 r1052  
    11#ifndef _Test3_H__
    22#define _Test3_H__
     3
     4#include <vector>
    35
    46#include "core/BaseObject.h"
     
    3638            Vector3             value_vector3_;
    3739            ColourValue         value_colourvalue_;
     40
     41            std::vector<int>         vector_int_;
     42            std::vector<std::string> vector_string_;
     43            std::vector<Vector3>     vector_vector3_;
    3844    };
    3945}
  • code/trunk/src/orxonox/GraphicsEngine.cc

    r1042 r1052  
    4242
    4343#include "core/CoreIncludes.h"
     44#include "core/ConfigValueIncludes.h"
    4445#include "core/Debug.h"
    4546
    4647
    4748namespace orxonox {
    48 
    49   using namespace Ogre;
    5049
    5150  /**
     
    9695    this->renderWindow_ = 0;
    9796    // 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();
    103102    }
    104103    COUT(4) << "*** GraphicsEngine: Destroying objects done" << std::endl;
     
    121120    //TODO: Check if file exists (maybe not here)
    122121/*#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",
    124123                     configPath_ + "Ogre.log");
    125124#else
    126     root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
     125    root_ = new Ogre::Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
    127126#endif*/
    128127#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG)
     
    153152    // Root will detect that we've already created a Log
    154153    COUT(4) << "*** GraphicsEngine: Creating Ogre Root..." << std::endl;
    155     root_ = new Root(plugin_filename);
     154    root_ = new Ogre::Root(plugin_filename);
    156155    COUT(4) << "*** GraphicsEngine: Creating Ogre Root done" << std::endl;
    157156  }
     
    160159   * @return scene manager
    161160   */
    162   SceneManager* GraphicsEngine::getSceneManager()
     161  Ogre::SceneManager* GraphicsEngine::getSceneManager()
    163162  {
    164163    if(!scene_)
    165164    {
    166       scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager");
     165      scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
    167166      COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl;
    168167    }
     
    184183  {
    185184    this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
    186     TextureManager::getSingleton().setDefaultNumMipmaps(5);
     185    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    187186    //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();
    189188  }
    190189
     
    194193    //TODO: Work with ressource groups (should be generated by a special loader)
    195194    // Load resource paths from data file using configfile ressource type
    196     ConfigFile cf;
     195    Ogre::ConfigFile cf;
    197196    cf.load(dataPath + "resources.cfg");
    198197
    199198    // Go through all sections & settings in the file
    200     ConfigFile::SectionIterator seci = cf.getSectionIterator();
     199    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    201200
    202201    std::string secName, typeName, archName;
     
    204203    {
    205204      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;
    208207      for (i = settings->begin(); i != settings->end(); ++i)
    209208      {
     
    211210        archName = i->second; // name (and location) of archive
    212211
    213         ResourceGroupManager::getSingleton().addResourceLocation(
     212        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    214213                                           std::string(dataPath + archName),
    215214                                           typeName, secName);
     
    269268  */
    270269  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)
    272271  {
    273272    int orxonoxLevel;
    274273    switch (lml)
    275274    {
    276       case LML_TRIVIAL:
     275      case Ogre::LML_TRIVIAL:
    277276        orxonoxLevel = this->ogreLogLevelTrivial_;
    278277        break;
    279       case LML_NORMAL:
     278      case Ogre::LML_NORMAL:
    280279        orxonoxLevel = this->ogreLogLevelNormal_;
    281280        break;
    282       case LML_CRITICAL:
     281      case Ogre::LML_CRITICAL:
    283282        orxonoxLevel = this->ogreLogLevelCritical_;
    284283        break;
  • code/trunk/src/orxonox/Orxonox.cc

    r1039 r1052  
    5555
    5656// core
     57#include "core/ConsoleCommand.h"
    5758#include "core/Debug.h"
    5859#include "core/Factory.h"
    5960#include "core/Loader.h"
    6061#include "core/Tickable.h"
     62#include "core/InputBuffer.h"
    6163#include "core/InputManager.h"
    6264
     
    8082namespace orxonox
    8183{
     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
    82121  /**
    83122    @brief Reference to the only instance of the class.
     
    198237  {
    199238    COUT(2) << "initialising server" << std::endl;
    200    
     239
    201240    ogre_->setConfigPath(path);
    202241    ogre_->setup();
    203242    //root_ = ogre_->getRoot();
    204243    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
    205    
     244
    206245    server_g = new network::Server();
    207246  }
     
    210249  {
    211250    COUT(2) << "initialising client" << std::endl;\
    212    
     251
    213252    ogre_->setConfigPath(path);
    214253    ogre_->setup();
     
    219258    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
    220259  }
    221  
     260
    222261  void Orxonox::standaloneInit(std::string path)
    223262  {
    224263    COUT(2) << "initialising standalone mode" << std::endl;
    225    
     264
    226265    ogre_->setConfigPath(path);
    227266    ogre_->setup();
     
    229268    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
    230269  }
    231  
     270
    232271  /**
    233272   * start modules
     
    246285    }
    247286  }
    248  
     287
    249288  void Orxonox::clientStart(){
    250289    ogre_->initialise();
    251290    Factory::createClassHierarchy();
    252    
    253    
     291
     292
    254293    auMan_ = new audio::AudioManager();
    255294
    256295    //bulletMgr_ = new BulletManager();
    257    
     296
    258297    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
    259298    HUD* orxonoxHud;
     
    262301    orxonoxHud->setEnergyDistr(20,20,60);
    263302    hudOverlay->show();
    264    
     303
    265304    client_g->establishConnection();
    266305    client_g->tick(0);
    267    
    268    
     306
     307
    269308    //setupInputSystem();
    270    
     309
    271310    startRenderLoop();
    272311  }
    273  
     312
    274313  void Orxonox::serverStart(){
    275314    //TODO: start modules
     
    279318    createScene();
    280319    setupInputSystem();
    281    
     320
    282321    server_g->open();
    283    
     322
    284323    startRenderLoop();
    285324  }
    286  
     325
    287326  void Orxonox::standaloneStart(){
    288327    //TODO: start modules
     
    292331    createScene();
    293332    setupInputSystem();
    294    
     333
    295334    startRenderLoop();
    296335  }
     
    351390  void Orxonox::startRenderLoop()
    352391  {
     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
    353400    // first check whether ogre root object has been created
    354401    if (Ogre::Root::getSingletonPtr() == 0)
     
    395442      // Iterate through all Tickables and call their tick(dt) function
    396443      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
    397         (it++)->tick((float)evt.timeSinceLastFrame);
     444        (it++)->tick((float)evt.timeSinceLastFrame * this->timefactor_);
    398445
    399446      // don't forget to call _fireFrameStarted in ogre to make sure
  • code/trunk/src/orxonox/Orxonox.h

    r1039 r1052  
    4141      static void destroySingleton();
    4242
     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
    4348   private:
    4449      // don't mess with singletons
     
    7580      HUD*                  orxonoxHUD_;
    7681      bool                  bAbort_;        //!< aborts the render loop if true
     82      float                 timefactor_;    //!< A factor to change the gamespeed
    7783
    7884      // this is used to identify the mode (server/client/...) we're in
  • code/trunk/src/orxonox/OrxonoxStableHeaders.h

    r1032 r1052  
    9797
    9898#include "util/Math.h"
    99 #include "util/Convert.h"
    10099#include "util/Sleep.h"
    101100#include "util/String2Number.h"
  • code/trunk/src/orxonox/core/BaseObject.cc

    r1021 r1052  
    5252        this->bVisible_ = true;
    5353        this->level_ = 0;
     54        this->namespace_ = 0;
    5455    }
    5556
     
    7879        @return The XML-element
    7980    */
    80     void BaseObject::XMLPort(Element& xmlelement, bool loading)
     81    void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    8182    {
    82         XMLPortParam(BaseObject, "name", setName, getName, xmlelement, loading);
     83        XMLPortParam(BaseObject, "name", setName, getName, xmlelement, mode);
    8384    }
    8485
  • code/trunk/src/orxonox/core/BaseObject.h

    r871 r1052  
    5050            virtual ~BaseObject();
    5151            virtual void loadParams(TiXmlElement* xmlElem);
    52             virtual void XMLPort(Element& xmlelement, bool loading);
     52            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5353
    5454            /** @brief Sets the name of the object. @param name The name */
     
    7979            const std::string& getLevelfile() const;
    8080
     81            virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }
     82            inline Namespace* getNamespace() const { return this->namespace_; }
     83
    8184            /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */
    8285            inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; }
     
    9093            const Level* level_;                        //!< The level that loaded this object
    9194            std::string loaderIndentation_;             //!< Indentation of the debug output in the Loader
     95            Namespace* namespace_;
    9296    };
    9397}
  • code/trunk/src/orxonox/core/CMakeLists.txt

    r1048 r1052  
    99  InputEventListener.cc
    1010  MetaObjectList.cc
     11  ConfigFileManager.cc
    1112  ConfigValueContainer.cc
    1213  Error.cc
    1314  SignalHandler.cc
    14   DebugLevel.cc
     15  CoreSettings.cc
    1516  OutputHandler.cc
    1617  Language.cc
     
    1920  Executor.cc
    2021  XMLPort.cc
     22  Namespace.cc
     23  NamespaceNode.cc
     24  CommandExecutor.cc
     25  InputBuffer.cc
    2126  Tickable.cc
    2227  Script.cc
  • code/trunk/src/orxonox/core/ClassTreeMask.cc

    r1021 r1052  
    327327        {
    328328            // 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)
    330330                if ((*it)->isA(this->root_->getClass()))
    331331                    if (overwrite || (!this->nodeExists(*it))) // If we don't want to overwrite, only add nodes that don't already exist
     
    422422    void ClassTreeMask::addSingle(const Identifier* subclass, bool bInclude, bool clean)
    423423    {
    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)
    425425            this->add(*it, this->isIncluded(*it), false, false);
    426426
     
    561561
    562562    /**
     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    /**
    563596        @brief Prefix operator + does nothing.
    564597        @return A reference to the mask itself
  • code/trunk/src/orxonox/core/ClassTreeMask.h

    r871 r1052  
    179179            ClassTreeMask& operator=(const ClassTreeMask& other);
    180180
     181            bool operator==(const ClassTreeMask& other) const;
     182            bool operator!=(const ClassTreeMask& other) const;
     183
    181184            ClassTreeMask& operator+();
    182185            ClassTreeMask operator-() const;
  • code/trunk/src/orxonox/core/ConfigValueContainer.cc

    r871 r1052  
    3434
    3535#include "ConfigValueContainer.h"
    36 #include "util/Tokenizer.h"
     36#include "Language.h"
     37#include "Identifier.h"
     38#include "util/SubString.h"
    3739#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
    4143
    4244namespace orxonox
     
    4446    /**
    4547        @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 name of the class the variable belongs to
     48        @param type The type of the corresponding config-file
     49        @param identifier The identifier of the class the variable belongs to
    4850        @param varname The name of the variable
    4951        @param defvalue The default-value
    5052    */
    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;
    5361        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();
    5580        this->varname_ = varname;
    5681
    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());
    99168            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        }
    176263    }
    177264
     
    181268        @return True if the string was successfully parsed
    182269    */
    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            {
    747283                if (!success)
    748284                {
    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;
    753286                }
    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;
    787304            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;
    939376    }
    940377
     
    947384        if (!this->bAddedDescription_)
    948385        {
    949             this->description_ = std::string("ConfigValueDescription::" + this->classname_ + "::" + this->varname_);
     386            this->description_ = std::string("ConfigValueDescription::" + this->identifier_->getName() + "::" + this->varname_);
    950387            AddLanguageEntry(this->description_, description);
    951388            this->bAddedDescription_ = true;
  • code/trunk/src/orxonox/core/ConfigValueContainer.h

    r871 r1052  
    4343#define _ConfigValueContainer_H__
    4444
    45 #include <list>
    4645#include <string>
     46#include <vector>
    4747
    4848#include "CorePrereqs.h"
     
    5050#include "util/Math.h"
    5151#include "util/MultiTypeMath.h"
     52#include "ConfigFileManager.h"
    5253
    5354namespace orxonox
     
    7273    {
    7374        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);
    7577
    7678            /** @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(); }
    10097
    10198            void description(const std::string& description);
    10299            const std::string& getDescription() const;
    103100
    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();
    108107
    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(); }
    112114
    113115        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);
    134118
    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);
    139123
    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
    142125
    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
    146132
    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
    148135
    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
    153138    };
    154139}
  • code/trunk/src/orxonox/core/CoreIncludes.h

    r871 r1052  
    2828/**
    2929    @file CoreIncludes.h
    30     @brief Definition of macros and typedefs.
     30    @brief Definition of macros for Identifier and Factory.
    3131
    3232    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
     
    4040#define _CoreIncludes_H__
    4141
    42 #include "CorePrereqs.h"
    43 
    44 // All needed header-files
    4542#include "Identifier.h"
    4643#include "ClassManager.h"
    4744#include "Factory.h"
    4845#include "ClassFactory.h"
    49 #include "Iterator.h"
    50 #include "OrxonoxClass.h"
    51 #include "ConfigValueContainer.h"
    5246#include "Debug.h"
    5347
    5448
    55 // All needed macros
    5649/**
    5750    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
     
    111104    orxonox::Factory::getIdentifier(StringOrInt)
    112105
    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 variable
    116     @param defvalue The default-value of the variable
    117 */
    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 variable
    130 */
    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::endl
    140 
    141106#endif /* _CoreIncludes_H__ */
  • code/trunk/src/orxonox/core/CorePrereqs.h

    r1024 r1052  
    6565namespace orxonox
    6666{
     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
    6779  typedef std::string LanguageEntryLabel;
    6880
     
    7991  class ClassTreeMaskIterator;
    8092  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;
    81101  class ConfigValueContainer;
    82   class DebugLevel;
     102  class CoreSettings;
    83103  class Error;
    84104  class Executor;
     105  template <class T>
     106  class ExecutorMember;
     107  class ExecutorStatic;
    85108  class Factory;
     109  class Functor;
     110  template <class T>
     111  class FunctorMember;
     112  class FunctorStatic;
    86113  class Identifier;
    87114  class IdentifierDistributor;
     115  class InputBuffer;
     116  class InputBufferListener;
    88117  class InputHandlerGame;
    89118  class InputHandlerGUI;
     
    98127  template <class T>
    99128  class MetaObjectListElement;
     129  class Namespace;
     130  class NamespaceNode;
    100131  template <class T>
    101132  class ObjectList;
     
    104135  class OrxonoxClass;
    105136  class OutputHandler;
     137  class Shell;
    106138  template <class T>
    107139  class SubclassIdentifier;
  • code/trunk/src/orxonox/core/Executor.cc

    r871 r1052  
    2929#include "Executor.h"
    3030#include "Language.h"
    31 #include "util/String.h"
     31#include "util/Math.h"
    3232
    3333namespace orxonox
    3434{
    35     Executor::Executor(Functor* functor, const std::string& name)
     35    Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level)
    3636    {
    3737        this->functor_ = functor;
    3838        this->name_ = name;
     39        this->accessLevel_ = level;
     40
    3941        this->bAddedDescription_ = false;
    4042        this->bAddedDescriptionReturnvalue_ = false;
     43
    4144        this->bAddedDescriptionParam_[0] = false;
    4245        this->bAddedDescriptionParam_[1] = false;
     
    4447        this->bAddedDescriptionParam_[3] = false;
    4548        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;
    4655    }
    4756
    4857    Executor::~Executor()
    4958    {
    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)
    63116    {
    64117        if (!this->bAddedDescription_)
     
    68121            this->bAddedDescription_ = true;
    69122        }
     123        return (*this);
    70124    }
    71125
     
    75129    }
    76130
    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)
    80134        {
    81135            if (!this->bAddedDescriptionParam_[param])
     
    83137                std::string paramnumber;
    84138                if (!Convert::ToString(&paramnumber, param))
    85                     return;
     139                    return (*this);
    86140
    87141                this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber);
     
    90144            }
    91145        }
     146        return (*this);
    92147    }
    93148
    94149    const std::string& Executor::getDescriptionParam(int param) const
    95150    {
    96         if (param > 0 && param <= 5)
    97         {
     151        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
    98152            return GetLocalisation(this->descriptionParam_[param]);
    99         }
    100153
    101154        return this->descriptionParam_[0];
    102155    }
    103156
    104     void Executor::descriptionReturnvalue(const std::string& description)
     157    Executor& Executor::setDescriptionReturnvalue(const std::string& description)
    105158    {
    106159        if (!this->bAddedDescriptionReturnvalue_)
     
    110163            this->bAddedDescriptionReturnvalue_ = true;
    111164        }
     165        return (*this);
    112166    }
    113167
     
    116170        return GetLocalisation(this->descriptionReturnvalue_);
    117171    }
     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    }
    118251}
  • code/trunk/src/orxonox/core/Executor.h

    r871 r1052  
    3232#include "CorePrereqs.h"
    3333#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
     134namespace AccessLevel
     135{
     136    enum Level
     137    {
     138        None,
     139        User,
     140        Admin,
     141        Offline,
     142        Debug,
     143        Disabled
     144    };
     145}
    34146
    35147namespace orxonox
     
    38150    {
    39151        public:
    40             Executor(Functor* functor, const std::string& name = "");
     152            Executor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None);
    41153            virtual ~Executor();
    42154
    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
    44166                { (*this->functor_)(param1, param2, param3, param4, param5); }
    45167
    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);
    50173            const std::string& getDescription() const;
    51174
    52             void descriptionParam(int param, const std::string& description);
     175            Executor& setDescriptionParam(int param, const std::string& description);
    53176            const std::string& getDescriptionParam(int param) const;
    54177
    55             void descriptionReturnvalue(const std::string& description);
     178            Executor& setDescriptionReturnvalue(const std::string& description);
    56179            const std::string& getDescriptionReturnvalue(int param) const;
    57180
    58             inline int getParamCount() const
     181            inline unsigned int getParamCount() const
    59182                { return this->functor_->getParamCount(); }
    60183            inline bool hasReturnvalue() const
     
    64187            inline MultiTypeMath getReturnvalue() const
    65188                { return this->functor_->getReturnvalue(); }
    66             inline std::string getTypenameParam(int param) const
     189            inline std::string getTypenameParam(unsigned int param) const
    67190                { return this->functor_->getTypenameParam(param); }
    68191            inline std::string getTypenameReturnvalue() const
    69192                { return this->functor_->getTypenameReturnvalue(); }
    70193
     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
    71228        protected:
    72229            Functor* functor_;
     230            std::string name_;
     231            MultiTypeMath defaultValue_[MAX_FUNCTOR_ARGUMENTS];
     232            bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS];
    73233
    74234        private:
    75             std::string name_;
    76 
    77235            LanguageEntryLabel description_;
    78236            LanguageEntryLabel descriptionReturnvalue_;
    79             LanguageEntryLabel descriptionParam_[5];
     237            LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
    80238
    81239            bool bAddedDescription_;
    82240            bool bAddedDescriptionReturnvalue_;
    83             bool bAddedDescriptionParam_[5];
     241            bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS];
     242
     243            AccessLevel::Level accessLevel_;
    84244    };
    85245
     
    87247    {
    88248        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) {}
    90250            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); }
    94251    };
    95252
     
    98255    {
    99256        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) {}
    101258            virtual ~ExecutorMember() {}
    102259
    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            }
    114301    };
     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    }
    115318}
    116319
  • code/trunk/src/orxonox/core/Functor.h

    r871 r1052  
    3535#include "CorePrereqs.h"
    3636
    37 
    38 enum FunctionType
     37#define MAX_FUNCTOR_ARGUMENTS 5
     38
     39namespace orxonox
    3940{
    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"; }
    4851
    4952#define CreateTypeToStringTemplate(type) \
    5053    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()
    125130            {
    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                }
    128152                else
    129153                {
    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                    }
    132161                }
    133162            }
    134             else
     163
     164            void setObject(T* object)
    135165            {
    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;
    143168            }
    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    };
    173181
    174182
     
    272280
    273281
     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
    274307
    275308
     
    295328            } \
    296329    \
     330            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     331            { \
     332                FUNCTOR_EVALUATE_PARAM(numparams); \
     333            } \
     334    \
    297335        private: \
    298336            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     
    334372            } \
    335373    \
     374            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     375            { \
     376                FUNCTOR_EVALUATE_PARAM(numparams); \
     377            } \
     378    \
    336379        private: \
    337380            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     
    359402            { \
    360403                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); \
    361409            } \
    362410    \
     
    412460
    413461
    414 CREATE_ALL_STATIC_FUNCTORS();
    415 CREATE_ALL_MEMBER_FUNCTORS();
     462    CREATE_ALL_STATIC_FUNCTORS();
     463    CREATE_ALL_MEMBER_FUNCTORS();
     464}
    416465
    417466#endif /* _Functor_H__ */
  • code/trunk/src/orxonox/core/Identifier.cc

    r871 r1052  
    3535#include "Identifier.h"
    3636#include "Factory.h"
     37#include "Executor.h"
     38#include "CommandExecutor.h"
    3739
    3840namespace orxonox
     
    5153        this->factory_ = 0;
    5254
    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*>();
    5560
    5661        // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables
     
    7277        @param parents A list containing all parents
    7378    */
    74     void Identifier::initialize(std::list<const Identifier*>* parents)
     79    void Identifier::initialize(std::set<const Identifier*>* parents)
    7580    {
    7681        COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl;
     
    8388
    8489            // 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)
    8691            {
    8792                // Tell the parent we're one of it's children
     
    8994
    9095                // 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)
    9297                {
    9398                    // 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)
    95100                    {
    96101                        if ((*it1) == (*it2))
     
    105110
    106111            // 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)
    108113            {
    109114                // Tell the parent we're one of it's direct children
     
    149154    bool Identifier::isA(const Identifier* identifier) const
    150155    {
    151         return (identifier == this || this->identifierIsInList(identifier, this->parents_));
     156        return (identifier == this || (this->parents_.find(identifier) != this->children_->end()));
    152157    }
    153158
     
    167172    bool Identifier::isChildOf(const Identifier* identifier) const
    168173    {
    169         return this->identifierIsInList(identifier, this->parents_);
     174        return (this->parents_.find(identifier) != this->children_->end());
    170175    }
    171176
     
    176181    bool Identifier::isDirectChildOf(const Identifier* identifier) const
    177182    {
    178         return this->identifierIsInList(identifier, this->directParents_);
     183        return (this->directParents_.find(identifier) != this->children_->end());
    179184    }
    180185
     
    185190    bool Identifier::isParentOf(const Identifier* identifier) const
    186191    {
    187         return this->identifierIsInList(identifier, *this->children_);
     192        return (this->children_->find(identifier) != this->children_->end());
    188193    }
    189194
     
    194199    bool Identifier::isDirectParentOf(const Identifier* identifier) const
    195200    {
    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;
    197234    }
    198235
     
    212249
    213250    /**
    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)
    241319            out << (*it)->getName() << " ";
    242320
  • code/trunk/src/orxonox/core/Identifier.h

    r1024 r1052  
    5252#define _Identifier_H__
    5353
    54 #include <list>
     54#include <set>
    5555#include <map>
    5656#include <string>
     
    6262#include "Debug.h"
    6363#include "Iterator.h"
     64#include "util/String.h"
    6465
    6566namespace orxonox
     
    105106            bool isDirectParentOf(const Identifier* identifier) const;
    106107
    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;
    109111
    110112            /** @brief Returns the name of the class the Identifier belongs to. @return The name */
    111113            inline const std::string& getName() const { return this->name_; }
    112114
     115
    113116            /** @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_; }
    115118            /** @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(); }
    117120            /** @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(); }
    119122
    120123            /** @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_); }
    122125            /** @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(); }
    124127            /** @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(); }
    126129
    127130            /** @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_; }
    129132            /** @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(); }
    131134            /** @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(); }
    133136
    134137            /** @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_); }
    136139            /** @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(); }
    138141            /** @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_; }
    140194
    141195            /** @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 */
     
    148202            void setNetworkID(unsigned int id);
    149203
     204            void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
    150205            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;
    153209            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;
    156212            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();
    160223
    161224        private:
     
    163226            Identifier(const Identifier& identifier) {} // don't copy
    164227            virtual ~Identifier();
    165             void initialize(std::list<const Identifier*>* parents);
     228            void initialize(std::set<const Identifier*>* parents);
    166229
    167230            /** @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_); }
    169232            /** @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_); }
    171234
    172235            /**
     
    188251            }
    189252
    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
    203273    };
    204274
    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);
    206276
    207277
     
    228298
    229299        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);
    231301            void addObject(T* object);
    232             void removeObjects() const;
    233302            void setName(const std::string& name);
     303            /** @brief Returns the list of all existing objects of this class. @return The list */
    234304            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;
    235309
    236310            XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
     
    245319            ~ClassIdentifier() {}                                       // don't delete
    246320
    247             ObjectList<T>* objects_;    //!< The ObjectList, containing all objects of type T
    248             bool bSetName_;             //!< True if the name is set
    249             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
    251325    };
    252326
     
    270344    */
    271345    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);
    275349
    276350        // Check if at least one object of the given type was created
    277         if (!this->bCreatedOneObject_)
     351        if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
    278352        {
    279353            // If no: We have to store the informations and initialize the Identifier
    280             this->setName(name);
    281 
    282354            COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
    283355            if (bRootClass)
     
    301373            this->name_ = name;
    302374            this->bSetName_ = true;
     375            Identifier::getIdentifierMapIntern()[name] = this;
     376            Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
    303377        }
    304378    }
     
    316390
    317391    /**
    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    */
    327406    template <class T>
    328407    XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname)
     
    335414    }
    336415
     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    */
    337421    template <class T>
    338422    void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
     
    341425    }
    342426
     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    */
    343432    template <class T>
    344433    XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname)
     
    351440    }
    352441
     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    */
    353447    template <class T>
    354448    void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
  • code/trunk/src/orxonox/core/InputBuffer.cc

    r1051 r1052  
    2929
    3030#include "InputBuffer.h"
     31#include "InputManager.h"
    3132#include "util/Clipboard.h"
    3233
    3334namespace orxonox
    3435{
    35     InputBuffer::InputBuffer(OIS::Keyboard* keyboard)
     36    InputBuffer::InputBuffer()
    3637    {
    3738        this->bActivated_ = false;
    3839        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"().:,;_-+*/=!?<>[|]";
    39         this->keyboard_ = keyboard;
     40        this->keyboard_ = InputManager::getSingleton().getKeyboard();
    4041        this->buffer_ = "";
    4142
  • code/trunk/src/orxonox/core/InputBuffer.h

    r1051 r1052  
    5858
    5959        public:
    60             InputBuffer(OIS::Keyboard* keyboard);
     60            InputBuffer();
    6161
    6262            template <class T>
  • code/trunk/src/orxonox/core/InputHandler.cc

    r1024 r1052  
    6666    {
    6767      // 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);
    7070    }
    7171    return true;
  • code/trunk/src/orxonox/core/Language.cc

    r871 r1052  
    2828/**
    2929    @file Language.cc
    30     @brief Implementation of the Language and the LanguageEntry class.
     30    @brief Implementation of the Language and the LanguageEntry classes.
    3131*/
    3232
    3333#include <fstream>
    3434
    35 #include "CoreIncludes.h"
    3635#include "Language.h"
     36#include "CoreSettings.h"
    3737
    3838namespace orxonox
     
    4747    LanguageEntry::LanguageEntry(const std::string& fallbackEntry)
    4848    {
    49         RegisterRootObject(LanguageEntry);
    50 
    5149        this->fallbackEntry_ = fallbackEntry;
    5250        this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned
     
    6159    {
    6260        // Check if the translation is more than just an empty string
    63         if (localisation.compare("") != 0)
     61        if ((localisation != "") && (localisation.size() > 0))
    6462        {
    6563            this->localisedEntry_ = localisation;
     
    9189    Language::Language()
    9290    {
    93         RegisterRootObject(Language);
    94 
    9591        this->defaultLanguage_ = "default";
    9692        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     
    10197
    10298    /**
    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 configured
    110         this->readTranslatedLanguageFile();
    111     }
    112 
    113     /**
    11499        @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function.
    115100        @return The reference to the only existing instance
     
    117102    Language& Language::getLanguage()
    118103    {
    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;
    131106    }
    132107
     
    244219
    245220            // Check if the line is empty
    246             if (lineString.compare("") != 0)
     221            if ((lineString != "") && (lineString.size() > 0))
    247222            {
    248223                unsigned int pos = lineString.find('=');
     
    252227                    this->createEntry(lineString.substr(0, pos), lineString.substr(pos + 1));
    253228                else
     229                {
    254230                    COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->defaultLanguage_) << std::endl;
     231                }
    255232            }
    256233        }
     
    264241    void Language::readTranslatedLanguageFile()
    265242    {
    266         COUT(4) << "Read translated language file (" << this->language_ << ")." << std::endl;
     243        COUT(4) << "Read translated language file (" << CoreSettings::getLanguage() << ")." << std::endl;
    267244
    268245        // Open the file
    269246        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);
    271248
    272249        if (!file.is_open())
    273250        {
    274251            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();
    277254            COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl;
    278255            return;
     
    288265
    289266            // Check if the line is empty
    290             if (lineString.compare("") != 0)
     267            if ((lineString != "") && (lineString.size() > 0))
    291268            {
    292269                unsigned int pos = lineString.find('=');
     
    304281                }
    305282                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                }
    307286            }
    308287        }
     
    330309
    331310        // 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;
    335314        }
    336315
  • code/trunk/src/orxonox/core/Language.h

    r871 r1052  
    4949
    5050#include "CorePrereqs.h"
    51 #include "OrxonoxClass.h"
    5251
    5352
     
    6564    // ###############################
    6665    //! The LanguageEntry class stores the default- and the translated string of a given entry in the language file.
    67     class _CoreExport LanguageEntry : public OrxonoxClass
     66    class _CoreExport LanguageEntry
    6867    {
    6968        public:
     
    112111    // ###############################
    113112    //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map.
    114     class _CoreExport Language : public OrxonoxClass
     113    class _CoreExport Language
    115114    {
    116         template <class T>
    117         friend class ClassIdentifier; // forward declaration because of the private destructor
     115        friend class CoreSettings;
    118116
    119117        public:
    120118            static Language& getLanguage();
    121             void setConfigValues();
    122119            void addEntry(const LanguageEntryLabel& label, const std::string& entry);
    123120            const std::string& getLocalisation(const LanguageEntryLabel& label) const;
     
    134131            LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry);
    135132
    136             std::string language_;                                  //!< The configured language
    137133            std::string defaultLanguage_;                           //!< The default language
    138134            std::string defaultLocalisation_;                       //!< The returned string, if an entry unavailable entry is requested
  • code/trunk/src/orxonox/core/Loader.cc

    r1021 r1052  
    3434#include "CoreIncludes.h"
    3535#include "Script.h"
     36#include "Namespace.h"
    3637
    3738#include "util/tinyxml/ticpp.h"
     
    129130            xmlfile.Parse(lua->getLuaOutput(), true);
    130131
    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);
    151146
    152147            COUT(0) << "Finished loading " << level->getFile() << "." << std::endl;
     148
     149            COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString("  ") << std::endl;
    153150
    154151            return true;
  • code/trunk/src/orxonox/core/MetaObjectList.h

    r1024 r1052  
    9999
    100100
    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;
    102102        delete this->element_;
    103103    }
  • code/trunk/src/orxonox/core/OrxonoxClass.h

    r871 r1052  
    3737#define _OrxonoxClass_H__
    3838
    39 #include <list>
     39#include <set>
    4040#include <string>
    4141
     
    6767
    6868            /** @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_; }
    7070
    7171            /** @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*>(); }
    7373
    7474            /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */
     
    157157        private:
    158158            Identifier* identifier_;                    //!< The Identifier of the object
    159             std::list<const Identifier*>* parents_;     //!< List of all parents of the object
     159            std::set<const Identifier*>* parents_;     //!< List of all parents of the object
    160160            MetaObjectList metaList_;                   //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
    161161    };
  • code/trunk/src/orxonox/core/OutputHandler.cc

    r871 r1052  
    3131*/
    3232
    33 #include "DebugLevel.h"
     33#include "CoreSettings.h"
    3434#include "OutputHandler.h"
     35#include "ConsoleCommand.h"
    3536
    3637namespace orxonox
    3738{
     39    ConsoleCommandShortcutGeneric(log, createExecutor(createFunctor(&OutputHandler::log), "log", AccessLevel::None));
     40
    3841    /**
    3942        @brief Constructor: Opens the logfile and writes the first line.
     
    4447        this->logfilename_ = logfilename;
    4548        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;
    4750        this->logfile_.flush();
    4851    }
     
    7477    int OutputHandler::getSoftDebugLevel(OutputHandler::OutputDevice device)
    7578    {
    76         return DebugLevel::getSoftDebugLevel(device);
     79        return CoreSettings::getSoftDebugLevel(device);
    7780    }
    7881
  • code/trunk/src/orxonox/core/OutputHandler.h

    r871 r1052  
    5858
    5959            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; }
    6064
    6165            /** @brief Returns a reference to the logfile. @return The logfile */
  • code/trunk/src/orxonox/core/Tickable.cc

    r1021 r1052  
    2727
    2828#include "core/CoreIncludes.h"
     29#include "core/ConsoleCommand.h"
    2930#include "Tickable.h"
    3031
  • code/trunk/src/orxonox/core/XMLPort.cc

    r871 r1052  
    2929#include "Language.h"
    3030#include "Loader.h"
     31#include "Namespace.h"
     32#include "CoreIncludes.h"
    3133
    3234namespace orxonox
    3335{
    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 
    6136    // ################################
    6237    // ###  XMLPortObjectContainer  ###
    6338    // ################################
    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 
    8639    bool XMLPortObjectContainer::identifierIsIncludedInLoaderMask(const Identifier* identifier)
    8740    {
    88         return Loader::currentMask_s.isIncluded(identifier);
     41        return ((!this->bApplyLoaderMask_) || identifier->isA(Class(Namespace)) || Loader::currentMask_s.isIncluded(identifier));
    8942    }
    9043}
  • code/trunk/src/orxonox/core/XMLPort.h

    r871 r1052  
    3232#include "util/MultiTypeMath.h"
    3333#include "util/tinyxml/ticpp.h"
    34 #include "util/SubString.h"
    35 #include "Functor.h"
     34#include "Executor.h"
    3635#include "Debug.h"
    3736#include "CoreIncludes.h"
     
    4140
    4241
    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) \
    4655    { \
    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); \
    4958    } \
    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) \
    5570    { \
    56         xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), 0); \
    57         this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \
     71        containername = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(std::string(sectionname), loadexecutor, saveexecutor, bApplyLoaderMask, bLoadBefore); \
     72        this->getIdentifier()->addXMLPortObjectContainer(sectionname, containername); \
    5873    } \
    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)
    6975
    7076
    7177namespace orxonox
    7278{
     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
    7392    // ###############################
    7493    // ###  XMLPortParamContainer  ###
     
    7695    class _CoreExport XMLPortParamContainer
    7796    {
     97        enum ParseResult
     98        {
     99            PR_not_started,
     100            PR_finished,
     101            PR_waiting_for_default_values
     102        };
     103
    78104        public:
    79             XMLPortParamContainer();
     105            XMLPortParamContainer()
     106                { this->parseResult_ = PR_not_started; }
     107            virtual ~XMLPortParamContainer() {}
    80108
    81109            inline const std::string& getName() const
    82110                { return this->paramname_; }
    83111
    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;
    97121
    98122        protected:
    99             std::string classname_;
    100123            std::string paramname_;
    101             MultiTypeMath defaultValues_[5];
    102 
    103         private:
    104             LanguageEntryLabel description_;
    105             bool bAddedDescription_;
    106             bool bAddedDefaultValues_;
     124            ParseResult parseResult_;
     125
    107126    };
    108127
     
    110129    class XMLPortClassParamContainer : public XMLPortParamContainer
    111130    {
     131        struct ParseParams
     132        {
     133            T* object;
     134            Element* xmlelement;
     135            XMLPort::Mode mode;
     136        };
     137
    112138        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            {
    116141                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)
    124153                {
    125154                    try
    126155                    {
    127156                        std::string attribute = xmlelement.GetAttribute(this->paramname_);
    128                         if (attribute.size() > 0)
     157                        if ((attribute.size() > 0) || (this->loadexecutor_->allDefaultValuesSet()))
    129158                        {
    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;
    155162                            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;
    159164                        }
    160165                    }
     
    162167                    {
    163168                        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;
    165170                        COUT(1) << ex.what() << std::endl;
    166171                    }
     
    168173                else
    169174                {
    170                     if (this->savefunction_)
     175                    if (this->saveexecutor_)
    171176                    {
    172177//                        xmlelement.SetAttribute(this->paramname_, "...");
     
    177182            }
    178183
     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
    179239        private:
    180             FunctorMember<T>* loadfunction_;
    181             FunctorMember<T>* savefunction_;
     240            ExecutorMember<T>* loadexecutor_;
     241            ExecutorMember<T>* saveexecutor_;
     242            ParseParams parseParams_;
    182243    };
    183244
     
    189250    {
    190251        public:
    191             XMLPortObjectContainer();
     252            XMLPortObjectContainer()
     253                { this->bApplyLoaderMask_ = false; }
     254            virtual ~XMLPortObjectContainer() {}
    192255
    193256            inline const std::string& getName() const
    194257                { return this->sectionname_; }
    195258
    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);
    199263
    200264        protected:
    201             std::string classname_;
    202265            std::string sectionname_;
    203 
    204         private:
    205             LanguageEntryLabel description_;
    206             bool bAddedDescription_;
     266            bool bApplyLoaderMask_;
     267            bool bLoadBefore_;
    207268    };
    208269
     
    211272    {
    212273        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            {
    216276                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)
    224286                {
    225287                    try
    226288                    {
    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;
    228294
    229295                        if (xmlsubelement)
    230296                        {
    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++)
    232298                            {
    233299                                Identifier* identifier = ID(child->Value());
     
    239305                                        {
    240306                                            COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
     307
    241308                                            O* newObject = (O*)identifier->fabricate();
    242309                                            newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
    243310                                            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;
    248330                                        }
    249331                                    }
     
    263345                    {
    264346                        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;
    266348                        COUT(1) << ex.what() << std::endl;
    267349                    }
     
    274356            }
    275357
     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
    276363        private:
    277             void     (T::*loadfunction_)(O*);
    278             const O* (T::*savefunction_)(unsigned int);
     364            ExecutorMember<T>* loadexecutor_;
     365            ExecutorMember<T>* saveexecutor_;
    279366    };
    280367}
  • code/trunk/src/orxonox/objects/Ambient.cc

    r1039 r1052  
    4242#include "GraphicsEngine.h"
    4343#include "core/XMLPort.h"
     44#include "core/ConsoleCommand.h"
    4445
    4546namespace orxonox
    4647{
     48    ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));
     49
    4750    CreateFactory(Ambient);
     51
     52    Ambient* Ambient::instance_s;
    4853
    4954    Ambient::Ambient()
    5055    {
    5156        RegisterObject(Ambient);
     57        Ambient::instance_s = this;
    5258    }
    5359
     
    8490        @return The XML-element
    8591    */
    86     void Ambient::XMLPort(Element& xmlelement, bool loading)
     92    void Ambient::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    8793    {
    88         BaseObject::XMLPort(xmlelement, loading);
     94        BaseObject::XMLPort(xmlelement, mode);
    8995
    90         XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, loading);
     96        XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode);
    9197    }
    9298}
  • code/trunk/src/orxonox/objects/Ambient.h

    r1040 r1052  
    4343
    4444            void loadParams(TiXmlElement* xmlElem);
    45             virtual void XMLPort(Element& xmlelement, bool loading);
     45            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646            void setAmbientLight(const ColourValue& colour);
    4747
     48            static void setAmbientLightTest(const ColourValue& colour)
     49                { Ambient::instance_s->setAmbientLight(colour); }
     50
    4851        private:
    49 
     52            static Ambient* instance_s;
    5053
    5154    };
  • code/trunk/src/orxonox/objects/Explosion.cc

    r1039 r1052  
    3434
    3535#include "core/CoreIncludes.h"
     36#include "core/Executor.h"
     37
    3638#include "util/Math.h"
    3739#include "GraphicsEngine.h"
     
    5153        if (owner)
    5254        {
    53             this->destroyTimer_.setTimer(this->lifetime_, false, this, &Explosion::destroyObject);
     55            this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Explosion::destroyObject)));
    5456
    5557            Vector3 position = owner->getNode()->getWorldPosition();
  • code/trunk/src/orxonox/objects/Model.cc

    r1039 r1052  
    6868        @return The XML-element
    6969    */
    70     void Model::XMLPort(Element& xmlelement, bool loading)
     70    void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7171    {
    72         WorldEntity::XMLPort(xmlelement, loading);
     72        WorldEntity::XMLPort(xmlelement, mode);
    7373
    74         XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, loading);
     74        XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, mode);
    7575
    7676        create();
     
    8484    bool Model::create(){
    8585      WorldEntity::create();
    86       if(meshSrc_.compare("")!=0){
     86      if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
     87      {
    8788        this->mesh_.setMesh(meshSrc_);
    8889        this->attachObject(this->mesh_.getEntity());
  • code/trunk/src/orxonox/objects/Model.h

    r1039 r1052  
    4343            virtual ~Model();
    4444            virtual void loadParams(TiXmlElement* xmlElem);
    45             virtual void XMLPort(Element& xmlelement, bool loading);
     45            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646            void setMesh(const std::string& meshname);
    4747            bool create();
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1039 r1052  
    2929#include "Projectile.h"
    3030
    31 #include "../core/CoreIncludes.h"
     31#include "core/CoreIncludes.h"
     32#include "core/Executor.h"
     33#include "core/ConfigValueIncludes.h"
     34
    3235#include "SpaceShip.h"
    3336#include "Explosion.h"
     
    5962        }
    6063
    61         this->destroyTimer_.setTimer(this->lifetime_, false, this, &Projectile::destroyObject);
     64        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    6265    }
    6366
     
    7073        SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive");
    7174        SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second");
     75
     76        this->setVelocity(Vector3(1, 0, 0) * this->speed_);
    7277    }
    7378
  • code/trunk/src/orxonox/objects/Skybox.cc

    r1039 r1052  
    7676        @return The XML-element
    7777    */
    78     void Skybox::XMLPort(Element& xmlelement, bool loading)
     78    void Skybox::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7979    {
    80         BaseObject::XMLPort(xmlelement, loading);
     80        BaseObject::XMLPort(xmlelement, mode);
    8181
    82         XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, loading);
     82        XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode);
    8383    }
    8484}
  • code/trunk/src/orxonox/objects/Skybox.h

    r1039 r1052  
    1515
    1616            void loadParams(TiXmlElement* xmlElem);
    17             virtual void XMLPort(Element& xmlelement, bool loading);
     17            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    1818            void setSkybox(const std::string& skyboxname);
    1919
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1039 r1052  
    4141#include "util/Math.h"
    4242#include "core/CoreIncludes.h"
     43#include "core/ConfigValueIncludes.h"
    4344#include "core/Debug.h"
    4445#include "GraphicsEngine.h"
     
    4748#include "Projectile.h"
    4849#include "core/XMLPort.h"
     50#include "core/ConsoleCommand.h"
    4951
    5052namespace orxonox
    5153{
     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
    5259    CreateFactory(SpaceShip);
     60
     61    SpaceShip* SpaceShip::instance_s;
    5362
    5463    SpaceShip::SpaceShip()
     
    5665        RegisterObject(SpaceShip);
    5766        this->registerAllVariables();
     67
     68        SpaceShip::instance_s = this;
    5869
    5970        this->setConfigValues();
     
    309320        @return The XML-element
    310321    */
    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);
    323334    }
    324335
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1039 r1052  
    4949            void setConfigValues();
    5050            virtual void loadParams(TiXmlElement* xmlElem);
    51             virtual void XMLPort(Element& xmlelement, bool loading);
     51            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5252            virtual void tick(float dt);
    5353
     
    6161            void setRotDamp(float value);
    6262
     63            static void setMaxSpeedTest(float value)
     64                { SpaceShip::instance_s->setMaxSpeed(value); }
     65
    6366            bool mouseMoved(const OIS::MouseEvent &e);
    6467            bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
     
    6770
    6871        private:
     72            static SpaceShip* instance_s;
     73
    6974            Vector3 testvector_;
    7075            bool bInvertYAxis_;
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r1039 r1052  
    176176        @return The XML-element
    177177    */
    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);
    190190    }
    191191
     
    219219    }
    220220
    221     const WorldEntity* WorldEntity::getAttachedWorldEntity(unsigned int index)
     221    const WorldEntity* WorldEntity::getAttachedWorldEntity(unsigned int index) const
    222222    {
    223223        if (index < this->attachedWorldEntities_.size())
  • code/trunk/src/orxonox/objects/WorldEntity.h

    r1039 r1052  
    5151            virtual void tick(float dt);
    5252            virtual void loadParams(TiXmlElement* xmlElem);
    53             virtual void XMLPort(Element& xmlelement, bool loading);
     53            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5454            inline bool create(){ return true; }
    5555
    5656            void attachWorldEntity(WorldEntity* entity);
    57             const WorldEntity* getAttachedWorldEntity(unsigned int index);
     57            const WorldEntity* getAttachedWorldEntity(unsigned int index) const;
    5858
    5959            inline Ogre::SceneNode* getNode()
  • code/trunk/src/orxonox/tools/Timer.cc

    r1039 r1052  
    2727
    2828#include "OrxonoxStableHeaders.h"
     29#include "core/Executor.h"
     30#include "core/CoreIncludes.h"
     31#include "core/ConsoleCommand.h"
     32#include "core/CommandExecutor.h"
    2933#include "Timer.h"
    30 
    31 #include "core/CoreIncludes.h"
    3234
    3335namespace orxonox
    3436{
     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
    3563    /**
    3664        @brief Constructor: Sets the default-values.
     
    4068        RegisterRootObject(TimerBase);
    4169
     70        this->executor_ = 0;
    4271        this->interval_ = 0;
    4372        this->bLoop_ = false;
     
    4574
    4675        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_)();
    4792    }
    4893
  • code/trunk/src/orxonox/tools/Timer.h

    r1039 r1052  
    4343
    4444    source.cc:
     45        include "core/Executor.h"
     46
    4547        ClassName::ClassName()
    4648        {
    47             myTimer.setTimer(interval_in_seconds, bLoop, this, &ClassName::functionName);
     49            myTimer.setTimer(interval_in_seconds, bLoop, this, createExecutor(createFunctor(&ClassName::functionName)));
    4850        }
    4951
     
    5961
    6062#include "OrxonoxPrereqs.h"
    61 
     63#include "core/CorePrereqs.h"
    6264#include "core/Tickable.h"
    6365
    6466namespace orxonox
    6567{
     68    class StaticTimer;
     69    void delay(float delay, const std::string& command);
     70    void executeDelayedCommand(StaticTimer* timer, const std::string& command);
     71
    6672    //! TimerBase is the parent of the Timer class.
    6773    class _OrxonoxExport TimerBase : public Tickable
    6874    {
    6975        public:
    70             TimerBase();
     76            ~TimerBase();
    7177
    72             virtual void run() const = 0;
     78            void run() const;
    7379
    7480            /** @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_; }
    7683            /** @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_; }
    7886            /** @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; }
    8089            /** @brief Unpauses the Timer - continues with the given state. */
    81             inline void unpauseTimer() { this->bActive_ = true; }
     90            inline void unpauseTimer()
     91                { this->bActive_ = true; }
    8292            /** @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; }
    84107
    85108            void tick(float dt);
    86109
    87110        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();
    91112
    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
    93120    };
    94121
     
    98125    {
    99126        public:
    100             /** @brief Constructor: Sets the default-values. */
    101             Timer()
    102             {
    103                 this->timerFunction_ = 0;
    104                 this->object_ = 0;
    105             }
     127            Timer() {}
    106128
    107129            /**
     
    110132                @param bLoop If true, the function gets called every 'interval' seconds
    111133                @param object The object owning the timer and the function
    112                 @param timerFunction A function pointer to the function to call
     134                @param exeuctor A executor of the function to call
    113135            */
    114             Timer(float interval, bool bLoop, T* object, void (T::*timerFunction)())
     136            Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor)
    115137            {
    116                 this->setTimer(interval, bLoop, timerFunction, object);
     138                this->setTimer(interval, bLoop, object, exeuctor);
    117139            }
    118140
     
    122144                @param bLoop If true, the function gets called every 'interval' seconds
    123145                @param object The object owning the timer and the function
    124                 @param timerFunction A function pointer to the function to call
     146                @param exeuctor A executor of the function to call
    125147            */
    126             void setTimer(float interval, bool bLoop, T* object, void (T::*timerFunction)())
     148            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor)
    127149            {
    128150                this->interval_ = interval;
    129151                this->bLoop_ = bLoop;
    130                 this->timerFunction_ = timerFunction;
    131                 this->object_ = object;
     152                executor->setObject(object);
     153                this->executor_ = (Executor*)executor;
    132154                this->bActive_ = true;
    133155
    134156                this->time_ = interval;
    135157            }
     158    };
    136159
    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)
    139173            {
    140                 ((*this->object_).*timerFunction_)();
     174                this->setTimer(interval, bLoop, executor);
    141175            }
    142176
    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            }
    146193    };
    147194
  • code/trunk/src/util/CMakeLists.txt

    r1051 r1052  
    88  Math.cc
    99  String.cc
     10  Clipboard.cc
    1011  SubString.cc
    1112  MultiTypePrimitive.cc
  • code/trunk/src/util/Convert.h

    r871 r1052  
    2121 *   Author:
    2222 *      Benjamin Grauer
     23 *      Fabian 'x3n' Landau
    2324 *   Co-authors:
    24  *      Fabian 'x3n' Landau
     25 *      ...
    2526 */
    2627
     
    4243
    4344
    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
     50enum ConversionPreference
     51{
     52    CP_PreferToType,
     53    CP_PreferFromType,
     54};
     55
     56// Helper classes to determine the preferred partial template specialization
     57class _ToType_   {};
     58class _FromType_ {};
     59class _Explicit_ {};
     60
     61
     62// The default convert functions
     63template <class FromType, class ToType, class Type>
     64struct 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
     73template <class BothTypes>
     74struct 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
     88template <class T> struct ConverterLevel           { enum { level = __high__ }; };
     89template <> struct ConverterLevel<std::string>     { enum { level = __mid__ }; };
     90template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; };
     91template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; };
     92template <> struct ConverterLevel<int>             { enum { level = __low__ }; };
     93template <> struct ConverterLevel<unsigned int>    { enum { level = __low__ }; };
     94template <> struct ConverterLevel<char>            { enum { level = __low__ }; };
     95template <> struct ConverterLevel<unsigned char>   { enum { level = __low__ }; };
     96template <> struct ConverterLevel<short>           { enum { level = __low__ }; };
     97template <> struct ConverterLevel<unsigned short>  { enum { level = __low__ }; };
     98template <> struct ConverterLevel<long>            { enum { level = __low__ }; };
     99template <> struct ConverterLevel<unsigned long>   { enum { level = __low__ }; };
     100template <> struct ConverterLevel<float>           { enum { level = __low__ }; };
     101template <> struct ConverterLevel<double>          { enum { level = __low__ }; };
     102template <> struct ConverterLevel<long double>     { enum { level = __low__ }; };
     103template <> struct ConverterLevel<bool>            { enum { level = __low__ }; };
     104
     105
     106// Calculates the preference based on the levels of FromType and ToType
     107template <int from, int to>
     108struct 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
     128template <int max, class FromType, class ToType>
     129struct 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>
     137template <class FromType, class ToType>
     138struct ConverterDefault<0, FromType, ToType>
     139{
     140    static bool convert(ToType* output, const FromType& input)
     141    {
     142        (*output) = (ToType)input;
    66143        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
     149template <int diff, int max, class FromType, class ToType, ConversionPreference pref>
     150struct Converter
     151{
     152    static bool convert(ToType* output, const FromType& input)
     153    {
     154        return false;
     155    }
     156};
     157// Converter: level{FromType} > level{ToType}
     158template <int max, class FromType, class ToType, ConversionPreference pref>
     159struct 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}
     163template <int max, class FromType, class ToType, ConversionPreference pref>
     164struct 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
     169template <int max, class FromType, class ToType>
     170struct 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
     174template <int max, class FromType, class ToType>
     175struct 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
     181template <class FromType, class ToType>
     182static 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
     203template<class FromType, class ToType>
     204static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType)
     205{
     206    return convertValue(output, input, preference);
     207}
     208template<class FromType, class ToType>
     209static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType)
     210{
     211    if (convertValue(output, input, preference))
    82212        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;
    94216}
    95217
    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
     219template<class FromType, class ToType>
     220static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType)
     221{
     222    ToType output = ToType();
     223    ConvertValue(&output, input, preference);
     224    return output;
    106225}
    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;
     226template<class FromType, class ToType>
     227static 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;
    115232}
    116233
    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
     244template <class FromType>
     245struct 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
     253template <class ToType>
     254struct 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
     262template <>
     263struct 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
     276template <class FromType>
     277struct 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
     294template <class ToType>
     295struct 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
    141308
    142309////////////////
     
    144311////////////////
    145312
    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
     314template <class ToType>
     315struct 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
     352template <class ToType>
     353struct 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
     368template <class ToType>
     369struct 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);
    289388    }
    290389};
     
    297396// Vector2 to std::string
    298397template <>
    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;
     398struct 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;
    312410    }
    313411};
     
    315413// Vector3 to std::string
    316414template <>
    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;
     415struct 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;
    330427    }
    331428};
     
    333430// Vector4 to std::string
    334431template <>
    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;
     432struct 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;
    348444    }
    349445};
     
    351447// Quaternion to std::string
    352448template <>
    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;
     449struct 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;
    366461    }
    367462};
     
    369464// ColourValue to std::string
    370465template <>
    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;
     466struct 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;
    384478    }
    385479};
     
    392486// std::string to Vector2
    393487template <>
    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;
     488struct 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;
    415507    }
    416508};
     
    418510// std::string to Vector3
    419511template <>
    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;
     512struct 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;
    443533    }
    444534};
     
    446536// std::string to Vector4
    447537template <>
    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;
     538struct 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;
    473561    }
    474562};
     
    476564// std::string to Quaternion
    477565template <>
    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;
     566struct 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;
    503589    }
    504590};
     
    506592// std::string to ColourValue
    507593template <>
    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;
     594struct 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;
    533617    }
    534618};
  • code/trunk/src/util/Math.h

    r892 r1052  
    2626 */
    2727
    28 #ifndef _Math_H__
    29 #define _Math_H__
     28#ifndef _Util_Math_H__
     29#define _Util_Math_H__
    3030
    3131#include <ostream>
     
    146146}
    147147
    148 #endif /* _Math_H__ */
    149 
     148#endif /* _Util_Math_H__ */
  • code/trunk/src/util/MultiType.h

    r871 r1052  
    3535{
    3636    MT_null,
     37    MT_void,
    3738    MT_int,
    3839    MT_uint,
     
    4950    MT_constchar,
    5051    MT_string,
     52    MT_xmlelement,
    5153    MT_vector2,
    5254    MT_vector3,
     
    5961union _UtilExport MultiTypeValue
    6062{
     63    void*           void_;
    6164    int             int_;
    6265    unsigned int    uint_;
  • code/trunk/src/util/MultiTypeMath.cc

    r871 r1052  
    8888}
    8989
     90MultiTypeMath::operator void*() const
     91{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeMath, void*>(*this, 0); }
    9092MultiTypeMath::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); }
    9294MultiTypeMath::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); }
    9496MultiTypeMath::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); }
    9698MultiTypeMath::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); }
    98100MultiTypeMath::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); }
    100102MultiTypeMath::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); }
    102104MultiTypeMath::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); }
    104106MultiTypeMath::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); }
    106108MultiTypeMath::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); }
    108110MultiTypeMath::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); }
    110112MultiTypeMath::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); }
    112114MultiTypeMath::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); }
    114116MultiTypeMath::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); }
    116118MultiTypeMath::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(); }
    118120MultiTypeMath::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); }
    120122MultiTypeMath::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); }
    122124MultiTypeMath::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); }
    124126MultiTypeMath::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); }
    126128MultiTypeMath::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); }
    128130MultiTypeMath::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); }
    130132
    131133void MultiTypeMath::setValue(const MultiTypeMath& mtm)
     
    138140    this->radian_ = mtm.radian_;
    139141    this->degree_ = mtm.degree_;
     142}
     143
     144std::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();
    140160}
    141161
  • code/trunk/src/util/MultiTypeMath.h

    r890 r1052  
    3838{
    3939    public:
    40         MultiTypeMath(MultiType      type = MT_null);
     40        MultiTypeMath(MultiType type = MT_null);
     41        inline MultiTypeMath(void*          value) : MultiTypeString(value) {}
    4142        inline MultiTypeMath(int            value) : MultiTypeString(value) {}
    4243        inline MultiTypeMath(unsigned int   value) : MultiTypeString(value) {}
     
    5152        inline MultiTypeMath(long double    value) : MultiTypeString(value) {}
    5253        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) {}
    5556        inline MultiTypeMath(const orxonox::Vector2&     value) { this->setValue(value); }
    5657        inline MultiTypeMath(const orxonox::Vector3&     value) { this->setValue(value); }
     
    8990        bool operator!=(const MultiTypeMath& mtm) const;
    9091
     92        virtual operator void*()                const;
    9193        virtual operator int()                  const;
    9294        virtual operator unsigned int()         const;
     
    141143        inline void getValue(orxonox::Degree*      variable) const { (*variable) = orxonox::Degree      (this->degree_);      }
    142144
     145        virtual std::string getTypename() const;
     146
    143147        virtual std::string toString() const;
    144148        virtual bool fromString(const std::string value);
  • code/trunk/src/util/MultiTypePrimitive.cc

    r871 r1052  
    3434    this->type_ = type;
    3535
    36     if (type == MT_int)
     36    if (type == MT_void)
     37        this->value_.void_ = 0;
     38    else if (type == MT_int)
    3739        this->value_.int_ = 0;
    3840    else if (type == MT_uint)
     
    5961        this->value_.bool_ = false;
    6062    else
    61         this->value_.int_ = 0;
     63        this->value_.void_ = 0;
    6264}
    6365
     
    6668    if (this->type_ == mtp.type_)
    6769    {
    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)
    6973            return (this->value_.int_ == mtp.value_.int_);
    7074        else if (this->type_ == MT_uint)
     
    99103    if (this->type_ == mtp.type_)
    100104    {
    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)
    102108            return (this->value_.int_ != mtp.value_.int_);
    103109        else if (this->type_ == MT_uint)
     
    128134}
    129135
     136MultiTypePrimitive::operator void*() const
     137{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypePrimitive, void*>(*this, 0); }
    130138MultiTypePrimitive::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); }
    132140MultiTypePrimitive::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); }
    134142MultiTypePrimitive::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); }
    136144MultiTypePrimitive::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); }
    138146MultiTypePrimitive::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); }
    140148MultiTypePrimitive::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); }
    142150MultiTypePrimitive::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); }
    144152MultiTypePrimitive::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); }
    146154MultiTypePrimitive::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); }
    148156MultiTypePrimitive::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); }
    150158MultiTypePrimitive::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); }
    152160MultiTypePrimitive::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); }
    154162
    155163void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp)
     
    159167}
    160168
     169std::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
    161201std::string MultiTypePrimitive::toString() const
    162202{
    163203    std::string output;
    164204
    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)
    166208        ConvertValue(&output, this->value_.int_);
    167209    else if (this->type_ == MT_uint)
     
    193235bool MultiTypePrimitive::fromString(const std::string value)
    194236{
    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)
    196240        return ConvertValue(&this->value_.int_, value, (int)0);
    197241    else if (this->type_ == MT_uint)
  • code/trunk/src/util/MultiTypePrimitive.h

    r890 r1052  
    3636#include "MultiType.h"
    3737
     38namespace orxonox
     39{
     40    class BaseObject;
     41}
    3842class _UtilExport MultiTypePrimitive
    3943{
    4044    public:
    41         MultiTypePrimitive(MultiType      type = MT_null);
     45        MultiTypePrimitive(MultiType type = MT_null);
     46        inline MultiTypePrimitive(void*          value) { this->setValue(value); }
    4247        inline MultiTypePrimitive(int            value) { this->setValue(value); }
    4348        inline MultiTypePrimitive(unsigned int   value) { this->setValue(value); }
     
    5661
    5762        inline MultiTypePrimitive& operator=(MultiType      value) { this->type_ = MT_null; return *this; }
     63        inline MultiTypePrimitive& operator=(void*          value) { this->setValue(value); return *this; }
    5864        inline MultiTypePrimitive& operator=(int            value) { this->setValue(value); return *this; }
    5965        inline MultiTypePrimitive& operator=(unsigned int   value) { this->setValue(value); return *this; }
     
    7076        inline MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; }
    7177
     78        inline bool operator==(void*          value) const { return (this->value_.void_       == value); }
    7279        inline bool operator==(int            value) const { return (this->value_.int_        == value); }
    7380        inline bool operator==(unsigned int   value) const { return (this->value_.uint_       == value); }
     
    8491        bool operator==(const MultiTypePrimitive& mtp) const;
    8592
    86         inline bool operator!=(int            value) const { return (this->value_.int_        != value); }
     93        inline bool operator!=(void*          value) const { return (this->value_.void_       != value); }
    8794        inline bool operator!=(unsigned int   value) const { return (this->value_.uint_       != value); }
    8895        inline bool operator!=(char           value) const { return (this->value_.char_       != value); }
     
    98105        bool operator!=(const MultiTypePrimitive& mtp) const;
    99106
     107        template <class T>
     108        operator T*()                     const
     109        { return ((T*)this->value_.void_); }
     110        virtual operator void*()          const;
    100111        virtual operator int()            const;
    101112        virtual operator unsigned int()   const;
     
    111122        virtual operator bool()           const;
    112123
     124        inline void setValue(void*          value) { this->type_ = MT_void;       this->value_.void_       = value; }
    113125        inline void setValue(int            value) { this->type_ = MT_int;        this->value_.int_        = value; }
    114126        inline void setValue(unsigned int   value) { this->type_ = MT_uint;       this->value_.uint_       = value; }
     
    125137        void setValue(const MultiTypePrimitive& mtp);
    126138
     139        inline void*          getVoid()          const { return this->value_.void_;        }
    127140        inline int            getInt()           const { return this->value_.int_;        }
    128141        inline unsigned int   getUnsignedInt()   const { return this->value_.uint_;       }
     
    151164        inline bool&           getBool()          { return this->value_.bool_;       }
    152165
     166        inline void getValue(void*           variable) const { variable    = this->value_.void_;       }
    153167        inline void getValue(int*            variable) const { (*variable) = this->value_.int_;        }
    154168        inline void getValue(unsigned int*   variable) const { (*variable) = this->value_.uint_;       }
     
    167181        inline bool      isA(MultiType type) const { return (this->type_ == type); }
    168182
     183        virtual std::string getTypename() const;
     184
    169185        virtual std::string toString() const;
    170186        virtual bool fromString(const std::string value);
  • code/trunk/src/util/MultiTypeString.cc

    r871 r1052  
    3232MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type)
    3333{
    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
    3835}
    3936
     
    6461}
    6562
     63MultiTypeString::operator void*() const
     64{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeString, void*>(*this, 0); }
    6665MultiTypeString::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); }
    6867MultiTypeString::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); }
    7069MultiTypeString::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); }
    7271MultiTypeString::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); }
    7473MultiTypeString::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); }
    7675MultiTypeString::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); }
    7877MultiTypeString::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); }
    8079MultiTypeString::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); }
    8281MultiTypeString::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); }
    8483MultiTypeString::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); }
    8685MultiTypeString::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); }
    8887MultiTypeString::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); }
    9089MultiTypeString::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); }
    9291MultiTypeString::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(); }
    9493
    9594void MultiTypeString::setValue(const MultiTypeString& mts)
     
    9998}
    10099
     100std::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
    101110std::string MultiTypeString::toString() const
    102111{
     112    std::string output;
     113
    103114    if (this->type_ == MT_constchar)
    104115        return this->string_;
     
    107118    else
    108119        return MultiTypePrimitive::toString();
     120
     121    return output;
    109122}
    110123
  • code/trunk/src/util/MultiTypeString.h

    r890 r1052  
    3939{
    4040    public:
    41         MultiTypeString(MultiType      type = MT_null);
     41        MultiTypeString(MultiType type = MT_null);
     42        inline MultiTypeString(void*          value) : MultiTypePrimitive(value) {}
    4243        inline MultiTypeString(int            value) : MultiTypePrimitive(value) {}
    4344        inline MultiTypeString(unsigned int   value) : MultiTypePrimitive(value) {}
     
    5253        inline MultiTypeString(long double    value) : MultiTypePrimitive(value) {}
    5354        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);   }
    5758        virtual inline ~MultiTypeString() {}
    5859
    5960        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; }
    6364
    6465        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);              }
    6768        bool operator==(const MultiTypeString& mts) const;
    6869
    6970        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);              }
    7273        bool operator!=(const MultiTypeString& mts) const;
    7374
    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;
    8890
    8991        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;              }
    9294        void setValue(const MultiTypeString& mts);
    9395
    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(); }
    9698
    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(); }
    99101
    100102        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;
    103107
    104108        virtual std::string toString() const;
     
    106110
    107111    protected:
    108         std::string string_;
     112        std::string      string_;
    109113};
    110114
  • code/trunk/src/util/String.cc

    r871 r1052  
    2626 */
    2727
     28#include <cctype>
     29#include <iostream>
    2830#include "String.h"
    2931
     
    5456
    5557/**
     58    @brief Returns a copy of a string without trailing whitespaces.
     59    @param str The string
     60    @return The modified copy
     61*/
     62std::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*/
     77unsigned 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*/
     102bool 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*/
     125bool 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*/
     137std::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*/
     152std::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/**
    56188    @brief Determines if a string in is a comment.
    57189    @param str The string to check
     
    70202    //  3) ;comment in unreal tournament config-file style
    71203    //  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    }
    74214
    75215    return false;
     
    83223bool isEmpty(const std::string& str)
    84224{
    85     return getStripped(str) == "";
     225    std::string temp = getStripped(str);
     226    return ((temp == "") || (temp.size() == 0));
    86227}
    87228
     
    109250}
    110251
     252std::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
     270std::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
    111300/**
    112301    @brief Replaces each char between A and Z with its lowercase equivalent.
     
    115304void lowercase(std::string* str)
    116305{
    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    }
    122310}
    123311
     
    140328void uppercase(std::string* str)
    141329{
    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    }
    147334}
    148335
     
    160347
    161348/**
    162  * @brief compares two strings without ignoring the case
    163  * @param s1 first string
    164  * @param s2 second string
    165  */
     349   @brief compares two strings without ignoring the case
     350   @param s1 first string
     351   @param s2 second string
     352*/
    166353int nocaseCmp(const std::string& s1, const std::string& s2)
    167354{
     
    188375
    189376/**
    190  * @brief compares two strings without ignoring the case
    191  * @param s1 first string
    192  * @param s2 second string
    193  * @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*/
    195382int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len)
    196383{
     
    212399    return 0;
    213400}
     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*/
     407bool 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*/
     417std::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*/
     427unsigned 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*/
     438unsigned 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  
    2626 */
    2727
    28 #ifndef _String_H__
    29 #define _String_H__
     28#ifndef _Util_String_H__
     29#define _Util_String_H__
    3030
    3131#include <string>
     
    3434#include "UtilPrereqs.h"
    3535
    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);
    3838
    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);
    4240
    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);
    4543
    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);
    4846
    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);
    5169
    5270//! The Convert class has some static member functions to convert strings to values and values to strings.
     
    144162};
    145163
    146 #endif /* _String_H__ */
     164#endif /* _Util_String_H__ */
  • code/trunk/src/util/SubString.cc

    r871 r1052  
    6666SubString::SubString(const std::string& string,
    6767                     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);
    7172}
    7273
     
    7980{
    8081  for (unsigned int i = subSetBegin; i < subString.size(); i++)
     82  {
    8183    this->strings.push_back(subString[i]);
     84    this->bInSafemode.push_back(subString.isInSafemode(i));
     85  }
    8286}
    8387
     
    9195SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd)
    9296{
    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  {
    9499    this->strings.push_back(subString[i]);
     100    this->bInSafemode.push_back(subString.isInSafemode(i));
     101  }
    95102}
    96103
     
    103110{
    104111  for(unsigned int i = 0; i < argc; ++i)
     112  {
    105113    this->strings.push_back(std::string(argv[i]));
     114    this->bInSafemode.push_back(false);
     115  }
    106116}
    107117
     
    129139{
    130140  this->strings = subString.strings;
     141  this->bInSafemode = subString.bInSafemode;
    131142  return *this;
    132143}
     
    140151bool SubString::operator==(const SubString& subString) const
    141152{
    142   return (this->strings == subString.strings);
     153  return ((this->strings == subString.strings) && (this->bInSafemode == subString.bInSafemode));
    143154}
    144155
     
    165176
    166177  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]))
    168179      return false;
    169180  return true;
     
    190201{
    191202  for (unsigned int i = 0; i < subString.size(); i++)
     203  {
    192204    this->strings.push_back(subString[i]);
     205    this->bInSafemode.push_back(subString.isInSafemode(i));
     206  }
    193207  return *this;
    194208}
     
    203217{
    204218  this->strings.clear();
     219  this->bInSafemode.clear();
    205220  char split[2];
    206221  split[0] = splitter;
    207222  split[1] = '\0';
    208   SubString::splitLine(this->strings, string, split);
     223  SubString::splitLine(this->strings, this->bInSafemode, string, split);
    209224  return strings.size();
    210225}
     
    223238unsigned int SubString::split(const std::string& string,
    224239                              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)
    226242{
    227243  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);
    229246  return this->strings.size();
    230247}
     
    292309 * @param escape_char: Escape carater (escapes splitters)
    293310 * @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
    294315 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line)
    295316 * @param start_state: the Initial state on how to parse the String.
    296  * @returns SPLIT_LINE_STATE the parser was in when returning
     317 * @return SPLIT_LINE_STATE the parser was in when returning
    297318 *
    298319 * This is the Actual Splitting Algorithm from Clemens Wacha
     
    302323SubString::SPLIT_LINE_STATE
    303324SubString::splitLine(std::vector<std::string>& ret,
     325                     std::vector<bool>& bInSafemode,
    304326                     const std::string& line,
    305327                     const std::string& delimiters,
     
    307329                     bool emptyEntries,
    308330                     char escape_char,
     331                     bool removeExcapeChar,
    309332                     char safemode_char,
     333                     bool removeSafemodeChar,
    310334                     char openparenthesis_char,
    311335                     char closeparenthesis_char,
     336                     bool removeParenthesisChars,
    312337                     char comment_char,
    313338                     SPLIT_LINE_STATE start_state)
     
    318343
    319344  std::string token;
     345  bool inSafemode = false;
    320346
    321347  if(start_state != SL_NORMAL && ret.size() > 0)
     
    323349    token = ret[ret.size()-1];
    324350    ret.pop_back();
     351  }
     352  if(start_state != SL_NORMAL && bInSafemode.size() > 0)
     353  {
     354    inSafemode = bInSafemode[bInSafemode.size()-1];
     355    bInSafemode.pop_back();
    325356  }
    326357
     
    333364        {
    334365          state = SL_ESCAPE;
     366          if (!removeExcapeChar)
     367            token += line[i];
    335368        }
    336369        else if(line[i] == safemode_char)
    337370        {
    338371          state = SL_SAFEMODE;
     372          inSafemode = true;
     373          if (!removeSafemodeChar)
     374            token += line[i];
    339375        }
    340376        else if(line[i] == openparenthesis_char)
    341377        {
    342378          state = SL_PARENTHESES;
     379          inSafemode = true;
     380          if (!removeParenthesisChars)
     381            token += line[i];
    343382        }
    344383        else if(line[i] == comment_char)
     
    351390            ret.push_back(token);
    352391            token.clear();
     392            bInSafemode.push_back(inSafemode);
     393            inSafemode = false;
    353394          }
    354395          token += line[i];       // EAT
     
    365406            ret.push_back(token);
    366407            token.clear();
     408            bInSafemode.push_back(inSafemode);
     409            inSafemode = false;
    367410          }
    368411          state = SL_NORMAL;
     
    386429        break;
    387430      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        }
    397445        state = SL_NORMAL;
    398446        break;
     
    401449        {
    402450          state = SL_NORMAL;
     451          if (!removeSafemodeChar)
     452            token += line[i];
    403453        }
    404454        else if(line[i] == escape_char)
     
    429479        {
    430480          state = SL_NORMAL;
     481          if (!removeParenthesisChars)
     482            token += line[i];
    431483        }
    432484        else if(line[i] == escape_char)
     
    461513            ret.push_back(token);
    462514            token.clear();
     515            bInSafemode.push_back(inSafemode);
     516            inSafemode = false;
    463517          }
    464518          state = SL_NORMAL;
     
    484538    ret.push_back(token);
    485539    token.clear();
     540    bInSafemode.push_back(inSafemode);
     541    inSafemode = false;
    486542  }
    487543  return(state);
  • code/trunk/src/util/SubString.h

    r871 r1052  
    8888  SubString(const std::string& string,
    8989            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');
    9192  SubString(unsigned int argc, const char** argv);
    9293  /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */
     
    111112  unsigned int split(const std::string& string,
    112113                     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');
    114116  std::string join(const std::string& delimiter = " ") const;
    115117  ////////////////////////////////////////
     
    120122
    121123  // retrieve Information from within
    122   /** @returns true if the SubString is empty */
     124  /** @brief Returns true if the SubString is empty */
    123125  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 */
    125127  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 */
    127129  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 */
    129131  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. */
    131135  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. */
    133137  inline const std::string& back() const { return this->strings.back(); };
    134138  /** @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(); };
    136140
    137141  // the almighty algorithm.
    138142  static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,
     143                                    std::vector<bool>& bInSafemode,
    139144                                    const std::string& line,
    140145                                    const std::string& delimiters = SubString::WhiteSpaces,
     
    142147                                    bool emptyEntries = false,
    143148                                    char escape_char = '\\',
     149                                    bool removeExcapeChar = true,
    144150                                    char safemode_char = '"',
     151                                    bool removeSafemodeChar = true,
    145152                                    char openparenthesis_char = '(',
    146153                                    char closeparenthesis_char = ')',
     154                                    bool removeParenthesisChars = true,
    147155                                    char comment_char = '\0',
    148156                                    SPLIT_LINE_STATE start_state = SL_NORMAL);
     
    157165private:
    158166  std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
     167  std::vector<bool>         bInSafemode;
    159168};
    160169
  • code/trunk/src/util/UtilPrereqs.h

    r1024 r1052  
    6161class ArgReader;
    6262class Convert;
    63 template <typename FromType, typename ToType>
    64 class Converter;
    6563class MultiTypePrimitive;
    6664class MultiTypeString;
  • code/trunk/src/util/tinyxml/ticpp.h

    r871 r1052  
    973973                Stream output operator.
    974974                */
    975                 friend std::ostream& operator <<( std::ostream& out, Node& base )
     975                friend std::ostream& operator <<( std::ostream& out, const Node& base )
    976976                {
    977977                        out << *base.GetTiXmlPointer();
Note: See TracChangeset for help on using the changeset viewer.