Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2087 for code/trunk/src/util


Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (16 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
15 edited
3 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/util

  • code/trunk/src/util/CMakeLists.txt

    r1844 r2087  
    88  OutputBuffer.cc
    99  OutputHandler.cc
     10  SignalHandler.cc
    1011  String.cc
    1112  SubString.cc
  • code/trunk/src/util/Convert.h

    r1889 r2087  
    2121 *
    2222 *   Author:
     23 *      Reto Grieder
    2324 *      Fabian 'x3n' Landau
    2425 *      Benjamin Grauer
     
    2829
    2930/*!
    30     @file Convert.h
     31    @file
    3132    @brief Definition and Implementation of the Convert class.
    3233*/
    3334
    34 #ifndef _Convert_H__
    35 #define _Convert_H__
     35#ifndef _Converter_H__
     36#define _Converter_H__
    3637
    3738#include "UtilPrereqs.h"
     
    3940#include <string>
    4041#include <sstream>
     42#include <istream>
     43#include <ostream>
    4144#include <typeinfo>
    4245
    43 #include "Math.h"
    4446#include "Debug.h"
    45 #include "SubString.h"
    4647#include "String.h"
    4748
    48 // disable annoying warning about forcing value to boolean
     49// GCC generates warnings when implicitely casting from float to int for instance.
     50// This is however exactly what convertValue does, so we need to suppress these warnings.
     51// They only occur when using the ImplicitConversion template.
     52#if ORXONOX_COMPILER == ORXONOX_COMPILER_GNUC
     53#  pragma GCC system_header
     54#endif
     55
     56
     57///////////////////////////////////////////////
     58// Static detection for conversion functions //
     59///////////////////////////////////////////////
     60
     61/* The idea to use the sizeof() operator on return functions to determine function existance
     62   is described in 'Modern C++ design' by Alexandrescu (2001). */
     63
     64// disable warnings about possible loss of data
    4965#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
    50 #pragma warning(push)
    51 #pragma warning(disable:4100 4800)
     66#  pragma warning(push)
     67#  pragma warning(disable:4244)
    5268#endif
    5369
    54 
    55 //////////
    56 // MAIN //
    57 //////////
    58 
    59 // Enum to declare the wanted conversion preference in case of equal type-levels
    60 enum ConversionPreference
    61 {
    62     CP_PreferToType,
    63     CP_PreferFromType,
    64 };
    65 
    66 // Helper classes to determine the preferred partial template specialization
    67 class _ToType_   {};
    68 class _FromType_ {};
    69 class _Explicit_ {};
    70 
    71 
    72 // The default convert functions
    73 template <class FromType, class ToType, class Type>
    74 struct ConverterSpecialized
    75 {
    76     enum { specialized = false };
     70template <class FromType, class ToType>
     71class ImplicitConversion
     72{
     73private:
     74    ImplicitConversion(); ImplicitConversion(const ImplicitConversion&); ~ImplicitConversion();
     75    // Gets chosen only if there is an implicit conversion from FromType to ToType.
     76    static char test(ToType);
     77    // Accepts any argument. Why do we not use a template? The reason is that with templates,
     78    // the function above is only taken iff it is an exact type match. But since we want to
     79    // check for implicit conversion, we have to use the ellipsis.
     80    static long long test(...);
     81    static FromType object; // helper object to handle private c'tor and d'tor
     82public:
     83    // test(object) only has 'long long' return type iff the compiler doesn't choose test(...)
     84    enum { exists = (sizeof(test(object)) == sizeof(char)) };
     85};
     86
     87#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     88#  pragma warning(pop)
     89#endif
     90
     91
     92////////////////////////////////////
     93//// ACTUAL CONVERSION SEQUENCE ////
     94////////////////////////////////////
     95/*
     96    There is a distinct priority when choosing the right conversion function:
     97    Overwrite:
     98    1. (Partial) template specialisation of ConverterExplicit::convert()
     99    Fallbacks:
     100    2. Any possible implicit conversion. This includes 'FooBar' --> 'int' if FooBar defines operator float().
     101    3. Global or member operators for stringstream when converting from or to std::string (or FROM const char*)
     102    4. (Partial) template specialisation of ConverterFallback::convert()
     103    5. Function that simply displays "Could not convert value" with type information obtained from typeid().
     104
     105    Notes:
     106    There has to be an exact type match when using template specialisations.
     107    Template specialisations can be defined after including this file. Any implicit cast function or iostream
     108    operator has to be declared BEFORE this file gets parsed.
     109
     110    Defining your own functions:
     111    There are obviously 4 ways to specifiy a user defined conversion. What should I use?
     112
     113    Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from
     114    'MyClass' to 'MyClass' by using another explicit template specialisation to avoid ambiguities.
     115
     116    However if you want to overwrite an implicit conversion or an iostream operator, you really need to
     117    make use of ConverterExplicit.
     118*/
     119
     120namespace
     121{
     122    //! Little template that maps integers to entire types (Alexandrescu 2001)
     123    template <int I>
     124    struct Int2Type { };
     125}
     126
     127
     128///////////////////
     129// No Conversion //
     130///////////////////
     131
     132// Default template. No conversion available at all.
     133template <class FromType, class ToType>
     134struct ConverterFallback
     135{
    77136    static bool convert(ToType* output, const FromType& input)
    78137    {
    79         COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl;
     138        COUT(2) << "Could not convert value of type " << typeid(FromType).name()
     139                << " to type " << typeid(ToType).name() << std::endl;
    80140        return false;
    81141    }
    82142};
    83143
    84 
    85 // The default convert function if both types are the same
    86 template <class BothTypes>
    87 struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_>
    88 {
    89     enum { specialized = true };
    90     static bool convert(BothTypes* output, const BothTypes& input)
    91     { (*output) = input; return true; }
    92 };
    93 
    94 
    95 // The possible levels
    96 #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)
    97 #define __mid__  1 // Everything that has overloaded << and >> operators to operate on a std::stream
    98 #define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions
    99 
    100 // Defines the levels of all types: Default is __high__ so you don't have to define every high-level type
    101 template <class T> struct ConverterLevel              { enum { level = __high__ }; };
    102 template <> struct ConverterLevel<std::string>        { enum { level = __mid__ }; };
    103 template <> struct ConverterLevel<orxonox::Radian>    { enum { level = __mid__ }; };
    104 template <> struct ConverterLevel<orxonox::Degree>    { enum { level = __mid__ }; };
    105 template <> struct ConverterLevel<int>                { enum { level = __low__ }; };
    106 template <> struct ConverterLevel<unsigned int>       { enum { level = __low__ }; };
    107 template <> struct ConverterLevel<char>               { enum { level = __low__ }; };
    108 template <> struct ConverterLevel<unsigned char>      { enum { level = __low__ }; };
    109 template <> struct ConverterLevel<short>              { enum { level = __low__ }; };
    110 template <> struct ConverterLevel<unsigned short>     { enum { level = __low__ }; };
    111 template <> struct ConverterLevel<long>               { enum { level = __low__ }; };
    112 template <> struct ConverterLevel<unsigned long>      { enum { level = __low__ }; };
    113 template <> struct ConverterLevel<long long>          { enum { level = __low__ }; };
    114 template <> struct ConverterLevel<unsigned long long> { enum { level = __low__ }; };
    115 template <> struct ConverterLevel<float>              { enum { level = __low__ }; };
    116 template <> struct ConverterLevel<double>             { enum { level = __low__ }; };
    117 template <> struct ConverterLevel<long double>        { enum { level = __low__ }; };
    118 template <> struct ConverterLevel<bool>               { enum { level = __low__ }; };
    119 
    120 
    121 // Calculates the preference based on the levels of FromType and ToType
    122 template <int from, int to>
    123 struct ConverterPreference
    124 {
    125     enum
    126     {
    127         // The maximum of both levels: element of {0, 1, 2}
    128         // max 0: Both types are primitives or have a similar behaviour
    129         // max 1: At least one type is not a primitive, but both can be put on a std::stream
    130         // max 2: There is at least one generic type that needs specialized conversions
    131         max = (from > to) ? from : to,
    132 
    133         // The difference between both levels limited to +-1: element of {-1, 0, 1}
    134         // diff -1: The FromType has higher level than the ToType
    135         // diff  0: Both types have the same level
    136         // diff  1: The ToType has higher level than the FromType
    137         diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from)
    138     };
    139 };
    140 
    141 
    142 // The default conversion: This usually does nothing
    143 template <int max, class FromType, class ToType>
    144 struct ConverterDefault
     144// If all else fails, try a dynamic_cast for pointer types.
     145template <class FromType, class ToType>
     146struct ConverterFallback<FromType*, ToType*>
     147{
     148    static bool convert(ToType** output, FromType* const input)
     149    {
     150        ToType* temp = dynamic_cast<ToType*>(input);
     151        if (temp)
     152        {
     153            *output = temp;
     154            return true;
     155        }
     156        else
     157            return false;
     158    }
     159};
     160
     161
     162///////////////////////
     163// ConverterFallback //
     164///////////////////////
     165
     166// Default template for stringstream
     167template <class FromType, class ToType>
     168struct ConverterStringStream
    145169{
    146170    static bool convert(ToType* output, const FromType& input)
    147171    {
    148         COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl;
    149         return false;
    150     }
    151 };
    152 // 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>
    153 template <class FromType, class ToType>
    154 struct ConverterDefault<0, FromType, ToType>
    155 {
    156     static bool convert(ToType* output, const FromType& input)
    157     {
    158         (*output) = (ToType)input;
    159         return true;
    160     }
    161 };
    162 
    163 
    164 // Converter: Converts input of FromType into output of ToType
    165 template <int diff, int max, class FromType, class ToType, ConversionPreference pref>
    166 struct Converter
    167 {
    168     static bool convert(ToType* output, const FromType& input)
    169     {
    170         return false;
    171     }
    172 };
    173 // Converter: level{FromType} > level{ToType}
    174 template <int max, class FromType, class ToType, ConversionPreference pref>
    175 struct Converter<-1, max, FromType, ToType, pref>
    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)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
    178 // Converter: level{FromType} < level{ToType}
    179 template <int max, class FromType, class ToType, ConversionPreference pref>
    180 struct Converter<1, max, FromType, ToType, pref>
    181 {   static bool convert(ToType* output, const FromType& input)
    182     { 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)); } };
    183 // Converter: level{FromType} = level{ToType}
    184 // CP_PreferToType
    185 template <int max, class FromType, class ToType>
    186 struct Converter<0, max, FromType, ToType, CP_PreferToType>
    187 {   static bool convert(ToType* output, const FromType& input)
    188     { 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)); } };
    189 // CP_PreferFromType
    190 template <int max, class FromType, class ToType>
    191 struct Converter<0, max, FromType, ToType, CP_PreferFromType>
    192 {   static bool convert(ToType* output, const FromType& input)
    193     { 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)); } };
    194 
    195 
    196 // Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference
    197 template <class FromType, class ToType>
    198 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType)
    199 {
    200     return (preference == CP_PreferToType) ?
    201            Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff,
    202                      ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max,
    203                      FromType,
    204                      ToType,
    205                      CP_PreferToType>::convert(output, input)
    206          : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff,
    207                      ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max,
    208                      FromType,
    209                      ToType,
    210                      CP_PreferFromType>::convert(output, input);
    211 }
    212 
    213 
    214 //////////////////////
    215 // HELPER FUNCTIONS //
    216 //////////////////////
    217 
    218 // Helper function: Calls convertValue with and without default value and returns true if the conversion was successful
    219 template<class FromType, class ToType>
    220 static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType)
    221 {
    222     return convertValue(output, input, preference);
    223 }
    224 template<class FromType, class ToType>
    225 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType)
    226 {
    227     if (convertValue(output, input, preference))
    228         return true;
    229 
    230     (*output) = fallback;
    231     return false;
    232 }
    233 
    234 // Helper function: Calls convertValue with and without default value and returns the converted value
    235 template<class FromType, class ToType>
    236 static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType)
    237 {
    238     ToType output = ToType();
    239     ConvertValue(&output, input, preference);
    240     return output;
    241 }
    242 template<class FromType, class ToType>
    243 static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType)
    244 {
    245     ToType output = fallback;
    246     ConvertValue(&output, input, fallback, preference);
    247     return output;
    248 }
    249 
    250 
    251 /////////////////////
    252 // SPECIALIZATIONS //
    253 /////////////////////
     172        return ConverterFallback<FromType, ToType>::convert(output, input);
     173    }
     174};
     175
    254176
    255177/////////////
    256 // SAMPLES //
     178// OStream //
    257179/////////////
    258 /*
    259 // convert everything to xyz
     180
     181namespace fallbackTemplates
     182{
     183    template <class FromType>
     184    inline bool operator <<(std::ostream& outstream,  const FromType& input)
     185    {
     186        std::string temp;
     187        if (ConverterFallback<FromType, std::string>::convert(&temp, input))
     188        {
     189            std::operator <<(outstream, temp);
     190            return true;
     191        }
     192        else
     193            return false;
     194    }
     195}
     196
     197// template that evaluates whether we can convert to std::string via ostringstream
    260198template <class FromType>
    261 struct ConverterSpecialized<FromType, xyz, _ToType_>
    262 {
    263     enum { specialized = true };
    264     static bool convert(xyz* output, const FromType& input)
    265     { return ...; }
    266 };
    267 
    268 // convert xyz to everything
    269 template <class ToType>
    270 struct ConverterSpecialized<xyz, ToType, _FromType_>
    271 {
    272     enum { specialized = true };
    273     static bool convert(ToType* output, const xyz& input)
    274     { return ...; }
    275 };
    276 
    277 // convert abc to xyz
    278 template <>
    279 struct ConverterSpecialized<abc, xyz, _Explicit_>
    280 {
    281     enum { specialized = true };
    282     static bool convert(xyz* output, const abc& input)
    283     { return ...; }
    284 };
    285 */
    286 
    287 ////////////
    288 // STRING //
    289 ////////////
    290 
    291 // convert to string
    292 template <class FromType>
    293 struct ConverterSpecialized<FromType, std::string, _ToType_>
    294 {
    295     enum { specialized = true };
     199struct ConverterStringStream<FromType, std::string>
     200{
    296201    static bool convert(std::string* output, const FromType& input)
    297202    {
     203        using namespace fallbackTemplates;
     204        // this operator call only chooses fallbackTemplates::operator<< if there's no other fitting function
    298205        std::ostringstream oss;
    299206        if (oss << input)
     
    307214};
    308215
     216
     217/////////////
     218// IStream //
     219/////////////
     220
     221namespace fallbackTemplates
     222{
     223    template <class ToType>
     224    inline bool operator >>(std::istream& instream, ToType& output)
     225    {
     226        return ConverterFallback<std::string, ToType>
     227            ::convert(&output, static_cast<std::istringstream&>(instream).str());
     228    }
     229}
     230
     231// template that evaluates whether we can convert from std::string via ostringstream
     232template <class ToType>
     233struct ConverterStringStream<std::string, ToType>
     234{
     235    static bool convert(ToType* output, const std::string& input)
     236    {
     237        using namespace fallbackTemplates;
     238        std::istringstream iss(input);
     239        // this operator call only chooses fallbackTemplates::operator>> if there's no other fitting function
     240        if (iss >> (*output))
     241        {
     242            return true;
     243        }
     244        else
     245            return false;
     246    }
     247};
     248
     249
     250///////////////////
     251// Implicit Cast //
     252///////////////////
     253
     254// implicit cast not possible, try stringstream conversion next
     255template <class FromType, class ToType>
     256inline bool convertImplicitely(ToType* output, const FromType& input, ::Int2Type<false>)
     257{
     258    return ConverterStringStream<FromType, ToType>::convert(output, input);
     259}
     260
     261// We can cast implicitely
     262template <class FromType, class ToType>
     263inline bool convertImplicitely(ToType* output, const FromType& input, ::Int2Type<true>)
     264{
     265    (*output) = static_cast<ToType>(input);
     266    return true;
     267}
     268
     269
     270////////////////////////////////
     271// ConverterExplicit Fallback //
     272////////////////////////////////
     273
     274// Default template if no specialisation is available
     275template <class FromType, class ToType>
     276struct ConverterExplicit
     277{
     278    static bool convert(ToType* output, const FromType& input)
     279    {
     280        // Try implict cast and probe first. If a simple cast is not possible, it will not compile
     281        // We therefore have to out source it into another template function
     282        const bool probe = ImplicitConversion<FromType, ToType>::exists;
     283        return convertImplicitely(output, input, ::Int2Type<probe>());
     284    }
     285};
     286
     287
     288//////////////////////
     289// Public Functions //
     290//////////////////////
     291
     292/**
     293@brief
     294    Converts any value to any other as long as there exists a conversion.
     295    Otherwise, the conversion will generate a runtime warning and return false.
     296    For information about the different conversion methods (user defined too), see the section
     297    'Actual conversion sequence' in this file above.
     298*/
     299template <class FromType, class ToType>
     300inline bool convertValue(ToType* output, const FromType& input)
     301{
     302    return ConverterExplicit<FromType, ToType>::convert(output, input);
     303}
     304
     305// For compatibility reasons. The same, but with capital ConvertValue
     306template<class FromType, class ToType>
     307inline bool ConvertValue(ToType* output, const FromType& input)
     308{
     309    return convertValue(output, input);
     310}
     311
     312// Calls convertValue and returns true if the conversion was successful.
     313// Otherwise the fallback is used.
     314/**
     315@brief
     316    Converts any value to any other as long as there exists a conversion.
     317    Otherwise, the conversion will generate a runtime warning and return false.
     318    For information about the different conversion methods (user defined too), see the section
     319    'Actual conversion sequence' in this file above.
     320    If the conversion doesn't succeed, 'fallback' is written to '*output'.
     321@param fallback
     322    A default value that gets written to '*output' if there is no conversion.
     323*/
     324template<class FromType, class ToType>
     325inline bool convertValue(ToType* output, const FromType& input, const ToType& fallback)
     326{
     327    if (convertValue(output, input))
     328        return true;
     329    else
     330    {
     331        (*output) = fallback;
     332        return false;
     333    }
     334}
     335
     336// for compatibility reason. (capital 'c' in ConvertValue)
     337template<class FromType, class ToType>
     338inline bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)
     339{
     340    return convertValue(output, input, fallback);
     341}
     342
     343// Directly returns the converted value, even if the conversion was not successful.
     344template<class FromType, class ToType>
     345inline ToType getConvertedValue(const FromType& input)
     346{
     347    ToType output;
     348    convertValue(&output, input);
     349    return output;
     350}
     351
     352// Directly returns the converted value, but uses the fallback on failure.
     353template<class FromType, class ToType>
     354inline ToType getConvertedValue(const FromType& input, const ToType& fallback)
     355{
     356    ToType output;
     357    convertValue(&output, input, fallback);
     358    return output;
     359}
     360
     361// Like getConvertedValue, but the template argument order is in reverse.
     362// That means you can call it exactly like static_cast<ToType>(fromTypeValue).
     363template<class ToType, class FromType>
     364inline ToType omni_cast(const FromType& input)
     365{
     366    ToType output;
     367    convertValue(&output, input);
     368    return output;
     369}
     370
    309371// convert to string Shortcut
    310372template <class FromType>
    311 std::string convertToString(FromType value)
     373inline std::string convertToString(FromType value)
    312374{
    313375  return getConvertedValue<FromType, std::string>(value);
    314376}
    315377
    316 // convert from string
     378// convert from string Shortcut
    317379template <class ToType>
    318 struct ConverterSpecialized<std::string, ToType, _FromType_>
    319 {
    320     enum { specialized = true };
    321     static bool convert(ToType* output, const std::string& input)
    322     {
     380inline ToType convertFromString(std::string str)
     381{
     382  return getConvertedValue<std::string, ToType>(str);
     383}
     384
     385////////////////////////////////
     386// Special string conversions //
     387////////////////////////////////
     388
     389// Delegate conversion from const char* to std::string
     390template <class ToType>
     391struct ConverterExplicit<const char*, ToType>
     392{
     393    static bool convert(ToType* output, const char* input)
     394    {
     395        return convertValue<std::string, ToType>(output, input);
     396    }
     397};
     398
     399// These conversions would exhibit ambiguous << or >> operators when using stringstream
     400template <>
     401struct ConverterExplicit<char, std::string>
     402{
     403    static bool convert(std::string* output, const char input)
     404    {
     405        *output = std::string(1, input);
     406        return true;
     407    }
     408};
     409template <>
     410struct ConverterExplicit<unsigned char, std::string>
     411{
     412    static bool convert(std::string* output, const unsigned char input)
     413    {
     414        *output = std::string(1, input);
     415        return true;
     416    }
     417};
     418template <>
     419struct ConverterExplicit<std::string, char>
     420{
     421    static bool convert(char* output, const std::string input)
     422    {
     423        if (input != "")
     424            *output = input[0];
     425        else
     426            *output = '\0';
     427        return true;
     428    }
     429};
     430template <>
     431struct ConverterExplicit<std::string, unsigned char>
     432{
     433    static bool convert(unsigned char* output, const std::string input)
     434    {
     435        if (input != "")
     436            *output = input[0];
     437        else
     438            *output = '\0';
     439        return true;
     440    }
     441};
     442
     443
     444// bool to std::string
     445template <>
     446struct ConverterExplicit<bool, std::string>
     447{
     448    static bool convert(std::string* output, const bool& input)
     449    {
     450        if (input)
     451          *output = "true";
     452        else
     453          *output = "false";
     454        return false;
     455    }
     456};
     457
     458// std::string to bool
     459template <>
     460struct ConverterExplicit<std::string, bool>
     461{
     462    static bool convert(bool* output, const std::string& input)
     463    {
     464        std::string stripped = getLowercase(removeTrailingWhitespaces(input));
     465        if (stripped == "true" || stripped == "on" || stripped == "yes")
     466        {
     467          *output = true;
     468          return true;
     469        }
     470        else if (stripped == "false" || stripped == "off" || stripped == "no")
     471        {
     472          *output = false;
     473          return true;
     474        }
     475
    323476        std::istringstream iss(input);
    324477        if (iss >> (*output))
     
    329482};
    330483
    331 // convert from string Shortcut
    332 template <class ToType>
    333 ToType convertFromString(std::string str)
    334 {
    335   return getConvertedValue<std::string, ToType>(str);
    336 }
    337 
    338 
    339 //////////
    340 // MATH //
    341 //////////
    342 // convert everything to Degree
    343 template <class FromType>
    344 struct ConverterSpecialized<FromType, Ogre::Degree, _ToType_>
    345 {
    346     enum { specialized = true };
    347     static bool convert(Ogre::Degree* output, const FromType& input)
    348     {
    349         float angle = 0;
    350         bool success = ConvertValue<FromType, float>(&angle, input);
    351         (*output) = angle;
    352         return success;
    353     }
    354 };
    355 
    356 // convert everything to Radian
    357 template <class FromType>
    358 struct ConverterSpecialized<FromType, Ogre::Radian, _ToType_>
    359 {
    360     enum { specialized = true };
    361     static bool convert(Ogre::Radian* output, const FromType& input)
    362     {
    363         float angle = 0;
    364         bool success = ConvertValue<FromType, float>(&angle, input);
    365         (*output) = angle;
    366         return success;
    367     }
    368 };
    369 
    370 
    371 ////////////////////
    372 // MATH TO STRING //
    373 ////////////////////
    374 
    375 // bool to std::string
    376 template <>
    377 struct ConverterSpecialized<bool, std::string, _Explicit_>
    378 {
    379     enum { specialized = true };
    380     static bool convert(std::string* output, const bool& input)
    381     {
    382         if (input)
    383           *output = "true";
    384         else
    385           *output = "false";
    386         return false;
    387     }
    388 };
    389 
    390 // Vector2 to std::string
    391 template <>
    392 struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_>
    393 {
    394     enum { specialized = true };
    395     static bool convert(std::string* output, const orxonox::Vector2& input)
    396     {
    397         std::ostringstream ostream;
    398         if (ostream << input.x << "," << input.y)
    399         {
    400             (*output) = ostream.str();
    401             return true;
    402         }
    403         return false;
    404     }
    405 };
    406 
    407 // Vector3 to std::string
    408 template <>
    409 struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_>
    410 {
    411     enum { specialized = true };
    412     static bool convert(std::string* output, const orxonox::Vector3& input)
    413     {
    414         std::ostringstream ostream;
    415         if (ostream << input.x << "," << input.y << "," << input.z)
    416         {
    417             (*output) = ostream.str();
    418             return true;
    419         }
    420         return false;
    421     }
    422 };
    423 
    424 // Vector4 to std::string
    425 template <>
    426 struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_>
    427 {
    428     enum { specialized = true };
    429     static bool convert(std::string* output, const orxonox::Vector4& input)
    430     {
    431         std::ostringstream ostream;
    432         if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
    433         {
    434             (*output) = ostream.str();
    435             return true;
    436         }
    437         return false;
    438     }
    439 };
    440 
    441 // Quaternion to std::string
    442 template <>
    443 struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_>
    444 {
    445     enum { specialized = true };
    446     static bool convert(std::string* output, const orxonox::Quaternion& input)
    447     {
    448         std::ostringstream ostream;
    449         if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
    450         {
    451             (*output) = ostream.str();
    452             return true;
    453         }
    454         return false;
    455     }
    456 };
    457 
    458 // ColourValue to std::string
    459 template <>
    460 struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_>
    461 {
    462     enum { specialized = true };
    463     static bool convert(std::string* output, const orxonox::ColourValue& input)
    464     {
    465         std::ostringstream ostream;
    466         if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
    467         {
    468             (*output) = ostream.str();
    469             return true;
    470         }
    471         return false;
    472     }
    473 };
    474 
    475 
    476 ////////////////////
    477 // STRING TO MATH //
    478 ////////////////////
    479 
    480 // std::string to bool
    481 template <>
    482 struct ConverterSpecialized<std::string, bool, _Explicit_>
    483 {
    484     enum { specialized = true };
    485     static bool convert(bool* output, const std::string& input)
    486     {
    487         std::string stripped = getLowercase(removeTrailingWhitespaces(input));
    488         if (stripped == "true" || stripped == "on" || stripped == "yes")
    489         {
    490           *output = true;
    491           return true;
    492         }
    493         else if (stripped == "false" || stripped == "off" || stripped == "no")
    494         {
    495           *output = false;
    496           return true;
    497         }
    498 
    499         std::istringstream iss(input);
    500         if (iss >> (*output))
    501             return true;
    502         else
    503             return false;
    504     }
    505 };
    506 
    507 // std::string to Vector2
    508 template <>
    509 struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_>
    510 {
    511     enum { specialized = true };
    512     static bool convert(orxonox::Vector2* output, const std::string& input)
    513     {
    514         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    515         if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    516 
    517         SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    518         if (tokens.size() >= 2)
    519         {
    520             if (!ConvertValue(&(output->x), tokens[0]))
    521                 return false;
    522             if (!ConvertValue(&(output->y), tokens[1]))
    523                 return false;
    524 
    525             return true;
    526         }
    527         return false;
    528     }
    529 };
    530 
    531 // std::string to Vector3
    532 template <>
    533 struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_>
    534 {
    535     enum { specialized = true };
    536     static bool convert(orxonox::Vector3* output, const std::string& input)
    537     {
    538         size_t 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() >= 3)
    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 
    551             return true;
    552         }
    553         return false;
    554     }
    555 };
    556 
    557 // std::string to Vector4
    558 template <>
    559 struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_>
    560 {
    561     enum { specialized = true };
    562     static bool convert(orxonox::Vector4* output, const std::string& input)
    563     {
    564         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    565         if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    566 
    567         SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    568         if (tokens.size() >= 4)
    569         {
    570             if (!ConvertValue(&(output->x), tokens[0]))
    571                 return false;
    572             if (!ConvertValue(&(output->y), tokens[1]))
    573                 return false;
    574             if (!ConvertValue(&(output->z), tokens[2]))
    575                 return false;
    576             if (!ConvertValue(&(output->w), tokens[3]))
    577                 return false;
    578 
    579             return true;
    580         }
    581         return false;
    582     }
    583 };
    584 
    585 // std::string to Quaternion
    586 template <>
    587 struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_>
    588 {
    589     enum { specialized = true };
    590     static bool convert(orxonox::Quaternion* output, const std::string& input)
    591     {
    592         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    593         if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    594 
    595         SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    596         if (tokens.size() >= 4)
    597         {
    598             if (!ConvertValue(&(output->w), tokens[0]))
    599                 return false;
    600             if (!ConvertValue(&(output->x), tokens[1]))
    601                 return false;
    602             if (!ConvertValue(&(output->y), tokens[2]))
    603                 return false;
    604             if (!ConvertValue(&(output->z), tokens[3]))
    605                 return false;
    606 
    607             return true;
    608         }
    609         return false;
    610     }
    611 };
    612 
    613 // std::string to ColourValue
    614 template <>
    615 struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_>
    616 {
    617     enum { specialized = true };
    618     static bool convert(orxonox::ColourValue* output, const std::string& input)
    619     {
    620         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    621         if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    622 
    623         SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    624         if (tokens.size() >= 3)
    625         {
    626             if (!ConvertValue(&(output->r), tokens[0]))
    627                 return false;
    628             if (!ConvertValue(&(output->g), tokens[1]))
    629                 return false;
    630             if (!ConvertValue(&(output->b), tokens[2]))
    631                 return false;
    632             if (tokens.size() >= 4)
    633             {
    634                 if (!ConvertValue(&(output->a), tokens[3]))
    635                     return false;
    636             }
    637             else
    638                 output->a = 1.0;
    639 
    640             return true;
    641         }
    642         return false;
    643     }
    644 };
    645 
    646 
    647 ///////////////////////////
    648 // Static type detection //
    649 ///////////////////////////
    650 
    651 /**
    652     Template class that determines whether type T converts implicitly to type U.
    653 @note
    654     This allows to detect type conversion at compile time.
    655     From 'Modern C++ Design' (Alexandrescu 2001).
    656 */
    657 template <class T, class U>
    658 class StaticConversion
    659 {
    660     class Small { char dummy[1]; };
    661     class Big   { char dummy[1024]; };
    662     static Small Test(U);
    663     static Big   Test(...);
    664     static T MakeT();
    665 public:
    666     enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };
    667 };
    668 
    669 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
    670 #pragma warning(pop)
    671 #endif
    672 
    673484#endif /* _Convert_H__ */
  • code/trunk/src/util/Debug.h

    r1791 r2087  
    7777}
    7878
     79namespace orxonox
     80{
     81    using std::endl;
     82}
    7983
    8084// DEFINE ERROR MODES
  • code/trunk/src/util/Exception.cc

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/trunk/src/util/Exception.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/trunk/src/util/Math.cc

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

    r1840 r2087  
    3939#include <ostream>
    4040#include <string>
     41#include <boost/static_assert.hpp>
    4142
    4243#include <OgreMath.h>
     
    189190}
    190191
     192template <typename T>
     193inline T zeroise()
     194{
     195    BOOST_STATIC_ASSERT(sizeof(T) == 0);
     196    return T();
     197}
     198
     199template <> inline char                 zeroise<char>()                 { return 0; }
     200template <> inline unsigned char        zeroise<unsigned char>()        { return 0; }
     201template <> inline short                zeroise<short>()                { return 0; }
     202template <> inline unsigned short       zeroise<unsigned short>()       { return 0; }
     203template <> inline int                  zeroise<int>()                  { return 0; }
     204template <> inline unsigned int         zeroise<unsigned int>()         { return 0; }
     205template <> inline long                 zeroise<long>()                 { return 0; }
     206template <> inline unsigned long        zeroise<unsigned long>()        { return 0; }
     207template <> inline long long            zeroise<long long>()            { return 0; }
     208template <> inline unsigned long long   zeroise<unsigned long long>()   { return 0; }
     209template <> inline float                zeroise<float>()                { return 0; }
     210template <> inline double               zeroise<double>()               { return 0; }
     211template <> inline long double          zeroise<long double>()          { return 0; }
     212template <> inline bool                 zeroise<bool>()                 { return 0; }
     213template <> inline void*                zeroise<void*>()                { return 0; }
     214template <> inline std::string          zeroise<std::string>()          { return ""; }
     215template <> inline orxonox::Radian      zeroise<orxonox::Radian>()      { return orxonox::Radian(0.0f); }
     216template <> inline orxonox::Degree      zeroise<orxonox::Degree>()      { return orxonox::Degree(0.0f); }
     217template <> inline orxonox::Vector2     zeroise<orxonox::Vector2>()     { return orxonox::Vector2    (0, 0)      ; }
     218template <> inline orxonox::Vector3     zeroise<orxonox::Vector3>()     { return orxonox::Vector3    (0, 0, 0)   ; }
     219template <> inline orxonox::Vector4     zeroise<orxonox::Vector4>()     { return orxonox::Vector4    (0, 0, 0, 0); }
     220template <> inline orxonox::ColourValue zeroise<orxonox::ColourValue>() { return orxonox::ColourValue(0, 0, 0, 0); }
     221template <> inline orxonox::Quaternion  zeroise<orxonox::Quaternion>()  { return orxonox::Quaternion (0, 0, 0, 0); }
     222
    191223/**
    192224    @brief Interpolates between two values for a time between 0 and 1.
     
    243275
    244276_UtilExport unsigned long getUniqueNumber();
    245 _UtilExport std::string getUniqueNumberStr();
    246277
    247278class _UtilExport IntVector2
  • code/trunk/src/util/MultiType.cc

    r1791 r2087  
    3939    @param type The type
    4040*/
    41 void MultiType::convert(MT_Type type)
     41bool MultiType::convert(MT_Type type)
    4242{
    4343    switch (type)
    4444    {
    4545        case MT_char:
    46             this->convert<char>(); break;
     46            return this->convert<char>(); break;
    4747        case MT_uchar:
    48             this->convert<unsigned char>(); break;
     48            return this->convert<unsigned char>(); break;
    4949        case MT_short:
    50             this->convert<short>(); break;
     50            return this->convert<short>(); break;
    5151        case MT_ushort:
    52             this->convert<unsigned short>(); break;
     52            return this->convert<unsigned short>(); break;
    5353        case MT_int:
    54             this->convert<int>(); break;
     54            return this->convert<int>(); break;
    5555        case MT_uint:
    56             this->convert<unsigned int>(); break;
     56            return this->convert<unsigned int>(); break;
    5757        case MT_long:
    58             this->convert<long>(); break;
     58            return this->convert<long>(); break;
    5959        case MT_ulong:
    60             this->convert<unsigned long>(); break;
     60            return this->convert<unsigned long>(); break;
    6161        case MT_longlong:
    62             this->convert<long long>(); break;
     62            return this->convert<long long>(); break;
    6363        case MT_ulonglong:
    64             this->convert<unsigned long long>(); break;
     64            return this->convert<unsigned long long>(); break;
    6565        case MT_float:
    66             this->convert<float>(); break;
     66            return this->convert<float>(); break;
    6767        case MT_double:
    68             this->convert<double>(); break;
     68            return this->convert<double>(); break;
    6969        case MT_longdouble:
    70             this->convert<long double>(); break;
     70            return this->convert<long double>(); break;
    7171        case MT_bool:
    72             this->convert<bool>(); break;
     72            return this->convert<bool>(); break;
    7373        case MT_void:
    74             this->convert<void*>(); break;
     74            return this->convert<void*>(); break;
    7575        case MT_string:
    76             this->convert<std::string>(); break;
     76            return this->convert<std::string>(); break;
    7777        case MT_vector2:
    78             this->convert<orxonox::Vector2>(); break;
     78            return this->convert<orxonox::Vector2>(); break;
    7979        case MT_vector3:
    80             this->convert<orxonox::Vector3>(); break;
     80            return this->convert<orxonox::Vector3>(); break;
    8181        case MT_vector4:
    82             this->convert<orxonox::Vector4>(); break;
     82            return this->convert<orxonox::Vector4>(); break;
    8383        case MT_colourvalue:
    84             this->convert<orxonox::ColourValue>(); break;
     84            return this->convert<orxonox::ColourValue>(); break;
    8585        case MT_quaternion:
    86             this->convert<orxonox::Quaternion>(); break;
     86            return this->convert<orxonox::Quaternion>(); break;
    8787        case MT_radian:
    88             this->convert<orxonox::Radian>(); break;
     88            return this->convert<orxonox::Radian>(); break;
    8989        case MT_degree:
    90             this->convert<orxonox::Degree>(); break;
     90            return this->convert<orxonox::Degree>(); break;
    9191        default:
    92             this->reset(); break;
     92            this->reset(); return false; break;
    9393    };
    9494}
     
    168168MultiType::operator double()               const { return (this->value_) ? ((this->value_->type_ == MT_double     ) ? ((MT_Value<double>              *)this->value_)->value_ : (*this->value_)) : 0;                      } /** @brief Returns the current value, converted to the requested type. */
    169169MultiType::operator long double()          const { return (this->value_) ? ((this->value_->type_ == MT_longdouble ) ? ((MT_Value<long double>         *)this->value_)->value_ : (*this->value_)) : 0;                      } /** @brief Returns the current value, converted to the requested type. */
    170 MultiType::operator bool()                 const { return (this->value_) ? ((this->value_->type_ == MT_bool       ) ? ((MT_Value<bool>                *)this->value_)->value_ : (*this->value_)) : false;                  } /** @brief Returns the current value, converted to the requested type. */
    171 MultiType::operator void*()                const { return (this->value_) ? ((this->value_->type_ == MT_void       ) ? ((MT_Value<void*>               *)this->value_)->value_ : (*this->value_)) : (void*)0;               } /** @brief Returns the current value, converted to the requested type. */
    172 MultiType::operator std::string()          const { return (this->value_) ? ((this->value_->type_ == MT_string     ) ? ((MT_Value<std::string>         *)this->value_)->value_ : (*this->value_)) : std::string();          } /** @brief Returns the current value, converted to the requested type. */
    173 MultiType::operator orxonox::Vector2()     const { return (this->value_) ? ((this->value_->type_ == MT_vector2    ) ? ((MT_Value<orxonox::Vector2>    *)this->value_)->value_ : (*this->value_)) : orxonox::Vector2();     } /** @brief Returns the current value, converted to the requested type. */
    174 MultiType::operator orxonox::Vector3()     const { return (this->value_) ? ((this->value_->type_ == MT_vector3    ) ? ((MT_Value<orxonox::Vector3>    *)this->value_)->value_ : (*this->value_)) : orxonox::Vector3();     } /** @brief Returns the current value, converted to the requested type. */
    175 MultiType::operator orxonox::Vector4()     const { return (this->value_) ? ((this->value_->type_ == MT_vector4    ) ? ((MT_Value<orxonox::Vector4>    *)this->value_)->value_ : (*this->value_)) : orxonox::Vector4();     } /** @brief Returns the current value, converted to the requested type. */
    176 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : orxonox::ColourValue(); } /** @brief Returns the current value, converted to the requested type. */
    177 MultiType::operator orxonox::Quaternion()  const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : orxonox::Quaternion();  } /** @brief Returns the current value, converted to the requested type. */
    178 MultiType::operator orxonox::Radian()      const { return (this->value_) ? ((this->value_->type_ == MT_radian     ) ? ((MT_Value<orxonox::Radian>     *)this->value_)->value_ : (*this->value_)) : orxonox::Radian();      } /** @brief Returns the current value, converted to the requested type. */
    179 MultiType::operator orxonox::Degree()      const { return (this->value_) ? ((this->value_->type_ == MT_degree     ) ? ((MT_Value<orxonox::Degree>     *)this->value_)->value_ : (*this->value_)) : orxonox::Degree();      } /** @brief Returns the current value, converted to the requested type. */
     170MultiType::operator bool()                 const { return (this->value_) ? ((this->value_->type_ == MT_bool       ) ? ((MT_Value<bool>                *)this->value_)->value_ : (*this->value_)) : 0;                      } /** @brief Returns the current value, converted to the requested type. */
     171MultiType::operator void*()                const { return (this->value_) ? ((this->value_->type_ == MT_void       ) ? ((MT_Value<void*>               *)this->value_)->value_ : (*this->value_)) : 0;                      } /** @brief Returns the current value, converted to the requested type. */
     172MultiType::operator std::string()          const { return (this->value_) ? ((this->value_->type_ == MT_string     ) ? ((MT_Value<std::string>         *)this->value_)->value_ : (*this->value_)) : zeroise<std::string>();          } /** @brief Returns the current value, converted to the requested type. */
     173MultiType::operator orxonox::Vector2()     const { return (this->value_) ? ((this->value_->type_ == MT_vector2    ) ? ((MT_Value<orxonox::Vector2>    *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector2>();     } /** @brief Returns the current value, converted to the requested type. */
     174MultiType::operator orxonox::Vector3()     const { return (this->value_) ? ((this->value_->type_ == MT_vector3    ) ? ((MT_Value<orxonox::Vector3>    *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector3>();     } /** @brief Returns the current value, converted to the requested type. */
     175MultiType::operator orxonox::Vector4()     const { return (this->value_) ? ((this->value_->type_ == MT_vector4    ) ? ((MT_Value<orxonox::Vector4>    *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector4>();     } /** @brief Returns the current value, converted to the requested type. */
     176MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::ColourValue>(); } /** @brief Returns the current value, converted to the requested type. */
     177MultiType::operator orxonox::Quaternion()  const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Quaternion>();  } /** @brief Returns the current value, converted to the requested type. */
     178MultiType::operator orxonox::Radian()      const { return (this->value_) ? ((this->value_->type_ == MT_radian     ) ? ((MT_Value<orxonox::Radian>     *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Radian>();      } /** @brief Returns the current value, converted to the requested type. */
     179MultiType::operator orxonox::Degree()      const { return (this->value_) ? ((this->value_->type_ == MT_degree     ) ? ((MT_Value<orxonox::Degree>     *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Degree>();      } /** @brief Returns the current value, converted to the requested type. */
    180180
    181181template <> void MultiType::createNewValueContainer(const char& value)                 { this->value_ = new MT_Value<char>                (value, MT_char       ); } /** @brief Creates a new value container for the given type. */
  • code/trunk/src/util/MultiType.h

    r1854 r2087  
    5858    a.convert<bool>();         // converts 3.14 to bool, which is true
    5959    a = false;                 // assigns false, this is equivalent to a.setValue(false)
     60
     61    @note
     62    Whenever a value gets converted, there is a boolean return value telling you whether it was
     63    successful or not. If it wasn't a zero value is assigned with the help of zeroise<T>().
    6064*/
    6165
     
    128132    struct _UtilExport MT_ValueBase
    129133    {
    130         MT_ValueBase(MT_Type type) : type_(type) {}
     134        MT_ValueBase(MT_Type type) : type_(type), bHasDefaultValue_(false) {}
    131135        virtual ~MT_ValueBase() {}
    132136
     
    134138
    135139        virtual void reset() = 0;
    136         virtual void assimilate(const MultiType& other) = 0;
     140        virtual bool assimilate(const MultiType& other) = 0;
    137141
    138142        /** @brief Returns the type of the current value. */
    139143        const MT_Type& getType() const { return this->type_; }
    140144
    141         virtual void setValue(const char& value)                 = 0;
    142         virtual void setValue(const unsigned char& value)        = 0;
    143         virtual void setValue(const short& value)                = 0;
    144         virtual void setValue(const unsigned short& value)       = 0;
    145         virtual void setValue(const int& value)                  = 0;
    146         virtual void setValue(const unsigned int& value)         = 0;
    147         virtual void setValue(const long& value)                 = 0;
    148         virtual void setValue(const unsigned long& value)        = 0;
    149         virtual void setValue(const long long& value)            = 0;
    150         virtual void setValue(const unsigned long long& value)   = 0;
    151         virtual void setValue(const float& value)                = 0;
    152         virtual void setValue(const double& value)               = 0;
    153         virtual void setValue(const long double& value)          = 0;
    154         virtual void setValue(const bool& value)                 = 0;
    155         virtual void setValue(      void* const& value)          = 0;
    156         virtual void setValue(const std::string& value)          = 0;
    157         virtual void setValue(const orxonox::Vector2& value)     = 0;
    158         virtual void setValue(const orxonox::Vector3& value)     = 0;
    159         virtual void setValue(const orxonox::Vector4& value)     = 0;
    160         virtual void setValue(const orxonox::ColourValue& value) = 0;
    161         virtual void setValue(const orxonox::Quaternion& value)  = 0;
    162         virtual void setValue(const orxonox::Radian& value)      = 0;
    163         virtual void setValue(const orxonox::Degree& value)      = 0;
     145        /** @brief Checks whether the value is a default one. */
     146        bool hasDefaultValue()   const { return this->bHasDefaultValue_; }
     147
     148        virtual bool setValue(const char& value)                 = 0;
     149        virtual bool setValue(const unsigned char& value)        = 0;
     150        virtual bool setValue(const short& value)                = 0;
     151        virtual bool setValue(const unsigned short& value)       = 0;
     152        virtual bool setValue(const int& value)                  = 0;
     153        virtual bool setValue(const unsigned int& value)         = 0;
     154        virtual bool setValue(const long& value)                 = 0;
     155        virtual bool setValue(const unsigned long& value)        = 0;
     156        virtual bool setValue(const long long& value)            = 0;
     157        virtual bool setValue(const unsigned long long& value)   = 0;
     158        virtual bool setValue(const float& value)                = 0;
     159        virtual bool setValue(const double& value)               = 0;
     160        virtual bool setValue(const long double& value)          = 0;
     161        virtual bool setValue(const bool& value)                 = 0;
     162        virtual bool setValue(      void* const& value)          = 0;
     163        virtual bool setValue(const std::string& value)          = 0;
     164        virtual bool setValue(const orxonox::Vector2& value)     = 0;
     165        virtual bool setValue(const orxonox::Vector3& value)     = 0;
     166        virtual bool setValue(const orxonox::Vector4& value)     = 0;
     167        virtual bool setValue(const orxonox::ColourValue& value) = 0;
     168        virtual bool setValue(const orxonox::Quaternion& value)  = 0;
     169        virtual bool setValue(const orxonox::Radian& value)      = 0;
     170        virtual bool setValue(const orxonox::Degree& value)      = 0;
     171
     172        virtual bool getValue(char*                 value) const = 0;
     173        virtual bool getValue(unsigned char*        value) const = 0;
     174        virtual bool getValue(short*                value) const = 0;
     175        virtual bool getValue(unsigned short*       value) const = 0;
     176        virtual bool getValue(int*                  value) const = 0;
     177        virtual bool getValue(unsigned int*         value) const = 0;
     178        virtual bool getValue(long*                 value) const = 0;
     179        virtual bool getValue(unsigned long*        value) const = 0;
     180        virtual bool getValue(long long*            value) const = 0;
     181        virtual bool getValue(unsigned long long*   value) const = 0;
     182        virtual bool getValue(float*                value) const = 0;
     183        virtual bool getValue(double*               value) const = 0;
     184        virtual bool getValue(long double*          value) const = 0;
     185        virtual bool getValue(bool*                 value) const = 0;
     186        virtual bool getValue(void**                value) const = 0;
     187        virtual bool getValue(std::string*          value) const = 0;
     188        virtual bool getValue(orxonox::Vector2*     value) const = 0;
     189        virtual bool getValue(orxonox::Vector3*     value) const = 0;
     190        virtual bool getValue(orxonox::Vector4*     value) const = 0;
     191        virtual bool getValue(orxonox::ColourValue* value) const = 0;
     192        virtual bool getValue(orxonox::Quaternion*  value) const = 0;
     193        virtual bool getValue(orxonox::Radian*      value) const = 0;
     194        virtual bool getValue(orxonox::Degree*      value) const = 0;
    164195
    165196        virtual operator char()                 const = 0;
     
    189220        virtual void toString(std::ostream& outstream) const = 0;
    190221
    191         MT_Type type_; //!< The type of the current value
     222        MT_Type type_;          //!< The type of the current value
     223        bool bHasDefaultValue_; //!< True if the last conversion wasn't successful
    192224    };
    193225
     
    229261        inline                       const MultiType& operator=(MT_Type type)           { this->setType(type);   return (*this); } /** @brief Resets the value and changes the type. */
    230262
    231         inline void                                   setValue(const char& value);
    232         inline void                                   setValue(const unsigned char& value);
    233         inline void                                   setValue(const short& value);
    234         inline void                                   setValue(const unsigned short& value);
    235         inline void                                   setValue(const int& value);
    236         inline void                                   setValue(const unsigned int& value);
    237         inline void                                   setValue(const long& value);
    238         inline void                                   setValue(const unsigned long& value);
    239         inline void                                   setValue(const long long& value);
    240         inline void                                   setValue(const unsigned long long& value);
    241         inline void                                   setValue(const float& value);
    242         inline void                                   setValue(const double& value);
    243         inline void                                   setValue(const long double& value);
    244         inline void                                   setValue(const bool& value);
    245         inline void                                   setValue(      void* const& value);
    246         inline void                                   setValue(const std::string& value);
    247         inline void                                   setValue(const orxonox::Vector2& value);
    248         inline void                                   setValue(const orxonox::Vector3& value);
    249         inline void                                   setValue(const orxonox::Vector4& value);
    250         inline void                                   setValue(const orxonox::ColourValue& value);
    251         inline void                                   setValue(const orxonox::Quaternion& value);
    252         inline void                                   setValue(const orxonox::Radian& value);
    253         inline void                                   setValue(const orxonox::Degree& value);
    254         inline void                                   setValue(const char* value);
     263        inline bool                                   setValue(const char& value);
     264        inline bool                                   setValue(const unsigned char& value);
     265        inline bool                                   setValue(const short& value);
     266        inline bool                                   setValue(const unsigned short& value);
     267        inline bool                                   setValue(const int& value);
     268        inline bool                                   setValue(const unsigned int& value);
     269        inline bool                                   setValue(const long& value);
     270        inline bool                                   setValue(const unsigned long& value);
     271        inline bool                                   setValue(const long long& value);
     272        inline bool                                   setValue(const unsigned long long& value);
     273        inline bool                                   setValue(const float& value);
     274        inline bool                                   setValue(const double& value);
     275        inline bool                                   setValue(const long double& value);
     276        inline bool                                   setValue(const bool& value);
     277        inline bool                                   setValue(      void* const& value);
     278        inline bool                                   setValue(const std::string& value);
     279        inline bool                                   setValue(const orxonox::Vector2& value);
     280        inline bool                                   setValue(const orxonox::Vector3& value);
     281        inline bool                                   setValue(const orxonox::Vector4& value);
     282        inline bool                                   setValue(const orxonox::ColourValue& value);
     283        inline bool                                   setValue(const orxonox::Quaternion& value);
     284        inline bool                                   setValue(const orxonox::Radian& value);
     285        inline bool                                   setValue(const orxonox::Degree& value);
     286        inline bool                                   setValue(const char* value);
    255287        /** @brief Assigns a pointer. */
    256         template <typename V> inline void             setValue(V* value)               { if (this->value_) { this->value_->setValue((void*)value); } else { this->assignValue((void*)value); } }
     288        template <typename V> inline bool             setValue(V* value)               { if (this->value_) { return this->value_->setValue((void*)value); } else { return this->assignValue((void*)value); } }
    257289        /** @brief Assigns the value of the other MultiType and converts it to the current type. */
    258         void                                          setValue(const MultiType& other) { if (this->value_) { this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } } }
     290        bool                                          setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } }
    259291        /** @brief Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). */
    260         template <typename T, typename V> inline void setValue(const V& value)         { this->setType<T>(); this->setValue(value); }
     292        template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); }
    261293
    262294
     
    264296        inline void                       copy(const MultiType& other)    { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; }
    265297
    266         template <typename T> inline void convert()                       { this->setValue<T>((T)(*this));  } /** @brief Converts the current value to type T. */
    267         inline void                       convert(const MultiType& other) { this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */
    268         void                              convert(MT_Type type);
    269 
    270         /** @brief Resets the value to the defaultvalue of the current type. */
    271         inline void                       reset()                         { if (this->value_) { delete this->value_; this->value_ = 0; } }
     298        template <typename T> inline bool convert()                       { return this->setValue<T>((T)(*this));  } /** @brief Converts the current value to type T. */
     299        inline bool                       convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */
     300        bool                              convert(MT_Type type);
     301
     302        /** @brief Current content gets deleted. New type is MT_null */
     303        inline void                       reset()                         { if (this->value_) this->value_->reset(); }
    272304
    273305        template <typename T> inline void setType()                       { this->assignValue(T());                            } /** @brief Resets the value and changes the internal type to T. */
     
    282314        template <typename T> inline bool isType()                  const { return false; } // Only works for specialized values - see below
    283315        std::string                       getTypename()             const;
     316
     317        /** @brief Checks whether the value is a default one. */
     318        bool                              hasDefaultValue()         const { return this->value_->hasDefaultValue(); }
    284319
    285320        operator char()                  const;
     
    309344        template <class T> operator T*() const { return ((T*)this->operator void*()); }
    310345
    311         inline void getValue(char*                 value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    312         inline void getValue(unsigned char*        value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    313         inline void getValue(short*                value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    314         inline void getValue(unsigned short*       value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    315         inline void getValue(int*                  value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    316         inline void getValue(unsigned int*         value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    317         inline void getValue(long*                 value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    318         inline void getValue(unsigned long*        value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    319         inline void getValue(long long*            value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    320         inline void getValue(unsigned long long*   value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    321         inline void getValue(float*                value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    322         inline void getValue(double*               value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    323         inline void getValue(long double*          value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    324         inline void getValue(bool*                 value) const { if (this->value_) { (*value) = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    325         inline void getValue(void*                 value) const { if (this->value_) {   value  = (*this->value_); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    326         inline void getValue(std::string*          value) const { if (this->value_) { (*value) = this->value_->operator std::string();          } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    327         inline void getValue(orxonox::Vector2*     value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector2();     } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    328         inline void getValue(orxonox::Vector3*     value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector3();     } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    329         inline void getValue(orxonox::Vector4*     value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector4();     } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    330         inline void getValue(orxonox::ColourValue* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::ColourValue(); } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    331         inline void getValue(orxonox::Quaternion*  value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Quaternion();  } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    332         inline void getValue(orxonox::Radian*      value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Radian();      } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    333         inline void getValue(orxonox::Degree*      value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Degree();      } } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     346        inline bool getValue(char*                 value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     347        inline bool getValue(unsigned char*        value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     348        inline bool getValue(short*                value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     349        inline bool getValue(unsigned short*       value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     350        inline bool getValue(int*                  value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     351        inline bool getValue(unsigned int*         value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     352        inline bool getValue(long*                 value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     353        inline bool getValue(unsigned long*        value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     354        inline bool getValue(long long*            value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     355        inline bool getValue(unsigned long long*   value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     356        inline bool getValue(float*                value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     357        inline bool getValue(double*               value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     358        inline bool getValue(long double*          value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     359        inline bool getValue(bool*                 value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     360        inline bool getValue(void**                value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     361        inline bool getValue(std::string*          value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     362        inline bool getValue(orxonox::Vector2*     value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     363        inline bool getValue(orxonox::Vector3*     value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     364        inline bool getValue(orxonox::Vector4*     value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     365        inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     366        inline bool getValue(orxonox::Quaternion*  value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     367        inline bool getValue(orxonox::Radian*      value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     368        inline bool getValue(orxonox::Degree*      value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
    334369
    335370        inline char                     getChar()             const { return this->operator char();                 } /** @brief Returns the current value, converted to the requested type. */
     
    359394
    360395    private:
    361         inline void assignValue(const char& value)                 { if (this->value_ && this->value_->type_ == MT_char)        { this->value_->setValue(value); } else { this->changeValueContainer<char>(value);                } } /** @brief Assigns a new value by changing type and creating a new container. */
    362         inline void assignValue(const unsigned char& value)        { if (this->value_ && this->value_->type_ == MT_uchar)       { this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value);        } } /** @brief Assigns a new value by changing type and creating a new container. */
    363         inline void assignValue(const short& value)                { if (this->value_ && this->value_->type_ == MT_short)       { this->value_->setValue(value); } else { this->changeValueContainer<short>(value);                } } /** @brief Assigns a new value by changing type and creating a new container. */
    364         inline void assignValue(const unsigned short& value)       { if (this->value_ && this->value_->type_ == MT_ushort)      { this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value);      } } /** @brief Assigns a new value by changing type and creating a new container. */
    365         inline void assignValue(const int& value)                  { if (this->value_ && this->value_->type_ == MT_int)         { this->value_->setValue(value); } else { this->changeValueContainer<int>(value);                  } } /** @brief Assigns a new value by changing type and creating a new container. */
    366         inline void assignValue(const unsigned int& value)         { if (this->value_ && this->value_->type_ == MT_uint)        { this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value);        } } /** @brief Assigns a new value by changing type and creating a new container. */
    367         inline void assignValue(const long& value)                 { if (this->value_ && this->value_->type_ == MT_long)        { this->value_->setValue(value); } else { this->changeValueContainer<long>(value);                } } /** @brief Assigns a new value by changing type and creating a new container. */
    368         inline void assignValue(const unsigned long& value)        { if (this->value_ && this->value_->type_ == MT_ulong)       { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value);        } } /** @brief Assigns a new value by changing type and creating a new container. */
    369         inline void assignValue(const long long& value)            { if (this->value_ && this->value_->type_ == MT_longlong)    { this->value_->setValue(value); } else { this->changeValueContainer<long long>(value);            } } /** @brief Assigns a new value by changing type and creating a new container. */
    370         inline void assignValue(const unsigned long long& value)   { if (this->value_ && this->value_->type_ == MT_ulonglong)   { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value);  } } /** @brief Assigns a new value by changing type and creating a new container. */
    371         inline void assignValue(const float& value)                { if (this->value_ && this->value_->type_ == MT_float)       { this->value_->setValue(value); } else { this->changeValueContainer<float>(value);                } } /** @brief Assigns a new value by changing type and creating a new container. */
    372         inline void assignValue(const double& value)               { if (this->value_ && this->value_->type_ == MT_double)      { this->value_->setValue(value); } else { this->changeValueContainer<double>(value);              } } /** @brief Assigns a new value by changing type and creating a new container. */
    373         inline void assignValue(const long double& value)          { if (this->value_ && this->value_->type_ == MT_longdouble)  { this->value_->setValue(value); } else { this->changeValueContainer<long double>(value);          } } /** @brief Assigns a new value by changing type and creating a new container. */
    374         inline void assignValue(const bool& value)                 { if (this->value_ && this->value_->type_ == MT_bool)        { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value);                } } /** @brief Assigns a new value by changing type and creating a new container. */
    375         inline void assignValue(      void* const& value)          { if (this->value_ && this->value_->type_ == MT_void)        { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value);                } } /** @brief Assigns a new value by changing type and creating a new container. */
    376         inline void assignValue(const std::string& value)          { if (this->value_ && this->value_->type_ == MT_string)      { this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value);          } } /** @brief Assigns a new value by changing type and creating a new container. */
    377         inline void assignValue(const orxonox::Vector2& value)     { if (this->value_ && this->value_->type_ == MT_vector2)     { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value);    } } /** @brief Assigns a new value by changing type and creating a new container. */
    378         inline void assignValue(const orxonox::Vector3& value)     { if (this->value_ && this->value_->type_ == MT_vector3)     { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value);    } } /** @brief Assigns a new value by changing type and creating a new container. */
    379         inline void assignValue(const orxonox::Vector4& value)     { if (this->value_ && this->value_->type_ == MT_vector4)     { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value);    } } /** @brief Assigns a new value by changing type and creating a new container. */
    380         inline void assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_colourvalue) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); } } /** @brief Assigns a new value by changing type and creating a new container. */
    381         inline void assignValue(const orxonox::Quaternion& value)  { if (this->value_ && this->value_->type_ == MT_quaternion)  { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); } } /** @brief Assigns a new value by changing type and creating a new container. */
    382         inline void assignValue(const orxonox::Radian& value)      { if (this->value_ && this->value_->type_ == MT_radian)      { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value);      } } /** @brief Assigns a new value by changing type and creating a new container. */
    383         inline void assignValue(const orxonox::Degree& value)      { if (this->value_ && this->value_->type_ == MT_degree)      { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value);      } } /** @brief Assigns a new value by changing type and creating a new container. */
     396        inline bool assignValue(const char& value)                 { if (this->value_ && this->value_->type_ == MT_char)        { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value);                 return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     397        inline bool assignValue(const unsigned char& value)        { if (this->value_ && this->value_->type_ == MT_uchar)       { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value);        return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     398        inline bool assignValue(const short& value)                { if (this->value_ && this->value_->type_ == MT_short)       { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value);                return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     399        inline bool assignValue(const unsigned short& value)       { if (this->value_ && this->value_->type_ == MT_ushort)      { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value);       return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     400        inline bool assignValue(const int& value)                  { if (this->value_ && this->value_->type_ == MT_int)         { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value);                  return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     401        inline bool assignValue(const unsigned int& value)         { if (this->value_ && this->value_->type_ == MT_uint)        { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value);         return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     402        inline bool assignValue(const long& value)                 { if (this->value_ && this->value_->type_ == MT_long)        { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value);                 return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     403        inline bool assignValue(const unsigned long& value)        { if (this->value_ && this->value_->type_ == MT_ulong)       { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value);        return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     404        inline bool assignValue(const long long& value)            { if (this->value_ && this->value_->type_ == MT_longlong)    { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value);            return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     405        inline bool assignValue(const unsigned long long& value)   { if (this->value_ && this->value_->type_ == MT_ulonglong)   { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value);   return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     406        inline bool assignValue(const float& value)                { if (this->value_ && this->value_->type_ == MT_float)       { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value);                return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     407        inline bool assignValue(const double& value)               { if (this->value_ && this->value_->type_ == MT_double)      { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value);               return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     408        inline bool assignValue(const long double& value)          { if (this->value_ && this->value_->type_ == MT_longdouble)  { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value);          return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     409        inline bool assignValue(const bool& value)                 { if (this->value_ && this->value_->type_ == MT_bool)        { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value);                 return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     410        inline bool assignValue(      void* const& value)          { if (this->value_ && this->value_->type_ == MT_void)        { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value);                return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     411        inline bool assignValue(const std::string& value)          { if (this->value_ && this->value_->type_ == MT_string)      { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value);          return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     412        inline bool assignValue(const orxonox::Vector2& value)     { if (this->value_ && this->value_->type_ == MT_vector2)     { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value);     return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     413        inline bool assignValue(const orxonox::Vector3& value)     { if (this->value_ && this->value_->type_ == MT_vector3)     { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value);     return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     414        inline bool assignValue(const orxonox::Vector4& value)     { if (this->value_ && this->value_->type_ == MT_vector4)     { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value);     return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     415        inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_colourvalue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     416        inline bool assignValue(const orxonox::Quaternion& value)  { if (this->value_ && this->value_->type_ == MT_quaternion)  { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value);  return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     417        inline bool assignValue(const orxonox::Radian& value)      { if (this->value_ && this->value_->type_ == MT_radian)      { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value);      return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
     418        inline bool assignValue(const orxonox::Degree& value)      { if (this->value_ && this->value_->type_ == MT_degree)      { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value);      return true; } } /** @brief Assigns a new value by changing type and creating a new container. */
    384419
    385420        /** @brief Changes the value container. */
    386421        template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); }
    387422        /** @brief Creates a new value container (works only with specialized types). */
    388         template <typename T>        void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }
     423        template <typename T>        void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; }
    389424
    390425        MT_ValueBase* value_; //!< A pointer to the value container
     
    419454
    420455// Specialization to avoid ambiguities with the conversion operator
    421 template <> inline void MultiType::convert<std::string>()          { this->setValue<std::string>         (this->operator std::string());          } /** @brief Converts the current value to the given type. */
    422 template <> inline void MultiType::convert<orxonox::Vector2>()     { this->setValue<orxonox::Vector2>    (this->operator orxonox::Vector2());     } /** @brief Converts the current value to the given type. */
    423 template <> inline void MultiType::convert<orxonox::Vector3>()     { this->setValue<orxonox::Vector3>    (this->operator orxonox::Vector3());     } /** @brief Converts the current value to the given type. */
    424 template <> inline void MultiType::convert<orxonox::Vector4>()     { this->setValue<orxonox::Vector4>    (this->operator orxonox::Vector4());     } /** @brief Converts the current value to the given type. */
    425 template <> inline void MultiType::convert<orxonox::ColourValue>() { this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } /** @brief Converts the current value to the given type. */
    426 template <> inline void MultiType::convert<orxonox::Quaternion>()  { this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion());  } /** @brief Converts the current value to the given type. */
    427 template <> inline void MultiType::convert<orxonox::Radian>()      { this->setValue<orxonox::Radian>     (this->operator orxonox::Radian());      } /** @brief Converts the current value to the given type. */
    428 template <> inline void MultiType::convert<orxonox::Degree>()      { this->setValue<orxonox::Degree>     (this->operator orxonox::Degree());      } /** @brief Converts the current value to the given type. */
     456template <> inline bool MultiType::convert<std::string>()          { return this->setValue<std::string>         (this->operator std::string());          } /** @brief Converts the current value to the given type. */
     457template <> inline bool MultiType::convert<orxonox::Vector2>()     { return this->setValue<orxonox::Vector2>    (this->operator orxonox::Vector2());     } /** @brief Converts the current value to the given type. */
     458template <> inline bool MultiType::convert<orxonox::Vector3>()     { return this->setValue<orxonox::Vector3>    (this->operator orxonox::Vector3());     } /** @brief Converts the current value to the given type. */
     459template <> inline bool MultiType::convert<orxonox::Vector4>()     { return this->setValue<orxonox::Vector4>    (this->operator orxonox::Vector4());     } /** @brief Converts the current value to the given type. */
     460template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } /** @brief Converts the current value to the given type. */
     461template <> inline bool MultiType::convert<orxonox::Quaternion>()  { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion());  } /** @brief Converts the current value to the given type. */
     462template <> inline bool MultiType::convert<orxonox::Radian>()      { return this->setValue<orxonox::Radian>     (this->operator orxonox::Radian());      } /** @brief Converts the current value to the given type. */
     463template <> inline bool MultiType::convert<orxonox::Degree>()      { return this->setValue<orxonox::Degree>     (this->operator orxonox::Degree());      } /** @brief Converts the current value to the given type. */
    429464
    430465// Specialization to avoid ambiguities with the conversion operator
    431 template <> inline void MultiType::convert<const std::string&>()          { this->convert<std::string>();          } /** @brief Converts the current value to the given type. */
    432 template <> inline void MultiType::convert<const orxonox::Vector2&>()     { this->convert<orxonox::Vector2>();     } /** @brief Converts the current value to the given type. */
    433 template <> inline void MultiType::convert<const orxonox::Vector3&>()     { this->convert<orxonox::Vector3>();     } /** @brief Converts the current value to the given type. */
    434 template <> inline void MultiType::convert<const orxonox::Vector4&>()     { this->convert<orxonox::Vector4>();     } /** @brief Converts the current value to the given type. */
    435 template <> inline void MultiType::convert<const orxonox::ColourValue&>() { this->convert<orxonox::ColourValue>(); } /** @brief Converts the current value to the given type. */
    436 template <> inline void MultiType::convert<const orxonox::Quaternion&>()  { this->convert<orxonox::Quaternion>();  } /** @brief Converts the current value to the given type. */
    437 template <> inline void MultiType::convert<const orxonox::Radian&>()      { this->convert<orxonox::Radian>();      } /** @brief Converts the current value to the given type. */
    438 template <> inline void MultiType::convert<const orxonox::Degree&>()      { this->convert<orxonox::Degree>();      } /** @brief Converts the current value to the given type. */
     466template <> inline bool MultiType::convert<const std::string&>()          { return this->convert<std::string>();          } /** @brief Converts the current value to the given type. */
     467template <> inline bool MultiType::convert<const orxonox::Vector2&>()     { return this->convert<orxonox::Vector2>();     } /** @brief Converts the current value to the given type. */
     468template <> inline bool MultiType::convert<const orxonox::Vector3&>()     { return this->convert<orxonox::Vector3>();     } /** @brief Converts the current value to the given type. */
     469template <> inline bool MultiType::convert<const orxonox::Vector4&>()     { return this->convert<orxonox::Vector4>();     } /** @brief Converts the current value to the given type. */
     470template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } /** @brief Converts the current value to the given type. */
     471template <> inline bool MultiType::convert<const orxonox::Quaternion&>()  { return this->convert<orxonox::Quaternion>();  } /** @brief Converts the current value to the given type. */
     472template <> inline bool MultiType::convert<const orxonox::Radian&>()      { return this->convert<orxonox::Radian>();      } /** @brief Converts the current value to the given type. */
     473template <> inline bool MultiType::convert<const orxonox::Degree&>()      { return this->convert<orxonox::Degree>();      } /** @brief Converts the current value to the given type. */
    439474
    440475template <> void MultiType::createNewValueContainer(const char& value);
     
    462497template <> void MultiType::createNewValueContainer(const orxonox::Degree& value);
    463498
    464 inline void MultiType::setValue(const char& value)                  { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    465 inline void MultiType::setValue(const unsigned char& value)         { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    466 inline void MultiType::setValue(const short& value)                 { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    467 inline void MultiType::setValue(const unsigned short& value)        { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    468 inline void MultiType::setValue(const int& value)                   { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    469 inline void MultiType::setValue(const unsigned int& value)          { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    470 inline void MultiType::setValue(const long& value)                  { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    471 inline void MultiType::setValue(const unsigned long& value)         { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    472 inline void MultiType::setValue(const long long& value)             { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    473 inline void MultiType::setValue(const unsigned long long& value)    { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    474 inline void MultiType::setValue(const float& value)                 { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    475 inline void MultiType::setValue(const double& value)                { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    476 inline void MultiType::setValue(const long double& value)           { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    477 inline void MultiType::setValue(const bool& value)                  { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    478 inline void MultiType::setValue(      void* const& value)           { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    479 inline void MultiType::setValue(const std::string& value)           { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    480 inline void MultiType::setValue(const orxonox::Vector2& value)      { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    481 inline void MultiType::setValue(const orxonox::Vector3& value)      { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    482 inline void MultiType::setValue(const orxonox::Vector4& value)      { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    483 inline void MultiType::setValue(const orxonox::ColourValue& value)  { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    484 inline void MultiType::setValue(const orxonox::Quaternion& value)   { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    485 inline void MultiType::setValue(const orxonox::Radian& value)       { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    486 inline void MultiType::setValue(const orxonox::Degree& value)       { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
    487 
    488 inline void MultiType::setValue(const char* value)                  { if (this->value_) { this->value_->setValue(std::string(value)); } else { this->assignValue(std::string(value)); } }  /** @brief Assigns the given value and converts it to the current type. */
     499inline bool MultiType::setValue(const char& value)                  { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     500inline bool MultiType::setValue(const unsigned char& value)         { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     501inline bool MultiType::setValue(const short& value)                 { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     502inline bool MultiType::setValue(const unsigned short& value)        { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     503inline bool MultiType::setValue(const int& value)                   { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     504inline bool MultiType::setValue(const unsigned int& value)          { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     505inline bool MultiType::setValue(const long& value)                  { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     506inline bool MultiType::setValue(const unsigned long& value)         { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     507inline bool MultiType::setValue(const long long& value)             { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     508inline bool MultiType::setValue(const unsigned long long& value)    { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     509inline bool MultiType::setValue(const float& value)                 { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     510inline bool MultiType::setValue(const double& value)                { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     511inline bool MultiType::setValue(const long double& value)           { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     512inline bool MultiType::setValue(const bool& value)                  { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     513inline bool MultiType::setValue(      void* const& value)           { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     514inline bool MultiType::setValue(const std::string& value)           { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     515inline bool MultiType::setValue(const orxonox::Vector2& value)      { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     516inline bool MultiType::setValue(const orxonox::Vector3& value)      { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     517inline bool MultiType::setValue(const orxonox::Vector4& value)      { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     518inline bool MultiType::setValue(const orxonox::ColourValue& value)  { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     519inline bool MultiType::setValue(const orxonox::Quaternion& value)   { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     520inline bool MultiType::setValue(const orxonox::Radian& value)       { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     521inline bool MultiType::setValue(const orxonox::Degree& value)       { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */
     522
     523inline bool MultiType::setValue(const char* value)                  { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } }  /** @brief Assigns the given value and converts it to the current type. */
    489524
    490525#endif /* _MultiType_H__ */
  • code/trunk/src/util/MultiTypeValue.h

    r1854 r2087  
    3838
    3939#include "UtilPrereqs.h"
    40 #include "Convert.h"
     40#include "MathConvert.h"
    4141#include "MultiType.h"
    4242
     
    5454
    5555    /** @brief Resets the current value to the default. */
    56     inline void reset() { this->value_ = T(); }
     56    inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; }
    5757
    5858    /** @brief Assigns the value of the other MultiType, converted to T. @param other The other MultiType */
    59     inline void assimilate(const MultiType& other) { if (other.value_) { T temp; other.getValue(&temp); this->value_ = temp; } else { this->value_ = T(); } }
     59    inline bool assimilate(const MultiType& other)
     60    {
     61        if (other.value_)
     62        {
     63            return !(bHasDefaultValue_ = !other.value_->getValue(&value_));
     64        }
     65        else
     66        {
     67            this->value_ = zeroise<T>();
     68            return !(bHasDefaultValue_ = true);
     69        }
     70    }
    6071
    61     inline void setValue(const char& value)                 { this->value_ = getConvertedValue<char,                 T>(value); } /** @brief Assigns the value by converting it to T. */
    62     inline void setValue(const unsigned char& value)        { this->value_ = getConvertedValue<unsigned char,        T>(value); } /** @brief Assigns the value by converting it to T. */
    63     inline void setValue(const short& value)                { this->value_ = getConvertedValue<short,                T>(value); } /** @brief Assigns the value by converting it to T. */
    64     inline void setValue(const unsigned short& value)       { this->value_ = getConvertedValue<unsigned short,       T>(value); } /** @brief Assigns the value by converting it to T. */
    65     inline void setValue(const int& value)                  { this->value_ = getConvertedValue<int,                  T>(value); } /** @brief Assigns the value by converting it to T. */
    66     inline void setValue(const unsigned int& value)         { this->value_ = getConvertedValue<unsigned int,         T>(value); } /** @brief Assigns the value by converting it to T. */
    67     inline void setValue(const long& value)                 { this->value_ = getConvertedValue<long,                 T>(value); } /** @brief Assigns the value by converting it to T. */
    68     inline void setValue(const unsigned long& value)        { this->value_ = getConvertedValue<unsigned long,        T>(value); } /** @brief Assigns the value by converting it to T. */
    69     inline void setValue(const long long& value)            { this->value_ = getConvertedValue<long long,            T>(value); } /** @brief Assigns the value by converting it to T. */
    70     inline void setValue(const unsigned long long& value)   { this->value_ = getConvertedValue<unsigned long long,   T>(value); } /** @brief Assigns the value by converting it to T. */
    71     inline void setValue(const float& value)                { this->value_ = getConvertedValue<float,                T>(value); } /** @brief Assigns the value by converting it to T. */
    72     inline void setValue(const double& value)               { this->value_ = getConvertedValue<double,               T>(value); } /** @brief Assigns the value by converting it to T. */
    73     inline void setValue(const long double& value)          { this->value_ = getConvertedValue<long double,          T>(value); } /** @brief Assigns the value by converting it to T. */
    74     inline void setValue(const bool& value)                 { this->value_ = getConvertedValue<bool,                 T>(value); } /** @brief Assigns the value by converting it to T. */
    75     inline void setValue(      void* const& value)          { this->value_ = getConvertedValue<void*,                T>(value); } /** @brief Assigns the value by converting it to T. */
    76     inline void setValue(const std::string& value)          { this->value_ = getConvertedValue<std::string,          T>(value); } /** @brief Assigns the value by converting it to T. */
    77     inline void setValue(const orxonox::Vector2& value)     { this->value_ = getConvertedValue<orxonox::Vector2,     T>(value); } /** @brief Assigns the value by converting it to T. */
    78     inline void setValue(const orxonox::Vector3& value)     { this->value_ = getConvertedValue<orxonox::Vector3,     T>(value); } /** @brief Assigns the value by converting it to T. */
    79     inline void setValue(const orxonox::Vector4& value)     { this->value_ = getConvertedValue<orxonox::Vector4,     T>(value); } /** @brief Assigns the value by converting it to T. */
    80     inline void setValue(const orxonox::ColourValue& value) { this->value_ = getConvertedValue<orxonox::ColourValue, T>(value); } /** @brief Assigns the value by converting it to T. */
    81     inline void setValue(const orxonox::Quaternion& value)  { this->value_ = getConvertedValue<orxonox::Quaternion,  T>(value); } /** @brief Assigns the value by converting it to T. */
    82     inline void setValue(const orxonox::Radian& value)      { this->value_ = getConvertedValue<orxonox::Radian,      T>(value); } /** @brief Assigns the value by converting it to T. */
    83     inline void setValue(const orxonox::Degree& value)      { this->value_ = getConvertedValue<orxonox::Degree,      T>(value); } /** @brief Assigns the value by converting it to T. */
     72    inline bool getValue(char*                 value) const { return ConvertValue<T, char                >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     73    inline bool getValue(unsigned char*        value) const { return ConvertValue<T, unsigned char       >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     74    inline bool getValue(short*                value) const { return ConvertValue<T, short               >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     75    inline bool getValue(unsigned short*       value) const { return ConvertValue<T, unsigned short      >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     76    inline bool getValue(int*                  value) const { return ConvertValue<T, int                 >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     77    inline bool getValue(unsigned int*         value) const { return ConvertValue<T, unsigned int        >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     78    inline bool getValue(long*                 value) const { return ConvertValue<T, long                >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     79    inline bool getValue(unsigned long*        value) const { return ConvertValue<T, unsigned long       >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     80    inline bool getValue(long long*            value) const { return ConvertValue<T, long long           >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     81    inline bool getValue(unsigned long long*   value) const { return ConvertValue<T, unsigned long long  >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     82    inline bool getValue(float*                value) const { return ConvertValue<T, float               >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     83    inline bool getValue(double*               value) const { return ConvertValue<T, double              >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     84    inline bool getValue(long double*          value) const { return ConvertValue<T, long double         >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     85    inline bool getValue(bool*                 value) const { return ConvertValue<T, bool                >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     86    inline bool getValue(void**                value) const { return ConvertValue<T, void*               >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     87    inline bool getValue(std::string*          value) const { return ConvertValue<T, std::string         >(value, value_, zeroise<std::string>         ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     88    inline bool getValue(orxonox::Vector2*     value) const { return ConvertValue<T, orxonox::Vector2    >(value, value_, zeroise<orxonox::Vector2>    ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     89    inline bool getValue(orxonox::Vector3*     value) const { return ConvertValue<T, orxonox::Vector3    >(value, value_, zeroise<orxonox::Vector3>    ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     90    inline bool getValue(orxonox::Vector4*     value) const { return ConvertValue<T, orxonox::Vector4    >(value, value_, zeroise<orxonox::Vector4>    ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     91    inline bool getValue(orxonox::ColourValue* value) const { return ConvertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     92    inline bool getValue(orxonox::Quaternion*  value) const { return ConvertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     93    inline bool getValue(orxonox::Radian*      value) const { return ConvertValue<T, orxonox::Radian     >(value, value_, zeroise<orxonox::Radian>     ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     94    inline bool getValue(orxonox::Degree*      value) const { return ConvertValue<T, orxonox::Degree     >(value, value_, zeroise<orxonox::Degree>     ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */
     95
     96    inline bool setValue(const char& value)                 { return !(bHasDefaultValue_ = !ConvertValue<char                , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     97    inline bool setValue(const unsigned char& value)        { return !(bHasDefaultValue_ = !ConvertValue<unsigned char       , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     98    inline bool setValue(const short& value)                { return !(bHasDefaultValue_ = !ConvertValue<short               , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     99    inline bool setValue(const unsigned short& value)       { return !(bHasDefaultValue_ = !ConvertValue<unsigned short      , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     100    inline bool setValue(const int& value)                  { return !(bHasDefaultValue_ = !ConvertValue<int                 , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     101    inline bool setValue(const unsigned int& value)         { return !(bHasDefaultValue_ = !ConvertValue<unsigned int        , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     102    inline bool setValue(const long& value)                 { return !(bHasDefaultValue_ = !ConvertValue<long                , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     103    inline bool setValue(const unsigned long& value)        { return !(bHasDefaultValue_ = !ConvertValue<unsigned long       , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     104    inline bool setValue(const long long& value)            { return !(bHasDefaultValue_ = !ConvertValue<long long           , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     105    inline bool setValue(const unsigned long long& value)   { return !(bHasDefaultValue_ = !ConvertValue<unsigned long long  , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     106    inline bool setValue(const float& value)                { return !(bHasDefaultValue_ = !ConvertValue<float               , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     107    inline bool setValue(const double& value)               { return !(bHasDefaultValue_ = !ConvertValue<double              , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     108    inline bool setValue(const long double& value)          { return !(bHasDefaultValue_ = !ConvertValue<long double         , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     109    inline bool setValue(const bool& value)                 { return !(bHasDefaultValue_ = !ConvertValue<bool                , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     110    inline bool setValue(      void* const& value)          { return !(bHasDefaultValue_ = !ConvertValue<void*               , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     111    inline bool setValue(const std::string& value)          { return !(bHasDefaultValue_ = !ConvertValue<std::string         , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     112    inline bool setValue(const orxonox::Vector2& value)     { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector2    , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     113    inline bool setValue(const orxonox::Vector3& value)     { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector3    , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     114    inline bool setValue(const orxonox::Vector4& value)     { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector4    , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     115    inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     116    inline bool setValue(const orxonox::Quaternion& value)  { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     117    inline bool setValue(const orxonox::Radian& value)      { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Radian     , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
     118    inline bool setValue(const orxonox::Degree& value)      { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Degree     , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */
    84119
    85120    inline operator char()                 const { return getConvertedValue<T, char>                (this->value_, 0); }     /** @brief Returns the current value, converted to the requested type. */
     
    96131    inline operator double()               const { return getConvertedValue<T, double>              (this->value_, 0); }     /** @brief Returns the current value, converted to the requested type. */
    97132    inline operator long double()          const { return getConvertedValue<T, long double>         (this->value_, 0); }     /** @brief Returns the current value, converted to the requested type. */
    98     inline operator bool()                 const { return getConvertedValue<T, bool>                (this->value_, false); } /** @brief Returns the current value, converted to the requested type. */
     133    inline operator bool()                 const { return getConvertedValue<T, bool>                (this->value_, 0); }    /** @brief Returns the current value, converted to the requested type. */
    99134    inline operator void*()                const { return getConvertedValue<T, void*>               (this->value_, 0); }     /** @brief Returns the current value, converted to the requested type. */
    100     inline operator std::string()          const { return getConvertedValue<T, std::string>         (this->value_); }        /** @brief Returns the current value, converted to the requested type. */
    101     inline operator orxonox::Vector2()     const { return getConvertedValue<T, orxonox::Vector2>    (this->value_); }        /** @brief Returns the current value, converted to the requested type. */
    102     inline operator orxonox::Vector3()     const { return getConvertedValue<T, orxonox::Vector3>    (this->value_); }        /** @brief Returns the current value, converted to the requested type. */
    103     inline operator orxonox::Vector4()     const { return getConvertedValue<T, orxonox::Vector4>    (this->value_); }        /** @brief Returns the current value, converted to the requested type. */
    104     inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_); }        /** @brief Returns the current value, converted to the requested type. */
    105     inline operator orxonox::Quaternion()  const { return getConvertedValue<T, orxonox::Quaternion> (this->value_); }        /** @brief Returns the current value, converted to the requested type. */
    106     inline operator orxonox::Radian()      const { return getConvertedValue<T, orxonox::Radian>     (this->value_); }        /** @brief Returns the current value, converted to the requested type. */
    107     inline operator orxonox::Degree()      const { return getConvertedValue<T, orxonox::Degree>     (this->value_); }        /** @brief Returns the current value, converted to the requested type. */
     135    inline operator std::string()          const { return getConvertedValue<T, std::string>         (this->value_, zeroise<std::string         >()); } /** @brief Returns the current value, converted to the requested type. */
     136    inline operator orxonox::Vector2()     const { return getConvertedValue<T, orxonox::Vector2>    (this->value_, zeroise<orxonox::Vector2    >()); } /** @brief Returns the current value, converted to the requested type. */
     137    inline operator orxonox::Vector3()     const { return getConvertedValue<T, orxonox::Vector3>    (this->value_, zeroise<orxonox::Vector3    >()); } /** @brief Returns the current value, converted to the requested type. */
     138    inline operator orxonox::Vector4()     const { return getConvertedValue<T, orxonox::Vector4>    (this->value_, zeroise<orxonox::Vector4    >()); } /** @brief Returns the current value, converted to the requested type. */
     139    inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, zeroise<orxonox::ColourValue>()); } /** @brief Returns the current value, converted to the requested type. */
     140    inline operator orxonox::Quaternion()  const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, zeroise<orxonox::Quaternion >()); } /** @brief Returns the current value, converted to the requested type. */
     141    inline operator orxonox::Radian()      const { return getConvertedValue<T, orxonox::Radian>     (this->value_, zeroise<orxonox::Radian     >()); } /** @brief Returns the current value, converted to the requested type. */
     142    inline operator orxonox::Degree()      const { return getConvertedValue<T, orxonox::Degree>     (this->value_, zeroise<orxonox::Degree     >()); } /** @brief Returns the current value, converted to the requested type. */
    108143
    109144    /** @brief Puts the current value on the stream */
  • code/trunk/src/util/OutputHandler.cc

    r1791 r2087  
    3333
    3434#include "OutputHandler.h"
     35#include <time.h>
    3536
    3637namespace orxonox
     
    4647        this->logfilename_ = logfilename;
    4748        this->logfile_.open(this->logfilename_.c_str(), std::fstream::out);
    48         this->logfile_ << "Started log at yyyy/mm/dd hh:mm:ss" << std::endl; // Todo: Get date and time
     49
     50        time_t rawtime;
     51        struct tm* timeinfo;
     52        time(&rawtime);
     53        timeinfo = localtime(&rawtime);
     54
     55        this->logfile_ << "Started log at " << asctime(timeinfo) << std::endl;
    4956        this->logfile_.flush();
    5057    }
  • code/trunk/src/util/String.cc

    r1894 r2087  
    3737#include <iostream>
    3838
    39 /**
    40     @brief Blank string as variable so you can use const std::string& even if you have to return "".
    41 */
    42 std::string blankString = "";
     39#include "Convert.h"
     40#include "Math.h"
     41
     42std::string BLANKSTRING("");
     43
     44std::string getUniqueNumberString()
     45{
     46    return convertToString(getUniqueNumber());
     47}
    4348
    4449/**
  • code/trunk/src/util/String.h

    r1889 r2087  
    4040#include <sstream>
    4141
    42 extern _UtilExport std::string blankString;
     42extern _UtilExport std::string BLANKSTRING;
     43_UtilExport std::string getUniqueNumberString();
    4344
    4445_UtilExport void        strip(std::string* str);
Note: See TracChangeset for help on using the changeset viewer.