Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1052 for code/trunk/src/util


Ignore:
Timestamp:
Apr 14, 2008, 3:42:49 AM (16 years ago)
Author:
landauf
Message:

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

Location:
code/trunk/src/util
Files:
16 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/util/CMakeLists.txt

    r1051 r1052  
    88  Math.cc
    99  String.cc
     10  Clipboard.cc
    1011  SubString.cc
    1112  MultiTypePrimitive.cc
  • code/trunk/src/util/Convert.h

    r871 r1052  
    2121 *   Author:
    2222 *      Benjamin Grauer
     23 *      Fabian 'x3n' Landau
    2324 *   Co-authors:
    24  *      Fabian 'x3n' Landau
     25 *      ...
    2526 */
    2627
     
    4243
    4344
    44 // DEFAULT CLASS
    45 template <typename FromType, typename ToType>
    46 class Converter
    47 {
    48   public:
    49     bool operator()(ToType* output, const FromType& input) const
    50     {
    51       return false;
    52     }
    53 };
    54 
    55 // PARTIAL SPECIALIZATION TO CONVERT TO STRINGS
    56 template<typename FromType>
    57 class Converter<FromType, std::string>
    58 {
    59   public:
    60     bool operator()(std::string* output, const FromType& input) const
    61     {
    62       std::ostringstream oss;
    63       if (oss << input)
    64       {
    65         (*output) = oss.str();
     45//////////
     46// MAIN //
     47//////////
     48
     49// Enum to declare the wanted conversion preference in case of equal type-levels
     50enum ConversionPreference
     51{
     52    CP_PreferToType,
     53    CP_PreferFromType,
     54};
     55
     56// Helper classes to determine the preferred partial template specialization
     57class _ToType_   {};
     58class _FromType_ {};
     59class _Explicit_ {};
     60
     61
     62// The default convert functions
     63template <class FromType, class ToType, class Type>
     64struct ConverterSpecialized
     65{
     66    enum { specialized = false };
     67    static bool convert(ToType* output, const FromType& input)
     68    { return false; }
     69};
     70
     71
     72// The default convert function if both types are the same
     73template <class BothTypes>
     74struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_>
     75{
     76    enum { specialized = true };
     77    static bool convert(BothTypes* output, const BothTypes& input)
     78    { (*output) = input; return true; }
     79};
     80
     81
     82// The possible levels
     83#define __low__  0 // Everything that is or behaves like a primitive type (an can be converted with a typecast to every other low-level type)
     84#define __mid__  1 // Everything that has overloaded << and >> operators to operate on a std::stream
     85#define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions
     86
     87// Defines the levels of all types: Default is __high__ so you don't have to define every high-level type
     88template <class T> struct ConverterLevel           { enum { level = __high__ }; };
     89template <> struct ConverterLevel<std::string>     { enum { level = __mid__ }; };
     90template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; };
     91template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; };
     92template <> struct ConverterLevel<int>             { enum { level = __low__ }; };
     93template <> struct ConverterLevel<unsigned int>    { enum { level = __low__ }; };
     94template <> struct ConverterLevel<char>            { enum { level = __low__ }; };
     95template <> struct ConverterLevel<unsigned char>   { enum { level = __low__ }; };
     96template <> struct ConverterLevel<short>           { enum { level = __low__ }; };
     97template <> struct ConverterLevel<unsigned short>  { enum { level = __low__ }; };
     98template <> struct ConverterLevel<long>            { enum { level = __low__ }; };
     99template <> struct ConverterLevel<unsigned long>   { enum { level = __low__ }; };
     100template <> struct ConverterLevel<float>           { enum { level = __low__ }; };
     101template <> struct ConverterLevel<double>          { enum { level = __low__ }; };
     102template <> struct ConverterLevel<long double>     { enum { level = __low__ }; };
     103template <> struct ConverterLevel<bool>            { enum { level = __low__ }; };
     104
     105
     106// Calculates the preference based on the levels of FromType and ToType
     107template <int from, int to>
     108struct ConverterPreference
     109{
     110    enum
     111    {
     112        // The maximum of both levels: element of {0, 1, 2}
     113        // max 0: Both types are primitives or have a similar behaviour
     114        // max 1: At least one type is not a primitive, but both can be put on a std::stream
     115        // max 2: There is at least one generic type that needs specialized conversions
     116        max = (from > to) ? from : to,
     117
     118        // The difference between both levels limited to +-1: element of {-1, 0, 1}
     119        // diff -1: The FromType has higher level than the ToType
     120        // diff  0: Both types have the same level
     121        // diff  1: The ToType has higher level than the FromType
     122        diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from)
     123    };
     124};
     125
     126
     127// The default conversion: This usually does nothing
     128template <int max, class FromType, class ToType>
     129struct ConverterDefault
     130{
     131    static bool convert(ToType* output, const FromType& input)
     132    {
     133        return false;
     134    }
     135};
     136// The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes)    template <int max, class FromType, class ToType>
     137template <class FromType, class ToType>
     138struct ConverterDefault<0, FromType, ToType>
     139{
     140    static bool convert(ToType* output, const FromType& input)
     141    {
     142        (*output) = (ToType)input;
    66143        return true;
    67       }
    68       else
    69         return false;
    70     }
    71 };
    72 
    73 // PARTIAL SPECIALIZATION TO CONVERT FROM STRING
    74 template<typename ToType>
    75 class Converter<std::string, ToType>
    76 {
    77   public:
    78     bool operator()(ToType* output, const std::string& input) const
    79     {
    80       std::istringstream iss(input);
    81       if (iss >> (*output))
     144    }
     145};
     146
     147
     148// Converter: Converts input of FromType into output of ToType
     149template <int diff, int max, class FromType, class ToType, ConversionPreference pref>
     150struct Converter
     151{
     152    static bool convert(ToType* output, const FromType& input)
     153    {
     154        return false;
     155    }
     156};
     157// Converter: level{FromType} > level{ToType}
     158template <int max, class FromType, class ToType, ConversionPreference pref>
     159struct Converter<-1, max, FromType, ToType, pref>
     160{   static bool convert(ToType* output, const FromType& input)
     161    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     162// Converter: level{FromType} < level{ToType}
     163template <int max, class FromType, class ToType, ConversionPreference pref>
     164struct Converter<1, max, FromType, ToType, pref>
     165{   static bool convert(ToType* output, const FromType& input)
     166    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     167// Converter: level{FromType} = level{ToType}
     168// CP_PreferToType
     169template <int max, class FromType, class ToType>
     170struct Converter<0, max, FromType, ToType, CP_PreferToType>
     171{   static bool convert(ToType* output, const FromType& input)
     172    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     173// CP_PreferFromType
     174template <int max, class FromType, class ToType>
     175struct Converter<0, max, FromType, ToType, CP_PreferFromType>
     176{   static bool convert(ToType* output, const FromType& input)
     177    { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };
     178
     179
     180// Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference
     181template <class FromType, class ToType>
     182static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType)
     183{
     184    return (preference == CP_PreferToType) ?
     185           Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff,
     186                     ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max,
     187                     FromType,
     188                     ToType,
     189                     CP_PreferToType>::convert(output, input)
     190         : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff,
     191                     ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max,
     192                     FromType,
     193                     ToType,
     194                     CP_PreferFromType>::convert(output, input);
     195}
     196
     197
     198//////////////////////
     199// HELPER FUNCTIONS //
     200//////////////////////
     201
     202// Helper function: Calls convertValue with and without default value and returns true if the conversion was successful
     203template<class FromType, class ToType>
     204static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType)
     205{
     206    return convertValue(output, input, preference);
     207}
     208template<class FromType, class ToType>
     209static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType)
     210{
     211    if (convertValue(output, input, preference))
    82212        return true;
    83       else
    84         return false;
    85     }
    86 };
    87 
    88 // FUNCTION SO WE DO NOT HAVE TO TELL THE COMPILER ABOUT THE TYPE
    89 template<typename FromType, typename ToType>
    90 static bool ConvertValue(ToType* output, const FromType& input)
    91 {
    92   Converter<FromType, ToType> converter;
    93   return converter(output, input);
     213
     214    (*output) = fallback;
     215    return false;
    94216}
    95217
    96 // THE SAME, BUT WITH DEFAULT VALUE
    97 template<typename FromType, typename ToType>
    98 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)
    99 {
    100   Converter<FromType, ToType> converter;
    101   if (converter(output, input))
    102     return true;
    103 
    104   (*output) = fallback;
    105   return false;
     218// Helper function: Calls convertValue with and without default value and returns the converted value
     219template<class FromType, class ToType>
     220static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType)
     221{
     222    ToType output = ToType();
     223    ConvertValue(&output, input, preference);
     224    return output;
    106225}
    107 
    108 // THE SAME LIKE BEFORE, BUT NEEDS NO POINTER TO THE OUTPUT
    109 template<typename FromType, typename ToType>
    110 static ToType ConvertValueAndReturn(const FromType& input)
    111 {
    112   ToType output;
    113   ConvertValue(&output, input);
    114   return output;
     226template<class FromType, class ToType>
     227static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType)
     228{
     229    ToType output = fallback;
     230    ConvertValue(&output, input, fallback, preference);
     231    return output;
    115232}
    116233
    117 // THE SAME, BUT WITH DEFAULT VALUE
    118 template<typename FromType, typename ToType>
    119 static ToType ConvertValueAndReturn(const FromType& input, const FromType& fallback)
    120 {
    121   ToType output;
    122   ConvertValue(&output, input, fallback);
    123   return output;
    124 }
    125 
    126 //////////////////////////
    127 // MORE SPECIALISATIONS //
    128 //////////////////////////
    129 
    130 // STRING TO STRING
    131 template<>
    132 class Converter<std::string, std::string>
    133 {
    134   public:
    135     bool operator()(std::string* output, const std::string& input) const
    136     {
    137         (*output) = std::string(input);
    138         return true;
    139     }
    140 };
     234
     235/////////////////////
     236// SPECIALIZATIONS //
     237/////////////////////
     238
     239/////////////
     240// SAMPLES //
     241/////////////
     242/*
     243// convert everything to xyz
     244template <class FromType>
     245struct ConverterSpecialized<FromType, xyz, _ToType_>
     246{
     247    enum { specialized = true };
     248    static bool convert(xyz* output, const FromType& input)
     249    { return ...; }
     250};
     251
     252// convert xyz to everything
     253template <class ToType>
     254struct ConverterSpecialized<xyz, ToType, _FromType_>
     255{
     256    enum { specialized = true };
     257    static bool convert(ToType* output, const xyz& input)
     258    { return ...; }
     259};
     260
     261// convert abc to xyz
     262template <>
     263struct ConverterSpecialized<abc, xyz, _Explicit_>
     264{
     265    enum { specialized = true };
     266    static bool convert(xyz* output, const abc& input)
     267    { return ...; }
     268};
     269*/
     270
     271////////////
     272// STRING //
     273////////////
     274
     275// convert to string
     276template <class FromType>
     277struct ConverterSpecialized<FromType, std::string, _ToType_>
     278{
     279    enum { specialized = true };
     280    static bool convert(std::string* output, const FromType& input)
     281    {
     282        std::ostringstream oss;
     283        if (oss << input)
     284        {
     285            (*output) = oss.str();
     286            return true;
     287        }
     288        else
     289            return false;
     290    }
     291};
     292
     293// convert from string
     294template <class ToType>
     295struct ConverterSpecialized<std::string, ToType, _FromType_>
     296{
     297    enum { specialized = true };
     298    static bool convert(ToType* output, const std::string& input)
     299    {
     300        std::istringstream iss(input);
     301        if (iss >> (*output))
     302            return true;
     303        else
     304            return false;
     305    }
     306};
     307
    141308
    142309////////////////
     
    144311////////////////
    145312
    146 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEPRIMITIVE
    147 template<typename ToType>
    148 class Converter<MultiTypePrimitive, ToType>
    149 {
    150   public:
    151     bool operator()(ToType* output, const MultiTypePrimitive& input) const
    152     {
    153       if (input.getType() == MT_int)
    154         return ConvertValue(output, input.getInt());
    155       else if (input.getType() == MT_uint)
    156         return ConvertValue(output, input.getUnsignedInt());
    157       else if (input.getType() == MT_char)
    158         return ConvertValue(output, input.getChar());
    159       else if (input.getType() == MT_uchar)
    160         return ConvertValue(output, input.getUnsignedChar());
    161       else if (input.getType() == MT_short)
    162         return ConvertValue(output, input.getShort());
    163       else if (input.getType() == MT_ushort)
    164         return ConvertValue(output, input.getUnsignedShort());
    165       else if (input.getType() == MT_long)
    166         return ConvertValue(output, input.getLong());
    167       else if (input.getType() == MT_ulong)
    168         return ConvertValue(output, input.getUnsignedLong());
    169       else if (input.getType() == MT_float)
    170         return ConvertValue(output, input.getFloat());
    171       else if (input.getType() == MT_double)
    172         return ConvertValue(output, input.getDouble());
    173       else if (input.getType() == MT_longdouble)
    174         return ConvertValue(output, input.getLongDouble());
    175       else if (input.getType() == MT_bool)
    176         return ConvertValue(output, input.getBool());
    177       else
    178         return false;
    179     }
    180 };
    181 template<>
    182 class Converter<MultiTypePrimitive, std::string>
    183 {
    184   public:
    185     bool operator()(std::string* output, const MultiTypePrimitive& input) const
    186     {
    187       if (input.getType() == MT_int)
    188         return ConvertValue(output, input.getInt());
    189       else if (input.getType() == MT_uint)
    190         return ConvertValue(output, input.getUnsignedInt());
    191       else if (input.getType() == MT_char)
    192         return ConvertValue(output, input.getChar());
    193       else if (input.getType() == MT_uchar)
    194         return ConvertValue(output, input.getUnsignedChar());
    195       else if (input.getType() == MT_short)
    196         return ConvertValue(output, input.getShort());
    197       else if (input.getType() == MT_ushort)
    198         return ConvertValue(output, input.getUnsignedShort());
    199       else if (input.getType() == MT_long)
    200         return ConvertValue(output, input.getLong());
    201       else if (input.getType() == MT_ulong)
    202         return ConvertValue(output, input.getUnsignedLong());
    203       else if (input.getType() == MT_float)
    204         return ConvertValue(output, input.getFloat());
    205       else if (input.getType() == MT_double)
    206         return ConvertValue(output, input.getDouble());
    207       else if (input.getType() == MT_longdouble)
    208         return ConvertValue(output, input.getLongDouble());
    209       else if (input.getType() == MT_bool)
    210         return ConvertValue(output, input.getBool());
    211       else
    212         return false;
    213     }
    214 };
    215 
    216 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPESTRING
    217 template<typename ToType>
    218 class Converter<MultiTypeString, ToType>
    219 {
    220   public:
    221     bool operator()(ToType* output, const MultiTypeString& input) const
    222     {
    223       if (input.getType() == MT_constchar)
    224         return ConvertValue(output, input.getConstChar());
    225       else if (input.getType() == MT_string)
    226         return ConvertValue(output, input.getString());
    227       else
    228         return ConvertValue(output, (MultiTypePrimitive)input);
    229     }
    230 };
    231 template<>
    232 class Converter<MultiTypeString, std::string>
    233 {
    234   public:
    235     bool operator()(std::string* output, const MultiTypeString& input) const
    236     {
    237       if (input.getType() == MT_constchar)
    238         return ConvertValue(output, input.getConstChar());
    239       else if (input.getType() == MT_string)
    240         return ConvertValue(output, input.getString());
    241       else
    242         return ConvertValue(output, (MultiTypePrimitive)input);
    243     }
    244 };
    245 
    246 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEMATH
    247 template<typename ToType>
    248 class Converter<MultiTypeMath, ToType>
    249 {
    250   public:
    251     bool operator()(ToType* output, const MultiTypeMath& input) const
    252     {
    253       if (input.getType() == MT_vector2)
    254         return ConvertValue(output, input.getVector2());
    255       else if (input.getType() == MT_vector3)
    256         return ConvertValue(output, input.getVector3());
    257       else if (input.getType() == MT_quaternion)
    258         return ConvertValue(output, input.getQuaternion());
    259       else if (input.getType() == MT_colourvalue)
    260         return ConvertValue(output, input.getColourValue());
    261       else if (input.getType() == MT_radian)
    262         return ConvertValue(output, input.getRadian());
    263       else if (input.getType() == MT_degree)
    264         return ConvertValue(output, input.getDegree());
    265       else
    266         return ConvertValue(output, (MultiTypeString)input);
    267     }
    268 };
    269 template<>
    270 class Converter<MultiTypeMath, std::string>
    271 {
    272   public:
    273     bool operator()(std::string* output, const MultiTypeMath& input) const
    274     {
    275       if (input.getType() == MT_vector2)
    276         return ConvertValue(output, input.getVector2());
    277       else if (input.getType() == MT_vector3)
    278         return ConvertValue(output, input.getVector3());
    279       else if (input.getType() == MT_quaternion)
    280         return ConvertValue(output, input.getQuaternion());
    281       else if (input.getType() == MT_colourvalue)
    282         return ConvertValue(output, input.getColourValue());
    283       else if (input.getType() == MT_radian)
    284         return ConvertValue(output, input.getRadian());
    285       else if (input.getType() == MT_degree)
    286         return ConvertValue(output, input.getDegree());
    287       else
    288         return ConvertValue(output, (MultiTypeString)input);
     313// convert from MultiTypePrimitive
     314template <class ToType>
     315struct ConverterSpecialized<MultiTypePrimitive, ToType, _FromType_>
     316{
     317    enum { specialized = true };
     318    static bool convert(ToType* output, const MultiTypePrimitive& input)
     319    {
     320        if (input.getType() == MT_void)
     321            return ConvertValue(output, input.getVoid());
     322        else if (input.getType() == MT_int)
     323            return ConvertValue(output, input.getInt());
     324        else if (input.getType() == MT_uint)
     325            return ConvertValue(output, input.getUnsignedInt());
     326        else if (input.getType() == MT_char)
     327            return ConvertValue(output, input.getChar());
     328        else if (input.getType() == MT_uchar)
     329            return ConvertValue(output, input.getUnsignedChar());
     330        else if (input.getType() == MT_short)
     331            return ConvertValue(output, input.getShort());
     332        else if (input.getType() == MT_ushort)
     333            return ConvertValue(output, input.getUnsignedShort());
     334        else if (input.getType() == MT_long)
     335            return ConvertValue(output, input.getLong());
     336        else if (input.getType() == MT_ulong)
     337            return ConvertValue(output, input.getUnsignedLong());
     338        else if (input.getType() == MT_float)
     339            return ConvertValue(output, input.getFloat());
     340        else if (input.getType() == MT_double)
     341            return ConvertValue(output, input.getDouble());
     342        else if (input.getType() == MT_longdouble)
     343            return ConvertValue(output, input.getLongDouble());
     344        else if (input.getType() == MT_bool)
     345            return ConvertValue(output, input.getBool());
     346        else
     347            return false;
     348    }
     349};
     350
     351// convert from MultiTypeString
     352template <class ToType>
     353struct ConverterSpecialized<MultiTypeString, ToType, _FromType_>
     354{
     355    enum { specialized = true };
     356    static bool convert(ToType* output, const MultiTypeString& input)
     357    {
     358        if (input.getType() == MT_constchar)
     359            return ConvertValue(output, input.getConstChar());
     360        else if (input.getType() == MT_string)
     361            return ConvertValue(output, input.getString());
     362        else
     363            return ConvertValue(output, (MultiTypePrimitive)input);
     364    }
     365};
     366
     367// convert from MultiTypeMath
     368template <class ToType>
     369struct ConverterSpecialized<MultiTypeMath, ToType, _FromType_>
     370{
     371    enum { specialized = true };
     372    static bool convert(ToType* output, const MultiTypeMath& input)
     373    {
     374        if (input.getType() == MT_vector2)
     375            return ConvertValue(output, input.getVector2());
     376        else if (input.getType() == MT_vector3)
     377            return ConvertValue(output, input.getVector3());
     378        else if (input.getType() == MT_quaternion)
     379            return ConvertValue(output, input.getQuaternion());
     380        else if (input.getType() == MT_colourvalue)
     381            return ConvertValue(output, input.getColourValue());
     382        else if (input.getType() == MT_radian)
     383            return ConvertValue(output, input.getRadian());
     384        else if (input.getType() == MT_degree)
     385            return ConvertValue(output, input.getDegree());
     386        else
     387            return ConvertValue(output, (MultiTypeString)input);
    289388    }
    290389};
     
    297396// Vector2 to std::string
    298397template <>
    299 class Converter<orxonox::Vector2, std::string>
    300 {
    301   public:
    302     bool operator()(std::string* output, const orxonox::Vector2& input) const
    303     {
    304       std::ostringstream ostream;
    305       if (ostream << input.x << "," << input.y)
    306       {
    307         (*output) = ostream.str();
    308         return true;
    309       }
    310 
    311       return false;
     398struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_>
     399{
     400    enum { specialized = true };
     401    static bool convert(std::string* output, const orxonox::Vector2& input)
     402    {
     403        std::ostringstream ostream;
     404        if (ostream << input.x << "," << input.y)
     405        {
     406            (*output) = ostream.str();
     407            return true;
     408        }
     409        return false;
    312410    }
    313411};
     
    315413// Vector3 to std::string
    316414template <>
    317 class Converter<orxonox::Vector3, std::string>
    318 {
    319   public:
    320     bool operator()(std::string* output, const orxonox::Vector3& input) const
    321     {
    322       std::ostringstream ostream;
    323       if (ostream << input.x << "," << input.y << "," << input.z)
    324       {
    325         (*output) = ostream.str();
    326         return true;
    327       }
    328 
    329       return false;
     415struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_>
     416{
     417    enum { specialized = true };
     418    static bool convert(std::string* output, const orxonox::Vector3& input)
     419    {
     420        std::ostringstream ostream;
     421        if (ostream << input.x << "," << input.y << "," << input.z)
     422        {
     423            (*output) = ostream.str();
     424            return true;
     425        }
     426        return false;
    330427    }
    331428};
     
    333430// Vector4 to std::string
    334431template <>
    335 class Converter<orxonox::Vector4, std::string>
    336 {
    337   public:
    338     bool operator()(std::string* output, const orxonox::Vector4& input) const
    339     {
    340       std::ostringstream ostream;
    341       if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
    342       {
    343         (*output) = ostream.str();
    344         return true;
    345       }
    346 
    347       return false;
     432struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_>
     433{
     434    enum { specialized = true };
     435    static bool convert(std::string* output, const orxonox::Vector4& input)
     436    {
     437        std::ostringstream ostream;
     438        if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
     439        {
     440            (*output) = ostream.str();
     441            return true;
     442        }
     443        return false;
    348444    }
    349445};
     
    351447// Quaternion to std::string
    352448template <>
    353 class Converter<orxonox::Quaternion, std::string>
    354 {
    355   public:
    356     bool operator()(std::string* output, const orxonox::Quaternion& input) const
    357     {
    358       std::ostringstream ostream;
    359       if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
    360       {
    361         (*output) = ostream.str();
    362         return true;
    363       }
    364 
    365       return false;
     449struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_>
     450{
     451    enum { specialized = true };
     452    static bool convert(std::string* output, const orxonox::Quaternion& input)
     453    {
     454        std::ostringstream ostream;
     455        if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
     456        {
     457            (*output) = ostream.str();
     458            return true;
     459        }
     460        return false;
    366461    }
    367462};
     
    369464// ColourValue to std::string
    370465template <>
    371 class Converter<orxonox::ColourValue, std::string>
    372 {
    373   public:
    374     bool operator()(std::string* output, const orxonox::ColourValue& input) const
    375     {
    376       std::ostringstream ostream;
    377       if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
    378       {
    379         (*output) = ostream.str();
    380         return true;
    381       }
    382 
    383       return false;
     466struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_>
     467{
     468    enum { specialized = true };
     469    static bool convert(std::string* output, const orxonox::ColourValue& input)
     470    {
     471        std::ostringstream ostream;
     472        if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
     473        {
     474            (*output) = ostream.str();
     475            return true;
     476        }
     477        return false;
    384478    }
    385479};
     
    392486// std::string to Vector2
    393487template <>
    394 class Converter<std::string, orxonox::Vector2>
    395 {
    396   public:
    397     bool operator()(orxonox::Vector2* output, const std::string& input) const
    398     {
    399       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    400       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    401 
    402       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
    403 
    404       if (tokens.size() >= 2)
    405       {
    406         if (!ConvertValue(&(output->x), tokens[0]))
    407           return false;
    408         if (!ConvertValue(&(output->y), tokens[1]))
    409           return false;
    410 
    411         return true;
    412       }
    413 
    414       return false;
     488struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_>
     489{
     490    enum { specialized = true };
     491    static bool convert(orxonox::Vector2* output, const std::string& input)
     492    {
     493        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     494        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     495
     496        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     497        if (tokens.size() >= 2)
     498        {
     499            if (!ConvertValue(&(output->x), tokens[0]))
     500                return false;
     501            if (!ConvertValue(&(output->y), tokens[1]))
     502                return false;
     503
     504            return true;
     505        }
     506        return false;
    415507    }
    416508};
     
    418510// std::string to Vector3
    419511template <>
    420 class Converter<std::string, orxonox::Vector3>
    421 {
    422   public:
    423     bool operator()(orxonox::Vector3* output, const std::string& input) const
    424     {
    425       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    426       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    427 
    428       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
    429 
    430       if (tokens.size() >= 3)
    431       {
    432         if (!ConvertValue(&(output->x), tokens[0]))
    433           return false;
    434         if (!ConvertValue(&(output->y), tokens[1]))
    435           return false;
    436         if (!ConvertValue(&(output->z), tokens[2]))
    437           return false;
    438 
    439         return true;
    440       }
    441 
    442       return false;
     512struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_>
     513{
     514    enum { specialized = true };
     515    static bool convert(orxonox::Vector3* output, const std::string& input)
     516    {
     517        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     518        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     519
     520        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     521        if (tokens.size() >= 3)
     522        {
     523            if (!ConvertValue(&(output->x), tokens[0]))
     524                return false;
     525            if (!ConvertValue(&(output->y), tokens[1]))
     526                return false;
     527            if (!ConvertValue(&(output->z), tokens[2]))
     528                return false;
     529
     530            return true;
     531        }
     532        return false;
    443533    }
    444534};
     
    446536// std::string to Vector4
    447537template <>
    448 class Converter<std::string, orxonox::Vector4>
    449 {
    450   public:
    451     bool operator()(orxonox::Vector4* output, const std::string& input) const
    452     {
    453       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    454       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    455 
    456       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
    457 
    458       if (tokens.size() >= 4)
    459       {
    460         if (!ConvertValue(&(output->x), tokens[0]))
    461           return false;
    462         if (!ConvertValue(&(output->y), tokens[1]))
    463           return false;
    464         if (!ConvertValue(&(output->z), tokens[2]))
    465           return false;
    466         if (!ConvertValue(&(output->w), tokens[3]))
    467           return false;
    468 
    469         return true;
    470       }
    471 
    472       return false;
     538struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_>
     539{
     540    enum { specialized = true };
     541    static bool convert(orxonox::Vector4* output, const std::string& input)
     542    {
     543        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     544        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     545
     546        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     547        if (tokens.size() >= 4)
     548        {
     549            if (!ConvertValue(&(output->x), tokens[0]))
     550                return false;
     551            if (!ConvertValue(&(output->y), tokens[1]))
     552                return false;
     553            if (!ConvertValue(&(output->z), tokens[2]))
     554                return false;
     555            if (!ConvertValue(&(output->w), tokens[3]))
     556                return false;
     557
     558            return true;
     559        }
     560        return false;
    473561    }
    474562};
     
    476564// std::string to Quaternion
    477565template <>
    478 class Converter<std::string, orxonox::Quaternion>
    479 {
    480   public:
    481     bool operator()(orxonox::Quaternion* output, const std::string& input) const
    482     {
    483       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    484       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    485 
    486       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
    487 
    488       if (tokens.size() >= 4)
    489       {
    490         if (!ConvertValue(&(output->w), tokens[0]))
    491           return false;
    492         if (!ConvertValue(&(output->x), tokens[1]))
    493           return false;
    494         if (!ConvertValue(&(output->y), tokens[2]))
    495           return false;
    496         if (!ConvertValue(&(output->z), tokens[3]))
    497           return false;
    498 
    499         return true;
    500       }
    501 
    502       return false;
     566struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_>
     567{
     568    enum { specialized = true };
     569    static bool convert(orxonox::Quaternion* output, const std::string& input)
     570    {
     571        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     572        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     573
     574        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     575        if (tokens.size() >= 4)
     576        {
     577            if (!ConvertValue(&(output->w), tokens[0]))
     578                return false;
     579            if (!ConvertValue(&(output->x), tokens[1]))
     580                return false;
     581            if (!ConvertValue(&(output->y), tokens[2]))
     582                return false;
     583            if (!ConvertValue(&(output->z), tokens[3]))
     584                return false;
     585
     586            return true;
     587        }
     588        return false;
    503589    }
    504590};
     
    506592// std::string to ColourValue
    507593template <>
    508 class Converter<std::string, orxonox::ColourValue>
    509 {
    510   public:
    511     bool operator()(orxonox::ColourValue* output, const std::string& input) const
    512     {
    513       unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
    514       if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    515 
    516       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
    517 
    518       if (tokens.size() >= 4)
    519       {
    520         if (!ConvertValue(&(output->r), tokens[0]))
    521           return false;
    522         if (!ConvertValue(&(output->g), tokens[1]))
    523           return false;
    524         if (!ConvertValue(&(output->b), tokens[2]))
    525           return false;
    526         if (!ConvertValue(&(output->a), tokens[3]))
    527           return false;
    528 
    529         return true;
    530       }
    531 
    532       return false;
     594struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_>
     595{
     596    enum { specialized = true };
     597    static bool convert(orxonox::ColourValue* output, const std::string& input)
     598    {
     599        unsigned int opening_parenthesis, closing_parenthesis = input.find(')');
     600        if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     601
     602        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     603        if (tokens.size() >= 4)
     604        {
     605            if (!ConvertValue(&(output->r), tokens[0]))
     606                return false;
     607            if (!ConvertValue(&(output->g), tokens[1]))
     608                return false;
     609            if (!ConvertValue(&(output->b), tokens[2]))
     610                return false;
     611            if (!ConvertValue(&(output->a), tokens[3]))
     612                return false;
     613
     614            return true;
     615        }
     616        return false;
    533617    }
    534618};
  • code/trunk/src/util/Math.h

    r892 r1052  
    2626 */
    2727
    28 #ifndef _Math_H__
    29 #define _Math_H__
     28#ifndef _Util_Math_H__
     29#define _Util_Math_H__
    3030
    3131#include <ostream>
     
    146146}
    147147
    148 #endif /* _Math_H__ */
    149 
     148#endif /* _Util_Math_H__ */
  • code/trunk/src/util/MultiType.h

    r871 r1052  
    3535{
    3636    MT_null,
     37    MT_void,
    3738    MT_int,
    3839    MT_uint,
     
    4950    MT_constchar,
    5051    MT_string,
     52    MT_xmlelement,
    5153    MT_vector2,
    5254    MT_vector3,
     
    5961union _UtilExport MultiTypeValue
    6062{
     63    void*           void_;
    6164    int             int_;
    6265    unsigned int    uint_;
  • code/trunk/src/util/MultiTypeMath.cc

    r871 r1052  
    8888}
    8989
     90MultiTypeMath::operator void*() const
     91{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeMath, void*>(*this, 0); }
    9092MultiTypeMath::operator int() const
    91 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this); }
     93{ return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeMath, int>(*this, 0); }
    9294MultiTypeMath::operator unsigned int() const
    93 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeMath, unsigned int>(*this); }
     95{ return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeMath, unsigned int>(*this, 0); }
    9496MultiTypeMath::operator char() const
    95 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeMath, char>(*this); }
     97{ return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeMath, char>(*this, 0); }
    9698MultiTypeMath::operator unsigned char() const
    97 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeMath, unsigned char>(*this); }
     99{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeMath, unsigned char>(*this, 0); }
    98100MultiTypeMath::operator short() const
    99 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeMath, short>(*this); }
     101{ return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeMath, short>(*this, 0); }
    100102MultiTypeMath::operator unsigned short() const
    101 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeMath, unsigned short>(*this); }
     103{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeMath, unsigned short>(*this, 0); }
    102104MultiTypeMath::operator long() const
    103 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeMath, long>(*this); }
     105{ return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeMath, long>(*this, 0); }
    104106MultiTypeMath::operator unsigned long() const
    105 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeMath, unsigned long>(*this); }
     107{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeMath, unsigned long>(*this, 0); }
    106108MultiTypeMath::operator float() const
    107 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeMath, float>(*this); }
     109{ return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeMath, float>(*this, 0); }
    108110MultiTypeMath::operator double() const
    109 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeMath, double>(*this); }
     111{ return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeMath, double>(*this, 0); }
    110112MultiTypeMath::operator long double() const
    111 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeMath, long double>(*this); }
     113{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeMath, long double>(*this, 0); }
    112114MultiTypeMath::operator bool() const
    113 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeMath, bool>(*this); }
     115{ return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeMath, bool>(*this, 0); }
    114116MultiTypeMath::operator std::string() const
    115 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this); }
     117{ return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this); }
    116118MultiTypeMath::operator const char*() const
    117 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this)).c_str(); }
     119{ return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this)).c_str(); }
    118120MultiTypeMath::operator orxonox::Vector2() const
    119 { return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector2>(*this); }
     121{ return (this->type_ == MT_vector2) ? this->vector2_ : getConvertedValue<MultiTypeMath, orxonox::Vector2>(*this); }
    120122MultiTypeMath::operator orxonox::Vector3() const
    121 { return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector3>(*this); }
     123{ return (this->type_ == MT_vector3) ? this->vector3_ : getConvertedValue<MultiTypeMath, orxonox::Vector3>(*this); }
    122124MultiTypeMath::operator orxonox::Quaternion() const
    123 { return (this->type_ == MT_quaternion) ? this->quaternion_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Quaternion>(*this); }
     125{ return (this->type_ == MT_quaternion) ? this->quaternion_ : getConvertedValue<MultiTypeMath, orxonox::Quaternion>(*this); }
    124126MultiTypeMath::operator orxonox::ColourValue() const
    125 { return (this->type_ == MT_colourvalue) ? this->colourvalue_ : ConvertValueAndReturn<MultiTypeMath, orxonox::ColourValue>(*this); }
     127{ return (this->type_ == MT_colourvalue) ? this->colourvalue_ : getConvertedValue<MultiTypeMath, orxonox::ColourValue>(*this); }
    126128MultiTypeMath::operator orxonox::Radian() const
    127 { return (this->type_ == MT_radian) ? this->radian_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Radian>(*this); }
     129{ return (this->type_ == MT_radian) ? this->radian_ : getConvertedValue<MultiTypeMath, orxonox::Radian>(*this); }
    128130MultiTypeMath::operator orxonox::Degree() const
    129 { return (this->type_ == MT_degree) ? this->degree_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Degree>(*this); }
     131{ return (this->type_ == MT_degree) ? this->degree_ : getConvertedValue<MultiTypeMath, orxonox::Degree>(*this); }
    130132
    131133void MultiTypeMath::setValue(const MultiTypeMath& mtm)
     
    138140    this->radian_ = mtm.radian_;
    139141    this->degree_ = mtm.degree_;
     142}
     143
     144std::string MultiTypeMath::getTypename() const
     145{
     146    if (this->type_ == MT_vector2)
     147        return "Vector2";
     148    else if (this->type_ == MT_vector3)
     149        return "Vector3";
     150    else if (this->type_ == MT_colourvalue)
     151        return "ColourValue";
     152    else if (this->type_ == MT_quaternion)
     153        return "Quaternion";
     154    else if (this->type_ == MT_radian)
     155        return "Radian";
     156    else if (this->type_ == MT_degree)
     157        return "Degree";
     158    else
     159        return MultiTypeString::getTypename();
    140160}
    141161
  • code/trunk/src/util/MultiTypeMath.h

    r890 r1052  
    3838{
    3939    public:
    40         MultiTypeMath(MultiType      type = MT_null);
     40        MultiTypeMath(MultiType type = MT_null);
     41        inline MultiTypeMath(void*          value) : MultiTypeString(value) {}
    4142        inline MultiTypeMath(int            value) : MultiTypeString(value) {}
    4243        inline MultiTypeMath(unsigned int   value) : MultiTypeString(value) {}
     
    5152        inline MultiTypeMath(long double    value) : MultiTypeString(value) {}
    5253        inline MultiTypeMath(bool           value) : MultiTypeString(value) {}
    53         inline MultiTypeMath(const char*        value) : MultiTypeString(value) {}
    54         inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {}
     54        inline MultiTypeMath(const char*             value) : MultiTypeString(value) {}
     55        inline MultiTypeMath(const std::string&      value) : MultiTypeString(value) {}
    5556        inline MultiTypeMath(const orxonox::Vector2&     value) { this->setValue(value); }
    5657        inline MultiTypeMath(const orxonox::Vector3&     value) { this->setValue(value); }
     
    8990        bool operator!=(const MultiTypeMath& mtm) const;
    9091
     92        virtual operator void*()                const;
    9193        virtual operator int()                  const;
    9294        virtual operator unsigned int()         const;
     
    141143        inline void getValue(orxonox::Degree*      variable) const { (*variable) = orxonox::Degree      (this->degree_);      }
    142144
     145        virtual std::string getTypename() const;
     146
    143147        virtual std::string toString() const;
    144148        virtual bool fromString(const std::string value);
  • code/trunk/src/util/MultiTypePrimitive.cc

    r871 r1052  
    3434    this->type_ = type;
    3535
    36     if (type == MT_int)
     36    if (type == MT_void)
     37        this->value_.void_ = 0;
     38    else if (type == MT_int)
    3739        this->value_.int_ = 0;
    3840    else if (type == MT_uint)
     
    5961        this->value_.bool_ = false;
    6062    else
    61         this->value_.int_ = 0;
     63        this->value_.void_ = 0;
    6264}
    6365
     
    6668    if (this->type_ == mtp.type_)
    6769    {
    68         if (this->type_ == MT_int)
     70        if (this->type_ == MT_void)
     71            return (this->value_.void_ == mtp.value_.void_);
     72        else if (this->type_ == MT_int)
    6973            return (this->value_.int_ == mtp.value_.int_);
    7074        else if (this->type_ == MT_uint)
     
    99103    if (this->type_ == mtp.type_)
    100104    {
    101         if (this->type_ == MT_int)
     105        if (this->type_ == MT_void)
     106            return (this->value_.void_ != mtp.value_.void_);
     107        else if (this->type_ == MT_int)
    102108            return (this->value_.int_ != mtp.value_.int_);
    103109        else if (this->type_ == MT_uint)
     
    128134}
    129135
     136MultiTypePrimitive::operator void*() const
     137{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypePrimitive, void*>(*this, 0); }
    130138MultiTypePrimitive::operator int() const
    131 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this); }
     139{ return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypePrimitive, int>(*this, 0); }
    132140MultiTypePrimitive::operator unsigned int() const
    133 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this); }
     141{ return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypePrimitive, unsigned int>(*this, 0); }
    134142MultiTypePrimitive::operator char() const
    135 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this); }
     143{ return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypePrimitive, char>(*this, 0); }
    136144MultiTypePrimitive::operator unsigned char() const
    137 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this); }
     145{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypePrimitive, unsigned char>(*this, 0); }
    138146MultiTypePrimitive::operator short() const
    139 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this); }
     147{ return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypePrimitive, short>(*this, 0); }
    140148MultiTypePrimitive::operator unsigned short() const
    141 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this); }
     149{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypePrimitive, unsigned short>(*this, 0); }
    142150MultiTypePrimitive::operator long() const
    143 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this); }
     151{ return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypePrimitive, long>(*this, 0); }
    144152MultiTypePrimitive::operator unsigned long() const
    145 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this); }
     153{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypePrimitive, unsigned long>(*this, 0); }
    146154MultiTypePrimitive::operator float() const
    147 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this); }
     155{ return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypePrimitive, float>(*this, 0); }
    148156MultiTypePrimitive::operator double() const
    149 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this); }
     157{ return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypePrimitive, double>(*this, 0); }
    150158MultiTypePrimitive::operator long double() const
    151 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this); }
     159{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypePrimitive, long double>(*this, 0); }
    152160MultiTypePrimitive::operator bool() const
    153 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this); }
     161{ return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypePrimitive, bool>(*this, 0); }
    154162
    155163void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp)
     
    159167}
    160168
     169std::string MultiTypePrimitive::getTypename() const
     170{
     171    if (this->type_ == MT_void)
     172        return "pointer";
     173    else if (this->type_ == MT_int)
     174        return "int";
     175    else if (this->type_ == MT_uint)
     176        return "unsigned int";
     177    else if (this->type_ == MT_char)
     178        return "char";
     179    else if (this->type_ == MT_uchar)
     180        return "unsigned char";
     181    else if (this->type_ == MT_short)
     182        return "short";
     183    else if (this->type_ == MT_ushort)
     184        return "unsigned short";
     185    else if (this->type_ == MT_long)
     186        return "long";
     187    else if (this->type_ == MT_ulong)
     188        return "unsigned long";
     189    else if (this->type_ == MT_float)
     190        return "float";
     191    else if (this->type_ == MT_double)
     192        return "double";
     193    else if (this->type_ == MT_longdouble)
     194        return "long double";
     195    else if (this->type_ == MT_bool)
     196        return "bool";
     197    else
     198        return "unknown";
     199}
     200
    161201std::string MultiTypePrimitive::toString() const
    162202{
    163203    std::string output;
    164204
    165     if (this->type_ == MT_int)
     205    if (this->type_ == MT_void)
     206        ConvertValue(&output, this->value_.void_);
     207    else if (this->type_ == MT_int)
    166208        ConvertValue(&output, this->value_.int_);
    167209    else if (this->type_ == MT_uint)
     
    193235bool MultiTypePrimitive::fromString(const std::string value)
    194236{
    195     if (this->type_ == MT_int)
     237    if (this->type_ == MT_void)
     238        return ConvertValue(&this->value_.void_, value, (void*)0);
     239    else if (this->type_ == MT_int)
    196240        return ConvertValue(&this->value_.int_, value, (int)0);
    197241    else if (this->type_ == MT_uint)
  • code/trunk/src/util/MultiTypePrimitive.h

    r890 r1052  
    3636#include "MultiType.h"
    3737
     38namespace orxonox
     39{
     40    class BaseObject;
     41}
    3842class _UtilExport MultiTypePrimitive
    3943{
    4044    public:
    41         MultiTypePrimitive(MultiType      type = MT_null);
     45        MultiTypePrimitive(MultiType type = MT_null);
     46        inline MultiTypePrimitive(void*          value) { this->setValue(value); }
    4247        inline MultiTypePrimitive(int            value) { this->setValue(value); }
    4348        inline MultiTypePrimitive(unsigned int   value) { this->setValue(value); }
     
    5661
    5762        inline MultiTypePrimitive& operator=(MultiType      value) { this->type_ = MT_null; return *this; }
     63        inline MultiTypePrimitive& operator=(void*          value) { this->setValue(value); return *this; }
    5864        inline MultiTypePrimitive& operator=(int            value) { this->setValue(value); return *this; }
    5965        inline MultiTypePrimitive& operator=(unsigned int   value) { this->setValue(value); return *this; }
     
    7076        inline MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; }
    7177
     78        inline bool operator==(void*          value) const { return (this->value_.void_       == value); }
    7279        inline bool operator==(int            value) const { return (this->value_.int_        == value); }
    7380        inline bool operator==(unsigned int   value) const { return (this->value_.uint_       == value); }
     
    8491        bool operator==(const MultiTypePrimitive& mtp) const;
    8592
    86         inline bool operator!=(int            value) const { return (this->value_.int_        != value); }
     93        inline bool operator!=(void*          value) const { return (this->value_.void_       != value); }
    8794        inline bool operator!=(unsigned int   value) const { return (this->value_.uint_       != value); }
    8895        inline bool operator!=(char           value) const { return (this->value_.char_       != value); }
     
    98105        bool operator!=(const MultiTypePrimitive& mtp) const;
    99106
     107        template <class T>
     108        operator T*()                     const
     109        { return ((T*)this->value_.void_); }
     110        virtual operator void*()          const;
    100111        virtual operator int()            const;
    101112        virtual operator unsigned int()   const;
     
    111122        virtual operator bool()           const;
    112123
     124        inline void setValue(void*          value) { this->type_ = MT_void;       this->value_.void_       = value; }
    113125        inline void setValue(int            value) { this->type_ = MT_int;        this->value_.int_        = value; }
    114126        inline void setValue(unsigned int   value) { this->type_ = MT_uint;       this->value_.uint_       = value; }
     
    125137        void setValue(const MultiTypePrimitive& mtp);
    126138
     139        inline void*          getVoid()          const { return this->value_.void_;        }
    127140        inline int            getInt()           const { return this->value_.int_;        }
    128141        inline unsigned int   getUnsignedInt()   const { return this->value_.uint_;       }
     
    151164        inline bool&           getBool()          { return this->value_.bool_;       }
    152165
     166        inline void getValue(void*           variable) const { variable    = this->value_.void_;       }
    153167        inline void getValue(int*            variable) const { (*variable) = this->value_.int_;        }
    154168        inline void getValue(unsigned int*   variable) const { (*variable) = this->value_.uint_;       }
     
    167181        inline bool      isA(MultiType type) const { return (this->type_ == type); }
    168182
     183        virtual std::string getTypename() const;
     184
    169185        virtual std::string toString() const;
    170186        virtual bool fromString(const std::string value);
  • code/trunk/src/util/MultiTypeString.cc

    r871 r1052  
    3232MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type)
    3333{
    34     if (type == MT_constchar)
    35         this->string_ = std::string("");
    36     else if (type == MT_string)
    37         this->string_ = std::string("");
     34    // Nothing to do for string and xml-element
    3835}
    3936
     
    6461}
    6562
     63MultiTypeString::operator void*() const
     64{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeString, void*>(*this, 0); }
    6665MultiTypeString::operator int() const
    67 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this); }
     66{ return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeString, int>(*this, 0); }
    6867MultiTypeString::operator unsigned int() const
    69 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeString, unsigned int>(*this); }
     68{ return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeString, unsigned int>(*this, 0); }
    7069MultiTypeString::operator char() const
    71 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeString, char>(*this); }
     70{ return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeString, char>(*this, 0); }
    7271MultiTypeString::operator unsigned char() const
    73 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeString, unsigned char>(*this); }
     72{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeString, unsigned char>(*this, 0); }
    7473MultiTypeString::operator short() const
    75 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeString, short>(*this); }
     74{ return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeString, short>(*this, 0); }
    7675MultiTypeString::operator unsigned short() const
    77 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeString, unsigned short>(*this); }
     76{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeString, unsigned short>(*this, 0); }
    7877MultiTypeString::operator long() const
    79 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeString, long>(*this); }
     78{ return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeString, long>(*this, 0); }
    8079MultiTypeString::operator unsigned long() const
    81 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeString, unsigned long>(*this); }
     80{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeString, unsigned long>(*this, 0); }
    8281MultiTypeString::operator float() const
    83 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeString, float>(*this); }
     82{ return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeString, float>(*this, 0); }
    8483MultiTypeString::operator double() const
    85 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeString, double>(*this); }
     84{ return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeString, double>(*this, 0); }
    8685MultiTypeString::operator long double() const
    87 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeString, long double>(*this); }
     86{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeString, long double>(*this, 0); }
    8887MultiTypeString::operator bool() const
    89 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeString, bool>(*this); }
     88{ return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeString, bool>(*this, 0); }
    9089MultiTypeString::operator std::string() const
    91 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this); }
     90{ return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this); }
    9291MultiTypeString::operator const char*() const
    93 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this)).c_str(); }
     92{ return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this)).c_str(); }
    9493
    9594void MultiTypeString::setValue(const MultiTypeString& mts)
     
    9998}
    10099
     100std::string MultiTypeString::getTypename() const
     101{
     102    if (this->type_ == MT_constchar)
     103        return "string";
     104    else if (this->type_ == MT_string)
     105        return "string";
     106    else
     107        return MultiTypePrimitive::getTypename();
     108}
     109
    101110std::string MultiTypeString::toString() const
    102111{
     112    std::string output;
     113
    103114    if (this->type_ == MT_constchar)
    104115        return this->string_;
     
    107118    else
    108119        return MultiTypePrimitive::toString();
     120
     121    return output;
    109122}
    110123
  • code/trunk/src/util/MultiTypeString.h

    r890 r1052  
    3939{
    4040    public:
    41         MultiTypeString(MultiType      type = MT_null);
     41        MultiTypeString(MultiType type = MT_null);
     42        inline MultiTypeString(void*          value) : MultiTypePrimitive(value) {}
    4243        inline MultiTypeString(int            value) : MultiTypePrimitive(value) {}
    4344        inline MultiTypeString(unsigned int   value) : MultiTypePrimitive(value) {}
     
    5253        inline MultiTypeString(long double    value) : MultiTypePrimitive(value) {}
    5354        inline MultiTypeString(bool           value) : MultiTypePrimitive(value) {}
    54         inline MultiTypeString(const char*        value)   { this->setValue(value); }
    55         inline MultiTypeString(const std::string& value)   { this->setValue(value); }
    56         inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts);   }
     55        inline MultiTypeString(const char*           value)   { this->setValue(value); }
     56        inline MultiTypeString(const std::string&    value)   { this->setValue(value); }
     57        inline MultiTypeString(const MultiTypeString& mts)    { this->setValue(mts);   }
    5758        virtual inline ~MultiTypeString() {}
    5859
    5960        using MultiTypePrimitive::operator=;
    60         inline MultiTypeString& operator=(const char*        value)   { this->setValue(value); return *this; }
    61         inline MultiTypeString& operator=(const std::string& value)   { this->setValue(value); return *this; }
    62         inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts);   return *this; }
     61        inline MultiTypeString& operator=(const char*             value)   { this->setValue(value); return *this; }
     62        inline MultiTypeString& operator=(const std::string&      value)   { this->setValue(value); return *this; }
     63        inline MultiTypeString& operator=(const MultiTypeString& mts)      { this->setValue(mts);   return *this; }
    6364
    6465        using MultiTypePrimitive::operator==;
    65         inline bool operator==(const char*        value) const { return (this->string_ == std::string(value)); }
    66         inline bool operator==(const std::string& value) const { return (this->string_ == value);              }
     66        inline bool operator==(const char*             value) const { return (this->string_      == std::string(value)); }
     67        inline bool operator==(const std::string&      value) const { return (this->string_      == value);              }
    6768        bool operator==(const MultiTypeString& mts) const;
    6869
    6970        using MultiTypePrimitive::operator!=;
    70         inline bool operator!=(const char*        value) const { return (this->string_ != std::string(value)); }
    71         inline bool operator!=(const std::string& value) const { return (this->string_ != value);              }
     71        inline bool operator!=(const char*             value) const { return (this->string_      != std::string(value)); }
     72        inline bool operator!=(const std::string&      value) const { return (this->string_      != value);              }
    7273        bool operator!=(const MultiTypeString& mts) const;
    7374
    74         virtual operator int()            const;
    75         virtual operator unsigned int()   const;
    76         virtual operator char()           const;
    77         virtual operator unsigned char()  const;
    78         virtual operator short()          const;
    79         virtual operator unsigned short() const;
    80         virtual operator long()           const;
    81         virtual operator unsigned long()  const;
    82         virtual operator float ()         const;
    83         virtual operator double ()        const;
    84         virtual operator long double()    const;
    85         virtual operator bool()           const;
    86         virtual operator std::string()    const;
    87         virtual operator const char*()    const;
     75        virtual operator void*()                const;
     76        virtual operator int()                  const;
     77        virtual operator unsigned int()         const;
     78        virtual operator char()                 const;
     79        virtual operator unsigned char()        const;
     80        virtual operator short()                const;
     81        virtual operator unsigned short()       const;
     82        virtual operator long()                 const;
     83        virtual operator unsigned long()        const;
     84        virtual operator float ()               const;
     85        virtual operator double ()              const;
     86        virtual operator long double()          const;
     87        virtual operator bool()                 const;
     88        virtual operator std::string()          const;
     89        virtual operator const char*()          const;
    8890
    8991        using MultiTypePrimitive::setValue;
    90         inline void setValue(const char*        value) { this->type_ = MT_string; this->string_ = std::string(value); }
    91         inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value;              }
     92        inline void setValue(const char*             value) { this->type_ = MT_string;     this->string_    = std::string(value); }
     93        inline void setValue(const std::string&      value) { this->type_ = MT_string;     this->string_    = value;              }
    9294        void setValue(const MultiTypeString& mts);
    9395
    94         inline const std::string getString() const { return this->string_;         }
    95         inline const char*  getConstChar()   const { return this->string_.c_str(); }
     96        inline std::string getString()          const { return this->string_;         }
     97        inline const char*  getConstChar()      const { return this->string_.c_str(); }
    9698
    97         inline const std::string& getString() { return this->string_;         }
    98         inline const char*  getConstChar()    { return this->string_.c_str(); }
     99        inline std::string& getString()          { return this->string_;         }
     100        inline const char*  getConstChar()       { return this->string_.c_str(); }
    99101
    100102        using MultiTypePrimitive::getValue;
    101         inline void getValue(std::string* variable) const { (*variable) = this->string_;         }
    102         inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); }
     103        inline void getValue(std::string*      variable) const { (*variable) = this->string_;         }
     104        inline void getValue(const char**      variable) const { (*variable) = this->string_.c_str(); }
     105
     106        virtual std::string getTypename() const;
    103107
    104108        virtual std::string toString() const;
     
    106110
    107111    protected:
    108         std::string string_;
     112        std::string      string_;
    109113};
    110114
  • code/trunk/src/util/String.cc

    r871 r1052  
    2626 */
    2727
     28#include <cctype>
     29#include <iostream>
    2830#include "String.h"
    2931
     
    5456
    5557/**
     58    @brief Returns a copy of a string without trailing whitespaces.
     59    @param str The string
     60    @return The modified copy
     61*/
     62std::string removeTrailingWhitespaces(const std::string& str)
     63{
     64    unsigned int pos1 = 0;
     65    unsigned int pos2 = str.size() - 1;
     66    for (; pos1 < str.size() && (str[pos1] == ' ' || str[pos1] == '\t' || str[pos1] == '\n'); pos1++);
     67    for (; pos2 >= 0         && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
     68    return str.substr(pos1, pos2 - pos1 + 1);
     69}
     70
     71/**
     72    @brief Returns the position of the next quote in the string, starting with start.
     73    @param str The string
     74    @param start The startposition
     75    @return The position of the next quote (std::string::npos if there is no next quote)
     76*/
     77unsigned int getNextQuote(const std::string& str, unsigned int start)
     78{
     79    unsigned int quote = start - 1;
     80
     81    while ((quote = str.find('\"', quote + 1)) != std::string::npos)
     82    {
     83        unsigned int backslash = quote;
     84        unsigned int numbackslashes = 0;
     85        for (; backslash > 0; backslash--, numbackslashes++)
     86            if (str[backslash - 1] != '\\')
     87                break;
     88
     89        if (numbackslashes % 2 == 0)
     90            break;
     91    }
     92
     93    return quote;
     94}
     95
     96/**
     97    @brief Returns true if pos is between two quotes.
     98    @param str The string
     99    @param pos The position to check
     100    @return True if pos is between two quotes
     101*/
     102bool isBetweenQuotes(const std::string& str, unsigned int pos)
     103{
     104    if (pos == std::string::npos)
     105        return false;
     106
     107    unsigned int quotecount = 0;
     108    unsigned int quote = 0;
     109    while ((quote = getNextQuote(str, quote)) < pos)
     110    {
     111        quotecount++;
     112    }
     113
     114    if (quote == std::string::npos)
     115        return false;
     116
     117    return ((quotecount % 2) == 1);
     118}
     119
     120/**
     121    @brief Returns true if the string contains something like '..."between quotes"...'
     122    @param The string
     123    @return True if there is something between quotes
     124*/
     125bool hasStringBetweenQuotes(const std::string& str)
     126{
     127    unsigned int pos1 = getNextQuote(str, 0);
     128    unsigned int pos2 = getNextQuote(str, pos1 + 1);
     129    return (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1);
     130}
     131
     132/**
     133    @brief If the string contains something like '..."between quotes"...' then 'between quotes' gets returned (without quotes).
     134    @param The string
     135    @param The string between the quotes
     136*/
     137std::string getStringBetweenQuotes(const std::string& str)
     138{
     139    unsigned int pos1 = getNextQuote(str, 0);
     140    unsigned int pos2 = getNextQuote(str, pos1 + 1);
     141    if (pos1 != std::string::npos && pos2 != std::string::npos)
     142        return str.substr(pos1, pos2 - pos1 + 1);
     143    else
     144        return "";
     145}
     146
     147/**
     148    @brief Removes enclosing quotes if available.
     149    @brief str The string to strip
     150    @return The string with removed quotes
     151*/
     152std::string stripEnclosingQuotes(const std::string& str)
     153{
     154    unsigned int start = std::string::npos;
     155    unsigned int end = 0;
     156
     157    for (unsigned int pos = 0; (pos < str.size()) && (pos < std::string::npos); pos++)
     158    {
     159        if (str[pos] == '"')
     160        {
     161            start = pos;
     162            break;
     163        }
     164
     165        if ((str[pos] != ' ') && (str[pos] != '\t') && (str[pos] != '\n'))
     166            return str;
     167    }
     168
     169    for (unsigned int pos = str.size() - 1; pos < std::string::npos; pos--)
     170    {
     171        if (str[pos] == '"')
     172        {
     173            end = pos;
     174            break;
     175        }
     176
     177        if ((str[pos] != ' ') && (str[pos] != '\t') && (str[pos] != '\n'))
     178            return str;
     179    }
     180
     181    if ((start != std::string::npos) && (end != 0))
     182        return str.substr(start + 1, end - start - 1);
     183    else
     184        return str;
     185}
     186
     187/**
    56188    @brief Determines if a string in is a comment.
    57189    @param str The string to check
     
    70202    //  3) ;comment in unreal tournament config-file style
    71203    //  4) //comment in code style
    72     if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[0] == '/'))
    73         return true;
     204    if (teststring.size() >= 2)
     205    {
     206        if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[1] == '/'))
     207            return true;
     208    }
     209    else if (teststring.size() == 1)
     210    {
     211        if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';')
     212            return true;
     213    }
    74214
    75215    return false;
     
    83223bool isEmpty(const std::string& str)
    84224{
    85     return getStripped(str) == "";
     225    std::string temp = getStripped(str);
     226    return ((temp == "") || (temp.size() == 0));
    86227}
    87228
     
    109250}
    110251
     252std::string addSlashes(const std::string& str)
     253{
     254    std::string output = str;
     255
     256    for (unsigned int pos = 0; (pos = output.find('\\', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\\"); }
     257    for (unsigned int pos = 0; (pos = output.find('\n', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\n"); }
     258    for (unsigned int pos = 0; (pos = output.find('\t', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\t"); }
     259    for (unsigned int pos = 0; (pos = output.find('\v', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\v"); }
     260    for (unsigned int pos = 0; (pos = output.find('\b', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\b"); }
     261    for (unsigned int pos = 0; (pos = output.find('\r', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\r"); }
     262    for (unsigned int pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\f"); }
     263    for (unsigned int pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\a"); }
     264    for (unsigned int pos = 0; (pos = output.find('"', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }
     265    for (unsigned int pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\0"); }
     266
     267    return output;
     268}
     269
     270std::string removeSlashes(const std::string& str)
     271{
     272    if (str.size() == 0)
     273        return str;
     274
     275    std::string output = "";
     276    for (unsigned int pos = 0; pos < str.size() - 1; )
     277    {
     278        if (str[pos] == '\\')
     279        {
     280            if (str[pos + 1] == '\\') { output += '\\'; pos += 2; continue; }
     281            else if (str[pos + 1] == 'n') { output += '\n'; pos += 2; continue; }
     282            else if (str[pos + 1] == 't') { output += '\t'; pos += 2; continue; }
     283            else if (str[pos + 1] == 'v') { output += '\v'; pos += 2; continue; }
     284            else if (str[pos + 1] == 'b') { output += '\b'; pos += 2; continue; }
     285            else if (str[pos + 1] == 'r') { output += '\r'; pos += 2; continue; }
     286            else if (str[pos + 1] == 'f') { output += '\f'; pos += 2; continue; }
     287            else if (str[pos + 1] == 'a') { output += '\a'; pos += 2; continue; }
     288            else if (str[pos + 1] == '"') { output += '"'; pos += 2; continue; }
     289            else if (str[pos + 1] == '0') { output += '\0'; pos += 2; continue; }
     290        }
     291        output += str[pos];
     292        pos++;
     293        if (pos == str.size() - 1)
     294            output += str[pos];
     295    }
     296
     297    return output;
     298}
     299
    111300/**
    112301    @brief Replaces each char between A and Z with its lowercase equivalent.
     
    115304void lowercase(std::string* str)
    116305{
    117     static unsigned const char difference_between_A_and_a = 'A' - 'a';
    118 
    119     for (std::string::iterator it = (*str).begin(); it != (*str).end(); ++it)
    120         if ((*it) >= 'A' && (*it) <= 'Z')
    121             (*it) -= difference_between_A_and_a;
     306    for (unsigned int i = 0; i < str->size(); ++i)
     307    {
     308        (*str)[i] = tolower((*str)[i]);
     309    }
    122310}
    123311
     
    140328void uppercase(std::string* str)
    141329{
    142     static unsigned const char difference_between_A_and_a = 'A' - 'a';
    143 
    144     for (std::string::iterator it = (*str).begin(); it != (*str).end(); ++it)
    145         if ((*it) >= 'a' && (*it) <= 'z')
    146             (*it) += difference_between_A_and_a;
     330    for (unsigned int i = 0; i < str->size(); ++i)
     331    {
     332        (*str)[i] = toupper((*str)[i]);
     333    }
    147334}
    148335
     
    160347
    161348/**
    162  * @brief compares two strings without ignoring the case
    163  * @param s1 first string
    164  * @param s2 second string
    165  */
     349   @brief compares two strings without ignoring the case
     350   @param s1 first string
     351   @param s2 second string
     352*/
    166353int nocaseCmp(const std::string& s1, const std::string& s2)
    167354{
     
    188375
    189376/**
    190  * @brief compares two strings without ignoring the case
    191  * @param s1 first string
    192  * @param s2 second string
    193  * @param len how far from the beginning to start.
    194  */
     377   @brief compares two strings without ignoring the case
     378   @param s1 first string
     379   @param s2 second string
     380   @param len how far from the beginning to start.
     381*/
    195382int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len)
    196383{
     
    212399    return 0;
    213400}
     401
     402/**
     403    @brief Returns true if the string contains a comment, introduced by #, %, ; or //.
     404    @param str The string
     405    @return True if the string contains a comment
     406*/
     407bool hasComment(const std::string& str)
     408{
     409    return (getCommentPosition(str) != std::string::npos);
     410}
     411
     412/**
     413    @brief If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise.
     414    @param str The string
     415    @return The comment
     416*/
     417std::string getComment(const std::string& str)
     418{
     419    return str.substr(getCommentPosition(str));
     420}
     421
     422/**
     423    @brief If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise.
     424    @param str The string
     425    @return The position
     426*/
     427unsigned int getCommentPosition(const std::string& str)
     428{
     429    return getNextCommentPosition(str, 0);
     430}
     431
     432/**
     433    @brief Returns the position of the next comment-symbol, starting with start.
     434    @param str The string
     435    @param start The startposition
     436    @return The position
     437*/
     438unsigned int getNextCommentPosition(const std::string& str, unsigned int start)
     439{
     440    for (unsigned int i = start; i < str.size(); i++)
     441        if (isComment(str.substr(i)))
     442            return i;
     443
     444    return std::string::npos;
     445}
  • code/trunk/src/util/String.h

    r871 r1052  
    2626 */
    2727
    28 #ifndef _String_H__
    29 #define _String_H__
     28#ifndef _Util_String_H__
     29#define _Util_String_H__
    3030
    3131#include <string>
     
    3434#include "UtilPrereqs.h"
    3535
    36 _UtilExport void        strip(std::string* str);
    37 _UtilExport std::string getStripped(const std::string& str);
     36_UtilExport void         strip(std::string* str);
     37_UtilExport std::string  getStripped(const std::string& str);
    3838
    39 _UtilExport bool        isEmpty(const std::string& str);
    40 _UtilExport bool        isComment(const std::string& str);
    41 _UtilExport bool        isNumeric(const std::string& str);
     39_UtilExport std::string  removeTrailingWhitespaces(const std::string& str);
    4240
    43 _UtilExport void        lowercase(std::string* str);
    44 _UtilExport std::string getLowercase(const std::string& str);
     41_UtilExport unsigned int getNextQuote(const std::string& str, unsigned int start);
     42_UtilExport bool         isBetweenQuotes(const std::string& str, unsigned int pos);
    4543
    46 _UtilExport void        uppercase(std::string* str);
    47 _UtilExport std::string getUppercase(const std::string& str);
     44_UtilExport bool         hasStringBetweenQuotes(const std::string& str);
     45_UtilExport std::string  getStringBetweenQuotes(const std::string& str);
    4846
    49 _UtilExport int         nocaseCmp(const std::string& s1, const std::string& s2);
    50 _UtilExport int         nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len);
     47_UtilExport std::string  stripEnclosingQuotes(const std::string& str);
     48
     49_UtilExport bool         isEmpty(const std::string& str);
     50_UtilExport bool         isComment(const std::string& str);
     51_UtilExport bool         isNumeric(const std::string& str);
     52
     53_UtilExport std::string  addSlashes(const std::string& str);
     54_UtilExport std::string  removeSlashes(const std::string& str);
     55
     56_UtilExport void         lowercase(std::string* str);
     57_UtilExport std::string  getLowercase(const std::string& str);
     58
     59_UtilExport void         uppercase(std::string* str);
     60_UtilExport std::string  getUppercase(const std::string& str);
     61
     62_UtilExport int          nocaseCmp(const std::string& s1, const std::string& s2);
     63_UtilExport int          nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len);
     64
     65_UtilExport bool         hasComment(const std::string& str);
     66_UtilExport std::string  getComment(const std::string& str);
     67_UtilExport unsigned int getCommentPosition(const std::string& str);
     68_UtilExport unsigned int getNextCommentPosition(const std::string& str, unsigned int start = 0);
    5169
    5270//! The Convert class has some static member functions to convert strings to values and values to strings.
     
    144162};
    145163
    146 #endif /* _String_H__ */
     164#endif /* _Util_String_H__ */
  • code/trunk/src/util/SubString.cc

    r871 r1052  
    6666SubString::SubString(const std::string& string,
    6767                     const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    68                      char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char)
    69 {
    70   SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char);
     68                     char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar,
     69                     char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
     70{
     71  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
    7172}
    7273
     
    7980{
    8081  for (unsigned int i = subSetBegin; i < subString.size(); i++)
     82  {
    8183    this->strings.push_back(subString[i]);
     84    this->bInSafemode.push_back(subString.isInSafemode(i));
     85  }
    8286}
    8387
     
    9195SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd)
    9296{
    93   for (unsigned int i = subSetBegin; i < subString.size() || i < subSetEnd; i++)
     97  for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++)
     98  {
    9499    this->strings.push_back(subString[i]);
     100    this->bInSafemode.push_back(subString.isInSafemode(i));
     101  }
    95102}
    96103
     
    103110{
    104111  for(unsigned int i = 0; i < argc; ++i)
     112  {
    105113    this->strings.push_back(std::string(argv[i]));
     114    this->bInSafemode.push_back(false);
     115  }
    106116}
    107117
     
    129139{
    130140  this->strings = subString.strings;
     141  this->bInSafemode = subString.bInSafemode;
    131142  return *this;
    132143}
     
    140151bool SubString::operator==(const SubString& subString) const
    141152{
    142   return (this->strings == subString.strings);
     153  return ((this->strings == subString.strings) && (this->bInSafemode == subString.bInSafemode));
    143154}
    144155
     
    165176
    166177  for (unsigned int i = 0; i < length; i++)
    167     if (this->strings[i] != subString.strings[i])
     178    if ((this->strings[i] != subString.strings[i]) || (this->bInSafemode[i] != subString.bInSafemode[i]))
    168179      return false;
    169180  return true;
     
    190201{
    191202  for (unsigned int i = 0; i < subString.size(); i++)
     203  {
    192204    this->strings.push_back(subString[i]);
     205    this->bInSafemode.push_back(subString.isInSafemode(i));
     206  }
    193207  return *this;
    194208}
     
    203217{
    204218  this->strings.clear();
     219  this->bInSafemode.clear();
    205220  char split[2];
    206221  split[0] = splitter;
    207222  split[1] = '\0';
    208   SubString::splitLine(this->strings, string, split);
     223  SubString::splitLine(this->strings, this->bInSafemode, string, split);
    209224  return strings.size();
    210225}
     
    223238unsigned int SubString::split(const std::string& string,
    224239                              const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    225                               char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char)
     240                              char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar,
     241                              char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
    226242{
    227243  this->strings.clear();
    228   SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char);
     244  this->bInSafemode.clear();
     245  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
    229246  return this->strings.size();
    230247}
     
    292309 * @param escape_char: Escape carater (escapes splitters)
    293310 * @param safemode_char: the beginning of the safemode is marked with this
     311 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token
     312 * @param openparenthesis_char the beginning of a safemode is marked with this
     313 * @param closeparenthesis_char the ending of a safemode is marked with this
     314 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token
    294315 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line)
    295316 * @param start_state: the Initial state on how to parse the String.
    296  * @returns SPLIT_LINE_STATE the parser was in when returning
     317 * @return SPLIT_LINE_STATE the parser was in when returning
    297318 *
    298319 * This is the Actual Splitting Algorithm from Clemens Wacha
     
    302323SubString::SPLIT_LINE_STATE
    303324SubString::splitLine(std::vector<std::string>& ret,
     325                     std::vector<bool>& bInSafemode,
    304326                     const std::string& line,
    305327                     const std::string& delimiters,
     
    307329                     bool emptyEntries,
    308330                     char escape_char,
     331                     bool removeExcapeChar,
    309332                     char safemode_char,
     333                     bool removeSafemodeChar,
    310334                     char openparenthesis_char,
    311335                     char closeparenthesis_char,
     336                     bool removeParenthesisChars,
    312337                     char comment_char,
    313338                     SPLIT_LINE_STATE start_state)
     
    318343
    319344  std::string token;
     345  bool inSafemode = false;
    320346
    321347  if(start_state != SL_NORMAL && ret.size() > 0)
     
    323349    token = ret[ret.size()-1];
    324350    ret.pop_back();
     351  }
     352  if(start_state != SL_NORMAL && bInSafemode.size() > 0)
     353  {
     354    inSafemode = bInSafemode[bInSafemode.size()-1];
     355    bInSafemode.pop_back();
    325356  }
    326357
     
    333364        {
    334365          state = SL_ESCAPE;
     366          if (!removeExcapeChar)
     367            token += line[i];
    335368        }
    336369        else if(line[i] == safemode_char)
    337370        {
    338371          state = SL_SAFEMODE;
     372          inSafemode = true;
     373          if (!removeSafemodeChar)
     374            token += line[i];
    339375        }
    340376        else if(line[i] == openparenthesis_char)
    341377        {
    342378          state = SL_PARENTHESES;
     379          inSafemode = true;
     380          if (!removeParenthesisChars)
     381            token += line[i];
    343382        }
    344383        else if(line[i] == comment_char)
     
    351390            ret.push_back(token);
    352391            token.clear();
     392            bInSafemode.push_back(inSafemode);
     393            inSafemode = false;
    353394          }
    354395          token += line[i];       // EAT
     
    365406            ret.push_back(token);
    366407            token.clear();
     408            bInSafemode.push_back(inSafemode);
     409            inSafemode = false;
    367410          }
    368411          state = SL_NORMAL;
     
    386429        break;
    387430      case SL_ESCAPE:
    388         if(line[i] == 'n') token += '\n';
    389         else if(line[i] == 't') token += '\t';
    390         else if(line[i] == 'v') token += '\v';
    391         else if(line[i] == 'b') token += '\b';
    392         else if(line[i] == 'r') token += '\r';
    393         else if(line[i] == 'f') token += '\f';
    394         else if(line[i] == 'a') token += '\a';
    395         else if(line[i] == '?') token += '\?';
    396         else token += line[i];  // EAT
     431        if (!removeSafemodeChar)
     432          token += line[i];
     433        else
     434        {
     435          if(line[i] == 'n') token += '\n';
     436          else if(line[i] == 't') token += '\t';
     437          else if(line[i] == 'v') token += '\v';
     438          else if(line[i] == 'b') token += '\b';
     439          else if(line[i] == 'r') token += '\r';
     440          else if(line[i] == 'f') token += '\f';
     441          else if(line[i] == 'a') token += '\a';
     442          else if(line[i] == '?') token += '\?';
     443          else token += line[i];  // EAT
     444        }
    397445        state = SL_NORMAL;
    398446        break;
     
    401449        {
    402450          state = SL_NORMAL;
     451          if (!removeSafemodeChar)
     452            token += line[i];
    403453        }
    404454        else if(line[i] == escape_char)
     
    429479        {
    430480          state = SL_NORMAL;
     481          if (!removeParenthesisChars)
     482            token += line[i];
    431483        }
    432484        else if(line[i] == escape_char)
     
    461513            ret.push_back(token);
    462514            token.clear();
     515            bInSafemode.push_back(inSafemode);
     516            inSafemode = false;
    463517          }
    464518          state = SL_NORMAL;
     
    484538    ret.push_back(token);
    485539    token.clear();
     540    bInSafemode.push_back(inSafemode);
     541    inSafemode = false;
    486542  }
    487543  return(state);
  • code/trunk/src/util/SubString.h

    r871 r1052  
    8888  SubString(const std::string& string,
    8989            const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false,
    90             char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0');
     90            char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true,
     91            char openparenthesis_char = '(', char closeparenthesis_char = ')',  bool removeParenthesisChars = true, char comment_char = '\0');
    9192  SubString(unsigned int argc, const char** argv);
    9293  /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */
     
    111112  unsigned int split(const std::string& string,
    112113                     const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false,
    113                      char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0');
     114                     char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true,
     115                     char openparenthesis_char = '(', char closeparenthesis_char = ')',  bool removeParenthesisChars = true, char comment_char = '\0');
    114116  std::string join(const std::string& delimiter = " ") const;
    115117  ////////////////////////////////////////
     
    120122
    121123  // retrieve Information from within
    122   /** @returns true if the SubString is empty */
     124  /** @brief Returns true if the SubString is empty */
    123125  inline bool empty() const { return this->strings.empty(); };
    124   /** @returns the count of Strings stored in this substring */
     126  /** @brief Returns the count of Strings stored in this substring */
    125127  inline unsigned int size() const { return this->strings.size(); };
    126   /** @param i the i'th String @returns the i'th string from the subset of Strings */
     128  /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */
    127129  inline const std::string& operator[](unsigned int i) const { return this->strings[i]; };
    128   /** @param i the i'th String @returns the i'th string from the subset of Strings */
     130  /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */
    129131  inline const std::string& getString(unsigned int i) const { return (*this)[i]; };
    130   /** @returns the front of the StringList. */
     132  /** @brief Returns true if the token is in safemode. @param i the i'th token */
     133  inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; }
     134  /** @brief Returns the front of the StringList. */
    131135  inline const std::string& front() const { return this->strings.front(); };
    132   /** @returns the back of the StringList. */
     136  /** @brief Returns the back of the StringList. */
    133137  inline const std::string& back() const { return this->strings.back(); };
    134138  /** @brief removes the back of the strings list. */
    135   inline void pop_back() { this->strings.pop_back(); };
     139  inline void pop_back() { this->strings.pop_back(); this->bInSafemode.pop_back(); };
    136140
    137141  // the almighty algorithm.
    138142  static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,
     143                                    std::vector<bool>& bInSafemode,
    139144                                    const std::string& line,
    140145                                    const std::string& delimiters = SubString::WhiteSpaces,
     
    142147                                    bool emptyEntries = false,
    143148                                    char escape_char = '\\',
     149                                    bool removeExcapeChar = true,
    144150                                    char safemode_char = '"',
     151                                    bool removeSafemodeChar = true,
    145152                                    char openparenthesis_char = '(',
    146153                                    char closeparenthesis_char = ')',
     154                                    bool removeParenthesisChars = true,
    147155                                    char comment_char = '\0',
    148156                                    SPLIT_LINE_STATE start_state = SL_NORMAL);
     
    157165private:
    158166  std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
     167  std::vector<bool>         bInSafemode;
    159168};
    160169
  • code/trunk/src/util/UtilPrereqs.h

    r1024 r1052  
    6161class ArgReader;
    6262class Convert;
    63 template <typename FromType, typename ToType>
    64 class Converter;
    6563class MultiTypePrimitive;
    6664class MultiTypeString;
  • code/trunk/src/util/tinyxml/ticpp.h

    r871 r1052  
    973973                Stream output operator.
    974974                */
    975                 friend std::ostream& operator <<( std::ostream& out, Node& base )
     975                friend std::ostream& operator <<( std::ostream& out, const Node& base )
    976976                {
    977977                        out << *base.GetTiXmlPointer();
Note: See TracChangeset for help on using the changeset viewer.