Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 848


Ignore:
Timestamp:
Mar 5, 2008, 1:29:47 AM (16 years ago)
Author:
landauf
Message:

several changes:

  • XMLPort is now theoretically able to load something (but still buggy)
  • Expanded Convert with several partial template specializations
  • Expanded all MultiTypes with new functions, mostly to convert values
  • Expanded SubString with a new functionality: chars inside parentheses aren't split

It's not yet working as it should (at least not in all cases - loading the objects name works)

Location:
code/branches/core/src/util
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/util/Convert.h

    r845 r848  
    3838#include "UtilPrereqs.h"
    3939#include "Math.h"
     40#include "SubString.h"
     41#include "MultiTypeMath.h"
     42
    4043
    4144// DEFAULT CLASS
     
    103106}
    104107
    105 
    106 
    107 // MORE SPECIALISATIONS
     108// THE SAME LIKE BEFORE, BUT NEEDS NO POINTER TO THE OUTPUT
     109template<typename FromType, typename ToType>
     110static ToType ConvertValueAndReturn(const FromType& input)
     111{
     112  ToType output;
     113  ConvertValue(&output, input);
     114  return output;
     115}
     116
     117// THE SAME, BUT WITH DEFAULT VALUE
     118template<typename FromType, typename ToType>
     119static ToType ConvertValueAndReturn(const FromType& input, const FromType& fallback)
     120{
     121  ToType output;
     122  ConvertValue(&output, input, fallback);
     123  return output;
     124}
     125
     126//////////////////////////
     127// MORE SPECIALISATIONS //
     128//////////////////////////
     129
     130// STRING TO STRING
     131template<>
     132class Converter<std::string, std::string>
     133{
     134  public:
     135    bool operator()(std::string* output, const std::string& input) const
     136    {
     137        (*output) = std::string(input);
     138        return true;
     139    }
     140};
     141
     142////////////////
     143// MULTITYPES //
     144////////////////
     145
     146// PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEPRIMITIVE
     147template<typename ToType>
     148class Converter<MultiTypePrimitive, ToType>
     149{
     150  public:
     151    bool operator()(ToType* output, const MultiTypePrimitive& input) const
     152    {
     153      if (input.getType() == MT_int)
     154        return ConvertValue(output, input.getInt());
     155      else if (input.getType() == MT_uint)
     156        return ConvertValue(output, input.getUnsignedInt());
     157      else if (input.getType() == MT_char)
     158        return ConvertValue(output, input.getChar());
     159      else if (input.getType() == MT_uchar)
     160        return ConvertValue(output, input.getUnsignedChar());
     161      else if (input.getType() == MT_short)
     162        return ConvertValue(output, input.getShort());
     163      else if (input.getType() == MT_ushort)
     164        return ConvertValue(output, input.getUnsignedShort());
     165      else if (input.getType() == MT_long)
     166        return ConvertValue(output, input.getLong());
     167      else if (input.getType() == MT_ulong)
     168        return ConvertValue(output, input.getUnsignedLong());
     169      else if (input.getType() == MT_float)
     170        return ConvertValue(output, input.getFloat());
     171      else if (input.getType() == MT_double)
     172        return ConvertValue(output, input.getDouble());
     173      else if (input.getType() == MT_longdouble)
     174        return ConvertValue(output, input.getLongDouble());
     175      else if (input.getType() == MT_bool)
     176        return ConvertValue(output, input.getBool());
     177      else
     178        return false;
     179    }
     180};
     181template<>
     182class Converter<MultiTypePrimitive, std::string>
     183{
     184  public:
     185    bool operator()(std::string* output, const MultiTypePrimitive& input) const
     186    {
     187      if (input.getType() == MT_int)
     188        return ConvertValue(output, input.getInt());
     189      else if (input.getType() == MT_uint)
     190        return ConvertValue(output, input.getUnsignedInt());
     191      else if (input.getType() == MT_char)
     192        return ConvertValue(output, input.getChar());
     193      else if (input.getType() == MT_uchar)
     194        return ConvertValue(output, input.getUnsignedChar());
     195      else if (input.getType() == MT_short)
     196        return ConvertValue(output, input.getShort());
     197      else if (input.getType() == MT_ushort)
     198        return ConvertValue(output, input.getUnsignedShort());
     199      else if (input.getType() == MT_long)
     200        return ConvertValue(output, input.getLong());
     201      else if (input.getType() == MT_ulong)
     202        return ConvertValue(output, input.getUnsignedLong());
     203      else if (input.getType() == MT_float)
     204        return ConvertValue(output, input.getFloat());
     205      else if (input.getType() == MT_double)
     206        return ConvertValue(output, input.getDouble());
     207      else if (input.getType() == MT_longdouble)
     208        return ConvertValue(output, input.getLongDouble());
     209      else if (input.getType() == MT_bool)
     210        return ConvertValue(output, input.getBool());
     211      else
     212        return false;
     213    }
     214};
     215
     216// PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPESTRING
     217template<typename ToType>
     218class Converter<MultiTypeString, ToType>
     219{
     220  public:
     221    bool operator()(ToType* output, const MultiTypeString& input) const
     222    {
     223      if (input.getType() == MT_constchar)
     224        return ConvertValue(output, input.getConstChar());
     225      else if (input.getType() == MT_string)
     226        return ConvertValue(output, input.getString());
     227      else
     228        return false;
     229    }
     230};
     231template<>
     232class Converter<MultiTypeString, std::string>
     233{
     234  public:
     235    bool operator()(std::string* output, const MultiTypeString& input) const
     236    {
     237      if (input.getType() == MT_constchar)
     238        return ConvertValue(output, input.getConstChar());
     239      else if (input.getType() == MT_string)
     240        return ConvertValue(output, input.getString());
     241      else
     242        return false;
     243    }
     244};
     245
     246// PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEMATH
     247template<typename ToType>
     248class Converter<MultiTypeMath, ToType>
     249{
     250  public:
     251    bool operator()(ToType* output, const MultiTypeMath& input) const
     252    {
     253      if (input.getType() == MT_vector2)
     254        return ConvertValue(output, input.getVector2());
     255      else if (input.getType() == MT_vector3)
     256        return ConvertValue(output, input.getVector3());
     257      else if (input.getType() == MT_quaternion)
     258        return ConvertValue(output, input.getQuaternion());
     259      else if (input.getType() == MT_colourvalue)
     260        return ConvertValue(output, input.getColourValue());
     261      else if (input.getType() == MT_radian)
     262        return ConvertValue(output, input.getRadian());
     263      else if (input.getType() == MT_degree)
     264        return ConvertValue(output, input.getDegree());
     265      else
     266        return false;
     267    }
     268};
     269template<>
     270class Converter<MultiTypeMath, std::string>
     271{
     272  public:
     273    bool operator()(std::string* output, const MultiTypeMath& input) const
     274    {
     275      if (input.getType() == MT_vector2)
     276        return ConvertValue(output, input.getVector2());
     277      else if (input.getType() == MT_vector3)
     278        return ConvertValue(output, input.getVector3());
     279      else if (input.getType() == MT_quaternion)
     280        return ConvertValue(output, input.getQuaternion());
     281      else if (input.getType() == MT_colourvalue)
     282        return ConvertValue(output, input.getColourValue());
     283      else if (input.getType() == MT_radian)
     284        return ConvertValue(output, input.getRadian());
     285      else if (input.getType() == MT_degree)
     286        return ConvertValue(output, input.getDegree());
     287      else
     288        return false;
     289    }
     290};
     291
     292
     293////////////////////
     294// MATH TO STRING //
     295////////////////////
     296
    108297// Vector2 to std::string
    109298template <>
     
    196385};
    197386
     387
     388////////////////////
     389// STRING TO MATH //
     390////////////////////
     391
     392// std::string to Vector2
     393template <>
     394class Converter<std::string, orxonox::Vector2>
     395{
     396  public:
     397    bool operator()(orxonox::Vector2* output, const std::string& input) const
     398    {
     399      SubString tokens(input, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     400
     401      if (tokens.size() >= 2)
     402      {
     403        if (!ConvertValue(&(output->x), tokens[0]))
     404          return false;
     405        if (!ConvertValue(&(output->y), tokens[1]))
     406          return false;
     407
     408        return true;
     409      }
     410
     411      return false;
     412    }
     413};
     414
     415// std::string to Vector3
     416template <>
     417class Converter<std::string, orxonox::Vector3>
     418{
     419  public:
     420    bool operator()(orxonox::Vector3* output, const std::string& input) const
     421    {
     422      SubString tokens(input, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     423
     424      if (tokens.size() >= 3)
     425      {
     426        if (!ConvertValue(&(output->x), tokens[0]))
     427          return false;
     428        if (!ConvertValue(&(output->y), tokens[1]))
     429          return false;
     430        if (!ConvertValue(&(output->z), tokens[2]))
     431          return false;
     432
     433        return true;
     434      }
     435
     436      return false;
     437    }
     438};
     439
     440// std::string to Vector4
     441template <>
     442class Converter<std::string, orxonox::Vector4>
     443{
     444  public:
     445    bool operator()(orxonox::Vector4* output, const std::string& input) const
     446    {
     447      SubString tokens(input, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     448
     449      if (tokens.size() >= 4)
     450      {
     451        if (!ConvertValue(&(output->x), tokens[0]))
     452          return false;
     453        if (!ConvertValue(&(output->y), tokens[1]))
     454          return false;
     455        if (!ConvertValue(&(output->z), tokens[2]))
     456          return false;
     457        if (!ConvertValue(&(output->w), tokens[3]))
     458          return false;
     459
     460        return true;
     461      }
     462
     463      return false;
     464    }
     465};
     466
     467// std::string to Quaternion
     468template <>
     469class Converter<std::string, orxonox::Quaternion>
     470{
     471  public:
     472    bool operator()(orxonox::Quaternion* output, const std::string& input) const
     473    {
     474      SubString tokens(input, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     475
     476      if (tokens.size() >= 4)
     477      {
     478        if (!ConvertValue(&(output->w), tokens[0]))
     479          return false;
     480        if (!ConvertValue(&(output->x), tokens[1]))
     481          return false;
     482        if (!ConvertValue(&(output->y), tokens[2]))
     483          return false;
     484        if (!ConvertValue(&(output->z), tokens[3]))
     485          return false;
     486
     487        return true;
     488      }
     489
     490      return false;
     491    }
     492};
     493
     494// std::string to ColourValue
     495template <>
     496class Converter<std::string, orxonox::ColourValue>
     497{
     498  public:
     499    bool operator()(orxonox::ColourValue* output, const std::string& input) const
     500    {
     501      SubString tokens(input, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     502
     503      if (tokens.size() >= 4)
     504      {
     505        if (!ConvertValue(&(output->r), tokens[0]))
     506          return false;
     507        if (!ConvertValue(&(output->g), tokens[1]))
     508          return false;
     509        if (!ConvertValue(&(output->b), tokens[2]))
     510          return false;
     511        if (!ConvertValue(&(output->a), tokens[3]))
     512          return false;
     513
     514        return true;
     515      }
     516
     517      return false;
     518    }
     519};
     520
    198521#endif /* _Convert_H__ */
  • code/branches/core/src/util/MultiTypeMath.cc

    r797 r848  
    2828
    2929#include "MultiTypeMath.h"
     30#include "Convert.h"
    3031
    3132MultiTypeMath::MultiTypeMath(MultiType type) : MultiTypeString(type)
     
    100101}
    101102
     103MultiTypeMath::operator orxonox::Vector2() const
     104{
     105    return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Vector2>(*this);
     106}
     107
     108MultiTypeMath::operator orxonox::Vector3() const
     109{
     110    return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Vector3>(*this);
     111}
     112
     113MultiTypeMath::operator orxonox::Quaternion() const
     114{
     115    return (this->type_ == MT_quaternion) ? this->quaternion_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Quaternion>(*this);
     116}
     117
     118MultiTypeMath::operator orxonox::ColourValue() const
     119{
     120    return (this->type_ == MT_colourvalue) ? this->colourvalue_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::ColourValue>(*this);
     121}
     122
     123MultiTypeMath::operator orxonox::Radian() const
     124{
     125    return (this->type_ == MT_radian) ? this->radian_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Radian>(*this);
     126}
     127
     128MultiTypeMath::operator orxonox::Degree() const
     129{
     130    return (this->type_ == MT_degree) ? this->degree_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Degree>(*this);
     131}
     132
    102133void MultiTypeMath::setValue(const MultiTypeMath& mtm)
    103134{
    104135    this->type_ = mtm.type_;
    105136    this->value_ = mtm.value_;
     137}
     138
     139std::string MultiTypeMath::toString() const
     140{
     141    std::string output;
     142
     143    if (this->type_ == MT_vector2)
     144        ConvertValue(&output, this->vector2_);
     145    else if (this->type_ == MT_vector3)
     146        ConvertValue(&output, this->vector3_);
     147    else if (this->type_ == MT_colourvalue)
     148        ConvertValue(&output, this->colourvalue_);
     149    else if (this->type_ == MT_quaternion)
     150        ConvertValue(&output, this->quaternion_);
     151    else if (this->type_ == MT_radian)
     152        ConvertValue(&output, this->radian_);
     153    else if (this->type_ == MT_degree)
     154        ConvertValue(&output, this->degree_);
     155    else
     156        return MultiTypeString::toString();
     157
     158    return output;
     159}
     160
     161bool MultiTypeMath::fromString(const std::string value)
     162{
     163    if (this->type_ == MT_vector2)
     164        return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0));
     165    else if (this->type_ == MT_vector3)
     166        return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0));
     167    else if (this->type_ == MT_colourvalue)
     168        return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0));
     169    else if (this->type_ == MT_quaternion)
     170        return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0));
     171    else if (this->type_ == MT_radian)
     172        return ConvertValue(&this->radian_, value, orxonox::Radian(0));
     173    else if (this->type_ == MT_degree)
     174        return ConvertValue(&this->degree_, value, orxonox::Degree(0));
     175    else
     176        return MultiTypeString::fromString(value);
    106177}
    107178
  • code/branches/core/src/util/MultiTypeMath.h

    r834 r848  
    8888        bool operator!=(const MultiTypeMath& mtm) const;
    8989
    90         inline operator orxonox::Vector2()     const { return this->vector2_;     }
    91         inline operator orxonox::Vector3()     const { return this->vector3_;     }
    92         inline operator orxonox::ColourValue() const { return this->colourvalue_; }
    93         inline operator orxonox::Quaternion()  const { return this->quaternion_;  }
    94         inline operator orxonox::Radian()      const { return this->radian_;      }
    95         inline operator orxonox::Degree()      const { return this->degree_;      }
     90        operator orxonox::Vector2()     const;
     91        operator orxonox::Vector3()     const;
     92        operator orxonox::ColourValue() const;
     93        operator orxonox::Quaternion()  const;
     94        operator orxonox::Radian()      const;
     95        operator orxonox::Degree()      const;
    9696
    9797        using MultiTypeString::setValue;
     
    103103        inline void setValue(const orxonox::Degree&      value) { this->type_ = MT_degree;      this->degree_      = value; }
    104104        void setValue(const MultiTypeMath& mtm);
     105
     106        inline orxonox::Vector2     getVector2()     const { return this->vector2_;     }
     107        inline orxonox::Vector3     getVector3()     const { return this->vector3_;     }
     108        inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; }
     109        inline orxonox::Quaternion  getQuaternion()  const { return this->quaternion_;  }
     110        inline orxonox::Radian      getRadian()      const { return this->radian_;      }
     111        inline orxonox::Degree      getDegree()      const { return this->degree_;      }
    105112
    106113        inline orxonox::Vector2&     getVector2()     { return this->vector2_;     }
     
    119126        inline void getValue(orxonox::Degree*      variable) const { (*variable) = orxonox::Degree      (this->degree_);      }
    120127
     128        std::string toString() const;
     129        bool fromString(const std::string value);
     130
    121131    protected:
    122132        orxonox::Vector2      vector2_;
  • code/branches/core/src/util/MultiTypePrimitive.cc

    r797 r848  
    2828
    2929#include "MultiTypePrimitive.h"
     30#include "Convert.h"
    3031
    3132MultiTypePrimitive::MultiTypePrimitive(MultiType type)
     
    140141}
    141142
     143MultiTypePrimitive::operator int() const
     144{
     145    return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this);
     146}
     147
     148MultiTypePrimitive::operator unsigned int() const
     149{
     150    return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this);
     151}
     152
     153MultiTypePrimitive::operator char() const
     154{
     155    return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this);
     156}
     157
     158MultiTypePrimitive::operator unsigned char() const
     159{
     160    return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this);
     161}
     162
     163MultiTypePrimitive::operator short() const
     164{
     165    return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this);
     166}
     167
     168MultiTypePrimitive::operator unsigned short() const
     169{
     170    return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this);
     171}
     172
     173MultiTypePrimitive::operator long() const
     174{
     175    return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this);
     176}
     177
     178MultiTypePrimitive::operator unsigned long() const
     179{
     180    return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this);
     181}
     182
     183MultiTypePrimitive::operator float() const
     184{
     185    return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this);
     186}
     187
     188MultiTypePrimitive::operator double() const
     189{
     190    return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this);
     191}
     192
     193MultiTypePrimitive::operator long double() const
     194{
     195    return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this);
     196}
     197
     198MultiTypePrimitive::operator bool() const
     199{
     200    return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this);
     201}
     202
    142203void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp)
    143204{
    144205    this->type_ = mtp.type_;
    145206    this->value_ = mtp.value_;
     207}
     208
     209std::string MultiTypePrimitive::toString() const
     210{
     211    std::string output;
     212
     213    if (this->type_ == MT_int)
     214        ConvertValue(&output, this->value_.int_);
     215    else if (this->type_ == MT_uint)
     216        ConvertValue(&output, this->value_.uint_);
     217    else if (this->type_ == MT_char)
     218        ConvertValue(&output, this->value_.char_);
     219    else if (this->type_ == MT_uchar)
     220        ConvertValue(&output, this->value_.uchar_);
     221    else if (this->type_ == MT_short)
     222        ConvertValue(&output, this->value_.short_);
     223    else if (this->type_ == MT_ushort)
     224        ConvertValue(&output, this->value_.ushort_);
     225    else if (this->type_ == MT_long)
     226        ConvertValue(&output, this->value_.long_);
     227    else if (this->type_ == MT_ulong)
     228        ConvertValue(&output, this->value_.ulong_);
     229    else if (this->type_ == MT_float)
     230        ConvertValue(&output, this->value_.float_);
     231    else if (this->type_ == MT_double)
     232        ConvertValue(&output, this->value_.double_);
     233    else if (this->type_ == MT_longdouble)
     234        ConvertValue(&output, this->value_.longdouble_);
     235    else if (this->type_ == MT_bool)
     236        ConvertValue(&output, this->value_.bool_);
     237
     238    return output;
     239}
     240
     241bool MultiTypePrimitive::fromString(const std::string value)
     242{
     243    if (this->type_ == MT_int)
     244        return ConvertValue(&this->value_.int_, value, (int)0);
     245    else if (this->type_ == MT_uint)
     246        return ConvertValue(&this->value_.uint_, value, (unsigned int)0);
     247    else if (this->type_ == MT_char)
     248        return ConvertValue(&this->value_.char_, value, (char)0);
     249    else if (this->type_ == MT_uchar)
     250        return ConvertValue(&this->value_.uchar_, value, (unsigned char)0);
     251    else if (this->type_ == MT_short)
     252        return ConvertValue(&this->value_.short_, value, (short)0);
     253    else if (this->type_ == MT_ushort)
     254        return ConvertValue(&this->value_.ushort_, value, (unsigned short)0);
     255    else if (this->type_ == MT_long)
     256        return ConvertValue(&this->value_.long_, value, (long)0);
     257    else if (this->type_ == MT_ulong)
     258        return ConvertValue(&this->value_.ulong_, value, (unsigned long)0);
     259    else if (this->type_ == MT_float)
     260        return ConvertValue(&this->value_.float_, value, (float)0.0);
     261    else if (this->type_ == MT_double)
     262        return ConvertValue(&this->value_.double_, value, (double)0.0);
     263    else if (this->type_ == MT_longdouble)
     264        return ConvertValue(&this->value_.longdouble_, value, (long double)0.0);
     265    else if (this->type_ == MT_bool)
     266        return ConvertValue(&this->value_.bool_, value, false);
     267    else
     268        return false;
    146269}
    147270
  • code/branches/core/src/util/MultiTypePrimitive.h

    r834 r848  
    9797        bool operator!=(const MultiTypePrimitive& mtp) const;
    9898
    99         inline operator int()            const { return this->value_.int_;        }
    100         inline operator unsigned int()   const { return this->value_.uint_;       }
    101         inline operator char()           const { return this->value_.char_;       }
    102         inline operator unsigned char()  const { return this->value_.uchar_;      }
    103         inline operator short()          const { return this->value_.short_;      }
    104         inline operator unsigned short() const { return this->value_.ushort_;     }
    105         inline operator long()           const { return this->value_.long_;       }
    106         inline operator unsigned long()  const { return this->value_.ulong_;      }
    107         inline operator float ()         const { return this->value_.float_;      }
    108         inline operator double ()        const { return this->value_.double_;     }
    109         inline operator long double()    const { return this->value_.longdouble_; }
    110         inline operator bool()           const { return this->value_.bool_;       }
     99        operator int()            const;
     100        operator unsigned int()   const;
     101        operator char()           const;
     102        operator unsigned char()  const;
     103        operator short()          const;
     104        operator unsigned short() const;
     105        operator long()           const;
     106        operator unsigned long()  const;
     107        operator float ()         const;
     108        operator double ()        const;
     109        operator long double()    const;
     110        operator bool()           const;
    111111
    112112        inline void setValue(int            value) { this->type_ = MT_int;        this->value_.int_        = value; }
     
    137137        inline bool           getBool()          const { return this->value_.bool_;       }
    138138
     139        inline int&            getInt()           { return this->value_.int_;        }
     140        inline unsigned int&   getUnsignedInt()   { return this->value_.uint_;       }
     141        inline char&           getChar()          { return this->value_.char_;       }
     142        inline unsigned char&  getUnsignedChar()  { return this->value_.uchar_;      }
     143        inline short&          getShort()         { return this->value_.short_;      }
     144        inline unsigned short& getUnsignedShort() { return this->value_.ushort_;     }
     145        inline long&           getLong()          { return this->value_.long_;       }
     146        inline unsigned long&  getUnsignedLong()  { return this->value_.ulong_;      }
     147        inline float&          getFloat()         { return this->value_.float_;      }
     148        inline double&         getDouble()        { return this->value_.double_;     }
     149        inline long double&    getLongDouble()    { return this->value_.longdouble_; }
     150        inline bool&           getBool()          { return this->value_.bool_;       }
     151
    139152        inline void getValue(int*            variable) const { (*variable) = this->value_.int_;        }
    140153        inline void getValue(unsigned int*   variable) const { (*variable) = this->value_.uint_;       }
     
    153166        inline bool      isA(MultiType type) const { return (this->type_ == type); }
    154167
     168        std::string toString() const;
     169        bool fromString(const std::string value);
     170
    155171    protected:
    156172        MultiTypeValue  value_;
  • code/branches/core/src/util/MultiTypeString.cc

    r797 r848  
    2828
    2929#include "MultiTypeString.h"
     30#include "Convert.h"
    3031
    3132MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type)
     
    7677}
    7778
     79MultiTypeString::operator std::string() const
     80{
     81    return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypePrimitive, std::string>(*this);
     82}
     83
     84MultiTypeString::operator const char*() const
     85{
     86    return (this->type_ == MT_constchar) ? this->string_.c_str() : ConvertValueAndReturn<MultiTypePrimitive, const char*>(*this);
     87}
     88
    7889void MultiTypeString::setValue(const MultiTypeString& mts)
    7990{
    8091    this->type_ = mts.type_;
    8192    this->value_ = mts.value_;
     93}
     94
     95std::string MultiTypeString::toString() const
     96{
     97    if (this->type_ == MT_constchar)
     98        return this->string_;
     99    else if (this->type_ == MT_string)
     100        return this->string_;
     101    else
     102        return MultiTypePrimitive::toString();
     103}
     104
     105bool MultiTypeString::fromString(const std::string value)
     106{
     107    if (this->type_ == MT_constchar)
     108        this->string_ = value;
     109    else if (this->type_ == MT_string)
     110        this->string_ = value;
     111    else
     112        return MultiTypePrimitive::fromString(value);
     113
     114    return true;
    82115}
    83116
  • code/branches/core/src/util/MultiTypeString.h

    r834 r848  
    7171        bool operator!=(const MultiTypeString& mtp) const;
    7272
    73         inline operator std::string() const { return this->string_;         }
    74         inline operator const char*() const { return this->string_.c_str(); }
     73        operator std::string() const;
     74        operator const char*() const;
    7575
    7676        using MultiTypePrimitive::setValue;
     
    7979        void setValue(const MultiTypeString& mtp);
    8080
    81         inline std::string& getString()    { return this->string_;         }
    82         inline const char*  getConstChar() { return this->string_.c_str(); }
     81        inline const std::string getString() const { return this->string_;         }
     82        inline const char*  getConstChar()   const { return this->string_.c_str(); }
     83
     84        inline const std::string& getString() { return this->string_;         }
     85        inline const char*  getConstChar()    { return this->string_.c_str(); }
    8386
    8487        using MultiTypePrimitive::getValue;
    8588        inline void getValue(std::string* variable) const { (*variable) = this->string_;         }
    8689        inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); }
     90
     91        std::string toString() const;
     92        bool fromString(const std::string value);
    8793
    8894    protected:
  • code/branches/core/src/util/String.h

    r792 r848  
    6363            float f = 3.14;
    6464            std::string output;
    65             bool success = Convert::ToString(output, f);
     65            bool success = Convert::ToString(&output, f);
    6666        */
    6767        template <typename T>
     
    8888            float f = 3.14;
    8989            std::string output;
    90             bool success = Convert::ToString(output, f, "0.000000");
     90            bool success = Convert::ToString(&output, f, "0.000000");
    9191        */
    9292        template <typename T>
     
    109109            std::string input = "3.14";
    110110            float f;
    111             bool success = string2Number(f, input);
     111            bool success = string2Number(&f, input);
    112112        */
    113113        template <typename T>
     
    131131            std::string input = "3.14";
    132132            float f;
    133             bool success = string2Number(f, input, 0.000000);
     133            bool success = string2Number(&f, input, 0.000000);
    134134        */
    135135        template <typename T>
Note: See TracChangeset for help on using the changeset viewer.