Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 8, 2007, 5:37:26 PM (17 years ago)
Author:
landauf
Message:

added a config-file-parser and a makro ( SetConfigValue(variable, defaultvalue) ) to get user-modified values from the config-file (or to write the defaultvalue into it if the variable isn't yet in the file).

Location:
code/branches/objecthierarchy/src
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/CMakeLists.txt

    r375 r434  
    22
    33# create a few variables to simplify life
    4 SET(SRC_FILES orxonox/orxonox.cc loader/LevelLoader.cc xml/xmlParser.cc orxonox/core/IdentifierList.cc orxonox/core/Identifier.cc orxonox/core/MetaObjectList.cc orxonox/core/Factory.cc orxonox/core/OrxonoxClass.cc orxonox/objects/BaseObject.cc orxonox/objects/test1.cc orxonox/objects/test2.cc orxonox/objects/test3.cc)
    5 SET(INC_FILES loader/LevelLoader.h xml/xmlParser.h orxonox/core/IdentifierIncludes.h orxonox/core/Identifier.h orxonox/core/Factory.h orxonox/core/ClassFactory.h orxonox/core/IdentifierList.h orxonox/core/ObjectList.h orxonox/core/MetaObjectList.h orxonox/core/Iterator.h orxonox/core/OrxonoxClass.h orxonox/objects/BaseObject.h orxonox/objects/Test.h orxonox/objects/test1.h orxonox/objects/test2.h orxonox/objects/test3.h orxonox/objects/Tickable.h orxonox/objects/Timer.h)
     4SET(SRC_FILES orxonox/orxonox.cc loader/LevelLoader.cc xml/xmlParser.cc orxonox/core/IdentifierList.cc orxonox/core/Identifier.cc orxonox/core/MetaObjectList.cc orxonox/core/Factory.cc orxonox/core/OrxonoxClass.cc orxonox/core/ConfigValueContainer.cc orxonox/objects/BaseObject.cc orxonox/objects/test1.cc orxonox/objects/test2.cc orxonox/objects/test3.cc)
     5SET(INC_FILES loader/LevelLoader.h xml/xmlParser.h orxonox/core/IdentifierIncludes.h orxonox/core/Identifier.h orxonox/core/Factory.h orxonox/core/ClassFactory.h orxonox/core/IdentifierList.h orxonox/core/ObjectList.h orxonox/core/MetaObjectList.h orxonox/core/Iterator.h orxonox/core/OrxonoxClass.h orxonox/core/ConfigValueContainer.h orxonox/objects/BaseObject.h orxonox/objects/Test.h orxonox/objects/test1.h orxonox/objects/test2.h orxonox/objects/test3.h orxonox/objects/Tickable.h orxonox/objects/Timer.h)
    66
    77#Creates an executable
  • code/branches/objecthierarchy/src/orxonox/core/Identifier.h

    r365 r434  
    2525
    2626#include <iostream>
     27#include <map>
    2728
    2829#include "IdentifierList.h"
    2930#include "ObjectList.h"
    3031#include "Factory.h"
    31 
    32 #define HIERARCHY_VERBOSE false
     32#include "ConfigValueContainer.h"
     33
     34#define HIERARCHY_VERBOSE 0
    3335
    3436
     
    9395            void setNetworkID(unsigned int id);
    9496
     97            inline ConfigValueContainer* getConfigValueContainer(const std::string& varname)
     98                { return this->configValues_[varname]; }
     99
     100            inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
     101                { this->configValues_[varname] = container; }
     102
    95103        private:
    96104            Identifier();
     
    121129            }
    122130
    123             IdentifierList parents_;                    //!< The Parents of the class the Identifier belongs to
    124             IdentifierList* children_;                  //!< The Children of the class the Identifier belongs to
    125 
    126             std::string name_;                          //!< The name of the class the Identifier belongs to
    127 
    128             BaseFactory* factory_;                      //!< The Factory, able to create new objects of the given class
    129             bool bCreatedOneObject_;                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    130             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)
    131             static unsigned int classIDcounter_s;       //!< The number of unique Identifiers
    132             unsigned int classID_;                      //!< The networkID to identify a class through the network
     131            IdentifierList parents_;                                    //!< The Parents of the class the Identifier belongs to
     132            IdentifierList* children_;                                  //!< The Children of the class the Identifier belongs to
     133
     134            std::string name_;                                          //!< The name of the class the Identifier belongs to
     135
     136            BaseFactory* factory_;                                      //!< The Factory, able to create new objects of the given class
     137            bool bCreatedOneObject_;                                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     138            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)
     139            static unsigned int classIDcounter_s;                       //!< The number of unique Identifiers
     140            unsigned int classID_;                                      //!< The networkID to identify a class through the network
     141            std::map<std::string, ConfigValueContainer*> configValues_;
    133142    };
    134143
  • code/branches/objecthierarchy/src/orxonox/core/IdentifierIncludes.h

    r365 r434  
    1616#include "Iterator.h"
    1717#include "OrxonoxClass.h"
     18#include "ConfigValueContainer.h"
    1819
     20#include "OgreVector3.h"
     21#include "OgreColourValue.h"
     22
     23namespace orxonox
     24{
     25    typedef Ogre::Vector3 Vector3;
     26    typedef Ogre::ColourValue ColourValue;
     27}
    1928
    2029// Intern macro, containing the common parts of RegisterObject and RegisterRootObject
     
    6271#define ID(StringOrInt) \
    6372    Factory::getIdentifier(StringOrInt)
     73
     74// bla
     75#define SetConfigValue(varname, defvalue) \
     76    ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
     77    if (!container##varname) \
     78    { \
     79        container##varname = new ConfigValueContainer(this->getIdentifier()->getName(), #varname, defvalue); \
     80        this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \
     81    } \
     82    this->varname = container##varname->getValue(varname)
  • code/branches/objecthierarchy/src/orxonox/core/OrxonoxClass.h

    r366 r434  
    2727            OrxonoxClass();
    2828            virtual ~OrxonoxClass();
     29
     30            void setConfigValues() {};
    2931
    3032            /** @returns the Identifier of the object */
  • code/branches/objecthierarchy/src/orxonox/objects/Tickable.h

    r375 r434  
    33
    44#include "../core/IdentifierIncludes.h"
    5 #include "Ogre.h"
     5#include "OgreFrameListener.h"
    66
    77namespace orxonox
  • code/branches/objecthierarchy/src/orxonox/objects/Timer.h

    r375 r434  
    33
    44#include "../core/IdentifierIncludes.h"
    5 #include "Ogre.h"
     5#include "OgreFrameListener.h"
    66
    77namespace orxonox
  • code/branches/objecthierarchy/src/orxonox/objects/test3.cc

    r383 r434  
    1010    {
    1111        RegisterObject(Test3);
     12
     13        this->setConfigValues();
     14    }
     15
     16    void Test3::setConfigValues()
     17    {
     18        SetConfigValue(value_int_, -100);
     19        SetConfigValue(value_double_, 10.555678);
     20        SetConfigValue(value_bool_, true);
     21        SetConfigValue(value_string_, "Dies ist ein Test");
     22        SetConfigValue(value_vector3_, Vector3(13, 26, 39));
     23        SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887));
    1224    }
    1325
     
    1527    {
    1628    }
     29
     30    void Test3::configOutput()
     31    {
     32        std::cout << this->value_int_ << std::endl;
     33        std::cout << this->value_double_ << std::endl;
     34        std::cout << this->value_bool_ << std::endl;
     35        std::cout << this->value_string_ << std::endl;
     36        std::cout << this->value_vector3_ << std::endl;
     37        std::cout << this->value_colourvalue_ << std::endl;
     38    }
     39
    1740        #define testandcout(code) \
    1841          std::cout << #code << " " << code << "\n"
  • code/branches/objecthierarchy/src/orxonox/objects/test3.h

    r383 r434  
    1515            virtual ~Test3();
    1616
     17            void setConfigValues();
     18
    1719            void usefullClassesIsATest(Test1* test1);
    1820            void usefullClassesIsATest(Test2* test2);
     21
     22            void configOutput();
     23
     24        private:
     25            int                 value_int_;
     26            double              value_double_;
     27            bool                value_bool_;
     28            std::string         value_string_;
     29            Vector3             value_vector3_;
     30            ColourValue         value_colourvalue_;
    1931    };
    2032}
  • code/branches/objecthierarchy/src/orxonox/orxonox.cc

    r375 r434  
    623623
    624624        std::cout << "2\n";
     625        Test2* test11_2 = new Test2;
    625626*/
    626627
    627         Test2* test11_2 = new Test2;
    628628        std::cout << "3\n";
     629        Test3* test11_3 = new Test3;
     630        test11_3->configOutput();
     631
     632        std::cout << "4\n";
    629633
    630634        startRenderLoop();
Note: See TracChangeset for help on using the changeset viewer.