Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1001


Ignore:
Timestamp:
Apr 8, 2008, 1:51:25 AM (12 years ago)
Author:
landauf
Message:

ok, be aware, here comes a big one. people with weak nerves should probably better look away or take some serious drugs.
this update includes partial and explicit class template specialization, partial and explicit specialized template function overloading, template meta programming and a simple typecast.
yeah right, a typecast. but let me explain the whole story from the beginning.

it all started with a simple problem: i had a double in a MultiType and wanted a float, but i always got 0. what was the problem? the conversion 'MultiType to anyting' was handled by the Converter class in util/Convert.h and the Converter was specialized for strings, multitypes, vectors and so on, but not for int, float, bool, …
so i've first wanted to implement a typecast as default, but this was a bad idea because it doesn't work for almost every generic type.
implementing an explicit specialization for every possible pair of primitives (did you ever happened to use an unsigned short? or a long double? no? ignorants :D) would have been a simple but ugly solution.
but there were other problems: if there's a rule to convert a string into anything and another rule to convert anything into an int - what happens if you want to convert a string into an int? compiler error! …ambiguous partial template specialization.
so i've spent days and nights to find a solution. this is my 5th try or so and i'm still really unsure if it works, but it's the first version i want to commit to have at least a backup.
if you're interested in looking at the code you better wait until i've cleaned up the whole thing, it's a real mess. and i want to do further tests, but now i'm tired. good night ;)

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

