Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 792


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)

Location:
code/branches/core/src
Files:
13 added
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/orxonox/core/CMakeLists.txt

    r790 r792  
    1313  OutputHandler.cc
    1414  Language.cc
     15  Loader.cc
    1516)
    1617
  • 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    }
  • code/branches/core/src/orxonox/core/ConfigValueContainer.h

    r790 r792  
    4949
    5050#include "util/Math.h"
     51#include "util/MultiTypeMath.h"
    5152#include "Language.h"
    5253
     
    7273    {
    7374        public:
    74             enum VariableType
    75             {
    76                 VT_Int,
    77                 VT_uInt,
    78                 VT_Char,
    79                 VT_uChar,
    80                 VT_Float,
    81                 VT_Double,
    82                 VT_LongDouble,
    83                 VT_Bool,
    84                 VT_ConstChar,
    85                 VT_String,
    86                 VT_Vector2,
    87                 VT_Vector3,
    88                 VT_ColourValue
    89             };
    90 
    91             ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue);
    92             ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue);
    93             ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue);
    94             ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue);
    95             ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue);
    96             ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue);
    97             ConfigValueContainer(const std::string& classname, const std::string& varname, long double defvalue);
    98             ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue);
    99             ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue);
    100             ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue);
    101             ConfigValueContainer(const std::string& classname, const std::string& varname, Vector2 defvalue);
    102             ConfigValueContainer(const std::string& classname, const std::string& varname, Vector3 defvalue);
    103             ConfigValueContainer(const std::string& classname, const std::string& varname, ColourValue defvalue);
     75            ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue);
    10476
    10577            /** @returns the value. @param value This is only needed to determine the right type. */
    106             inline ConfigValueContainer& getValue(int& value)                           { value = this->value_.value_int_; return *this; }
    107             /** @returns the value. @param value This is only needed to determine the right type. */
    108             inline ConfigValueContainer& getValue(unsigned int& value)                  { value = this->value_.value_uint_; return *this; }
    109             /** @returns the value. @param value This is only needed to determine the right type. */
    110             inline ConfigValueContainer& getValue(char& value)                          { value = this->value_.value_char_; return *this; }
    111             /** @returns the value. @param value This is only needed to determine the right type. */
    112             inline ConfigValueContainer& getValue(unsigned char& value)                 { value = this->value_.value_uchar_; return *this; }
    113             /** @returns the value. @param value This is only needed to determine the right type. */
    114             inline ConfigValueContainer& getValue(float& value)                         { value = this->value_.value_float_; return *this; }
    115             /** @returns the value. @param value This is only needed to determine the right type. */
    116             inline ConfigValueContainer& getValue(double& value)                        { value = this->value_.value_double_; return *this; }
    117             /** @returns the value. @param value This is only needed to determine the right type. */
    118             inline ConfigValueContainer& getValue(long double& value)                   { value = this->value_.value_long_double_; return *this; }
    119             /** @returns the value. @param value This is only needed to determine the right type. */
    120             inline ConfigValueContainer& getValue(bool& value)                          { value = this->value_.value_bool_; return *this; }
    121             /** @returns the value. @param value This is only needed to determine the right type. */
    122             inline ConfigValueContainer& getValue(std::string& value)                   { value = this->value_string_; return *this; }
    123             /** @returns the value. @param value This is only needed to determine the right type. */
    124             inline ConfigValueContainer& getValue(const char* value)                    { value = this->value_string_.c_str(); return *this; }
    125             /** @returns the value. @param value This is only needed to determine the right type. */
    126             inline ConfigValueContainer& getValue(Vector2& value)                       { value = this->value_vector2_; return *this; }
    127             /** @returns the value. @param value This is only needed to determine the right type. */
    128             inline ConfigValueContainer& getValue(Vector3& value)                       { value = this->value_vector3_; return *this; }
    129             /** @returns the value. @param value This is only needed to determine the right type. */
    130             inline ConfigValueContainer& getValue(ColourValue& value)                   { value = this->value_colourvalue_; return *this; }
     78/*            template <typename T>
     79            inline ConfigValueContainer& getValue(T& value)                           { this->value_.getValue(value); return *this; }
     80*/
     81            inline ConfigValueContainer& getValue(int* value)            { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     82            inline ConfigValueContainer& getValue(unsigned int* value)   { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     83            inline ConfigValueContainer& getValue(char* value)           { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     84            inline ConfigValueContainer& getValue(unsigned char* value)  { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     85            inline ConfigValueContainer& getValue(short* value)          { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     86            inline ConfigValueContainer& getValue(unsigned short* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     87            inline ConfigValueContainer& getValue(long* value)           { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     88            inline ConfigValueContainer& getValue(unsigned long* value)  { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     89            inline ConfigValueContainer& getValue(float* value)          { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     90            inline ConfigValueContainer& getValue(double* value)         { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     91            inline ConfigValueContainer& getValue(long double* value)    { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     92            inline ConfigValueContainer& getValue(bool* value)           { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
     93            inline ConfigValueContainer& getValue(std::string* value)    { ((MultiTypeString)this->value_).getValue(value); return *this; }
     94            inline ConfigValueContainer& getValue(Vector2* value)        { this->value_.getValue(value); return *this; }
     95            inline ConfigValueContainer& getValue(Vector3* value)        { this->value_.getValue(value); return *this; }
     96            inline ConfigValueContainer& getValue(ColourValue* value)    { this->value_.getValue(value); return *this; }
     97            inline ConfigValueContainer& getValue(Quaternion* value)     { this->value_.getValue(value); return *this; }
     98            inline ConfigValueContainer& getValue(Radian* value)         { this->value_.getValue(value); return *this; }
     99            inline ConfigValueContainer& getValue(Degree* value)         { this->value_.getValue(value); return *this; }
    131100
    132101            void description(const std::string& description);
    133102
    134             bool parseSting(const std::string& input);
     103            bool parseString(const std::string& input, MultiTypeMath& defvalue = MT_null);
     104            bool valueToString(std::string* output, MultiTypeMath& input);
    135105            void resetConfigFileEntry();
    136106            void resetConfigValue();
     
    141111
    142112        private:
    143             bool parseSting(const std::string& input, int defvalue);
    144             bool parseSting(const std::string& input, unsigned int defvalue);
    145             bool parseSting(const std::string& input, char defvalue);
    146             bool parseSting(const std::string& input, unsigned char defvalue);
    147             bool parseSting(const std::string& input, float defvalue);
    148             bool parseSting(const std::string& input, double defvalue);
    149             bool parseSting(const std::string& input, long double defvalue);
    150             bool parseSting(const std::string& input, bool defvalue);
    151             bool parseSting(const std::string& input, const std::string& defvalue);
    152             bool parseSting(const std::string& input, const char* defvalue);
    153             bool parseSting(const std::string& input, const Vector2& defvalue);
    154             bool parseSting(const std::string& input, const Vector3& defvalue);
    155             bool parseSting(const std::string& input, const ColourValue& defvalue);
     113            bool parseString(const std::string& input, int defvalue);
     114            bool parseString(const std::string& input, unsigned int defvalue);
     115            bool parseString(const std::string& input, char defvalue);
     116            bool parseString(const std::string& input, unsigned char defvalue);
     117            bool parseString(const std::string& input, short defvalue);
     118            bool parseString(const std::string& input, unsigned short defvalue);
     119            bool parseString(const std::string& input, long defvalue);
     120            bool parseString(const std::string& input, unsigned long defvalue);
     121            bool parseString(const std::string& input, float defvalue);
     122            bool parseString(const std::string& input, double defvalue);
     123            bool parseString(const std::string& input, long double defvalue);
     124            bool parseString(const std::string& input, bool defvalue);
     125            bool parseString(const std::string& input, const std::string& defvalue);
     126            bool parseString(const std::string& input, const char* defvalue);
     127            bool parseString(const std::string& input, const Vector2& defvalue);
     128            bool parseString(const std::string& input, const Vector3& defvalue);
     129            bool parseString(const std::string& input, const ColourValue& defvalue);
     130            bool parseString(const std::string& input, const Quaternion& defvalue);
     131            bool parseString(const std::string& input, const Radian& defvalue);
     132            bool parseString(const std::string& input, const Degree& defvalue);
    156133
    157134            static std::list<std::string>& getConfigFileLines();
     
    167144            std::string         defvalueString_;                //!< The string of the default-variable
    168145
    169             union MultiType
    170             {
    171                 int                 value_int_;                 //!< The value, if the variable is of the type int
    172                 unsigned int        value_uint_;                //!< The value, if the variable is of the type unsigned int
    173                 char                value_char_;                //!< The value, if the variable is of the type char
    174                 unsigned char       value_uchar_;               //!< The value, if the variable is of the type unsigned char
    175                 float               value_float_;               //!< The value, if the variable is of the type float
    176                 double              value_double_;              //!< The value, if the variable is of the type double
    177                 long double         value_long_double_;         //!< The value, if the variable is of the type long double
    178                 bool                value_bool_;                //!< The value, if the variable is of the type bool
    179             } value_;                                           //!< The value of the variable
    180 
    181             std::string         value_string_;                  //!< The value, if the variable is of the type string
    182             Vector2             value_vector2_;                 //!< The value, if the variable is of the type Vector2
    183             Vector3             value_vector3_;                 //!< The value, if the variable is of the type Vector3
    184             ColourValue         value_colourvalue_;             //!< The value, if the variable is of the type ColourValue
     146            MultiTypeMath       value_;                         //!< The value
    185147
    186148            std::list<std::string>::iterator configFileLine_;   //!< An iterator, pointing to the entry of the variable in the config-file
    187149
    188             VariableType type_;                                 //!< The type of the variable
    189150            bool bAddedDescription_;                            //!< True if a description was added
    190151            LanguageEntryName description_;                     //!< The description
  • code/branches/core/src/orxonox/core/CoreIncludes.h

    r790 r792  
    139139        this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \
    140140    } \
    141     container##varname->getValue(varname)
     141    container##varname->getValue(&varname)
    142142
    143143/**
     
    150150    { \
    151151        container##varname##reset->resetConfigValue(); \
    152         container##varname##reset->getValue(varname); \
     152        container##varname##reset->getValue(&varname); \
    153153    } \
    154154    else \
  • code/branches/core/src/orxonox/core/CorePrereqs.h

    r790 r792  
    2727
    2828/**
    29  @file  OrxonoxPrereq.h
     29 @file  CorePrereq.h
    3030 @brief Contains all the necessary forward declarations for all classes, structs and enums.
    3131 */
  • code/branches/core/src/orxonox/core/OrxonoxClass.h

    r790 r792  
    4747    //! The class all objects and interfaces of the game-logic (not the engine) are derived from.
    4848    /**
    49         The BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
     49        The BaseObject and Interfaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
    5050        OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList.
    5151    */
  • code/branches/core/src/util/CMakeLists.txt

    r790 r792  
    55SET (UTIL_SRC_FILES
    66  ${TINYXML_SRC_FILES}
     7  Math.cc
     8  String.cc
    79  substring.cc
     10  MultiTypePrimitive.cc
     11  MultiTypeString.cc
     12  MultiTypeMath.cc
    813)
    914
    10 IF(WIN32)
    11   ADD_LIBRARY( util ${UTIL_SRC_FILES} )
    12 ELSE(WIN32)
    13   ADD_LIBRARY( util SHARED ${UTIL_SRC_FILES} )
    14 ENDIF(WIN32)
     15ADD_LIBRARY( util SHARED ${UTIL_SRC_FILES} )
    1516SET_TARGET_PROPERTIES( util PROPERTIES LINK_FLAGS "--no-undefined" )
    16 
    1717
    1818IF(TESTING_ENABLED)
    1919  ADD_SUBDIRECTORY(testing)
    2020ENDIF(TESTING_ENABLED)
     21
     22TARGET_LINK_LIBRARIES( util
     23  ${OGRE_LIBRARIES}
     24)
  • code/branches/core/src/util/Convert.h

    r790 r792  
    3636#include <sstream>
    3737
     38#include "UtilPrereqs.h"
    3839
    3940// DEFAULT CLASS
    4041template <typename FromType, typename ToType>
    41 class Converter
     42class _UtilExport Converter
    4243{
    4344 public:
     
    5051// PARTIAL SPECIALIZATION TO CONVERT TO STRINGS
    5152template<typename FromType>
    52 class Converter<FromType, std::string>
     53class _UtilExport Converter<FromType, std::string>
    5354{
    5455 public:
     
    6869// PARTIAL SPECIALIZATION TO CONVERT FROM STRING
    6970template<typename ToType>
    70 class Converter<std::string, ToType>
     71class _UtilExport Converter<std::string, ToType>
    7172{
    7273 public:
     
    8384// FUNCTION SO WE DO NOT HAVE TO TELL THE COMPILER ABOUT THE TYPE
    8485template<typename FromType, typename ToType>
    85 static bool ConvertValue(ToType* output, const FromType& input)
     86static _UtilExport bool ConvertValue(ToType* output, const FromType& input)
    8687{
    8788  Converter<FromType, ToType> converter;
     
    9192// THE SAME, BUT WITH DEFAULT VALUE
    9293template<typename FromType, typename ToType>
    93 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)
     94static _UtilExport bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)
    9495{
    9596  Converter<FromType, ToType> converter;
  • code/branches/core/src/util/Math.h

    r790 r792  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software; you can redistribute it and/or
     8 *   modify it under the terms of the GNU General Public License
     9 *   as published by the Free Software Foundation; either version 2
     10 *   of the License, or (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program; if not, write to the Free Software
     19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     20 *
     21 *   Author:
     22 *      Fabian 'x3n' Landau
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28#ifndef _Math_H__
     29#define _Math_H__
     30
     31#include <ostream>
     32
     33#include "UtilPrereqs.h"
     34
    135#include <OgreMath.h>
    236#include <OgreVector2.h>
     
    1852  typedef Ogre::ColourValue ColourValue;
    1953}
     54
     55_UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian);
     56_UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian);
     57_UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);
     58_UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree);
     59
     60template <typename T>
     61inline _UtilExport T sgn(T x)
     62{
     63    return (x >= 0) ? 1 : -1;
     64}
     65
     66template <typename T>
     67inline _UtilExport T min(T a, T b)
     68{
     69    return (a <= b) ? a : b;
     70}
     71
     72template <typename T>
     73inline _UtilExport T max(T a, T b)
     74{
     75    return (a >= b) ? a : b;
     76}
     77
     78template <typename T>
     79inline _UtilExport T clamp(T x, T min, T max)
     80{
     81    if (x < min)
     82        return min;
     83
     84    if (x > max)
     85        return max;
     86
     87    return x;
     88}
     89
     90template <typename T>
     91inline _UtilExport T square(T x)
     92{
     93    return x*x;
     94}
     95
     96template <typename T>
     97inline _UtilExport T cube(T x)
     98{
     99    return x*x*x;
     100}
     101
     102template <typename T>
     103inline _UtilExport int floor(T x)
     104{
     105    return (int)(x);
     106}
     107
     108template <typename T>
     109inline _UtilExport int ceil(T x)
     110{
     111    int temp = floor(x);
     112    return (temp != x) ? (temp + 1) : temp;
     113}
     114
     115template <typename T>
     116inline _UtilExport int round(T x)
     117{
     118    return (int)(x + 0.5);
     119}
     120
     121template <typename T>
     122_UtilExport T interpolate(float time, const T& start, const T& end)
     123{
     124    return time * (end - start) + start;
     125}
     126
     127template <typename T>
     128_UtilExport T interpolateSmooth(float time, const T& start, const T& end)
     129{
     130    return (-2 * (end - start) * cube(time)) + (3 * (end - start) * square(time)) + start;
     131}
     132
     133inline _UtilExport float rnd()
     134{
     135    return ((float)rand() / RAND_MAX);
     136}
     137
     138inline _UtilExport float rnd(float max)
     139{
     140    return rnd() * max;
     141}
     142
     143inline _UtilExport float rnd(float min, float max)
     144{
     145    return rnd(max - min) + min;
     146}
     147
     148#endif /* _Math_H__ */
  • code/branches/core/src/util/String2Number.h

    r790 r792  
    77
    88#include "core/Debug.h"
     9#include "UtilPrereqs.h"
    910
    1011/**
     
    2324
    2425template <class T>
    25 class String2Number
     26class _UtilExport String2Number
    2627{
    2728  private:
  • code/branches/core/src/util/substring.h

    r790 r792  
    5959#include <string>
    6060
     61#include "UtilPrereqs.h"
    6162
    6263//! A class that can load one string and split it in multipe ones
     
    6566 * It can be used, to Split strings append them and join them again.
    6667 */
    67 class SubString
     68class _UtilExport SubString
    6869{
    6970public:
Note: See TracChangeset for help on using the changeset viewer.