Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 30, 2008, 5:38:03 AM (16 years ago)
Author:
landauf
Message:
  • added set and tset functions to the ConfigValueContainer to (temporary) set a config-value to a new value
  • ConfigValueContainer uses now the functions of MultiTypeMath to convert and assign values
  • added some errorhandling to the CommandExecutor in case there are not enough parameters when executing the command
  • added updateConfigValues function to Identifier
  • added addTime and removeTime functions to the Timer
  • some changes in Executor to allow adding description and default-values when using the ConsoleCommand macro
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/ConfigValueContainer.cc

    r949 r957  
    3434
    3535#include "ConfigValueContainer.h"
    36 #include "util/Tokenizer.h"
    37 #include "util/Convert.h"
    3836#include "Language.h"
     37#include "Iterator.h"
     38#include "BaseObject.h"
    3939
    4040#define CONFIGFILEPATH "orxonox.ini"
     
    4949        @param defvalue The default-value
    5050    */
    51     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue)
     51    ConfigValueContainer::ConfigValueContainer(Identifier* identifier, const std::string& varname, MultiTypeMath defvalue)
    5252    {
    5353        this->bAddedDescription_ = false;
    54         this->classname_ = classname;
     54        this->identifier_ = identifier;
    5555        this->varname_ = varname;
    5656
    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";
    99             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;
     57        this->defvalueString_ = defvalue.toString();                                // Convert the default-value to a string
     58        this->searchLineInConfigFile();                                             // Search the entry in the config-file
     59
     60        std::string valueString = this->parseValueStringFromConfigFile(!(defvalue.isA(MT_string) || defvalue.isA(MT_constchar)));     // Parses the value string from the config-file-entry
     61        if (!this->parse(valueString, defvalue))                                    // Try to convert the string to a value
     62            this->resetLineInConfigFile();                                            // The conversion failed
     63    }
     64
     65    /**
     66        @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
     67        @param input The new value
     68        @return True if the new value was successfully assigned
     69    */
     70    bool ConfigValueContainer::set(const std::string& input)
     71    {
     72        bool success = this->tset(input);
     73        this->setLineInConfigFile(input);
     74        return success;
     75    }
     76
     77    /**
     78        @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
     79        @param input The new value
     80        @return True if the new value was successfully assigned
     81    */
     82    bool ConfigValueContainer::tset(const std::string& input)
     83    {
     84        bool success = this->parse(input);
     85        this->identifier_->updateConfigValues();
     86        return success;
     87    }
     88
     89    /**
     90        @brief Sets the value of the variable back to the default value and resets the config-file entry.
     91    */
     92    bool ConfigValueContainer::reset()
     93    {
     94        return this->set(this->defvalueString_);
    17695    }
    17796
     
    181100        @return True if the string was successfully parsed
    182101    */
    183     bool ConfigValueContainer::parseString(const std::string& input, const 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 
     102    bool ConfigValueContainer::parse(const std::string& input)
     103    {
     104        MultiTypeMath temp = this->value_;
     105        if (temp.fromString(input))
     106        {
     107            this->value_ = temp;
     108            return true;
     109        }
    226110        return false;
    227111    }
    228112
    229113    /**
    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.
     114        @brief Parses a given std::string into a value of the type of the associated variable and assigns it.
    231115        @param input The string to convert
    232         @param defvalue The default-value
     116        @param defvalue The default value to assign if the parsing fails
    233117        @return True if the string was successfully parsed
    234118    */
    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);
     119    bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue)
     120    {
     121        MultiTypeMath temp = defvalue;
     122        if (temp.fromString(input))
     123        {
     124            this->value_ = temp;
     125            return true;
     126        }
    404127        else
    405128        {
    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);
     129            this->value_ = defvalue;
     130            return false;
     131        }
     132    }
     133
     134    /**
     135        @brief Sets the corresponding entry in the config-file to a given value.
     136    */
     137    void ConfigValueContainer::setLineInConfigFile(const std::string& input)
     138    {
     139        (*this->configFileLine_) = this->varname_ + "=" + input;
     140        ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
    647141    }
    648142
     
    650144        @brief Sets the corresponding entry in the config-file back to the default value.
    651145    */
    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();
     146    void ConfigValueContainer::resetLineInConfigFile()
     147    {
     148        this->setLineInConfigFile(this->defvalueString_);
    665149    }
    666150
     
    668152        @brief Searches the corresponding entry in the config-file and creates it, if there is no entry.
    669153    */
    670     void ConfigValueContainer::searchConfigFileLine()
     154    void ConfigValueContainer::searchLineInConfigFile()
    671155    {
    672156        // Read the file if needed
     
    677161        std::string section = "";
    678162        section.append("[");
    679         section.append(this->classname_);
     163        section.append(this->identifier_->getName());
    680164        section.append("]");
    681165
     
    686170        {
    687171            // Don't try to parse comments
    688             if (this->isComment(*it1))
     172            if (isComment(*it1))
    689173                continue;
    690174
     
    700184                {
    701185                    // Don't try to parse comments
    702                     if (this->isComment(*it2))
     186                    if (isComment(*it2))
    703187                        continue;
    704188
     
    706190                    // section but in front of the following empty lines before the next section.
    707191                    // (So this helps to keep a nice formatting with empty-lines between sections in the config-file)
    708                     if (this->isEmpty(*it2))
     192                    if (isEmpty(*it2))
    709193                    {
    710194                        if (!bLineIsEmpty)
     
    760244        {
    761245            // We obviously didn't found the right section, so we'll create it
    762             this->getConfigFileLines().push_back("[" + this->classname_ + "]");                   // Create the section
     246            this->getConfigFileLines().push_back("[" + this->identifier_->getName() + "]");                   // Create the section
    763247            this->getConfigFileLines().push_back(this->varname_ + "=" + this->defvalueString_);   // Create the line
    764248            this->configFileLine_ = --this->getConfigFileLines().end();                           // Set the pointer to the last element
    765249            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] == '/'))
    787             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;
     250            this->getConfigFileLines().push_back("");                                             // Add an empty line - this is needed for the algorithm in the searchLineInConfigFile-function
     251            ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);                                // Save the changed config-file
     252        }
    817253    }
    818254
     
    822258        @return The value-string
    823259    */
    824     std::string ConfigValueContainer::parseValueString(bool bStripped)
     260    std::string ConfigValueContainer::parseValueStringFromConfigFile(bool bStripped)
    825261    {
    826262        std::string output;
    827263        if (bStripped)
    828             output = this->getStrippedLine(*this->configFileLine_);
     264            output = getStripped(*this->configFileLine_);
    829265        else
    830266            output = *this->configFileLine_;
     
    889325            file.getline(line, 1024);
    890326            ConfigValueContainer::getConfigFileLines().push_back(line);
    891 //            std::cout << "### ->" << line << "<- : empty: " << isEmpty(line) << " comment: " << isComment(line) << std::endl;
    892327        }
    893328
     
    896331
    897332        // Add an empty line to the end of the file if needed
    898         // this is needed for the algorithm in the searchConfigFileLine-function
     333        // this is needed for the algorithm in the searchLineInConfigFile-function
    899334        if ((ConfigValueContainer::getConfigFileLines().size() > 0) && !isEmpty(*ConfigValueContainer::getConfigFileLines().rbegin()))
    900         {
    901 //            std::cout << "### newline added" << std::endl;
    902335            ConfigValueContainer::getConfigFileLines().push_back("");
    903         }
    904336
    905337        file.close();
     
    949381        if (!this->bAddedDescription_)
    950382        {
    951             this->description_ = std::string("ConfigValueDescription::" + this->classname_ + "::" + this->varname_);
     383            this->description_ = std::string("ConfigValueDescription::" + this->identifier_->getName() + "::" + this->varname_);
    952384            AddLanguageEntry(this->description_, description);
    953385            this->bAddedDescription_ = true;
Note: See TracChangeset for help on using the changeset viewer.