Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1003


Ignore:
Timestamp:
Apr 8, 2008, 7:02:46 PM (17 years ago)
Author:
landauf
Message:

hopefully solved the conversion problem :)

it's a lot of metaprogramming now but this reduces the risk getting unnecessary compiler errors:
if (convert(a, b))

return true;

else

return convertFallback(a, b);

if convert(a, b) is defined and always used you could still get an error if convertFallback(a, b) uses something (like stream << object) that isn't supported for a or b. but with some template tricks it's possible to not even consider using convertFallback(a, b) at compiletime and avoid the error as long as convert(a, b) is implemented.

util/Conver.h is now opened for curious coders ;)

Location:
code/branches/core2/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/Functor.h

    r1001 r1003  
    325325            void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
    326326            { \
    327                 std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" << std::endl; \
    328                 std::cout << param1 << std::endl; \
    329                 std::cout << this->getTypenameParam(0) << std::endl; \
    330327                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
    331                 std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" << std::endl; \
    332328            } \
    333329    \
  • code/branches/core2/src/util/Convert.h

    r1001 r1003  
    2121 *   Author:
    2222 *      Benjamin Grauer
     23 *      Fabian 'x3n' Landau
    2324 *   Co-authors:
    24  *      Fabian 'x3n' Landau
     25 *      ...
    2526 */
    2627
     
    4546// Main //
    4647//////////
    47 /*
     48
     49// Enum to declare the wanted conversion preference in case of equal type-levels
    4850enum ConversionPreference
    4951{
    50     CP_ToType,
    51     CP_FromType
     52    CP_PreferToType,
     53    CP_PreferFromType,
    5254};
    5355
    5456// Helper classes to determine the preferred partial template specialization
    55 class _AnyType_  {};
    56 class _ToType_   {} static __to__;
    57 class _FromType_ {} static __from__;
    58 class _Explicit_ {} static __explicit__;
     57class _ToType_   {};
     58class _FromType_ {};
     59class _Explicit_ {};
    5960
    6061
    6162// The default convert functions
    62 template <class FromType, class ToType>
    63 static bool convert(ToType* output, const FromType& input, _ToType_* type)
    64 { std::cout << "default to" << std::endl; return false; }
    65 template <class FromType, class ToType>
    66 static bool convert(ToType* output, const FromType& input, _FromType_* type)
    67 { std::cout << "default from" << std::endl; return false; }
    68 template <class FromType, class ToType>
    69 static bool convert(ToType* output, const FromType& input, _Explicit_* type)
    70 { std::cout << "default explicit" << std::endl; return false; }
     63template <class FromType, class ToType, class Type>
     64struct ConverterSpecialized
     65{
     66    enum { specialized = false };
     67    static bool convert(ToType* output, const FromType& input)
     68    { return false; }
     69};
    7170
    7271
    7372// The default convert function if both types are the same
    7473template <class BothTypes>
    75 static bool convert(BothTypes* output, const BothTypes& input, _Explicit_* type)
    76 { (*output) = input; return true; }
    77 
    78 
    79 // The default conversion of primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes)
    80 template <class FromType, class ToType, class Type>
    81 static bool convertDefault(ToType* output, const FromType& input, Type* type)
    82 { return false; }
    83 #define CONVERT_PRIMITIVE_DEFAULT(primitive) \
    84 template <class FromType> static bool convertDefault(primitive* output, const FromType& input, _ToType_* type) { return convertDefault(output, input, &__from__); } \
    85 template <class ToType>   static bool convertDefault(ToType* output, const primitive& input, _FromType_* type) { (*output) = (ToType)input; return true; }
    86 CONVERT_PRIMITIVE_DEFAULT(int)
    87 CONVERT_PRIMITIVE_DEFAULT(unsigned int)
    88 CONVERT_PRIMITIVE_DEFAULT(char)
    89 CONVERT_PRIMITIVE_DEFAULT(unsigned char)
    90 CONVERT_PRIMITIVE_DEFAULT(short)
    91 CONVERT_PRIMITIVE_DEFAULT(unsigned short)
    92 CONVERT_PRIMITIVE_DEFAULT(long)
    93 CONVERT_PRIMITIVE_DEFAULT(unsigned long)
    94 CONVERT_PRIMITIVE_DEFAULT(float)
    95 CONVERT_PRIMITIVE_DEFAULT(double)
    96 CONVERT_PRIMITIVE_DEFAULT(long double)
    97 CONVERT_PRIMITIVE_DEFAULT(bool)
    98 
    99 // Calls all four possibilities of converting two values: (the order of 2 and 3 can be changed by setting bPreferToType to false)
    100 // 1) explicit specialization
    101 // 2) partial specialization for ToType
    102 // 3) partial specialization of the FromType
    103 // 4) default conversion if available
    104 template<class FromType, class ToType>
    105 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
    106 {
    107 std::cout << "1_1\n";
    108     if (convert(output, input, &__explicit__))
     74struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_>
     75{
     76    enum { specialized = true };
     77    static bool convert(BothTypes* output, const BothTypes& input)
     78    { (*output) = input; return true; }
     79};
     80
     81
     82// The possible levels
     83#define __low__  0 // Everything that is or behaves like a primitive type (an can be converted with a typecast to every other low-level type)
     84#define __mid__  1 // Everything that has overloaded << and >> operators to operate on a std::stream
     85#define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions
     86
     87// Defines the levels of all types: Default is __high__ so you don't have to define every high-level type
     88template <class T> struct ConverterLevel           { enum { level = __high__ }; };
     89template <> struct ConverterLevel<std::string>     { enum { level = __mid__ }; };
     90template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; };
     91template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; };
     92template <> struct ConverterLevel<int>             { enum { level = __low__ }; };
     93template <> struct ConverterLevel<unsigned int>    { enum { level = __low__ }; };
     94template <> struct ConverterLevel<char>            { enum { level = __low__ }; };
     95template <> struct ConverterLevel<unsigned char>   { enum { level = __low__ }; };
     96template <> struct ConverterLevel<short>           { enum { level = __low__ }; };
     97template <> struct ConverterLevel<unsigned short>  { enum { level = __low__ }; };
     98template <> struct ConverterLevel<long>            { enum { level = __low__ }; };
     99template <> struct ConverterLevel<unsigned long>   { enum { level = __low__ }; };
     100template <> struct ConverterLevel<float>           { enum { level = __low__ }; };
     101template <> struct ConverterLevel<double>          { enum { level = __low__ }; };
     102template <> struct ConverterLevel<long double>     { enum { level = __low__ }; };
     103template <> struct ConverterLevel<bool>            { enum { level = __low__ }; };
     104
     105
     106// Calculates the preference based on the levels of FromType and ToType
     107template <int from, int to>
     108struct ConverterPreference
     109{
     110    enum
     111    {
     112        // The maximum of both levels: element of {0, 1, 2}
     113        // max 0: Both types are primitives or have a similar behaviour
     114        // max 1: At least one type is not a primitive, but both can be put on a std::stream
     115        // max 2: There is at least one generic type that needs specialized conversions
     116        max = (from > to) ? from : to,
     117
     118        // The difference between both levels limited to +-1: element of {-1, 0, 1}
     119        // diff -1: The FromType has higher level than the ToType
     120        // diff  0: Both types have the same level
     121        // diff  1: The ToType has higher level than the FromType
     122        diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from)
     123    };
     124};
     125
     126
     127// The default conversion: This usually does nothing
     128template <int max, class FromType, class ToType>
     129struct ConverterDefault
     130{
     131    static bool convert(ToType* output, const FromType& input)
     132    {
     133        return false;
     134    }
     135};
     136// The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes)    template <int max, class FromType, class ToType>
     137template <class FromType, class ToType>
     138struct ConverterDefault<0, FromType, ToType>
     139{
     140    static bool convert(ToType* output, const FromType& input)
     141    {
     142        (*output) = (ToType)input;
    109143        return true;
    110 
    111 std::cout << "1_2\n";
    112     if (preference == CP_ToType)
    113     {
    114 std::cout << "1_3\n";
    115         if (convert(output, input, &__to__))
    116             return true;
    117 std::cout << "1_4\n";
    118         if (convert(output, input, &__from__))
    119             return true;
    120 std::cout << "1_5\n";
    121     }
    122     else
    123     {
    124 std::cout << "1_6\n";
    125         if (convert(output, input, &__from__))
    126             return true;
    127 std::cout << "1_7\n";
    128         if (convert(output, input, &__to__))
    129             return true;
    130 std::cout << "1_8\n";
    131     }
    132 std::cout << "1_9\n";
    133     return convertDefault(output, input, &__to__);
     144    }
     145};
     146
     147
     148// Converter: Converts input of FromType into output of ToType
     149template <int diff, int max, class FromType, class ToType, ConversionPreference pref>
     150struct Converter
     151{
     152    static bool convert(ToType* output, const FromType& input)
     153    {
     154        return false;
     155    }
     156};
     157// Converter: level{FromType} > level{ToType}
     158template <int max, class FromType, class ToType, ConversionPreference pref>
     159struct Converter<-1, max, FromType, ToType, pref>
     160{   static bool convert(ToType* output, const FromType& input)
     161    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     162// Converter: level{FromType} < level{ToType}
     163template <int max, class FromType, class ToType, ConversionPreference pref>
     164struct Converter<1, max, FromType, ToType, pref>
     165{   static bool convert(ToType* output, const FromType& input)
     166    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     167// Converter: level{FromType} = level{ToType}
     168// CP_PreferToType
     169template <int max, class FromType, class ToType>
     170struct Converter<0, max, FromType, ToType, CP_PreferToType>
     171{   static bool convert(ToType* output, const FromType& input)
     172    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     173// CP_PreferFromType
     174template <int max, class FromType, class ToType>
     175struct Converter<0, max, FromType, ToType, CP_PreferFromType>
     176{   static bool convert(ToType* output, const FromType& input)
     177    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     178
     179
     180// Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference
     181template <class FromType, class ToType>
     182static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType)
     183{
     184    return (preference == CP_PreferToType) ?
     185           Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff,
     186                     ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max,
     187                     FromType,
     188                     ToType,
     189                     CP_PreferToType>::convert(output, input)
     190         : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff,
     191                     ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max,
     192                     FromType,
     193                     ToType,
     194                     CP_PreferFromType>::convert(output, input);
    134195}
    135 */
    136 
    137     // Enum to declare the wanted conversion preference in case of equal type-levels
    138     enum ConversionPreference
    139     {
    140         CP_ToType,
    141         CP_FromType
    142     };
    143 
    144     // Helper classes to determine the preferred partial template specialization
    145     class _AnyType_  {};
    146     class _ToType_   {} static __to__;
    147     class _FromType_ {} static __from__;
    148     class _Explicit_ {} static __explicit__;
    149 
    150 
    151     // The default convert functions
    152     template <class FromType, class ToType>
    153     static bool convert(ToType* output, const FromType& input, _ToType_* type)
    154     { std::cout << "default to" << std::endl; return false; }
    155     template <class FromType, class ToType>
    156     static bool convert(ToType* output, const FromType& input, _FromType_* type)
    157     { std::cout << "default from" << std::endl; return false; }
    158     template <class FromType, class ToType>
    159     static bool convert(ToType* output, const FromType& input, _Explicit_* type)
    160     { std::cout << "default explicit" << std::endl; return false; }
    161 
    162 
    163     // The default convert function if both types are the same
    164     template <class BothTypes>
    165     static bool convert(BothTypes* output, const BothTypes& input, _Explicit_* type)
    166     { (*output) = input; return true; }
    167 
    168 
    169     // The possible levels
    170     #define __low__  0
    171     #define __mid__  1
    172     #define __high__ 2
    173 
    174     // Defines the levels of all types
    175     template <class T> struct ConverterLeveL          { enum { level = __high__ }; };
    176     template <> struct ConverterLeveL<std::string>    { enum { level = __mid__ }; };
    177     template <> struct ConverterLeveL<int>            { enum { level = __low__ }; };
    178     template <> struct ConverterLeveL<unsigned int>   { enum { level = __low__ }; };
    179     template <> struct ConverterLeveL<char>           { enum { level = __low__ }; };
    180     template <> struct ConverterLeveL<unsigned char>  { enum { level = __low__ }; };
    181     template <> struct ConverterLeveL<short>          { enum { level = __low__ }; };
    182     template <> struct ConverterLeveL<unsigned short> { enum { level = __low__ }; };
    183     template <> struct ConverterLeveL<long>           { enum { level = __low__ }; };
    184     template <> struct ConverterLeveL<unsigned long>  { enum { level = __low__ }; };
    185     template <> struct ConverterLeveL<float>          { enum { level = __low__ }; };
    186     template <> struct ConverterLeveL<double>         { enum { level = __low__ }; };
    187     template <> struct ConverterLeveL<long double>    { enum { level = __low__ }; };
    188     template <> struct ConverterLeveL<bool>           { enum { level = __low__ }; };
    189 
    190 
    191     // Calculates the preference based on the levels of FromType and ToType
    192     template <int from, int to>
    193     struct ConverterPreference
    194     {
    195         enum
    196         {
    197             max = (from > to) ? from : to,
    198             diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from)
    199         };
    200     };
    201 
    202 
    203     // The default conversion: This usually does nothing
    204     template <int max, class FromType, class ToType, class Type>
    205     struct ConverterDefault
    206     {
    207         static bool convert(ToType* output, const FromType& input, Type* type)
    208         {
    209             return false;
    210         }
    211     };
    212     // The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes)    template <int max, class FromType, class ToType>
    213     template <class FromType, class ToType, class Type>
    214     struct ConverterDefault<0, FromType, ToType, Type>
    215     {
    216         static bool convert(ToType* output, const FromType& input, Type* type)
    217         {
    218             (*output) = (ToType)input;
    219             return true;
    220         }
    221     };
    222 
    223 
    224     // Converter: Converts input of FromType into output of ToType
    225     template <int diff, int max, class FromType, class ToType>
    226     struct Converter
    227     {
    228         static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
    229         {
    230             return false;
    231         }
    232     };
    233     // Converter: FromType-level > ToType-level
    234     template <int max, class FromType, class ToType>
    235     struct Converter<-1, max, FromType, ToType>
    236     {
    237         static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
    238         {
    239             if (convert(output, input, &__explicit__))
    240                 return true;
    241             if (convert(output, input, &__from__))
    242                 return true;
    243             if (ConverterDefault<max, FromType, ToType, _ToType_>::convert(output, input, &__to__))
    244                 return true;
    245 
    246             return false;
    247         }
    248     };
    249     // Converter: ToType-level > FromType-level
    250     template <int max, class FromType, class ToType>
    251     struct Converter<1, max, FromType, ToType>
    252     {
    253         static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
    254         {
    255             if (convert(output, input, &__explicit__))
    256                 return true;
    257             if (convert(output, input, &__to__))
    258                 return true;
    259             if (ConverterDefault<max, FromType, ToType, _ToType_>::convert(output, input, &__to__))
    260                 return true;
    261 
    262             return false;
    263         }
    264     };
    265     // Converter: ToType-level = ToType-level
    266     template <int max, class FromType, class ToType>
    267     struct Converter<0, max, FromType, ToType>
    268     {
    269         static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
    270         {
    271             if (convert(output, input, &__explicit__))
    272                 return true;
    273 
    274             if (preference == CP_ToType)
    275             {
    276                 if (convert(output, input, &__to__))
    277                     return true;
    278                 if (convert(output, input, &__from__))
    279                     return true;
    280             }
    281             else
    282             {
    283                 if (convert(output, input, &__from__))
    284                     return true;
    285                 if (convert(output, input, &__to__))
    286                     return true;
    287             }
    288 
    289             if (ConverterDefault<max, FromType, ToType, _ToType_>::convert(output, input, &__to__))
    290                 return true;
    291 
    292             return false;
    293         }
    294     };
    295 
    296 
    297     // Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference
    298     template <class FromType, class ToType>
    299     static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
    300     {
    301         return Converter<ConverterPreference<ConverterLeveL<FromType>::level, ConverterLeveL<ToType>::level>::diff, ConverterPreference<ConverterLeveL<FromType>::level, ConverterLeveL<ToType>::level>::max, FromType, ToType>::convertValue(output, input, preference);
    302     }
    303196
    304197
    305198// Helper function: Calls convertValue with and without default value and returns true if the conversion was successful
    306199template<class FromType, class ToType>
    307 static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
     200static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType)
    308201{
    309202    return convertValue(output, input, preference);
    310203}
    311204template<class FromType, class ToType>
    312 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_ToType)
     205static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType)
    313206{
    314207    if (convertValue(output, input, preference))
     
    321214// Helper function: Calls convertValue with and without default value and returns the converted value
    322215template<class FromType, class ToType>
    323 static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_ToType)
     216static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType)
    324217{
    325218    ToType output = ToType();
     
    328221}
    329222template<class FromType, class ToType>
    330 static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_ToType)
     223static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType)
    331224{
    332225    ToType output = fallback;
     
    339232/////////////////////
    340233
     234/////////////
     235// Samples //
     236/////////////
    341237/*
     238// convert everything to xyz
    342239template <class FromType>
    343 static bool convertDefault(primitive* output, const FromType& input, _ToType_* type)
    344 {
    345 
    346 }
    347 
     240struct ConverterSpecialized<FromType, xyz, _ToType_>
     241{
     242    enum { specialized = true };
     243    static bool convert(xyz* output, const FromType& input)
     244    { return ...; }
     245};
     246
     247// convert xyz to everything
    348248template <class ToType>
    349 static bool convertDefault(ToType* output, const primitive& input, _FromType_* type)
    350 {
    351 
    352 }
    353 
    354 
    355 template <>
    356 static bool convertDefault(ToType* output, const FromType& input, _Explicit_* type)
    357 {
    358 
    359 }
     249struct ConverterSpecialized<xyz, ToType, _FromType_>
     250{
     251    enum { specialized = true };
     252    static bool convert(ToType* output, const xyz& input)
     253    { return ...; }
     254};
     255
     256// convert abc to xyz
     257template <>
     258struct ConverterSpecialized<abc, xyz, _Explicit_>
     259{
     260    enum { specialized = true };
     261    static bool convert(xyz* output, const abc& input)
     262    { return ...; }
     263};
    360264*/
    361265
     
    366270// convert to string
    367271template <class FromType>
    368 static bool convert(std::string* output, const FromType& input, _ToType_* type)
    369 {
    370     std::ostringstream oss;
    371     if (oss << input)
    372     {
    373         (*output) = oss.str();
    374         return true;
    375     }
    376     else
    377         return false;
    378 }
     272struct ConverterSpecialized<FromType, std::string, _ToType_>
     273{
     274    enum { specialized = true };
     275    static bool convert(std::string* output, const FromType& input)
     276    {
     277        std::ostringstream oss;
     278        if (oss << input)
     279        {
     280            (*output) = oss.str();
     281            return true;
     282        }
     283        else
     284            return false;
     285    }
     286};
    379287
    380288// convert from string
    381289template <class ToType>
    382 static bool convert(ToType* output, const std::string& input, _FromType_* type)
    383 {
    384     std::istringstream iss(input);
    385     if (iss >> (*output))
    386         return true;
    387     else
    388         return false;
    389 }
     290struct ConverterSpecialized<std::string, ToType, _FromType_>
     291{
     292    enum { specialized = true };
     293    static bool convert(ToType* output, const std::string& input)
     294    {
     295        std::istringstream iss(input);
     296        if (iss >> (*output))
     297            return true;
     298        else
     299            return false;
     300    }
     301};
    390302
    391303
     
    396308// convert from MultiTypePrimitive
    397309template <class ToType>
    398 static bool convert(ToType* output, const MultiTypePrimitive& input, _FromType_* type)
    399 {
    400     if (input.getType() == MT_void)
    401         return ConvertValue(output, input.getVoid());
    402     else if (input.getType() == MT_int)
    403         return ConvertValue(output, input.getInt());
    404     else if (input.getType() == MT_uint)
    405         return ConvertValue(output, input.getUnsignedInt());
    406     else if (input.getType() == MT_char)
    407         return ConvertValue(output, input.getChar());
    408     else if (input.getType() == MT_uchar)
    409         return ConvertValue(output, input.getUnsignedChar());
    410     else if (input.getType() == MT_short)
    411         return ConvertValue(output, input.getShort());
    412     else if (input.getType() == MT_ushort)
    413         return ConvertValue(output, input.getUnsignedShort());
    414     else if (input.getType() == MT_long)
    415         return ConvertValue(output, input.getLong());
    416     else if (input.getType() == MT_ulong)
    417         return ConvertValue(output, input.getUnsignedLong());
    418     else if (input.getType() == MT_float)
    419         return ConvertValue(output, input.getFloat());
    420     else if (input.getType() == MT_double)
    421         return ConvertValue(output, input.getDouble());
    422     else if (input.getType() == MT_longdouble)
    423         return ConvertValue(output, input.getLongDouble());
    424     else if (input.getType() == MT_bool)
    425         return ConvertValue(output, input.getBool());
    426     else
    427         return false;
    428 }
     310struct ConverterSpecialized<MultiTypePrimitive, ToType, _FromType_>
     311{
     312    enum { specialized = true };
     313    static bool convert(ToType* output, const MultiTypePrimitive& input)
     314    {
     315        if (input.getType() == MT_void)
     316            return ConvertValue(output, input.getVoid());
     317        else if (input.getType() == MT_int)
     318            return ConvertValue(output, input.getInt());
     319        else if (input.getType() == MT_uint)
     320            return ConvertValue(output, input.getUnsignedInt());
     321        else if (input.getType() == MT_char)
     322            return ConvertValue(output, input.getChar());
     323        else if (input.getType() == MT_uchar)
     324            return ConvertValue(output, input.getUnsignedChar());
     325        else if (input.getType() == MT_short)
     326            return ConvertValue(output, input.getShort());
     327        else if (input.getType() == MT_ushort)
     328            return ConvertValue(output, input.getUnsignedShort());
     329        else if (input.getType() == MT_long)
     330            return ConvertValue(output, input.getLong());
     331        else if (input.getType() == MT_ulong)
     332            return ConvertValue(output, input.getUnsignedLong());
     333        else if (input.getType() == MT_float)
     334            return ConvertValue(output, input.getFloat());
     335        else if (input.getType() == MT_double)
     336            return ConvertValue(output, input.getDouble());
     337        else if (input.getType() == MT_longdouble)
     338            return ConvertValue(output, input.getLongDouble());
     339        else if (input.getType() == MT_bool)
     340            return ConvertValue(output, input.getBool());
     341        else
     342            return false;
     343    }
     344};
    429345
    430346// convert from MultiTypeString
    431347template <class ToType>
    432 static bool convert(ToType* output, const MultiTypeString& input, _FromType_* type)
    433 {
    434     if (input.getType() == MT_constchar)
    435         return ConvertValue(output, input.getConstChar());
    436     else if (input.getType() == MT_string)
    437         return ConvertValue(output, input.getString());
    438     else
    439         return ConvertValue(output, (MultiTypePrimitive)input);
    440 }
     348struct ConverterSpecialized<MultiTypeString, ToType, _FromType_>
     349{
     350    enum { specialized = true };
     351    static bool convert(ToType* output, const MultiTypeString& input)
     352    {
     353        if (input.getType() == MT_constchar)
     354            return ConvertValue(output, input.getConstChar());
     355        else if (input.getType() == MT_string)
     356            return ConvertValue(output, input.getString());
     357        else
     358            return ConvertValue(output, (MultiTypePrimitive)input);
     359    }
     360};
    441361
    442362// convert from MultiTypeMath
    443363template <class ToType>
    444 static bool convert(ToType* output, const MultiTypeMath& input, _FromType_* type)
    445 {
    446     if (input.getType() == MT_vector2)
    447         return ConvertValue(output, input.getVector2(), CP_FromType);
    448     else if (input.getType() == MT_vector3)
    449         return ConvertValue(output, input.getVector3(), CP_FromType);
    450     else if (input.getType() == MT_quaternion)
    451         return ConvertValue(output, input.getQuaternion(), CP_FromType);
    452     else if (input.getType() == MT_colourvalue)
    453         return ConvertValue(output, input.getColourValue(), CP_FromType);
    454     else if (input.getType() == MT_radian)
    455         return ConvertValue(output, input.getRadian());
    456     else if (input.getType() == MT_degree)
    457         return ConvertValue(output, input.getDegree());
    458     else
    459         return ConvertValue(output, (MultiTypeString)input);
    460 }
     364struct ConverterSpecialized<MultiTypeMath, ToType, _FromType_>
     365{
     366    enum { specialized = true };
     367    static bool convert(ToType* output, const MultiTypeMath& input)
     368    {
     369        if (input.getType() == MT_vector2)
     370            return ConvertValue(output, input.getVector2());
     371        else if (input.getType() == MT_vector3)
     372            return ConvertValue(output, input.getVector3());
     373        else if (input.getType() == MT_quaternion)
     374            return ConvertValue(output, input.getQuaternion());
     375        else if (input.getType() == MT_colourvalue)
     376            return ConvertValue(output, input.getColourValue());
     377        else if (input.getType() == MT_radian)
     378            return ConvertValue(output, input.getRadian());
     379        else if (input.getType() == MT_degree)
     380            return ConvertValue(output, input.getDegree());
     381        else
     382            return ConvertValue(output, (MultiTypeString)input);
     383    }
     384};
    461385
    462386
     
    467391// Vector2 to std::string
    468392template <>
    469 static bool convert(std::string* output, const orxonox::Vector2& input, _Explicit_* type)
    470 {
    471     std::ostringstream ostream;
    472     if (ostream << input.x << "," << input.y)
    473     {
    474         (*output) = ostream.str();
    475         return true;
    476     }
    477     return false;
    478 }
    479 
    480 /*
    481 // Vector2 to std::string
    482 template <>
    483 class Converter<orxonox::Vector2, std::string>
    484 {
    485   public:
    486     bool operator()(std::string* output, const orxonox::Vector2& input) const
    487     {
    488       std::ostringstream ostream;
    489       if (ostream << input.x << "," << input.y)
    490       {
    491         (*output) = ostream.str();
    492         return true;
    493       }
    494 
    495       return false;
    496     }
    497 };
    498 */
     393struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_>
     394{
     395    enum { specialized = true };
     396    static bool convert(std::string* output, const orxonox::Vector2& input)
     397    {
     398        std::ostringstream ostream;
     399        if (ostream << input.x << "," << input.y)
     400        {
     401            (*output) = ostream.str();
     402            return true;
     403        }
     404        return false;
     405    }
     406};
     407
    499408// Vector3 to std::string
    500409template <>
    501 static bool convert(std::string* output, const orxonox::Vector3& input, _Explicit_* type)
    502 {
    503     std::ostringstream ostream;
    504     if (ostream << input.x << "," << input.y << "," << input.z)
    505     {
    506         (*output) = ostream.str();
    507         return true;
    508     }
    509     return false;
    510 }
    511 
    512 /*
    513 // Vector3 to std::string
    514 template <>
    515 class Converter<orxonox::Vector3, std::string>
    516 {
    517   public:
    518     bool operator()(std::string* output, const orxonox::Vector3& input) const
    519     {
    520       std::ostringstream ostream;
    521       if (ostream << input.x << "," << input.y << "," << input.z)
    522       {
    523         (*output) = ostream.str();
    524         return true;
    525       }
    526 
    527       return false;
    528     }
    529 };
    530 */
     410struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_>
     411{
     412    enum { specialized = true };
     413    static bool convert(std::string* output, const orxonox::Vector3& input)
     414    {
     415        std::ostringstream ostream;
     416        if (ostream << input.x << "," << input.y << "," << input.z)
     417        {
     418            (*output) = ostream.str();
     419            return true;
     420        }
     421        return false;
     422    }
     423};
     424
    531425// Vector4 to std::string
    532426template <>
    533 static bool convert(std::string* output, const orxonox::Vector4& input, _Explicit_* type)
    534 {
    535     std::ostringstream ostream;
    536     if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
    537     {
    538         (*output) = ostream.str();
    539         return true;
    540     }
    541     return false;
    542 }
    543 /*
    544 // Vector4 to std::string
    545 template <>
    546 class Converter<orxonox::Vector4, std::string>
    547 {
    548   public:
    549     bool operator()(std::string* output, const orxonox::Vector4& input) const
    550     {
    551       std::ostringstream ostream;
    552       if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
    553       {
    554         (*output) = ostream.str();
    555         return true;
    556       }
    557 
    558       return false;
    559     }
    560 };
    561 */
     427struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_>
     428{
     429    enum { specialized = true };
     430    static bool convert(std::string* output, const orxonox::Vector4& input)
     431    {
     432        std::ostringstream ostream;
     433        if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
     434        {
     435            (*output) = ostream.str();
     436            return true;
     437        }
     438        return false;
     439    }
     440};
     441
    562442// Quaternion to std::string
    563443template <>
    564 static bool convert(std::string* output, const orxonox::Quaternion& input, _Explicit_* type)
    565 {
    566     std::ostringstream ostream;
    567     if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
    568     {
    569         (*output) = ostream.str();
    570         return true;
    571     }
    572     return false;
    573 }
    574 /*
    575 // Quaternion to std::string
    576 template <>
    577 class Converter<orxonox::Quaternion, std::string>
    578 {
    579   public:
    580     bool operator()(std::string* output, const orxonox::Quaternion& input) const
    581     {
    582       std::ostringstream ostream;
    583       if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
    584       {
    585         (*output) = ostream.str();
    586         return true;
    587       }
    588 
    589       return false;
    590     }
    591 };
    592 */
     444struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_>
     445{
     446    enum { specialized = true };
     447    static bool convert(std::string* output, const orxonox::Quaternion& input)
     448    {
     449        std::ostringstream ostream;
     450        if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
     451        {
     452            (*output) = ostream.str();
     453            return true;
     454        }
     455        return false;
     456    }
     457};
     458
    593459// ColourValue to std::string
    594460template <>
    595 static bool convert(std::string* output, const orxonox::ColourValue& input, _Explicit_* type)
    596 {
    597     std::ostringstream ostream;
    598     if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
    599     {
    600         (*output) = ostream.str();
    601         return true;
    602     }
    603     return false;
    604 }
    605 /*
    606 // ColourValue to std::string
    607 template <>
    608 class Converter<orxonox::ColourValue, std::string>
    609 {
    610   public:
    611     bool operator()(std::string* output, const orxonox::ColourValue& input) const
    612     {
    613       std::ostringstream ostream;
    614       if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
    615       {
    616         (*output) = ostream.str();
    617         return true;
    618       }
    619 
    620       return false;
    621     }
    622 };
    623 */
     461struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_>
     462{
     463    enum { specialized = true };
     464    static bool convert(std::string* output, const orxonox::ColourValue& input)
     465    {
     466        std::ostringstream ostream;
     467        if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
     468        {
     469            (*output) = ostream.str();
     470            return true;
     471        }
     472        return false;
     473    }
     474};
    624475
    625476
     
    630481// std::string to Vector2
    631482template <>
    632 static bool convert(orxonox::Vector2* output, const std::string& input, _Explicit_* type)
    633 {
    634     unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    635     if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    636 
    637     SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    638     if (tokens.size() >= 2)
    639     {
    640         if (!ConvertValue(&(output->x), tokens[0]))
    641             return false;
    642         if (!ConvertValue(&(output->y), tokens[1]))
    643             return false;
    644 
    645         return true;
    646     }
    647     return false;
    648 }
    649 /*
    650 // std::string to Vector2
    651 template <>
    652 class Converter<std::string, orxonox::Vector2>
    653 {
    654   public:
    655     bool operator()(orxonox::Vector2* output, const std::string& input) const
    656     {
    657       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    658       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    659 
    660       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    661 
    662       if (tokens.size() >= 2)
    663       {
    664         if (!ConvertValue(&(output->x), tokens[0]))
    665           return false;
    666         if (!ConvertValue(&(output->y), tokens[1]))
    667           return false;
    668 
    669         return true;
    670       }
    671 
    672       return false;
    673     }
    674 };
    675 */
     483struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_>
     484{
     485    enum { specialized = true };
     486    static bool convert(orxonox::Vector2* output, const std::string& input)
     487    {
     488        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     489        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     490
     491        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     492        if (tokens.size() >= 2)
     493        {
     494            if (!ConvertValue(&(output->x), tokens[0]))
     495                return false;
     496            if (!ConvertValue(&(output->y), tokens[1]))
     497                return false;
     498
     499            return true;
     500        }
     501        return false;
     502    }
     503};
     504
    676505// std::string to Vector3
    677506template <>
    678 static bool convert(orxonox::Vector3* output, const std::string& input, _Explicit_* type)
    679 {
    680     unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    681     if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    682 
    683     SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    684     if (tokens.size() >= 3)
    685     {
    686         if (!ConvertValue(&(output->x), tokens[0]))
    687             return false;
    688         if (!ConvertValue(&(output->y), tokens[1]))
    689             return false;
    690         if (!ConvertValue(&(output->z), tokens[2]))
    691             return false;
    692 
    693         return true;
    694     }
    695     return false;
    696 }
    697 /*
    698 // std::string to Vector3
    699 template <>
    700 class Converter<std::string, orxonox::Vector3>
    701 {
    702   public:
    703     bool operator()(orxonox::Vector3* output, const std::string& input) const
    704     {
    705       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    706       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    707 
    708       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    709 
    710       if (tokens.size() >= 3)
    711       {
    712         if (!ConvertValue(&(output->x), tokens[0]))
    713           return false;
    714         if (!ConvertValue(&(output->y), tokens[1]))
    715           return false;
    716         if (!ConvertValue(&(output->z), tokens[2]))
    717           return false;
    718 
    719         return true;
    720       }
    721 
    722       return false;
    723     }
    724 };
    725 */
     507struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_>
     508{
     509    enum { specialized = true };
     510    static bool convert(orxonox::Vector3* output, const std::string& input)
     511    {
     512        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     513        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     514
     515        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     516        if (tokens.size() >= 3)
     517        {
     518            if (!ConvertValue(&(output->x), tokens[0]))
     519                return false;
     520            if (!ConvertValue(&(output->y), tokens[1]))
     521                return false;
     522            if (!ConvertValue(&(output->z), tokens[2]))
     523                return false;
     524
     525            return true;
     526        }
     527        return false;
     528    }
     529};
     530
    726531// std::string to Vector4
    727532template <>
    728 static bool convert(orxonox::Vector4* output, const std::string& input, _Explicit_* type)
    729 {
    730     unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    731     if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    732 
    733     SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    734     if (tokens.size() >= 4)
    735     {
    736         if (!ConvertValue(&(output->x), tokens[0]))
    737             return false;
    738         if (!ConvertValue(&(output->y), tokens[1]))
    739             return false;
    740         if (!ConvertValue(&(output->z), tokens[2]))
    741             return false;
    742         if (!ConvertValue(&(output->w), tokens[3]))
    743             return false;
    744 
    745         return true;
    746     }
    747     return false;
    748 }
    749 /*
    750 // std::string to Vector4
    751 template <>
    752 class Converter<std::string, orxonox::Vector4>
    753 {
    754   public:
    755     bool operator()(orxonox::Vector4* output, const std::string& input) const
    756     {
    757       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    758       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    759 
    760       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    761 
    762       if (tokens.size() >= 4)
    763       {
    764         if (!ConvertValue(&(output->x), tokens[0]))
    765           return false;
    766         if (!ConvertValue(&(output->y), tokens[1]))
    767           return false;
    768         if (!ConvertValue(&(output->z), tokens[2]))
    769           return false;
    770         if (!ConvertValue(&(output->w), tokens[3]))
    771           return false;
    772 
    773         return true;
    774       }
    775 
    776       return false;
    777     }
    778 };
    779 */
     533struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_>
     534{
     535    enum { specialized = true };
     536    static bool convert(orxonox::Vector4* output, const std::string& input)
     537    {
     538        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     539        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     540
     541        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     542        if (tokens.size() >= 4)
     543        {
     544            if (!ConvertValue(&(output->x), tokens[0]))
     545                return false;
     546            if (!ConvertValue(&(output->y), tokens[1]))
     547                return false;
     548            if (!ConvertValue(&(output->z), tokens[2]))
     549                return false;
     550            if (!ConvertValue(&(output->w), tokens[3]))
     551                return false;
     552
     553            return true;
     554        }
     555        return false;
     556    }
     557};
     558
    780559// std::string to Quaternion
    781560template <>
    782 static bool convert(orxonox::Quaternion* output, const std::string& input, _Explicit_* type)
    783 {
    784     unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    785     if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    786 
    787     SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    788     if (tokens.size() >= 4)
    789     {
    790         if (!ConvertValue(&(output->w), tokens[0]))
    791             return false;
    792         if (!ConvertValue(&(output->x), tokens[1]))
    793             return false;
    794         if (!ConvertValue(&(output->y), tokens[2]))
    795             return false;
    796         if (!ConvertValue(&(output->z), tokens[3]))
    797             return false;
    798 
    799         return true;
    800     }
    801     return false;
    802 }
    803 /*
    804 // std::string to Quaternion
    805 template <>
    806 class Converter<std::string, orxonox::Quaternion>
    807 {
    808   public:
    809     bool operator()(orxonox::Quaternion* output, const std::string& input) const
    810     {
    811       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    812       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    813 
    814       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    815 
    816       if (tokens.size() >= 4)
    817       {
    818         if (!ConvertValue(&(output->w), tokens[0]))
    819           return false;
    820         if (!ConvertValue(&(output->x), tokens[1]))
    821           return false;
    822         if (!ConvertValue(&(output->y), tokens[2]))
    823           return false;
    824         if (!ConvertValue(&(output->z), tokens[3]))
    825           return false;
    826 
    827         return true;
    828       }
    829 
    830       return false;
    831     }
    832 };
    833 */
     561struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_>
     562{
     563    enum { specialized = true };
     564    static bool convert(orxonox::Quaternion* output, const std::string& input)
     565    {
     566        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     567        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     568
     569        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     570        if (tokens.size() >= 4)
     571        {
     572            if (!ConvertValue(&(output->w), tokens[0]))
     573                return false;
     574            if (!ConvertValue(&(output->x), tokens[1]))
     575                return false;
     576            if (!ConvertValue(&(output->y), tokens[2]))
     577                return false;
     578            if (!ConvertValue(&(output->z), tokens[3]))
     579                return false;
     580
     581            return true;
     582        }
     583        return false;
     584    }
     585};
     586
    834587// std::string to ColourValue
    835588template <>
    836 static bool convert(orxonox::ColourValue* output, const std::string& input, _Explicit_* type)
    837 {
    838     unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    839     if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    840 
    841     SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    842     if (tokens.size() >= 4)
    843     {
    844         if (!ConvertValue(&(output->r), tokens[0]))
    845             return false;
    846         if (!ConvertValue(&(output->g), tokens[1]))
    847             return false;
    848         if (!ConvertValue(&(output->b), tokens[2]))
    849             return false;
    850         if (!ConvertValue(&(output->a), tokens[3]))
    851             return false;
    852 
    853         return true;
    854     }
    855     return false;
    856 }
    857 /*
    858 // std::string to ColourValue
    859 template <>
    860 class Converter<std::string, orxonox::ColourValue>
    861 {
    862   public:
    863     bool operator()(orxonox::ColourValue* output, const std::string& input) const
    864     {
    865       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    866       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    867 
    868       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    869 
    870       if (tokens.size() >= 4)
    871       {
    872         if (!ConvertValue(&(output->r), tokens[0]))
    873           return false;
    874         if (!ConvertValue(&(output->g), tokens[1]))
    875           return false;
    876         if (!ConvertValue(&(output->b), tokens[2]))
    877           return false;
    878         if (!ConvertValue(&(output->a), tokens[3]))
    879           return false;
    880 
    881         return true;
    882       }
    883 
    884       return false;
    885     }
    886 };
    887 */
    888 
     589struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_>
     590{
     591    enum { specialized = true };
     592    static bool convert(orxonox::ColourValue* output, const std::string& input)
     593    {
     594        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     595        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     596
     597        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     598        if (tokens.size() >= 4)
     599        {
     600            if (!ConvertValue(&(output->r), tokens[0]))
     601                return false;
     602            if (!ConvertValue(&(output->g), tokens[1]))
     603                return false;
     604            if (!ConvertValue(&(output->b), tokens[2]))
     605                return false;
     606            if (!ConvertValue(&(output->a), tokens[3]))
     607                return false;
     608
     609            return true;
     610        }
     611        return false;
     612    }
     613};
    889614
    890615#endif /* _Convert_H__ */
  • code/branches/core2/src/util/MultiTypeMath.cc

    r1001 r1003  
    165165
    166166    if (this->type_ == MT_vector2)
    167         ConvertValue(&output, this->vector2_, CP_FromType);
     167        ConvertValue(&output, this->vector2_);
    168168    else if (this->type_ == MT_vector3)
    169         ConvertValue(&output, this->vector3_, CP_FromType);
     169        ConvertValue(&output, this->vector3_);
    170170    else if (this->type_ == MT_colourvalue)
    171171    { std::cout << "3_1\n";
    172         ConvertValue(&output, this->colourvalue_, CP_FromType);}
     172        ConvertValue(&output, this->colourvalue_);}
    173173    else if (this->type_ == MT_quaternion)
    174         ConvertValue(&output, this->quaternion_, CP_FromType);
     174        ConvertValue(&output, this->quaternion_);
    175175    else if (this->type_ == MT_radian)
    176176        ConvertValue(&output, this->radian_);
     
    186186{
    187187    if (this->type_ == MT_vector2)
    188         return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0), CP_FromType);
     188        return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0));
    189189    else if (this->type_ == MT_vector3)
    190         return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0), CP_FromType);
     190        return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0));
    191191    else if (this->type_ == MT_colourvalue)
    192192    { std::cout << "4_1\n";
    193         return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0), CP_FromType); }
     193        return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0)); }
    194194    else if (this->type_ == MT_quaternion)
    195         return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0), CP_FromType);
     195        return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0));
    196196    else if (this->type_ == MT_radian)
    197197        return ConvertValue(&this->radian_, value, orxonox::Radian(0));
Note: See TracChangeset for help on using the changeset viewer.