Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.