Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 26, 2008, 1:54:15 AM (17 years ago)
Author:
rgrieder
Message:

Merged the changes in Convert.h from core3 branch back.
If it doesn't work, feel free to revert. I have however more or less checked every possible conversion on gcc (tardis) and msvc with a script.

Location:
code/branches/objecthierarchy/src/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/util

  • code/branches/objecthierarchy/src/util/Math.cc

    r1791 r2016  
    2828
    2929/**
    30     @file Math.cc
     30    @file
    3131    @brief Implementation of several math-functions.
    3232*/
    3333
     34#include "Math.h"
     35
    3436#include <OgrePlane.h>
    35 
    36 #include "Math.h"
    37 #include "Convert.h"
     37#include "MathConvert.h"
     38#include "SubString.h"
    3839
    3940/**
     
    205206    return convertToString(getUniqueNumber());
    206207}
     208
     209
     210//////////////////////////
     211// Conversion functions //
     212//////////////////////////
     213
     214// std::string to Vector2
     215bool ConverterFallback<std::string, orxonox::Vector2>::convert(orxonox::Vector2* output, const std::string& input)
     216{
     217    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     218    if ((opening_parenthesis = input.find('(')) == std::string::npos)
     219        opening_parenthesis = 0;
     220    else
     221        opening_parenthesis++;
     222
     223    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis),
     224                     ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     225    if (tokens.size() >= 2)
     226    {
     227        if (!ConvertValue(&(output->x), tokens[0]))
     228            return false;
     229        if (!ConvertValue(&(output->y), tokens[1]))
     230            return false;
     231
     232        return true;
     233    }
     234    return false;
     235}
     236
     237// std::string to Vector3
     238bool ConverterFallback<std::string, orxonox::Vector3>::convert(orxonox::Vector3* output, const std::string& input)
     239{
     240    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     241    if ((opening_parenthesis = input.find('(')) == std::string::npos)
     242        opening_parenthesis = 0;
     243    else
     244        opening_parenthesis++;
     245
     246    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis),
     247                     ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     248    if (tokens.size() >= 3)
     249    {
     250        if (!ConvertValue(&(output->x), tokens[0]))
     251            return false;
     252        if (!ConvertValue(&(output->y), tokens[1]))
     253            return false;
     254        if (!ConvertValue(&(output->z), tokens[2]))
     255            return false;
     256
     257        return true;
     258    }
     259    return false;
     260}
     261
     262// std::string to Vector4
     263bool ConverterFallback<std::string, orxonox::Vector4>::convert(orxonox::Vector4* output, const std::string& input)
     264{
     265    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     266    if ((opening_parenthesis = input.find('(')) == std::string::npos)
     267        opening_parenthesis = 0;
     268    else
     269        opening_parenthesis++;
     270
     271    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis),
     272                     ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     273    if (tokens.size() >= 4)
     274    {
     275        if (!ConvertValue(&(output->x), tokens[0]))
     276            return false;
     277        if (!ConvertValue(&(output->y), tokens[1]))
     278            return false;
     279        if (!ConvertValue(&(output->z), tokens[2]))
     280            return false;
     281        if (!ConvertValue(&(output->w), tokens[3]))
     282            return false;
     283
     284        return true;
     285    }
     286    return false;
     287}
     288
     289// std::string to Quaternion
     290bool ConverterFallback<std::string, orxonox::Quaternion>::convert(orxonox::Quaternion* output, const std::string& input)
     291{
     292    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     293    if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     294
     295    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     296    if (tokens.size() >= 4)
     297    {
     298        if (!ConvertValue(&(output->w), tokens[0]))
     299            return false;
     300        if (!ConvertValue(&(output->x), tokens[1]))
     301            return false;
     302        if (!ConvertValue(&(output->y), tokens[2]))
     303            return false;
     304        if (!ConvertValue(&(output->z), tokens[3]))
     305            return false;
     306
     307        return true;
     308    }
     309    return false;
     310}
     311
     312// std::string to ColourValue
     313bool ConverterFallback<std::string, orxonox::ColourValue>::convert(orxonox::ColourValue* output, const std::string& input)
     314{
     315    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     316    if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     317
     318    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     319    if (tokens.size() >= 3)
     320    {
     321        if (!ConvertValue(&(output->r), tokens[0]))
     322            return false;
     323        if (!ConvertValue(&(output->g), tokens[1]))
     324            return false;
     325        if (!ConvertValue(&(output->b), tokens[2]))
     326            return false;
     327        if (tokens.size() >= 4)
     328        {
     329            if (!ConvertValue(&(output->a), tokens[3]))
     330                return false;
     331        }
     332        else
     333            output->a = 1.0;
     334
     335        return true;
     336    }
     337    return false;
     338}
Note: See TracChangeset for help on using the changeset viewer.