Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 9, 2008, 7:32:06 PM (16 years ago)
Author:
landauf
Message:

upload of the work i did before the exams (not yet finished nor working)

File:
1 edited

Legend:

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

    r790 r792  
    2828#include <fstream>
    2929
     30#include "ConfigValueContainer.h"
    3031#include "util/Tokenizer.h"
    3132#include "util/Convert.h"
    32 #include "ConfigValueContainer.h"
    3333
    3434#define CONFIGFILEPATH "orxonox.ini"
     
    4343        @param defvalue The default-value
    4444    */
    45     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue)
     45    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue)
    4646    {
    4747        this->bAddedDescription_ = false;
    4848        this->classname_ = classname;
    4949        this->varname_ = varname;
    50         this->type_ = VT_Int;
    51 
    52         ConvertValue(&this->defvalueString_, defvalue, std::string("0"));           // Try to convert the default-value to a string
     50
     51        this->valueToString(&this->defvalueString_, defvalue);                      // Try to convert the default-value to a string
    5352        this->searchConfigFileLine();                                               // Search the entry in the config-file
    5453
    5554        std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    56         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
     55        if (!this->parseString(valueString, defvalue))                              // Try to convert the string to a value
    5756            this->resetConfigFileEntry();                                           // The conversion failed
    5857    }
    5958
    6059    /**
    61         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    62         @param value This is only needed to determine the right type.
    63         @param classname The name of the class the variable belongs to
    64         @param varname The name of the variable
    65         @param defvalue The default-value
    66     */
    67     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue)
    68     {
    69         this->bAddedDescription_ = false;
    70         this->classname_ = classname;
    71         this->varname_ = varname;
    72         this->type_ = VT_uInt;
    73 
    74         ConvertValue(&this->defvalueString_, defvalue, std::string("0"));           // Try to convert the default-value to a string
    75         this->searchConfigFileLine();                                               // Search the entry in the config-file
    76 
    77         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    78         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    79             this->resetConfigFileEntry();                                           // The conversion failed
    80     }
    81 
    82     /**
    83         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    84         @param value This is only needed to determine the right type.
    85         @param classname The name of the class the variable belongs to
    86         @param varname The name of the variable
    87         @param defvalue The default-value
    88     */
    89     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue)
    90     {
    91         this->bAddedDescription_ = false;
    92         this->classname_ = classname;
    93         this->varname_ = varname;
    94         this->type_ = VT_Char;
    95 
    96         ConvertValue(&this->defvalueString_, (int)defvalue, std::string("0"));      // Try to convert the default-value to a string
    97         this->searchConfigFileLine();                                               // Search the entry in the config-file
    98 
    99         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    100         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    101             this->resetConfigFileEntry();                                           // The conversion failed
    102     }
    103 
    104     /**
    105         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    106         @param value This is only needed to determine the right type.
    107         @param classname The name of the class the variable belongs to
    108         @param varname The name of the variable
    109         @param defvalue The default-value
    110     */
    111     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue)
    112     {
    113         this->bAddedDescription_ = false;
    114         this->classname_ = classname;
    115         this->varname_ = varname;
    116         this->type_ = VT_uChar;
    117 
    118         ConvertValue(&this->defvalueString_, (unsigned int)defvalue, std::string("0"));     // Try to convert the default-value to a string
    119         this->searchConfigFileLine();                                               // Search the entry in the config-file
    120 
    121         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    122         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    123             this->resetConfigFileEntry();                                           // The conversion failed
    124     }
    125 
    126     /**
    127         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    128         @param value This is only needed to determine the right type.
    129         @param classname The name of the class the variable belongs to
    130         @param varname The name of the variable
    131         @param defvalue The default-value
    132     */
    133     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue)
    134     {
    135         this->bAddedDescription_ = false;
    136         this->classname_ = classname;
    137         this->varname_ = varname;
    138         this->type_ = VT_Float;
    139 
    140         ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000"));    // Try to convert the default-value to a string
    141         this->searchConfigFileLine();                                               // Search the entry in the config-file
    142 
    143         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    144         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    145             this->resetConfigFileEntry();                                           // The conversion failed
    146     }
    147 
    148     /**
    149         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    150         @param value This is only needed to determine the right type.
    151         @param classname The name of the class the variable belongs to
    152         @param varname The name of the variable
    153         @param defvalue The default-value
    154     */
    155     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue)
    156     {
    157         this->bAddedDescription_ = false;
    158         this->classname_ = classname;
    159         this->varname_ = varname;
    160         this->type_ = VT_Double;
    161 
    162         ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000"));    // Try to convert the default-value to a string
    163         this->searchConfigFileLine();                                               // Search the entry in the config-file
    164 
    165         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    166         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    167             this->resetConfigFileEntry();                                           // The conversion failed
    168     }
    169 
    170     /**
    171         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    172         @param value This is only needed to determine the right type.
    173         @param classname The name of the class the variable belongs to
    174         @param varname The name of the variable
    175         @param defvalue The default-value
    176     */
    177     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, long double defvalue)
    178     {
    179         this->bAddedDescription_ = false;
    180         this->classname_ = classname;
    181         this->varname_ = varname;
    182         this->type_ = VT_LongDouble;
    183 
    184         ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000"));    // Try to convert the default-value to a string
    185         this->searchConfigFileLine();                                               // Search the entry in the config-file
    186 
    187         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    188         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    189             this->resetConfigFileEntry();                                           // The conversion failed
    190     }
    191 
    192     /**
    193         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    194         @param value This is only needed to determine the right type.
    195         @param classname The name of the class the variable belongs to
    196         @param varname The name of the variable
    197         @param defvalue The default-value
    198     */
    199     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue)
    200     {
    201         this->bAddedDescription_ = false;
    202         this->classname_ = classname;
    203         this->varname_ = varname;
    204         this->type_ = VT_Bool;
    205 
    206         // Convert the default-value from bool to string
    207         if (defvalue)
    208             this->defvalueString_ = "true";
    209         else
    210             this->defvalueString_ = "false";
    211 
    212         this->searchConfigFileLine();                                               // Search the entry in the config-file
    213         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    214         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    215             this->resetConfigFileEntry();                                           // The conversion failed
    216     }
    217 
    218     /**
    219         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    220         @param value This is only needed to determine the right type.
    221         @param classname The name of the class the variable belongs to
    222         @param varname The name of the variable
    223         @param defvalue The default-value
    224     */
    225     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue)
    226     {
    227         this->bAddedDescription_ = false;
    228         this->classname_ = classname;
    229         this->varname_ = varname;
    230         this->type_ = VT_String;
    231 
    232         this->defvalueString_ = "\"" + defvalue + "\"";                             // Convert the string to a "config-file-string" with quotes
    233         this->searchConfigFileLine();                                               // Search the entry in the config-file
    234         std::string valueString = this->parseValueString(false);                    // Parses the value string from the config-file-entry
    235         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    236             this->resetConfigFileEntry();                                           // The conversion failed
    237     }
    238 
    239     /**
    240         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    241         @param value This is only needed to determine the right type.
    242         @param classname The name of the class the variable belongs to
    243         @param varname The name of the variable
    244         @param defvalue The default-value
    245     */
    246     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue)
    247     {
    248         this->bAddedDescription_ = false;
    249         this->classname_ = classname;
    250         this->varname_ = varname;
    251         this->type_ = VT_ConstChar;
    252 
    253         this->defvalueString_ = "\"" + std::string(defvalue) + "\"";                // Convert the string to a "config-file-string" with quotes
    254         this->searchConfigFileLine();                                               // Search the entry in the config-file
    255         std::string valueString = this->parseValueString(false);                    // Parses the value string from the config-file-entry
    256         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    257             this->resetConfigFileEntry();                                           // The conversion failed
    258     }
    259 
    260     /**
    261         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    262         @param value This is only needed to determine the right type.
    263         @param classname The name of the class the variable belongs to
    264         @param varname The name of the variable
    265         @param defvalue The default-value
    266     */
    267     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Vector2 defvalue)
    268     {
    269         this->bAddedDescription_ = false;
    270         this->classname_ = classname;
    271         this->varname_ = varname;
    272         this->type_ = VT_Vector2;
    273 
    274         // Try to convert the default-value from Vector2 to string
    275         std::ostringstream ostream;
    276         if (ostream << "(" << defvalue.x << "," << defvalue.y << ")")
    277             this->defvalueString_ = ostream.str();
    278         else
    279             this->defvalueString_ = "(0,0)";
    280 
    281         this->searchConfigFileLine();                                               // Search the entry in the config-file
    282         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    283         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    284             this->resetConfigFileEntry();                                           // The conversion failed
    285     }
    286 
    287     /**
    288         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    289         @param value This is only needed to determine the right type.
    290         @param classname The name of the class the variable belongs to
    291         @param varname The name of the variable
    292         @param defvalue The default-value
    293     */
    294     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Vector3 defvalue)
    295     {
    296         this->bAddedDescription_ = false;
    297         this->classname_ = classname;
    298         this->varname_ = varname;
    299         this->type_ = VT_Vector3;
    300 
    301         // Try to convert the default-value from Vector3 to string
    302         std::ostringstream ostream;
    303         if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")")
    304             this->defvalueString_ = ostream.str();
    305         else
    306             this->defvalueString_ = "(0,0,0)";
    307 
    308         this->searchConfigFileLine();                                               // Search the entry in the config-file
    309         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    310         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    311             this->resetConfigFileEntry();                                           // The conversion failed
    312     }
    313 
    314     /**
    315         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    316         @param value This is only needed to determine the right type.
    317         @param classname The name of the class the variable belongs to
    318         @param varname The name of the variable
    319         @param defvalue The default-value
    320     */
    321     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, ColourValue defvalue)
    322     {
    323         this->bAddedDescription_ = false;
    324         this->classname_ = classname;
    325         this->varname_ = varname;
    326         this->type_ = VT_ColourValue;
    327 
    328         // Try to convert the default-value from ColourValue to string
    329         std::ostringstream ostream;
    330         if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")")
    331             this->defvalueString_ = ostream.str();
    332         else
    333             this->defvalueString_ = "(0,0,0,0)";
    334 
    335         this->searchConfigFileLine();                                               // Search the entry in the config-file
    336         std::string valueString = this->parseValueString();                         // Parses the value string from the config-file-entry
    337         if (!this->parseSting(valueString, defvalue))                               // Try to convert the string to a value
    338             this->resetConfigFileEntry();                                           // The conversion failed
     60        @brief Converts a value to a string.
     61        @param output The string to write to
     62        @param input The value to convert
     63        @return True if the converson was successful
     64    */
     65    bool ConfigValueContainer::valueToString(std::string* output, MultiTypeMath& input)
     66    {
     67        if (this->value_.getType() == MT_int)
     68            return ConvertValue(output, input.getInt(), std::string("0"));
     69        else if (this->value_.getType() == MT_uint)
     70            return ConvertValue(output, input.getUnsignedInt(), std::string("0"));
     71        else if (this->value_.getType() == MT_char)
     72            return ConvertValue(output, input.getChar(), std::string("0"));
     73        else if (this->value_.getType() == MT_uchar)
     74            return ConvertValue(output, input.getUnsignedChar(), std::string("0"));
     75        else if (this->value_.getType() == MT_short)
     76            return ConvertValue(output, input.getShort(), std::string("0"));
     77        else if (this->value_.getType() == MT_ushort)
     78            return ConvertValue(output, input.getUnsignedShort(), std::string("0"));
     79        else if (this->value_.getType() == MT_long)
     80            return ConvertValue(output, input.getLong(), std::string("0"));
     81        else if (this->value_.getType() == MT_ulong)
     82            return ConvertValue(output, input.getUnsignedLong(), std::string("0"));
     83        else if (this->value_.getType() == MT_float)
     84            return ConvertValue(output, input.getFloat(), std::string("0.000000"));
     85        else if (this->value_.getType() == MT_double)
     86            return ConvertValue(output, input.getDouble(), std::string("0.000000"));
     87        else if (this->value_.getType() == MT_longdouble)
     88            return ConvertValue(output, input.getChar(), std::string("0.000000"));
     89        else if (this->value_.getType() == MT_bool)
     90        {
     91            if (input.getBool())
     92                (*output) = "true";
     93            else
     94                (*output) = "false";
     95
     96            return true;
     97        }
     98        else if (this->value_.getType() == MT_constchar)
     99        {
     100            (*output) = "\"" + input.getString() + "\"";
     101            return true;
     102        }
     103        else if (this->value_.getType() == MT_string)
     104        {
     105            (*output) = "\"" + input.getString() + "\"";
     106            return true;
     107        }
     108        else if (this->value_.getType() == MT_vector2)
     109        {
     110            std::ostringstream ostream;
     111            if (ostream << "(" << input.getVector2().x << "," << input.getVector2().y << ")")
     112            {
     113                (*output) = ostream.str();
     114                return true;
     115            }
     116            else
     117            {
     118                (*output) = "(0,0)";
     119                return false;
     120            }
     121        }
     122        else if (this->value_.getType() == MT_vector3)
     123        {
     124            std::ostringstream ostream;
     125            if (ostream << "(" << input.getVector3().x << "," << input.getVector3().y << "," << input.getVector3().z << ")")
     126            {
     127                (*output) = ostream.str();
     128                return true;
     129            }
     130            else
     131            {
     132                (*output) = "(0,0,0)";
     133                return false;
     134            }
     135        }
     136        else if (this->value_.getType() == MT_colourvalue)
     137        {
     138            std::ostringstream ostream;
     139            if (ostream << "(" << input.getColourValue().r << "," << input.getColourValue().g << "," << input.getColourValue().b << "," << input.getColourValue().a << ")")
     140            {
     141                (*output) = ostream.str();
     142                return true;
     143            }
     144            else
     145            {
     146                (*output) = "(0,0,0,0)";
     147                return false;
     148            }
     149        }
     150        else if (this->value_.getType() == MT_quaternion)
     151        {
     152            std::ostringstream ostream;
     153            if (ostream << "(" << input.getQuaternion().w << "," << input.getQuaternion().x << "," << input.getQuaternion().y << "," << input.getQuaternion().z << ")")
     154            {
     155                (*output) = ostream.str();
     156                return true;
     157            }
     158            else
     159            {
     160                (*output) = "(0,0,0,0)";
     161                return false;
     162            }
     163        }
     164        else if (this->value_.getType() == MT_radian)
     165            return ConvertValue(output, input.getRadian(), std::string("0.000000"));
     166        else if (this->value_.getType() == MT_degree)
     167            return ConvertValue(output, input.getDegree(), std::string("0.000000"));
     168
     169        return false;
    339170    }
    340171
     
    344175        @return True if the string was successfully parsed
    345176    */
    346     bool ConfigValueContainer::parseSting(const std::string& input)
    347     {
    348         if (this->type_ == ConfigValueContainer::VT_Int)
    349             return this->parseSting(input, this->value_.value_int_);
    350         else if (this->type_ == ConfigValueContainer::VT_uInt)
    351             return this->parseSting(input, this->value_.value_uint_);
    352         else if (this->type_ == ConfigValueContainer::VT_Char)
    353             return this->parseSting(input, this->value_.value_char_);
    354         else if (this->type_ == ConfigValueContainer::VT_uChar)
    355             return this->parseSting(input, this->value_.value_uchar_);
    356         else if (this->type_ == ConfigValueContainer::VT_Float)
    357             return this->parseSting(input, this->value_.value_float_);
    358         else if (this->type_ == ConfigValueContainer::VT_Double)
    359             return this->parseSting(input, this->value_.value_double_);
    360         else if (this->type_ == ConfigValueContainer::VT_LongDouble)
    361             return this->parseSting(input, this->value_.value_long_double_);
    362         else if (this->type_ == ConfigValueContainer::VT_Bool)
    363             return this->parseSting(input, this->value_.value_bool_);
    364         else if (this->type_ == ConfigValueContainer::VT_String)
    365             return this->parseSting(input, this->value_string_);
    366         else if (this->type_ == ConfigValueContainer::VT_ConstChar)
    367             return this->parseSting(input, this->value_string_);
    368         else if (this->type_ == ConfigValueContainer::VT_Vector2)
    369             return this->parseSting(input, this->value_vector2_);
    370         else if (this->type_ == ConfigValueContainer::VT_Vector3)
    371             return this->parseSting(input, this->value_vector3_);
    372         else if (this->type_ == ConfigValueContainer::VT_ColourValue)
    373             return this->parseSting(input, this->value_colourvalue_);
     177    bool ConfigValueContainer::parseString(const std::string& input, MultiTypeMath& defvalue)
     178    {
     179        if (this->value_.getType() == MT_int)
     180            return this->parseString(input, defvalue.getInt());
     181        else if (this->value_.getType() == MT_uint)
     182            return this->parseString(input, defvalue.getUnsignedInt());
     183        else if (this->value_.getType() == MT_char)
     184            return this->parseString(input, defvalue.getChar());
     185        else if (this->value_.getType() == MT_uchar)
     186            return this->parseString(input, defvalue.getUnsignedChar());
     187        else if (this->value_.getType() == MT_short)
     188            return this->parseString(input, defvalue.getShort());
     189        else if (this->value_.getType() == MT_ushort)
     190            return this->parseString(input, defvalue.getUnsignedShort());
     191        else if (this->value_.getType() == MT_long)
     192            return this->parseString(input, defvalue.getLong());
     193        else if (this->value_.getType() == MT_ulong)
     194            return this->parseString(input, defvalue.getUnsignedLong());
     195        else if (this->value_.getType() == MT_float)
     196            return this->parseString(input, defvalue.getFloat());
     197        else if (this->value_.getType() == MT_double)
     198            return this->parseString(input, defvalue.getDouble());
     199        else if (this->value_.getType() == MT_longdouble)
     200            return this->parseString(input, defvalue.getLongDouble());
     201        else if (this->value_.getType() == MT_bool)
     202            return this->parseString(input, defvalue.getBool());
     203        else if (this->value_.getType() == MT_constchar)
     204            return this->parseString(input, defvalue.getString());
     205        else if (this->value_.getType() == MT_string)
     206            return this->parseString(input, defvalue.getString());
     207        else if (this->value_.getType() == MT_vector2)
     208            return this->parseString(input, defvalue.getVector2());
     209        else if (this->value_.getType() == MT_vector3)
     210            return this->parseString(input, defvalue.getVector3());
     211        else if (this->value_.getType() == MT_colourvalue)
     212            return this->parseString(input, defvalue.getColourValue());
     213        else if (this->value_.getType() == MT_quaternion)
     214            return this->parseString(input, defvalue.getQuaternion());
     215        else if (this->value_.getType() == MT_radian)
     216            return this->parseString(input, defvalue.getRadian());
     217        else if (this->value_.getType() == MT_degree)
     218            return this->parseString(input, defvalue.getDegree());
    374219
    375220        return false;
     
    382227        @return True if the string was successfully parsed
    383228    */
    384     bool ConfigValueContainer::parseSting(const std::string& input, int defvalue)
    385     {
    386         return ConvertValue(&this->value_.value_int_, input, defvalue);
     229    bool ConfigValueContainer::parseString(const std::string& input, int defvalue)
     230    {
     231        int temp;
     232        bool success = ConvertValue(&temp, input, defvalue);
     233        ((MultiTypePrimitive)this->value_).setValue(temp);
     234        return success;
    387235    }
    388236
     
    393241        @return True if the string was successfully parsed
    394242    */
    395     bool ConfigValueContainer::parseSting(const std::string& input, unsigned int defvalue)
    396     {
    397         return ConvertValue(&this->value_.value_uint_, input, defvalue);
     243    bool ConfigValueContainer::parseString(const std::string& input, unsigned int defvalue)
     244    {
     245        unsigned int temp;
     246        bool success = ConvertValue(&temp, input, defvalue);
     247        ((MultiTypePrimitive)this->value_).setValue(temp);
     248        return success;
    398249    }
    399250
     
    404255        @return True if the string was successfully parsed
    405256    */
    406     bool ConfigValueContainer::parseSting(const std::string& input, char defvalue)
     257    bool ConfigValueContainer::parseString(const std::string& input, char defvalue)
    407258    {
    408259        // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file
    409         return ConvertValue(&this->value_.value_int_, input, (int)defvalue);
     260        int temp;
     261        bool success = ConvertValue(&temp, input, (int)defvalue);
     262        ((MultiTypePrimitive)this->value_).setValue((char)temp);
     263        return success;
    410264    }
    411265
     
    416270        @return True if the string was successfully parsed
    417271    */
    418     bool ConfigValueContainer::parseSting(const std::string& input, unsigned char defvalue)
     272    bool ConfigValueContainer::parseString(const std::string& input, unsigned char defvalue)
    419273    {
    420274        // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file
    421         return ConvertValue(&this->value_.value_uint_, input, (unsigned int)defvalue);
     275        unsigned int temp;
     276        bool success = ConvertValue(&temp, input, (unsigned int)defvalue);
     277        ((MultiTypePrimitive)this->value_).setValue((unsigned char)temp);
     278        return success;
     279    }
     280
     281    /**
     282        @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.
     283        @param input The string to convert
     284        @param defvalue The default-value
     285        @return True if the string was successfully parsed
     286    */
     287    bool ConfigValueContainer::parseString(const std::string& input, short defvalue)
     288    {
     289        short temp;
     290        bool success = ConvertValue(&temp, input, defvalue);
     291        ((MultiTypePrimitive)this->value_).setValue(temp);
     292        return success;
     293    }
     294
     295    /**
     296        @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.
     297        @param input The string to convert
     298        @param defvalue The default-value
     299        @return True if the string was successfully parsed
     300    */
     301    bool ConfigValueContainer::parseString(const std::string& input, unsigned short defvalue)
     302    {
     303        unsigned short temp;
     304        bool success = ConvertValue(&temp, input, defvalue);
     305        ((MultiTypePrimitive)this->value_).setValue(temp);
     306        return success;
     307    }
     308
     309    /**
     310        @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.
     311        @param input The string to convert
     312        @param defvalue The default-value
     313        @return True if the string was successfully parsed
     314    */
     315    bool ConfigValueContainer::parseString(const std::string& input, long defvalue)
     316    {
     317        long temp;
     318        bool success = ConvertValue(&temp, input, defvalue);
     319        ((MultiTypePrimitive)this->value_).setValue(temp);
     320        return success;
     321    }
     322
     323    /**
     324        @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.
     325        @param input The string to convert
     326        @param defvalue The default-value
     327        @return True if the string was successfully parsed
     328    */
     329    bool ConfigValueContainer::parseString(const std::string& input, unsigned long defvalue)
     330    {
     331        unsigned long temp;
     332        bool success = ConvertValue(&temp, input, defvalue);
     333        ((MultiTypePrimitive)this->value_).setValue(temp);
     334        return success;
    422335    }
    423336
     
    428341        @return True if the string was successfully parsed
    429342    */
    430     bool ConfigValueContainer::parseSting(const std::string& input, float defvalue)
    431     {
    432         return ConvertValue(&this->value_.value_float_, input, defvalue);
     343    bool ConfigValueContainer::parseString(const std::string& input, float defvalue)
     344    {
     345        float temp;
     346        bool success = ConvertValue(&temp, input, defvalue);
     347        ((MultiTypePrimitive)this->value_).setValue(temp);
     348        return success;
    433349    }
    434350
     
    439355        @return True if the string was successfully parsed
    440356    */
    441     bool ConfigValueContainer::parseSting(const std::string& input, double defvalue)
    442     {
    443         return ConvertValue(&this->value_.value_double_, input, defvalue);
     357    bool ConfigValueContainer::parseString(const std::string& input, double defvalue)
     358    {
     359        double temp;
     360        bool success = ConvertValue(&temp, input, defvalue);
     361        ((MultiTypePrimitive)this->value_).setValue(temp);
     362        return success;
    444363    }
    445364
     
    450369        @return True if the string was successfully parsed
    451370    */
    452     bool ConfigValueContainer::parseSting(const std::string& input, long double defvalue)
    453     {
    454         return ConvertValue(&this->value_.value_long_double_, input, defvalue);
     371    bool ConfigValueContainer::parseString(const std::string& input, long double defvalue)
     372    {
     373        long double temp;
     374        bool success = ConvertValue(&temp, input, defvalue);
     375        ((MultiTypePrimitive)this->value_).setValue(temp);
     376        return success;
    455377    }
    456378
     
    461383        @return True if the string was successfully parsed
    462384    */
    463     bool ConfigValueContainer::parseSting(const std::string& input, bool defvalue)
     385    bool ConfigValueContainer::parseString(const std::string& input, bool defvalue)
    464386    {
    465387        // Try to parse the value-string - is it a word?
     
    468390         || input.find("yes") < input.size()
    469391         || input.find("Yes") < input.size())
    470             this->value_.value_bool_ = true;
     392            ((MultiTypePrimitive)this->value_).setValue(true);
    471393        else if (input.find("false") < input.size()
    472394              || input.find("False") < input.size()
    473395              || input.find("no") < input.size()
    474396              || input.find("No") < input.size())
    475             this->value_.value_bool_ = false;
     397            ((MultiTypePrimitive)this->value_).setValue(false);
    476398        else
    477399        {
    478400            // Its not a known word - is it a number?
    479             return ConvertValue(&this->value_.value_bool_, input, defvalue);
     401            bool temp;
     402            bool success = ConvertValue(&temp, input, defvalue);
     403            ((MultiTypePrimitive)this->value_).setValue(temp);
     404            return success;
    480405        }
    481406
     
    489414        @return True if the string was successfully parsed
    490415    */
    491     bool ConfigValueContainer::parseSting(const std::string& input, const std::string& defvalue)
     416    bool ConfigValueContainer::parseString(const std::string& input, const std::string& defvalue)
    492417    {
    493418        // Strip the quotes
     
    499424        {
    500425            // It was - get the string between the quotes
    501             this->value_string_ = input.substr(pos1, pos2 - pos1);
     426            this->value_.setValue(input.substr(pos1, pos2 - pos1));
    502427            return true;
    503428        }
    504429
    505430        // It wasn't - use the default-value and restore the entry in the config-file.
    506         this->value_string_ = defvalue;
     431        this->value_.setValue(defvalue);
    507432        return false;
    508433    }
     
    514439        @return True if the string was successfully parsed
    515440    */
    516     bool ConfigValueContainer::parseSting(const std::string& input, const char* defvalue)
     441    bool ConfigValueContainer::parseString(const std::string& input, const char* defvalue)
    517442    {
    518443        // Strip the quotes
     
    524449        {
    525450            // It was - get the string between the quotes
    526             this->value_string_ = input.substr(pos1, pos2 - pos1);
     451            this->value_.setValue(input.substr(pos1, pos2 - pos1));
    527452            return true;
    528453        }
    529454
    530455        // It wasn't - use the default-value and restore the entry in the config-file.
    531         this->value_string_ = defvalue;
     456        this->value_.setValue(defvalue);
    532457        return false;
    533458    }
     
    539464        @return True if the string was successfully parsed
    540465    */
    541     bool ConfigValueContainer::parseSting(const std::string& input, const Vector2& defvalue)
     466    bool ConfigValueContainer::parseString(const std::string& input, const Vector2& defvalue)
    542467    {
    543468        // Strip the value-string
     
    549474        {
    550475            std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ",");
    551             if (!ConvertValue(&this->value_vector2_.x, tokens[0]))
    552             {
    553                 this->value_vector2_ = defvalue;
    554                 return false;
    555             }
    556             if (!ConvertValue(&this->value_vector2_.y, tokens[1]))
    557             {
    558                 this->value_vector2_ = defvalue;
     476            if (!ConvertValue(&this->value_.getVector2().x, tokens[0]))
     477            {
     478                this->value_.setValue(defvalue);
     479                return false;
     480            }
     481            if (!ConvertValue(&this->value_.getVector2().y, tokens[1]))
     482            {
     483                this->value_.setValue(defvalue);
    559484                return false;
    560485            }
     
    563488        }
    564489
    565         this->value_vector2_ = defvalue;
     490        this->value_.setValue(defvalue);
    566491        return false;
    567492    }
     
    573498        @return True if the string was successfully parsed
    574499    */
    575     bool ConfigValueContainer::parseSting(const std::string& input, const Vector3& defvalue)
     500    bool ConfigValueContainer::parseString(const std::string& input, const Vector3& defvalue)
    576501    {
    577502        // Strip the value-string
     
    583508        {
    584509            std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ",");
    585             if (!ConvertValue(&this->value_vector3_.x, tokens[0]))
    586             {
    587                 this->value_vector3_ = defvalue;
    588                 return false;
    589             }
    590             if (!ConvertValue(&this->value_vector3_.y, tokens[1]))
    591             {
    592                 this->value_vector3_ = defvalue;
    593                 return false;
    594             }
    595             if (!ConvertValue(&this->value_vector3_.z, tokens[2]))
    596             {
    597                 this->value_vector3_ = defvalue;
     510            if (!ConvertValue(&this->value_.getVector3().x, tokens[0]))
     511            {
     512                this->value_.setValue(defvalue);
     513                return false;
     514            }
     515            if (!ConvertValue(&this->value_.getVector3().y, tokens[1]))
     516            {
     517                this->value_.setValue(defvalue);
     518                return false;
     519            }
     520            if (!ConvertValue(&this->value_.getVector3().z, tokens[2]))
     521            {
     522                this->value_.setValue(defvalue);
    598523                return false;
    599524            }
     
    602527        }
    603528
    604         this->value_vector3_ = defvalue;
     529        this->value_.setValue(defvalue);
    605530        return false;
    606531    }
     
    612537        @return True if the string was successfully parsed
    613538    */
    614     bool ConfigValueContainer::parseSting(const std::string& input, const ColourValue& defvalue)
     539    bool ConfigValueContainer::parseString(const std::string& input, const ColourValue& defvalue)
    615540    {
    616541        // Strip the value-string
     
    622547        {
    623548            std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ",");
    624             if (!ConvertValue(&this->value_colourvalue_.r, tokens[0]))
    625             {
    626                 this->value_colourvalue_ = defvalue;
    627                 return false;
    628             }
    629             if (!ConvertValue(&this->value_colourvalue_.g, tokens[1]))
    630             {
    631                 this->value_colourvalue_ = defvalue;
    632                 return false;
    633             }
    634             if (!ConvertValue(&this->value_colourvalue_.b, tokens[2]))
    635             {
    636                 this->value_colourvalue_ = defvalue;
    637                 return false;
    638             }
    639             if (!ConvertValue(&this->value_colourvalue_.a, tokens[3]))
    640             {
    641                 this->value_colourvalue_ = defvalue;
     549            if (!ConvertValue(&this->value_.getColourValue().r, tokens[0]))
     550            {
     551                this->value_.setValue(defvalue);
     552                return false;
     553            }
     554            if (!ConvertValue(&this->value_.getColourValue().g, tokens[1]))
     555            {
     556                this->value_.setValue(defvalue);
     557                return false;
     558            }
     559            if (!ConvertValue(&this->value_.getColourValue().b, tokens[2]))
     560            {
     561                this->value_.setValue(defvalue);
     562                return false;
     563            }
     564            if (!ConvertValue(&this->value_.getColourValue().a, tokens[3]))
     565            {
     566                this->value_.setValue(defvalue);
    642567                return false;
    643568            }
     
    646571        }
    647572
    648         this->value_colourvalue_ = defvalue;
     573        this->value_.setValue(defvalue);
    649574        return false;
     575    }
     576
     577    /**
     578        @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.
     579        @param input The string to convert
     580        @param defvalue The default-value
     581        @return True if the string was successfully parsed
     582    */
     583    bool ConfigValueContainer::parseString(const std::string& input, const Quaternion& defvalue)
     584    {
     585        // Strip the value-string
     586        unsigned int pos1 = input.find("(") + 1;
     587        unsigned int pos2 = input.find(")", pos1);
     588
     589        // Try to convert the stripped value-string to Vector3
     590        if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2)
     591        {
     592            std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ",");
     593            if (!ConvertValue(&this->value_.getQuaternion().w, tokens[0]))
     594            {
     595                this->value_.setValue(defvalue);
     596                return false;
     597            }
     598            if (!ConvertValue(&this->value_.getQuaternion().x, tokens[1]))
     599            {
     600                this->value_.setValue(defvalue);
     601                return false;
     602            }
     603            if (!ConvertValue(&this->value_.getQuaternion().y, tokens[2]))
     604            {
     605                this->value_.setValue(defvalue);
     606                return false;
     607            }
     608            if (!ConvertValue(&this->value_.getQuaternion().z, tokens[3]))
     609            {
     610                this->value_.setValue(defvalue);
     611                return false;
     612            }
     613
     614            return true;
     615        }
     616
     617        this->value_.setValue(defvalue);
     618        return false;
     619    }
     620
     621    /**
     622        @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.
     623        @param input The string to convert
     624        @param defvalue The default-value
     625        @return True if the string was successfully parsed
     626    */
     627    bool ConfigValueContainer::parseString(const std::string& input, const Radian& defvalue)
     628    {
     629        return ConvertValue(&this->value_.getRadian(), input, defvalue);
     630    }
     631
     632    /**
     633        @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.
     634        @param input The string to convert
     635        @param defvalue The default-value
     636        @return True if the string was successfully parsed
     637    */
     638    bool ConfigValueContainer::parseString(const std::string& input, const Degree& defvalue)
     639    {
     640        return ConvertValue(&this->value_.getDegree(), input, defvalue);
    650641    }
    651642
     
    664655    void ConfigValueContainer::resetConfigValue()
    665656    {
    666         this->parseSting(this->defvalueString_);
     657        this->parseString(this->defvalueString_, this->value_);
    667658        this->resetConfigFileEntry();
    668659    }
Note: See TracChangeset for help on using the changeset viewer.