Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 447


Ignore:
Timestamp:
Dec 9, 2007, 11:21:14 PM (17 years ago)
Author:
landauf
Message:
  • added comments and doxygen-tags to the ConfigValueContainer
  • changed some comments in the other files
Location:
code/branches/objecthierarchy/src/orxonox/core
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/core/ClassFactory.h

    r365 r447  
    3434    /**
    3535        @brief Adds the ClassFactory to the Identifier of the same type and creates a new object to retrieve the parents.
    36         @return True, because the compiler only allows assignments before main()
     36        @return Always true (this is needed because the compiler only allows assignments before main())
    3737    */
    3838    template <class T>
  • code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.cc

    r435 r447  
    88namespace orxonox
    99{
    10     std::list<std::string>* ConfigValueContainer::configFileLines_s = 0;
    11     bool ConfigValueContainer::readConfigFile_s = false;
    12 
     10    std::list<std::string>* ConfigValueContainer::configFileLines_s = 0; // Set the static member variable configFileLines_s to zero
     11    bool ConfigValueContainer::readConfigFile_s = false;                 // Set the static member variable readConfigFile_s to false
     12
     13    /**
     14        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_int_.
     15        @param classname The name of the class the variable belongs to
     16        @param varname The name of the variable
     17        @param defvalue The default-value
     18    */
    1319    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue)
    1420    {
     21        // Try to convert the default-value from int to string
    1522        std::ostringstream ostream;
    16 
    1723        if (ostream << defvalue)
    1824            this->defvalue_ = ostream.str();
     
    2026            this->defvalue_ = "0";
    2127
     28        // Set the default values, then get the value-string
    2229        this->setDefaultValues(classname, varname);
    2330        std::string valueString = this->getValueString();
    2431
     32        // Try to convert the value-string to int
    2533        std::istringstream istream(valueString);
    2634        if (!(istream >> this->value_int_))
    2735        {
     36            // The conversion failed - use the default value and restore the entry in the config-file
    2837            this->value_int_ = defvalue;
    2938            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    3241    }
    3342
     43    /**
     44        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_double_.
     45        @param classname The name of the class the variable belongs to
     46        @param varname The name of the variable
     47        @param defvalue The default-value
     48    */
    3449    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue)
    3550    {
     51        // Try to convert the default-value from double to string
    3652        std::ostringstream ostream;
    37 
    3853        if (ostream << defvalue)
    3954            this->defvalue_ = ostream.str();
     
    4156            this->defvalue_ = "0.000000";
    4257
     58        // Set the default values, then get the value-string
    4359        this->setDefaultValues(classname, varname);
    4460        std::string valueString = this->getValueString();
    4561
     62        // Try to convert the value-string to double
    4663        std::istringstream istream(valueString);
    4764        if (!(istream >> this->value_double_))
    4865        {
     66            // The conversion failed - use the default value and restore the entry in the config-file
    4967            this->value_double_ = defvalue;
    5068            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    5371    }
    5472
     73    /**
     74        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_bool_.
     75        @param classname The name of the class the variable belongs to
     76        @param varname The name of the variable
     77        @param defvalue The default-value
     78    */
    5579    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue)
    5680    {
     81        // Convert the default-value from bool to string
    5782        if (defvalue)
    5883            this->defvalue_ = "true";
     
    6085            this->defvalue_ = "false";
    6186
     87        // Set the default values, then get the value-string
    6288        this->setDefaultValues(classname, varname);
    6389        std::string valueString = this->getValueString();
    6490
     91        // Try to parse the value-string - is it a word?
    6592        if (valueString.find("true") < valueString.size() || valueString.find("yes") < valueString.size())
    6693            this->value_bool_ = true;
     
    6996        else
    7097        {
     98            // Its not a known word - is it a number?
    7199            std::istringstream istream(valueString);
    72100            if (!(istream >> this->value_bool_))
    73101            {
     102                // The conversion failed - use the default value and restore the entry in the config-file
    74103                this->value_bool_ = defvalue;
    75104                (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    79108    }
    80109
     110    /**
     111        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_string_.
     112        @param classname The name of the class the variable belongs to
     113        @param varname The name of the variable
     114        @param defvalue The default-value
     115    */
    81116    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue)
    82117    {
     118        // Not much to do here - just set all member-variables and check the config-file
    83119        this->defvalue_ = defvalue;
    84120        this->setDefaultValues(classname, varname);
     
    86122    }
    87123
     124    /**
     125        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector3_.
     126        @param classname The name of the class the variable belongs to
     127        @param varname The name of the variable
     128        @param defvalue The default-value
     129    */
    88130    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue)
    89131    {
     132        // Try to convert the default-value from Vector3 to string
    90133        std::ostringstream ostream;
    91134        if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")")
     
    94137            this->defvalue_ = "(0,0,0)";
    95138
     139        // Set the default values, then get the value-string
    96140        this->setDefaultValues(classname, varname);
    97141        std::string valueString = this->getValueString();
    98142
     143        // Strip the value-string
     144        valueString = this->getStrippedLine(valueString);
    99145        unsigned int pos;
    100         while ((pos = valueString.find(" ")) < valueString.length())
    101             valueString.erase(pos, 1);
    102146        while ((pos = valueString.find("(")) < valueString.length())
    103147            valueString.erase(pos, 1);
     
    107151            valueString.replace(pos, 1, " ");
    108152
     153        // Try to convert the stripped value-string to Vector3
    109154        std::istringstream istream(valueString);
    110 
    111155        if (!(istream >> this->value_vector3_.x))
    112156        {
     157            // The conversion failed - use the default value and restore the entry in the config-file
    113158            this->value_vector3_.x = defvalue.x;
    114159            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    117162        if (!(istream >> this->value_vector3_.y))
    118163        {
     164            // The conversion failed - use the default value and restore the entry in the config-file
    119165            this->value_vector3_.y = defvalue.y;
    120166            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    123169        if (!(istream >> this->value_vector3_.z))
    124170        {
     171            // The conversion failed - use the default value and restore the entry in the config-file
    125172            this->value_vector3_.z = defvalue.z;
    126173            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    129176    }
    130177
     178    /**
     179        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_colourvalue_.
     180        @param classname The name of the class the variable belongs to
     181        @param varname The name of the variable
     182        @param defvalue The default-value
     183    */
    131184    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue)
    132185    {
     186        // Try to convert the default-value from ColourValue to string
    133187        std::ostringstream ostream;
    134188        if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")")
     
    137191            this->defvalue_ = "(0,0,0,0)";
    138192
     193        // Set the default values, then get the value-string
    139194        this->setDefaultValues(classname, varname);
    140195        std::string valueString = this->getValueString();
    141196
     197        // Strip the value-string
     198        valueString = this->getStrippedLine(valueString);
    142199        unsigned int pos;
    143         while ((pos = valueString.find(" ")) < valueString.length())
    144             valueString.erase(pos, 1);
    145200        while ((pos = valueString.find("(")) < valueString.length())
    146201            valueString.erase(pos, 1);
     
    150205            valueString.replace(pos, 1, " ");
    151206
     207        // Try to convert the stripped value-string to Vector3
    152208        std::istringstream istream(valueString);
    153 
    154209        if (!(istream >> this->value_colourvalue_.r))
    155210        {
     211            // The conversion failed - use the default value and restore the entry in the config-file
    156212            this->value_colourvalue_.r = defvalue.r;
    157213            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    160216        if (!(istream >> this->value_colourvalue_.g))
    161217        {
     218            // The conversion failed - use the default value and restore the entry in the config-file
    162219            this->value_colourvalue_.g = defvalue.g;
    163220            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    166223        if (!(istream >> this->value_colourvalue_.b))
    167224        {
     225            // The conversion failed - use the default value and restore the entry in the config-file
    168226            this->value_colourvalue_.b = defvalue.b;
    169227            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    172230        if (!(istream >> this->value_colourvalue_.a))
    173231        {
     232            // The conversion failed - use the default value and restore the entry in the config-file
    174233            this->value_colourvalue_.a = defvalue.a;
    175234            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     
    178237    }
    179238
     239    /**
     240        @brief Sets the default values of the container and searches the coresponding entry in the config-file.
     241        @param classname The name of the class the variable belongs to
     242        @param varname The name of the variable
     243    */
    180244    void ConfigValueContainer::setDefaultValues(const std::string& classname, const std::string& varname)
    181245    {
     246        // Set the class and variable names
    182247        this->classname_ = classname;
    183248        this->varname_ = varname;
    184249
     250        // Search the entry in the config-file
    185251        this->searchConfigFileLine();
    186252
     253        // Set the values of all types to zero
    187254        this->value_int_ = 0;
    188255        this->value_double_ = 0.000000;
     
    193260    }
    194261
     262    /**
     263        @brief Searches the corresponding entry in the config-file and creates it, if there is no entry.
     264    */
    195265    void ConfigValueContainer::searchConfigFileLine()
    196266    {
     267        // Read the file if needed
    197268        if (!ConfigValueContainer::readConfigFile_s)
    198269            ConfigValueContainer::readConfigFile(CONFIGFILEPATH);
    199270
     271        // Just in case something goes wrong
    200272        this->configFileLine_ = 0;
    201273
     274        // The string of the section we're searching
    202275        std::string section = "";
    203276        section.append("[");
     
    205278        section.append("]");
    206279
     280        // Iterate through all config-file-lines
    207281        bool success = false;
    208282        std::list<std::string>::iterator it1;
    209283        for(it1 = ConfigValueContainer::configFileLines_s->begin(); it1 != ConfigValueContainer::configFileLines_s->end(); ++it1)
    210284        {
     285            // Don't try to parse comments
    211286            if (this->isComment(*it1))
    212287                continue;
     
    214289            if ((*it1).find(section) < (*it1).length())
    215290            {
     291                // We found the right section
    216292                bool bLineIsEmpty = false;
    217293                std::list<std::string>::iterator positionToPutNewLineAt;
    218294
     295                // Iterate through all lines in the section
    219296                std::list<std::string>::iterator it2;
    220297                for(it2 = ++it1; it2 != ConfigValueContainer::configFileLines_s->end(); ++it2)
    221298                {
     299                    // Don't try to parse comments
    222300                    if (this->isComment(*it2))
    223301                        continue;
    224302
     303                    // This if-else block is used to write a new line right after the last line of the
     304                    // section but in front of the following empty lines before the next section.
     305                    // (So this helps to keep a nice formatting with empty-lines between sections in the config-file)
    225306                    if (this->isEmpty(*it2))
    226307                    {
     
    239320                    }
    240321
     322                    // Look out for the beginning of the next section
    241323                    unsigned int open = (*it2).find("[");
    242324                    unsigned int close = (*it2).find("]");
    243325                    if ((open < (*it2).length()) && (close < (*it2).length()) && (open < close))
    244326                    {
     327                        // The next section startet, so our line isn't yet in the file - now we add it and safe the file
    245328                        this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalue_);
    246329                        ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     
    249332                    }
    250333
     334                    // Look out for the variable-name
    251335                    if ((*it2).find(this->varname_) < (*it2).length())
    252336                    {
     337                        // We found the right line - safe it and return
    253338                        this->configFileLine_ = it2;
    254339                        success = true;
     
    256341                    }
    257342                }
     343
     344                // Check if we succeeded
    258345                if (!success)
    259346                {
     347                    // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file
    260348                    this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalue_);
    261349                    ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     
    265353            }
    266354        }
     355
     356        // Check if we succeeded
    267357        if (!success)
    268358        {
    269             this->configFileLines_s->push_back("[" + this->classname_ + "]");
    270             this->configFileLines_s->push_back(this->varname_ + "=" + this->defvalue_);
    271             this->configFileLine_ = --this->configFileLines_s->end();
     359            // We obviously didn't found the right section, so we'll create it
     360            this->configFileLines_s->push_back("[" + this->classname_ + "]");           // Create the section
     361            this->configFileLines_s->push_back(this->varname_ + "=" + this->defvalue_); // Create the line
     362            this->configFileLine_ = --this->configFileLines_s->end();                   // Set the pointer to the last element
    272363            success = true;
    273             this->configFileLines_s->push_back("");
    274             ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
    275         }
    276     }
    277 
     364            this->configFileLines_s->push_back("");                                     // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function
     365            ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);                      // Save the changed config-file
     366        }
     367    }
     368
     369    /**
     370        @brief Determines if a line in the config-file is a comment.
     371        @param line The line to check
     372        @return True = it's a comment
     373    */
    278374    bool ConfigValueContainer::isComment(const std::string& line)
    279375    {
     376        // Strip the line, whitespaces are disturbing
    280377        std::string teststring = getStrippedLine(line);
    281378
     379        // There are four possible comment-symbols:
     380        //  1) #comment in script-language style
     381        //  2) %comment in matlab style
     382        //  3) ;comment in unreal tournament config-file style
     383        //  4) //comment in code style
    282384        if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[0] == '/'))
    283385            return true;
     
    286388    }
    287389
     390    /**
     391        @brief Determines if a line in the config-file is empty (contains only whitespaces).
     392        @param line The line to check
     393        @return True = it's empty
     394    */
    288395    bool ConfigValueContainer::isEmpty(const std::string& line)
    289396    {
     
    291398    }
    292399
     400    /**
     401        @brief Removes all whitespaces from a line.
     402        @param line The line to strip
     403        @return The stripped line
     404    */
    293405    std::string ConfigValueContainer::getStrippedLine(const std::string& line)
    294406    {
     
    301413    }
    302414
     415    /**
     416        @brief Returns the part in the corresponding config-file-entry of the container that defines the value.
     417        @param bStripped True = strip the value-string
     418        @return The value-string
     419    */
    303420    std::string ConfigValueContainer::getValueString(bool bStripped)
    304421    {
     
    312429    }
    313430
     431    /**
     432        @brief Reads the config-file and stores the lines in a list.
     433        @param filename The name of the config-file
     434    */
    314435    void ConfigValueContainer::readConfigFile(const std::string& filename)
    315436    {
    316437        ConfigValueContainer::readConfigFile_s = true;
    317438
     439        // Create the list if needed
    318440        if (!ConfigValueContainer::configFileLines_s)
    319441            ConfigValueContainer::configFileLines_s = new std::list<std::string>;
    320442
     443        // This creates the file if it's not existing
    321444        std::ofstream createFile;
    322445        createFile.open(filename.c_str(), std::fstream::app);
    323446        createFile.close();
    324447
     448        // Open the file
    325449        std::ifstream file;
    326450        file.open(filename.c_str(), std::fstream::in);
     
    328452        char line[1024];
    329453
     454        // Iterate through the file and add the lines into the list
    330455        while (file.good() && !file.eof())
    331456        {
     
    335460        }
    336461
     462        // The last line is useless
    337463        ConfigValueContainer::configFileLines_s->pop_back();
    338464
     465        // Add an empty line to the end of the file if needed
     466        // this is needed for the algorithm in the searchConfigFileLine-function
    339467        if ((ConfigValueContainer::configFileLines_s->size() > 0) && !isEmpty(*ConfigValueContainer::configFileLines_s->rbegin()))
    340468        {
     
    346474    }
    347475
     476    /**
     477        @param Writes the content of the list, containing all lines of the config-file, into the config-file.
     478        @param filename The name of the config-file
     479    */
    348480    void ConfigValueContainer::writeConfigFile(const std::string& filename)
    349481    {
    350         ConfigValueContainer::readConfigFile_s = true;
    351 
    352         if (!ConfigValueContainer::configFileLines_s)
    353             ConfigValueContainer::configFileLines_s = new std::list<std::string>;
    354 
    355         std::ofstream createFile;
    356         createFile.open(filename.c_str(), std::fstream::app);
    357         createFile.close();
    358 
     482        // Make sure we stored the config-file in the list
     483        if (!ConfigValueContainer::readConfigFile_s)
     484            ConfigValueContainer::readConfigFile(filename);
     485
     486        // Open the file
    359487        std::ofstream file;
    360488        file.open(filename.c_str(), std::fstream::out);
    361489
     490        // Iterate through the list an write the lines into the file
    362491        std::list<std::string>::iterator it;
    363492        for(it = ConfigValueContainer::configFileLines_s->begin(); it != ConfigValueContainer::configFileLines_s->end(); ++it)
  • code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.h

    r434 r447  
     1/*!
     2    @file ConfigValueContainer.h
     3    @brief Definition of the ConfigValueContainer class.
     4
     5    The ConfigValueContainer class contains all needed informations about a configurable variable:
     6     - the name of the variable
     7     - the name of the class the variable belongs to
     8     - the default value
     9     - the user-specified value
     10     - a pointer to the entry in the config-file
     11
     12    This is needed to assign the configured values to all newly created objects.
     13*/
     14
    115#ifndef _ConfigValueContainer_H__
    216#define _ConfigValueContainer_H__
     
    923namespace orxonox
    1024{
     25    //! The ConfigValuecontainer contains all needed informations about a configurable variable.
     26    /**
     27        The ConfigValueContainer class contains all needed informations about a configurable variable:
     28         - the name of the variable
     29         - the name of the class the variable belongs to
     30         - the default value
     31         - the user-specified value
     32         - a pointer to the entry in the config-file
     33
     34        This is needed to assign the configured values to all newly created objects.
     35
     36        The container searches for the entry in the config file.
     37        If there is an entry, it parses the specified value and assigns it to the variable of the right type.
     38        If there is no entry, it adds the entry with the default-value to the section of the variables class.
     39        If there is no section, the section and the entry are added to the end of the config-file.
     40    */
    1141    class ConfigValueContainer
    1242    {
     
    2959            static void writeConfigFile(const std::string& filename);
    3060
     61            /** @returns the value of the type int. @param value This is only needed to determine the right type. */
    3162            inline int getValue(int value)                                      { return this->value_int_; }
     63            /** @returns the value of the type double. @param value This is only needed to determine the right type. */
    3264            inline double getValue(double value)                                { return this->value_double_; }
     65            /** @returns the value of the type bool. @param value This is only needed to determine the right type. */
    3366            inline bool getValue(bool value)                                    { return this->value_bool_; }
     67            /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */
    3468            inline std::string getValue(const std::string& value)               { return this->value_string_; }
     69            /** @returns the value of the type Vector3. @param value This is only needed to determine the right type. */
    3570            inline Ogre::Vector3 getValue(const Ogre::Vector3& value)           { return this->value_vector3_; }
     71            /** @returns the value of the type Colour£Value. @param value This is only needed to determine the right type. */
    3672            inline Ogre::ColourValue getValue(const Ogre::ColourValue& value)   { return this->value_colourvalue_; }
    3773
    3874        private:
    39             std::string         classname_;
    40             std::string         varname_;
    41             std::string         defvalue_;
     75            std::string         classname_;                     //!< The name of the class the variable belongs to
     76            std::string         varname_;                       //!< The name of the variable
     77            std::string         defvalue_;                      //!< The string of the default-variable
    4278
    43             int                 value_int_;
    44             double              value_double_;
    45             bool                value_bool_;
    46             std::string         value_string_;
    47             Ogre::Vector3       value_vector3_;
    48             Ogre::ColourValue   value_colourvalue_;
     79            int                 value_int_;                     //!< The value, if the variable is of the type int
     80            double              value_double_;                  //!< The value, if the variable is of the type double
     81            bool                value_bool_;                    //!< The value, if the variable is of the type bool
     82            std::string         value_string_;                  //!< The value, if the variable is of the type string
     83            Ogre::Vector3       value_vector3_;                 //!< The value, if the variable is of the type Vector3
     84            Ogre::ColourValue   value_colourvalue_;             //!< The value, if the variable is of the type ColourValue
    4985
    50             std::list<std::string>::iterator configFileLine_;
    51             static std::list<std::string>* configFileLines_s;
    52             static bool readConfigFile_s;
     86            std::list<std::string>::iterator configFileLine_;   //!< An iterator, pointing to the entry of the variable in the config-file
     87            static std::list<std::string>* configFileLines_s;   //!< A list, containing all entrys in the config-file
     88            static bool readConfigFile_s;                       //!< True if the config-file is read and stored in the list
    5389    };
    5490}
  • code/branches/objecthierarchy/src/orxonox/core/CoreIncludes.h

    r443 r447  
    11/**
    22    @file CoreIncludes.h
    3     @brief Definition of macros for the class-hierarchy and the factory.
     3    @brief Definition of macros and typedefs.
    44
    55    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
     
    2121#include "OgreColourValue.h"
    2222
     23
     24// Some typedefs
    2325namespace orxonox
    2426{
     
    2729}
    2830
    29 // Intern macro, containing the common parts of RegisterObject and RegisterRootObject
     31
     32/**
     33    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
     34    @param ClassName The name of the class
     35    @param bRootClass True if the class is directly derived from OrxonoxClass
     36*/
    3037#define InternRegisterObject(ClassName, bRootClass) \
    3138    this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \
     
    3441    ClassIdentifier<ClassName>::addObject(this)
    3542
    36 // Intern macro, containing the specific part of RegisterRootObject
     43/**
     44    @brief Intern macro, containing the specific part of RegisterRootObject.
     45    @param ClassName The name of the class
     46*/
    3747#define InternRegisterRootObject(ClassName) \
    3848    if (Identifier::isCreatingHierarchy() && !this->getParents()) \
     
    4050    InternRegisterObject(ClassName, true)
    4151
    42 // RegisterObject - with and without debug output
     52/**
     53    @brief RegisterObject - with and without debug output.
     54    @param ClassName The name of the class
     55*/
    4356#if HIERARCHY_VERBOSE
    4457#define RegisterObject(ClassName) \
     
    5063#endif
    5164
    52 // RegisterRootObject - with and without debug output
     65/**
     66    @brief RegisterRootObject - with and without debug output.
     67    @param ClassName The name of the class
     68*/
    5369#if HIERARCHY_VERBOSE
    5470#define RegisterRootObject(ClassName) \
     
    6076#endif
    6177
    62 // Class(ClassName) returns the Identifier of the given class
     78/**
     79    @brief Returns the Identifier of the given class.
     80    @param ClassName The name of the class
     81*/
    6382#define Class(ClassName) \
    6483    ClassIdentifier<ClassName>::getIdentifier()
    6584
    66 // Creates the entry in the Factory
     85/**
     86    @brief Creates the entry in the Factory.
     87    @param ClassName The name of the class
     88*/
    6789#define CreateFactory(ClassName) \
    6890    bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create()
    6991
    70 // ID(StringOrInt) returns the Identifier with either a given name or a given NetworkID through the factory
     92/**
     93    @brief Returns the Identifier with either a given name or a given network ID through the factory.
     94    @param StringOrInt The name or the network ID of the class
     95*/
    7196#define ID(StringOrInt) \
    7297    Factory::getIdentifier(StringOrInt)
    7398
    74 // bla
     99/**
     100    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
     101    @param varname The name of the variable
     102    @param defvalue The default-value of the variable
     103*/
    75104#define SetConfigValue(varname, defvalue) \
    76105    ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
  • code/branches/objecthierarchy/src/orxonox/core/Factory.cc

    r365 r447  
    2424
    2525    /**
    26         @returns the Identifier with a given networkID.
    27         @param id The networkID of the wanted Identifier
     26        @returns the Identifier with a given network ID.
     27        @param id The network ID of the wanted Identifier
    2828    */
    2929    Identifier* Factory::getIdentifier(const unsigned int id)
     
    5050
    5151    /**
    52         @brief Removes the entry with the old networkID and adds a new one.
     52        @brief Removes the entry with the old network ID and adds a new one.
    5353        @param identifier The identifier to change
    5454        @param oldID The old networkID
  • code/branches/objecthierarchy/src/orxonox/core/Factory.h

    r383 r447  
    33    @brief Definition of the Factory and the BaseFactory class.
    44
    5     The Factory is a singleton, containing two maps to map either the name or the networkID
     5    The Factory is a singleton, containing two maps to map either the name or the network ID
    66    of a class with the corresponding Identifier.
    77
     
    2828    // ###         Factory         ###
    2929    // ###############################
    30     //! The Factory is used to map name or networkID of a class with its Identifier.
     30    //! The Factory is used to map the name or the network ID of a class with its Identifier.
    3131    class Factory
    3232    {
     
    4343
    4444            static Factory* pointer_s;                                          //!< The pointer to the singleton
    45             std::map<std::string, Identifier*> identifierStringMap_;            //!< The map mapping string with Identifier
    46             std::map<unsigned int, Identifier*> identifierNetworkIDMap_;        //!< The map mapping networkID with Identifier
     45            std::map<std::string, Identifier*> identifierStringMap_;            //!< The map, mapping the name with the Identifier
     46            std::map<unsigned int, Identifier*> identifierNetworkIDMap_;        //!< The map, mapping the network ID with the Identifier
    4747    };
    4848
  • code/branches/objecthierarchy/src/orxonox/core/Identifier.cc

    r365 r447  
    1212    // ###############################
    1313    int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero
    14     unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero
     14    unsigned int Identifier::classIDcounter_s = 0;  // Set the static member variable classIDcounter_s to zero
    1515
    1616    /**
     
    7979
    8080    /**
    81         @brief Sets the networkID to a new value and changes the entry in the Factory.
    82         @param id The new networkID
     81        @brief Sets the network ID to a new value and changes the entry in the Factory.
     82        @param id The new network ID
    8383    */
    8484    void Identifier::setNetworkID(unsigned int id)
  • code/branches/objecthierarchy/src/orxonox/core/Identifier.h

    r434 r447  
    77     - a list with all objects
    88     - parents and childs
    9      - the factory, if available
     9     - the factory (if available)
    1010     - the networkID that can be synchronised with the server
     11     - all configurable variables (if available)
    1112
    1213    Every object has a pointer to the Identifier of its class. This allows the use isA(...),
     
    1819
    1920    SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
    20     You can only assign Identifiers of the given class or a derivative to a SubclassIdentifier.
     21    You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
    2122*/
    2223
     
    4849         - a list with all objects
    4950         - parents and childs
    50          - the factory, if available
     51         - the factory (if available)
    5152         - the networkID that can be synchronised with the server
     53         - all configurable variables (if available)
    5254
    5355        Every object has a pointer to the Identifier of its class. This allows the use isA(...),
     
    8789            inline IdentifierList& getChildren() const { return *this->children_; }
    8890
    89             /** @returns true, if a branch of the class-hierarchy is getting created, causing all new objects to store their parents. */
     91            /** @returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. */
    9092            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    9193
    92             /** @returns the NetworkID to identify a class through the network. */
     94            /** @returns the network ID to identify a class through the network. */
    9395            inline const unsigned int getNetworkID() const { return this->classID_; }
    9496
     97            /** @brief Sets the network ID to a new value. @param id The new value */
    9598            void setNetworkID(unsigned int id);
    9699
     100            /** @returns the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variable */
    97101            inline ConfigValueContainer* getConfigValueContainer(const std::string& varname)
    98102                { return this->configValues_[varname]; }
    99103
     104            /** @brief Sets the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variablee @param container The container */
    100105            inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
    101106                { this->configValues_[varname] = container; }
     
    134139            std::string name_;                                          //!< The name of the class the Identifier belongs to
    135140
    136             BaseFactory* factory_;                                      //!< The Factory, able to create new objects of the given class
     141            BaseFactory* factory_;                                      //!< The Factory, able to create new objects of the given class (if available)
    137142            bool bCreatedOneObject_;                                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    138143            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_;
     144            static unsigned int classIDcounter_s;                       //!< The number of existing Identifiers
     145            unsigned int classID_;                                      //!< The network ID to identify a class through the network
     146            std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
    142147    };
    143148
     
    173178
    174179    /**
    175         @brief Constructor: Create the ObjectList.
     180        @brief Constructor: Creates the ObjectList.
    176181    */
    177182    template <class T>
     
    182187
    183188    /**
    184         @brief Destructor: Delete the ObjectList, set the singleton-pointer to zero.
     189        @brief Destructor: Deletes the ObjectList, sets the singleton-pointer to zero.
    185190    */
    186191    template <class T>
     
    195200        @param parents An IdentifierList, containing the Identifiers of all parents of the class
    196201        @param name A string, containing exactly the name of the class
    197         @param bRootClass True if the class is either an Interface or BaseObject itself
     202        @param bRootClass True if the class is either an Interface or the BaseObject itself
    198203        @return The ClassIdentifier itself
    199204    */
     
    235240
    236241    /**
    237         @returns the Identifier itself
     242        @returns the Identifier itself.
    238243    */
    239244    template <class T>
     
    270275    //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
    271276    /**
    272         You can only assign Identifiers that belong to a class of at least B (or derived) to a SubclassIdentifier<T>.
     277        You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
    273278        If you assign something else, the program aborts.
    274279        Because we know the minimal type, a dynamic_cast is done, which makes it easier to create a new object.
     
    323328
    324329            /**
    325                 @brief Creates a new object of the type of the assigned identifier and dynamic_casts it to the minimal type given by the SubclassIdentifier.
     330                @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
    326331                @return The new object
    327332            */
     
    330335                BaseObject* newObject = this->identifier_->fabricate();
    331336
    332                 // Check if the creation worked
     337                // Check if the creation was successful
    333338                if (newObject)
    334339                {
  • code/branches/objecthierarchy/src/orxonox/core/IdentifierList.cc

    r365 r447  
    101101
    102102    /**
    103         @returns a string, containing the names of all Identifiers in the list.
     103        @returns a string, containing a list of the names of all Identifiers in the list.
    104104    */
    105105    std::string IdentifierList::toString() const
  • code/branches/objecthierarchy/src/orxonox/core/Iterator.h

    r365 r447  
    44
    55    The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type.
    6     This is the only way to access the objects in an ObjectList.
     6    This is the only way to access the objects stored in an ObjectList.
    77
    88    Usage:
     
    1313    }
    1414
    15     Warning: Don't delete an object directly through the iterator.
     15    Warning: Don't delete objects directly through the iterator.
    1616*/
    1717
     
    2727        public:
    2828            /**
    29                 @brief Constructor: Sets the element whereon the iterator points to zero.
     29                @brief Constructor: Sets the element, whereon the iterator points, to zero.
    3030            */
    3131            Iterator()
     
    3535
    3636            /**
    37                 @brief Constructor: Sets the element whereon the iterator points to a given element.
     37                @brief Constructor: Sets the element, whereon the iterator points, to a given element.
    3838                @param element The element to start with
    3939            */
     
    4444
    4545            /**
    46                 @brief Overloading of the ++it operator: Iterator iterates to the next object in the list.
     46                @brief Overloading of the ++it operator: Iterator points to the next object in the list.
    4747                @return The Iterator itself
    4848            */
     
    5454
    5555            /**
    56                 @brief Overloading of the --it operator: Iterator iterates to the previous object in the list.
     56                @brief Overloading of the --it operator: Iterator points to the previous object in the list.
    5757                @return The Iterator itself
    5858            */
     
    9898            bool operator!=(int compare)
    9999            {
    100                 // Comparing with something except zero makes no sense
     100                // Comparing with anything except zero makes no sense
    101101                if (compare != 0)
    102102                    std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n";
     
    106106
    107107        private:
    108             ObjectListElement<T>* element_;     //!< The element the Iterator points to
     108            ObjectListElement<T>* element_;     //!< The element the Iterator points at
    109109    };
    110110}
  • code/branches/objecthierarchy/src/orxonox/core/MetaObjectList.h

    r365 r447  
    44
    55    The MetaObjectList is a single-linked list, containing all list-elements and their
    6     lists wherein the object that owns the MetaObjectList is registered.
    7     This allows much faster deleting of objects.
     6    lists wherein the object, owning the MetaObjectList, is registered.
     7    This allows much faster deletion of objects because no iteration is needed.
    88*/
    99
     
    2020    {
    2121        public:
    22             /** @brief Defaultdestructor */
     22            /** @brief Default destructor */
    2323            virtual ~BaseMetaObjectListElement() {};
    2424
     
    8383        The MetaObjectList is a single-linked list, containing all list-elements and their
    8484        lists wherein the object that owns the MetaObjectList is registered.
    85         This allows much faster deleting of objects.
     85        This allows much faster deletion of objects because no iteration is needed.
    8686    */
    8787    class MetaObjectList
  • code/branches/objecthierarchy/src/orxonox/core/ObjectList.h

    r365 r447  
    33    @brief Definition of the ObjectList class.
    44
    5     The ObjectList is a double-linked list, used by Identifiers to store all objects of a specific class in it.
    6     Created objects are added through the RegisterObject-macro in its constructor.
     5    The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class.
     6    Newly created objects are added through the RegisterObject-macro in its constructor.
    77    Use Iterator<class> to iterate through all objects of the class.
    88*/
     
    3232    /**
    3333        @brief Constructor: Creates the list-element with an object.
    34         @param Object The object to store
     34        @param object The object to store
    3535    */
    3636    template <class T>
     
    4949    class Iterator; // Forward declaration
    5050
    51     //! The ObjectList contains all objects of a specific class.
    52     /**
    53         The ObjectList is used by Identifiers to store all objects of a specific class in it.
     51    //! The ObjectList contains all objects of a given class.
     52    /**
     53        The ObjectList is used by Identifiers to store all objects of a given class.
    5454        Use Iterator<class> to iterate through all objects in the list.
    5555    */
     
    8282
    8383    /**
    84         @brief Constructor: Sets first_ and last_ to zero and the static member variable pointer_s to _this_
     84        @brief Constructor: Sets default values.
    8585    */
    8686    template <class T>
  • code/branches/objecthierarchy/src/orxonox/core/OrxonoxClass.h

    r434 r447  
    33    @brief Definition of the OrxonoxClass Class.
    44
    5     All objects and interfaces of the game-logic are derived from OrxonoxClass.
    6     It stores the Identifier and the MetaObjectList and has all needed functions to create the class-hierarchy.
     5    All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass.
     6    It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
    77*/
    88
     
    1717namespace orxonox
    1818{
    19     //! The class all objects and interfaces of the game-logic are derived from.
     19    //! The class all objects and interfaces of the game-logic (not the engine) are derived from.
    2020    /**
    21         BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
     21        The BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
    2222        OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList.
    2323    */
     
    4545            inline MetaObjectList& getMetaList() { return this->metaList_; }
    4646
     47
     48            /** @returns true if the objects class is of the given type or a derivative. */
    4749            inline bool isA(const Identifier* identifier)
    4850                { return this->getIdentifier()->isA(identifier); }
     51            /** @returns true if the objects class is exactly of the given type. */
    4952            inline bool isDirectlyA(const Identifier* identifier)
    5053                { return this->getIdentifier()->isDirectlyA(identifier); }
     54            /** @returns true if the objects class is a child of the given type. */
    5155            inline bool isChildOf(const Identifier* identifier)
    5256                { return this->getIdentifier()->isChildOf(identifier); }
     57            /** @returns true if the objects class is a parent of the given type. */
    5358            inline bool isParentOf(const Identifier* identifier)
    5459                { return this->getIdentifier()->isParentOf(identifier); }
    5560
     61
     62            /** @returns true if the objects class is of the given type or a derivative. */
    5663            inline bool isA(const SubclassIdentifier<class B>* identifier)
    5764                { return this->getIdentifier()->isA(identifier->getIdentifier()); }
     65            /** @returns true if the objects class is exactly of the given type. */
    5866            inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier)
    5967                { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); }
     68            /** @returns true if the objects class is a child of the given type. */
    6069            inline bool isChildOf(const SubclassIdentifier<class B>* identifier)
    6170                { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
     71            /** @returns true if the objects class is a parent of the given type. */
    6272            inline bool isParentOf(const SubclassIdentifier<class B>* identifier)
    6373                { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
    6474
     75
     76            /** @returns true if the objects class is of the given type or a derivative. */
    6577            inline bool isA(const SubclassIdentifier<class B> identifier)
    6678                { return this->getIdentifier()->isA(identifier.getIdentifier()); }
     79            /** @returns true if the objects class is exactly of the given type. */
    6780            inline bool isDirectlyA(const SubclassIdentifier<class B> identifier)
    6881                { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); }
     82            /** @returns true if the objects class is a child of the given type. */
    6983            inline bool isChildOf(const SubclassIdentifier<class B> identifier)
    7084                { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
     85            /** @returns true if the objects class is a parent of the given type. */
    7186            inline bool isParentOf(const SubclassIdentifier<class B> identifier)
    7287                { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
    7388
     89
     90            /** @returns true if the objects class is of the given type or a derivative. */
    7491            inline bool isA(const OrxonoxClass* object)
    7592                { return this->getIdentifier()->isA(object->getIdentifier()); }
     93            /** @returns true if the objects class is exactly of the given type. */
    7694            inline bool isDirectlyA(const OrxonoxClass* object)
    7795                { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); }
     96            /** @returns true if the objects class is a child of the given type. */
    7897            inline bool isChildOf(const OrxonoxClass* object)
    7998                { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
     99            /** @returns true if the objects class is a parent of the given type. */
    80100            inline bool isParentOf(const OrxonoxClass* object)
    81101                { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
    82102
    83103
     104            /** @brief Sets the name of the object. @param name The name */
    84105            inline void setName(const std::string& name) { this->name_ = name; }
     106
     107            /** @returns the name of the object. */
    85108            inline const std::string& getName() const { return this->name_; }
    86109
     110            /** @brief Sets the state of the objects activity. @param bActive True = active */
    87111            inline void setActive(bool bActive) { this->bActive_ = bActive; }
     112
     113            /** @returns the state of the objects activity. */
    88114            inline const bool isActive() const { return this->bActive_; }
    89115
     116            /** @brief Sets the state of the objects visibility. @param bVisible True = visible */
    90117            inline void setVisible(bool bVisible) { this->bVisible_ = bVisible; }
     118
     119            /** @returns the state of the objects visibility. */
    91120            inline const bool isVisible() const { return this->bVisible_; }
    92121
     
    96125            MetaObjectList metaList_;       //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
    97126
    98             std::string name_;
    99             bool bActive_;
    100             bool bVisible_;
     127            std::string name_;              //!< The name of the object
     128            bool bActive_;                  //!< True = the object is active
     129            bool bVisible_;                 //!< True = the object is visible
    101130    };
    102131}
Note: See TracChangeset for help on using the changeset viewer.