Legend:

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

    r871 r1001  
    8383
    8484#include "util/Math.h"
    85 #include "util/Convert.h"
    8685#include "util/Sleep.h"
    8786#include "util/String2Number.h"
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r994 r1001  
    297297    }
    298298
    299     bool CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
     299    Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
    300300    {
    301301        CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor;
    302302        CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor;
    303         return true;
     303        return (*executor);
    304304    }
    305305
  • code/branches/core2/src/orxonox/core/CommandExecutor.h

    r994 r1001  
    139139            static CommandEvaluation evaluate(const std::string& command);
    140140
    141             static bool addConsoleCommandShortcut(ExecutorStatic* executor);
     141            static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
    142142            static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);
    143143            static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);
  • code/branches/core2/src/orxonox/core/ConsoleCommand.h

    r993 r1001  
    5050
    5151#define ConsoleCommandShortcutGeneric(fakevariable, executor) \
    52     bool fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)
     52    Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)
    5353
    5454
  • code/branches/core2/src/orxonox/core/Functor.h

    r967 r1001  
    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; \
    327330                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
     331                std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" << std::endl; \
    328332            } \
    329333    \
  • code/branches/core2/src/orxonox/objects/Tickable.cc

    r871 r1001  
    11#include "core/CoreIncludes.h"
     2#include "core/ConsoleCommand.h"
    23#include "Tickable.h"
    34
    45namespace orxonox
    56{
     7    ConsoleCommandShortcutExtern(slomo, AccessLevel::Offline).setDefaultValue(0, 1.0);
     8    ConsoleCommandShortcutExtern(setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0);
     9
     10    static float timefactor = 1.0;
     11    void slomo(float factor)
     12    {
     13        setTimeFactor(factor);
     14    }
     15    void setTimeFactor(float factor)
     16    {
     17        timefactor = factor;
     18    }
     19    float getTimeFactor()
     20    {
     21        return timefactor;
     22    }
     23
    624    /**
    725        @brief Constructor: Registers the object in the Tickable-list
  • code/branches/core2/src/orxonox/objects/Tickable.h

    r871 r1001  
    5050    class TickFrameListener; // Forward declaration
    5151
     52    void slomo(float factor);
     53    void setTimeFactor(float factor = 1.0);
     54    float getTimeFactor();
     55
    5256    //! The Tickable interface provides a tick(dt) function, that gets called every frame.
    5357    class _OrxonoxExport Tickable : virtual public OrxonoxClass
     
    7175            bool frameStarted(const Ogre::FrameEvent &evt)
    7276            {
     77                float dt = evt.timeSinceLastFrame * getTimeFactor();
    7378                // Iterate through all Tickables and call their tick(dt) function
    7479                for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
    75                     (it++)->tick(evt.timeSinceLastFrame);
     80                    (it++)->tick(dt);
    7681
    7782                return FrameListener::frameStarted(evt);
  • code/branches/core2/src/orxonox/tools/Timer.h

    r995 r1001  
    6363#include "OrxonoxPrereqs.h"
    6464#include "core/CorePrereqs.h"
     65#include "../objects/Tickable.h"
    6566
    6667namespace orxonox
     
    200201            bool frameStarted(const Ogre::FrameEvent &evt)
    201202            {
     203                float dt = evt.timeSinceLastFrame * getTimeFactor();
    202204                // Iterate through all Timers
    203205                for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; )
     
    206208                    {
    207209                        // If active: Decrease the timer by the duration of the last frame
    208                         it->time_ -= evt.timeSinceLastFrame;
     210                        it->time_ -= dt;
    209211
    210212                        if (it->time_ <= 0)
  • code/branches/core2/src/util/Convert.h

    r994 r1001  
    4141#include "MultiTypeMath.h"
    4242
    43 // DEFAULT CLASS
    44 template <typename FromType, typename ToType>
    45 class Converter
    46 {
    47   public:
    48     bool operator()(ToType* output, const FromType& input) const
    49     {
    50       return false;
    51     }
    52 };
    53 
    54 // PARTIAL SPECIALIZATION TO CONVERT TO STRINGS
    55 template<typename FromType>
    56 class Converter<FromType, std::string>
    57 {
    58   public:
    59     bool operator()(std::string* output, const FromType& input) const
    60     {
    61       std::ostringstream oss;
    62       if (oss << input)
    63       {
     43
     44//////////
     45// Main //
     46//////////
     47/*
     48enum ConversionPreference
     49{
     50    CP_ToType,
     51    CP_FromType
     52};
     53
     54// Helper classes to determine the preferred partial template specialization
     55class _AnyType_  {};
     56class _ToType_   {} static __to__;
     57class _FromType_ {} static __from__;
     58class _Explicit_ {} static __explicit__;
     59
     60
     61// The default convert functions
     62template <class FromType, class ToType>
     63static bool convert(ToType* output, const FromType& input, _ToType_* type)
     64{ std::cout << "default to" << std::endl; return false; }
     65template <class FromType, class ToType>
     66static bool convert(ToType* output, const FromType& input, _FromType_* type)
     67{ std::cout << "default from" << std::endl; return false; }
     68template <class FromType, class ToType>
     69static bool convert(ToType* output, const FromType& input, _Explicit_* type)
     70{ std::cout << "default explicit" << std::endl; return false; }
     71
     72
     73// The default convert function if both types are the same
     74template <class BothTypes>
     75static 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)
     80template <class FromType, class ToType, class Type>
     81static bool convertDefault(ToType* output, const FromType& input, Type* type)
     82{ return false; }
     83#define CONVERT_PRIMITIVE_DEFAULT(primitive) \
     84template <class FromType> static bool convertDefault(primitive* output, const FromType& input, _ToType_* type) { return convertDefault(output, input, &__from__); } \
     85template <class ToType>   static bool convertDefault(ToType* output, const primitive& input, _FromType_* type) { (*output) = (ToType)input; return true; }
     86CONVERT_PRIMITIVE_DEFAULT(int)
     87CONVERT_PRIMITIVE_DEFAULT(unsigned int)
     88CONVERT_PRIMITIVE_DEFAULT(char)
     89CONVERT_PRIMITIVE_DEFAULT(unsigned char)
     90CONVERT_PRIMITIVE_DEFAULT(short)
     91CONVERT_PRIMITIVE_DEFAULT(unsigned short)
     92CONVERT_PRIMITIVE_DEFAULT(long)
     93CONVERT_PRIMITIVE_DEFAULT(unsigned long)
     94CONVERT_PRIMITIVE_DEFAULT(float)
     95CONVERT_PRIMITIVE_DEFAULT(double)
     96CONVERT_PRIMITIVE_DEFAULT(long double)
     97CONVERT_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
     104template<class FromType, class ToType>
     105static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
     106{
     107std::cout << "1_1\n";
     108    if (convert(output, input, &__explicit__))
     109        return true;
     110
     111std::cout << "1_2\n";
     112    if (preference == CP_ToType)
     113    {
     114std::cout << "1_3\n";
     115        if (convert(output, input, &__to__))
     116            return true;
     117std::cout << "1_4\n";
     118        if (convert(output, input, &__from__))
     119            return true;
     120std::cout << "1_5\n";
     121    }
     122    else
     123    {
     124std::cout << "1_6\n";
     125        if (convert(output, input, &__from__))
     126            return true;
     127std::cout << "1_7\n";
     128        if (convert(output, input, &__to__))
     129            return true;
     130std::cout << "1_8\n";
     131    }
     132std::cout << "1_9\n";
     133    return convertDefault(output, input, &__to__);
     134}
     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    }
     303
     304
     305// Helper function: Calls convertValue with and without default value and returns true if the conversion was successful
     306template<class FromType, class ToType>
     307static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType)
     308{
     309    return convertValue(output, input, preference);
     310}
     311template<class FromType, class ToType>
     312static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_ToType)
     313{
     314    if (convertValue(output, input, preference))
     315        return true;
     316
     317    (*output) = fallback;
     318    return false;
     319}
     320
     321// Helper function: Calls convertValue with and without default value and returns the converted value
     322template<class FromType, class ToType>
     323static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_ToType)
     324{
     325    ToType output = ToType();
     326    ConvertValue(&output, input, preference);
     327    return output;
     328}
     329template<class FromType, class ToType>
     330static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_ToType)
     331{
     332    ToType output = fallback;
     333    ConvertValue(&output, input, fallback, preference);
     334    return output;
     335}
     336
     337/////////////////////
     338// SPECIALISATIONS //
     339/////////////////////
     340
     341/*
     342template <class FromType>
     343static bool convertDefault(primitive* output, const FromType& input, _ToType_* type)
     344{
     345
     346}
     347
     348template <class ToType>
     349static bool convertDefault(ToType* output, const primitive& input, _FromType_* type)
     350{
     351
     352}
     353
     354
     355template <>
     356static bool convertDefault(ToType* output, const FromType& input, _Explicit_* type)
     357{
     358
     359}
     360*/
     361
     362////////////
     363// String //
     364////////////
     365
     366// convert to string
     367template <class FromType>
     368static bool convert(std::string* output, const FromType& input, _ToType_* type)
     369{
     370    std::ostringstream oss;
     371    if (oss << input)
     372    {
    64373        (*output) = oss.str();
    65374        return true;
    66       }
    67       else
     375    }
     376    else
    68377        return false;
    69     }
    70 };
    71 
    72 // PARTIAL SPECIALIZATION TO CONVERT FROM STRING
    73 template<typename ToType>
    74 class Converter<std::string, ToType>
    75 {
    76   public:
    77     bool operator()(ToType* output, const std::string& input) const
    78     {
    79       std::istringstream iss(input);
    80       if (iss >> (*output))
    81         return true;
    82       else
     378}
     379
     380// convert from string
     381template <class ToType>
     382static 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
    83388        return false;
    84     }
    85 };
    86 
    87 // FUNCTION SO WE DO NOT HAVE TO TELL THE COMPILER ABOUT THE TYPE
    88 template<typename FromType, typename ToType>
    89 static bool ConvertValue(ToType* output, const FromType& input)
    90 {
    91   Converter<FromType, ToType> converter;
    92   return converter(output, input);
    93 }
    94 
    95 // THE SAME, BUT WITH DEFAULT VALUE
    96 template<typename FromType, typename ToType>
    97 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)
    98 {
    99   Converter<FromType, ToType> converter;
    100   if (converter(output, input))
    101     return true;
    102 
    103   (*output) = fallback;
    104   return false;
    105 }
    106 
    107 // THE SAME LIKE BEFORE, BUT NEEDS NO POINTER TO THE OUTPUT
    108 template<typename FromType, typename ToType>
    109 static ToType ConvertValueAndReturn(const FromType& input)
    110 {
    111   ToType output = ToType();
    112   ConvertValue(&output, input);
    113   return output;
    114 }
    115 
    116 // THE SAME, BUT WITH DEFAULT VALUE
    117 template<typename FromType, typename ToType>
    118 static ToType ConvertValueAndReturn(const FromType& input, const ToType& fallback)
    119 {
    120   ToType output = fallback;
    121   ConvertValue(&output, input, fallback);
    122   return output;
    123 }
    124 
    125 //////////////////////////
    126 // MORE SPECIALISATIONS //
    127 //////////////////////////
    128 
    129 // STRING TO STRING
    130 template<>
    131 class Converter<std::string, std::string>
    132 {
    133   public:
    134     bool operator()(std::string* output, const std::string& input) const
    135     {
    136         (*output) = std::string(input);
    137         return true;
    138     }
    139 };
     389}
     390
    140391
    141392////////////////
     
    143394////////////////
    144395
    145 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEPRIMITIVE
    146 template<typename ToType>
    147 class Converter<MultiTypePrimitive, ToType>
    148 {
    149   public:
    150     bool operator()(ToType* output, const MultiTypePrimitive& input) const
    151     {
    152       if (input.getType() == MT_void)
     396// convert from MultiTypePrimitive
     397template <class ToType>
     398static bool convert(ToType* output, const MultiTypePrimitive& input, _FromType_* type)
     399{
     400    if (input.getType() == MT_void)
    153401        return ConvertValue(output, input.getVoid());
    154       else if (input.getType() == MT_int)
     402    else if (input.getType() == MT_int)
    155403        return ConvertValue(output, input.getInt());
    156       else if (input.getType() == MT_uint)
     404    else if (input.getType() == MT_uint)
    157405        return ConvertValue(output, input.getUnsignedInt());
    158       else if (input.getType() == MT_char)
     406    else if (input.getType() == MT_char)
    159407        return ConvertValue(output, input.getChar());
    160       else if (input.getType() == MT_uchar)
     408    else if (input.getType() == MT_uchar)
    161409        return ConvertValue(output, input.getUnsignedChar());
    162       else if (input.getType() == MT_short)
     410    else if (input.getType() == MT_short)
    163411        return ConvertValue(output, input.getShort());
    164       else if (input.getType() == MT_ushort)
     412    else if (input.getType() == MT_ushort)
    165413        return ConvertValue(output, input.getUnsignedShort());
    166       else if (input.getType() == MT_long)
     414    else if (input.getType() == MT_long)
    167415        return ConvertValue(output, input.getLong());
    168       else if (input.getType() == MT_ulong)
     416    else if (input.getType() == MT_ulong)
    169417        return ConvertValue(output, input.getUnsignedLong());
    170       else if (input.getType() == MT_float)
     418    else if (input.getType() == MT_float)
    171419        return ConvertValue(output, input.getFloat());
    172       else if (input.getType() == MT_double)
     420    else if (input.getType() == MT_double)
    173421        return ConvertValue(output, input.getDouble());
    174       else if (input.getType() == MT_longdouble)
     422    else if (input.getType() == MT_longdouble)
    175423        return ConvertValue(output, input.getLongDouble());
    176       else if (input.getType() == MT_bool)
     424    else if (input.getType() == MT_bool)
    177425        return ConvertValue(output, input.getBool());
    178       else
     426    else
    179427        return false;
    180     }
    181 };
    182 template<>
    183 class Converter<MultiTypePrimitive, std::string>
    184 {
    185   public:
    186     bool operator()(std::string* output, const MultiTypePrimitive& input) const
    187     {
    188       if (input.getType() == MT_void)
    189         return ConvertValue(output, input.getVoid());
    190       else if (input.getType() == MT_int)
    191         return ConvertValue(output, input.getInt());
    192       else if (input.getType() == MT_uint)
    193         return ConvertValue(output, input.getUnsignedInt());
    194       else if (input.getType() == MT_char)
    195         return ConvertValue(output, input.getChar());
    196       else if (input.getType() == MT_uchar)
    197         return ConvertValue(output, input.getUnsignedChar());
    198       else if (input.getType() == MT_short)
    199         return ConvertValue(output, input.getShort());
    200       else if (input.getType() == MT_ushort)
    201         return ConvertValue(output, input.getUnsignedShort());
    202       else if (input.getType() == MT_long)
    203         return ConvertValue(output, input.getLong());
    204       else if (input.getType() == MT_ulong)
    205         return ConvertValue(output, input.getUnsignedLong());
    206       else if (input.getType() == MT_float)
    207         return ConvertValue(output, input.getFloat());
    208       else if (input.getType() == MT_double)
    209         return ConvertValue(output, input.getDouble());
    210       else if (input.getType() == MT_longdouble)
    211         return ConvertValue(output, input.getLongDouble());
    212       else if (input.getType() == MT_bool)
    213         return ConvertValue(output, input.getBool());
    214       else
    215         return false;
    216     }
    217 };
    218 
    219 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPESTRING
    220 template<typename ToType>
    221 class Converter<MultiTypeString, ToType>
    222 {
    223   public:
    224     bool operator()(ToType* output, const MultiTypeString& input) const
    225     {
    226       if (input.getType() == MT_constchar)
     428}
     429
     430// convert from MultiTypeString
     431template <class ToType>
     432static bool convert(ToType* output, const MultiTypeString& input, _FromType_* type)
     433{
     434    if (input.getType() == MT_constchar)
    227435        return ConvertValue(output, input.getConstChar());
    228       else if (input.getType() == MT_string)
     436    else if (input.getType() == MT_string)
    229437        return ConvertValue(output, input.getString());
    230       else if (input.getType() == MT_xmlelement)
    231         return ConvertValue(output, input.getXMLElement());
    232       else
     438    else
    233439        return ConvertValue(output, (MultiTypePrimitive)input);
    234     }
    235 };
    236 template<>
    237 class Converter<MultiTypeString, std::string>
    238 {
    239   public:
    240     bool operator()(std::string* output, const MultiTypeString& input) const
    241     {
    242       if (input.getType() == MT_constchar)
    243         return ConvertValue(output, input.getConstChar());
    244       else if (input.getType() == MT_string)
    245         return ConvertValue(output, input.getString());
    246       else if (input.getType() == MT_xmlelement)
    247         return ConvertValue(output, input.getXMLElement());
    248       else
    249         return ConvertValue(output, (MultiTypePrimitive)input);
    250     }
    251 };
    252 
    253 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEMATH
    254 template<typename ToType>
    255 class Converter<MultiTypeMath, ToType>
    256 {
    257   public:
    258     bool operator()(ToType* output, const MultiTypeMath& input) const
    259     {
    260       if (input.getType() == MT_vector2)
    261         return ConvertValue(output, input.getVector2());
    262       else if (input.getType() == MT_vector3)
    263         return ConvertValue(output, input.getVector3());
    264       else if (input.getType() == MT_quaternion)
    265         return ConvertValue(output, input.getQuaternion());
    266       else if (input.getType() == MT_colourvalue)
    267         return ConvertValue(output, input.getColourValue());
    268       else if (input.getType() == MT_radian)
     440}
     441
     442// convert from MultiTypeMath
     443template <class ToType>
     444static 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)
    269455        return ConvertValue(output, input.getRadian());
    270       else if (input.getType() == MT_degree)
     456    else if (input.getType() == MT_degree)
    271457        return ConvertValue(output, input.getDegree());
    272       else
     458    else
    273459        return ConvertValue(output, (MultiTypeString)input);
    274     }
    275 };
    276 template<>
    277 class Converter<MultiTypeMath, std::string>
    278 {
    279   public:
    280     bool operator()(std::string* output, const MultiTypeMath& input) const
    281     {
    282       if (input.getType() == MT_vector2)
    283         return ConvertValue(output, input.getVector2());
    284       else if (input.getType() == MT_vector3)
    285         return ConvertValue(output, input.getVector3());
    286       else if (input.getType() == MT_quaternion)
    287         return ConvertValue(output, input.getQuaternion());
    288       else if (input.getType() == MT_colourvalue)
    289         return ConvertValue(output, input.getColourValue());
    290       else if (input.getType() == MT_radian)
    291         return ConvertValue(output, input.getRadian());
    292       else if (input.getType() == MT_degree)
    293         return ConvertValue(output, input.getDegree());
    294       else
    295         return ConvertValue(output, (MultiTypeString)input);
    296     }
    297 };
     460}
    298461
    299462
     
    304467// Vector2 to std::string
    305468template <>
     469static 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
     482template <>
    306483class Converter<orxonox::Vector2, std::string>
    307484{
     
    319496    }
    320497};
    321 
     498*/
     499// Vector3 to std::string
     500template <>
     501static 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/*
    322513// Vector3 to std::string
    323514template <>
     
    337528    }
    338529};
    339 
     530*/
     531// Vector4 to std::string
     532template <>
     533static 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/*
    340544// Vector4 to std::string
    341545template <>
     
    355559    }
    356560};
    357 
     561*/
     562// Quaternion to std::string
     563template <>
     564static 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/*
    358575// Quaternion to std::string
    359576template <>
     
    373590    }
    374591};
    375 
     592*/
     593// ColourValue to std::string
     594template <>
     595static 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/*
    376606// ColourValue to std::string
    377607template <>
     
    391621    }
    392622};
     623*/
    393624
    394625
     
    399630// std::string to Vector2
    400631template <>
     632static 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
     651template <>
    401652class Converter<std::string, orxonox::Vector2>
    402653{
     
    422673    }
    423674};
    424 
     675*/
     676// std::string to Vector3
     677template <>
     678static 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/*
    425698// std::string to Vector3
    426699template <>
     
    450723    }
    451724};
    452 
     725*/
     726// std::string to Vector4
     727template <>
     728static 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/*
    453750// std::string to Vector4
    454751template <>
     
    480777    }
    481778};
    482 
     779*/
     780// std::string to Quaternion
     781template <>
     782static 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/*
    483804// std::string to Quaternion
    484805template <>
     
    510831    }
    511832};
    512 
     833*/
     834// std::string to ColourValue
     835template <>
     836static 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/*
    513858// std::string to ColourValue
    514859template <>
     
    540885    }
    541886};
     887*/
     888
    542889
    543890#endif /* _Convert_H__ */
  • code/branches/core2/src/util/MultiTypeMath.cc

    r960 r1001  
    8989
    9090MultiTypeMath::operator void*() const
    91 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeMath, void*>(*this, 0); }
     91{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeMath, void*>(*this, 0); }
    9292MultiTypeMath::operator int() const
    93 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this, 0); }
     93{ return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeMath, int>(*this, 0); }
    9494MultiTypeMath::operator unsigned int() const
    95 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeMath, unsigned int>(*this, 0); }
     95{ return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeMath, unsigned int>(*this, 0); }
    9696MultiTypeMath::operator char() const
    97 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeMath, char>(*this, 0); }
     97{ return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeMath, char>(*this, 0); }
    9898MultiTypeMath::operator unsigned char() const
    99 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeMath, unsigned char>(*this, 0); }
     99{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeMath, unsigned char>(*this, 0); }
    100100MultiTypeMath::operator short() const
    101 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeMath, short>(*this, 0); }
     101{ return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeMath, short>(*this, 0); }
    102102MultiTypeMath::operator unsigned short() const
    103 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeMath, unsigned short>(*this, 0); }
     103{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeMath, unsigned short>(*this, 0); }
    104104MultiTypeMath::operator long() const
    105 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeMath, long>(*this, 0); }
     105{ return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeMath, long>(*this, 0); }
    106106MultiTypeMath::operator unsigned long() const
    107 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeMath, unsigned long>(*this, 0); }
     107{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeMath, unsigned long>(*this, 0); }
    108108MultiTypeMath::operator float() const
    109 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeMath, float>(*this, 0); }
     109{ return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeMath, float>(*this, 0); }
    110110MultiTypeMath::operator double() const
    111 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeMath, double>(*this, 0); }
     111{ return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeMath, double>(*this, 0); }
    112112MultiTypeMath::operator long double() const
    113 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeMath, long double>(*this, 0); }
     113{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeMath, long double>(*this, 0); }
    114114MultiTypeMath::operator bool() const
    115 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeMath, bool>(*this, 0); }
     115{ return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeMath, bool>(*this, 0); }
    116116MultiTypeMath::operator std::string() const
    117 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this); }
     117{ return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this); }
    118118MultiTypeMath::operator const char*() const
    119 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this)).c_str(); }
     119{ return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this)).c_str(); }
    120120MultiTypeMath::operator orxonox::Vector2() const
    121 { return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector2>(*this); }
    122 MultiTypeMath::operator orxonox::Element() const
    123 { return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Element>(*this); }
     121{ return (this->type_ == MT_vector2) ? this->vector2_ : getConvertedValue<MultiTypeMath, orxonox::Vector2>(*this); }
    124122MultiTypeMath::operator orxonox::Vector3() const
    125 { return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector3>(*this); }
     123{ return (this->type_ == MT_vector3) ? this->vector3_ : getConvertedValue<MultiTypeMath, orxonox::Vector3>(*this); }
    126124MultiTypeMath::operator orxonox::Quaternion() const
    127 { return (this->type_ == MT_quaternion) ? this->quaternion_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Quaternion>(*this); }
     125{ return (this->type_ == MT_quaternion) ? this->quaternion_ : getConvertedValue<MultiTypeMath, orxonox::Quaternion>(*this); }
    128126MultiTypeMath::operator orxonox::ColourValue() const
    129 { return (this->type_ == MT_colourvalue) ? this->colourvalue_ : ConvertValueAndReturn<MultiTypeMath, orxonox::ColourValue>(*this); }
     127{ return (this->type_ == MT_colourvalue) ? this->colourvalue_ : getConvertedValue<MultiTypeMath, orxonox::ColourValue>(*this); }
    130128MultiTypeMath::operator orxonox::Radian() const
    131 { return (this->type_ == MT_radian) ? this->radian_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Radian>(*this); }
     129{ return (this->type_ == MT_radian) ? this->radian_ : getConvertedValue<MultiTypeMath, orxonox::Radian>(*this); }
    132130MultiTypeMath::operator orxonox::Degree() const
    133 { return (this->type_ == MT_degree) ? this->degree_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Degree>(*this); }
     131{ return (this->type_ == MT_degree) ? this->degree_ : getConvertedValue<MultiTypeMath, orxonox::Degree>(*this); }
    134132
    135133void MultiTypeMath::setValue(const MultiTypeMath& mtm)
     
    167165
    168166    if (this->type_ == MT_vector2)
    169         ConvertValue(&output, this->vector2_);
     167        ConvertValue(&output, this->vector2_, CP_FromType);
    170168    else if (this->type_ == MT_vector3)
    171         ConvertValue(&output, this->vector3_);
     169        ConvertValue(&output, this->vector3_, CP_FromType);
    172170    else if (this->type_ == MT_colourvalue)
    173         ConvertValue(&output, this->colourvalue_);
     171    { std::cout << "3_1\n";
     172        ConvertValue(&output, this->colourvalue_, CP_FromType);}
    174173    else if (this->type_ == MT_quaternion)
    175         ConvertValue(&output, this->quaternion_);
     174        ConvertValue(&output, this->quaternion_, CP_FromType);
    176175    else if (this->type_ == MT_radian)
    177176        ConvertValue(&output, this->radian_);
     
    187186{
    188187    if (this->type_ == MT_vector2)
    189         return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0));
     188        return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0), CP_FromType);
    190189    else if (this->type_ == MT_vector3)
    191         return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0));
     190        return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0), CP_FromType);
    192191    else if (this->type_ == MT_colourvalue)
    193         return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0));
     192    { std::cout << "4_1\n";
     193        return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0), CP_FromType); }
    194194    else if (this->type_ == MT_quaternion)
    195         return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0));
     195        return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0), CP_FromType);
    196196    else if (this->type_ == MT_radian)
    197197        return ConvertValue(&this->radian_, value, orxonox::Radian(0));
  • code/branches/core2/src/util/MultiTypeMath.h

    r947 r1001  
    5454        inline MultiTypeMath(const char*             value) : MultiTypeString(value) {}
    5555        inline MultiTypeMath(const std::string&      value) : MultiTypeString(value) {}
    56         inline MultiTypeMath(const orxonox::Element& value) : MultiTypeString(value) {}
    5756        inline MultiTypeMath(const orxonox::Vector2&     value) { this->setValue(value); }
    5857        inline MultiTypeMath(const orxonox::Vector3&     value) { this->setValue(value); }
     
    106105        virtual operator std::string()          const;
    107106        virtual operator const char*()          const;
    108         virtual operator orxonox::Element()     const;
    109107        virtual operator orxonox::Vector2()     const;
    110108        virtual operator orxonox::Vector3()     const;
  • code/branches/core2/src/util/MultiTypePrimitive.cc

    r960 r1001  
    135135
    136136MultiTypePrimitive::operator void*() const
    137 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypePrimitive, void*>(*this, 0); }
     137{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypePrimitive, void*>(*this, 0); }
    138138MultiTypePrimitive::operator int() const
    139 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this, 0); }
     139{ return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypePrimitive, int>(*this, 0); }
    140140MultiTypePrimitive::operator unsigned int() const
    141 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this, 0); }
     141{ return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypePrimitive, unsigned int>(*this, 0); }
    142142MultiTypePrimitive::operator char() const
    143 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this, 0); }
     143{ return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypePrimitive, char>(*this, 0); }
    144144MultiTypePrimitive::operator unsigned char() const
    145 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this, 0); }
     145{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypePrimitive, unsigned char>(*this, 0); }
    146146MultiTypePrimitive::operator short() const
    147 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this, 0); }
     147{ return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypePrimitive, short>(*this, 0); }
    148148MultiTypePrimitive::operator unsigned short() const
    149 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this, 0); }
     149{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypePrimitive, unsigned short>(*this, 0); }
    150150MultiTypePrimitive::operator long() const
    151 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this, 0); }
     151{ return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypePrimitive, long>(*this, 0); }
    152152MultiTypePrimitive::operator unsigned long() const
    153 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this, 0); }
     153{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypePrimitive, unsigned long>(*this, 0); }
    154154MultiTypePrimitive::operator float() const
    155 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this, 0); }
     155{ return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypePrimitive, float>(*this, 0); }
    156156MultiTypePrimitive::operator double() const
    157 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this, 0); }
     157{ return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypePrimitive, double>(*this, 0); }
    158158MultiTypePrimitive::operator long double() const
    159 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this, 0); }
     159{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypePrimitive, long double>(*this, 0); }
    160160MultiTypePrimitive::operator bool() const
    161 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this, 0); }
     161{ return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypePrimitive, bool>(*this, 0); }
    162162
    163163void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp)
  • code/branches/core2/src/util/MultiTypeString.cc

    r960 r1001  
    4343        else if (this->type_ == MT_string)
    4444            return (this->string_ == mts.string_);
    45         else if (this->type_ == MT_xmlelement)
    46             return (&this->xmlelement_ == &mts.xmlelement_);
    4745    }
    4846
     
    5856        else if (this->type_ == MT_string)
    5957            return (this->string_ != mts.string_);
    60         else if (this->type_ == MT_xmlelement)
    61             return (&this->xmlelement_ != &mts.xmlelement_);
    6258    }
    6359
     
    6662
    6763MultiTypeString::operator void*() const
    68 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeString, void*>(*this, 0); }
     64{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeString, void*>(*this, 0); }
    6965MultiTypeString::operator int() const
    70 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this, 0); }
     66{ return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeString, int>(*this, 0); }
    7167MultiTypeString::operator unsigned int() const
    72 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeString, unsigned int>(*this, 0); }
     68{ return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeString, unsigned int>(*this, 0); }
    7369MultiTypeString::operator char() const
    74 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeString, char>(*this, 0); }
     70{ return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeString, char>(*this, 0); }
    7571MultiTypeString::operator unsigned char() const
    76 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeString, unsigned char>(*this, 0); }
     72{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeString, unsigned char>(*this, 0); }
    7773MultiTypeString::operator short() const
    78 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeString, short>(*this, 0); }
     74{ return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeString, short>(*this, 0); }
    7975MultiTypeString::operator unsigned short() const
    80 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeString, unsigned short>(*this, 0); }
     76{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeString, unsigned short>(*this, 0); }
    8177MultiTypeString::operator long() const
    82 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeString, long>(*this, 0); }
     78{ return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeString, long>(*this, 0); }
    8379MultiTypeString::operator unsigned long() const
    84 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeString, unsigned long>(*this, 0); }
     80{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeString, unsigned long>(*this, 0); }
    8581MultiTypeString::operator float() const
    86 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeString, float>(*this, 0); }
     82{ return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeString, float>(*this, 0); }
    8783MultiTypeString::operator double() const
    88 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeString, double>(*this, 0); }
     84{ return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeString, double>(*this, 0); }
    8985MultiTypeString::operator long double() const
    90 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeString, long double>(*this, 0); }
     86{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeString, long double>(*this, 0); }
    9187MultiTypeString::operator bool() const
    92 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeString, bool>(*this, 0); }
     88{ return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeString, bool>(*this, 0); }
    9389MultiTypeString::operator std::string() const
    94 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this); }
     90{ return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this); }
    9591MultiTypeString::operator const char*() const
    96 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this)).c_str(); }
    97 MultiTypeString::operator orxonox::Element() const
    98 { return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeString, orxonox::Element>(*this); }
     92{ return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this)).c_str(); }
    9993
    10094void MultiTypeString::setValue(const MultiTypeString& mts)
     
    110104    else if (this->type_ == MT_string)
    111105        return "string";
    112     else if (this->type_ == MT_xmlelement)
    113         return "XML-element";
    114106    else
    115107        return MultiTypePrimitive::getTypename();
     
    124116    else if (this->type_ == MT_string)
    125117        return this->string_;
    126     else if (this->type_ == MT_xmlelement)
    127         ConvertValue(&output, this->xmlelement_);
    128118    else
    129119        return MultiTypePrimitive::toString();
     
    138128    else if (this->type_ == MT_string)
    139129        this->string_ = value;
    140     else if (this->type_ == MT_xmlelement)
    141         return ConvertValue(&this->xmlelement_, value, orxonox::Element());
    142130    else
    143131        return MultiTypePrimitive::fromString(value);
  • code/branches/core2/src/util/MultiTypeString.h

    r947 r1001  
    3333#include <iostream>
    3434#include "UtilPrereqs.h"
    35 #include "XMLIncludes.h"
    36 #include "tinyxml/ticpp.h"
    3735
    3836#include "MultiTypePrimitive.h"
     
    5755        inline MultiTypeString(const char*           value)   { this->setValue(value); }
    5856        inline MultiTypeString(const std::string&    value)   { this->setValue(value); }
    59         inline MultiTypeString(const orxonox::Element& value) { this->setValue(value); }
    6057        inline MultiTypeString(const MultiTypeString& mts)    { this->setValue(mts);   }
    6158        virtual inline ~MultiTypeString() {}
     
    6461        inline MultiTypeString& operator=(const char*             value)   { this->setValue(value); return *this; }
    6562        inline MultiTypeString& operator=(const std::string&      value)   { this->setValue(value); return *this; }
    66         inline MultiTypeString& operator=(const orxonox::Element& value)   { this->setValue(value); return *this; }
    6763        inline MultiTypeString& operator=(const MultiTypeString& mts)      { this->setValue(mts);   return *this; }
    6864
     
    7066        inline bool operator==(const char*             value) const { return (this->string_      == std::string(value)); }
    7167        inline bool operator==(const std::string&      value) const { return (this->string_      == value);              }
    72         inline bool operator==(const orxonox::Element& value) const { return (&this->xmlelement_ == &value);             }
    7368        bool operator==(const MultiTypeString& mts) const;
    7469
     
    7671        inline bool operator!=(const char*             value) const { return (this->string_      != std::string(value)); }
    7772        inline bool operator!=(const std::string&      value) const { return (this->string_      != value);              }
    78         inline bool operator!=(const orxonox::Element& value) const { return (&this->xmlelement_ != &value);             }
    7973        bool operator!=(const MultiTypeString& mts) const;
    8074
     
    9488        virtual operator std::string()          const;
    9589        virtual operator const char*()          const;
    96         virtual operator orxonox::Element()     const;
    9790
    9891        using MultiTypePrimitive::setValue;
    9992        inline void setValue(const char*             value) { this->type_ = MT_string;     this->string_     = std::string(value); }
    10093        inline void setValue(const std::string&      value) { this->type_ = MT_string;     this->string_     = value;              }
    101         inline void setValue(const orxonox::Element& value) { this->type_ = MT_xmlelement; this->xmlelement_ = value;              }
    10294        void setValue(const MultiTypeString& mts);
    10395
    10496        inline std::string getString()          const { return this->string_;         }
    10597        inline const char*  getConstChar()      const { return this->string_.c_str(); }
    106         inline orxonox::Element getXMLElement() const { return this->xmlelement_;     }
    10798
    10899        inline std::string& getString()          { return this->string_;         }
    109100        inline const char*  getConstChar()       { return this->string_.c_str(); }
    110         inline orxonox::Element& getXMLElement() { return this->xmlelement_;     }
    111101
    112102        using MultiTypePrimitive::getValue;
    113103        inline void getValue(std::string*      variable) const { (*variable) = this->string_;         }
    114104        inline void getValue(const char**      variable) const { (*variable) = this->string_.c_str(); }
    115         inline void getValue(orxonox::Element* variable) const { (*variable) = this->xmlelement_;     }
    116105
    117106        virtual std::string getTypename() const;
     
    122111    protected:
    123112        std::string      string_;
    124         orxonox::Element xmlelement_;
    125113};
    126114
  • code/branches/core2/src/util/UtilPrereqs.h

    r871 r1001  
    6060//-----------------------------------------------------------------------
    6161class Convert;
    62 template <typename FromType, typename ToType>
    63 class Converter;
     62//template <typename FromType, typename ToType>
     63//class Converter;
    6464class MultiTypePrimitive;
    6565class MultiTypeString;
Note: See TracChangeset for help on using the changeset viewer.