Changeset 960 for code/branches/core2
- Timestamp:
- Mar 30, 2008, 4:54:44 PM (17 years ago)
- Location:
- code/branches/core2/src/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/util/Convert.h
r959 r960 116 116 // THE SAME, BUT WITH DEFAULT VALUE 117 117 template<typename FromType, typename ToType> 118 static ToType ConvertValueAndReturn(const FromType& input, const FromType& fallback)119 { 120 ToType output ;118 static ToType ConvertValueAndReturn(const FromType& input, const ToType& fallback) 119 { 120 ToType output = fallback; 121 121 ConvertValue(&output, input, fallback); 122 122 return output; … … 541 541 }; 542 542 543 ////////////////////////////////////////////544 // Some specializations to avoid warnings //545 ////////////////////////////////////////////546 #define CONVERT_VALUE_AND_RETURN_SPECIALIZATION(ToType) \547 template<typename FromType> \548 static ToType ConvertValueAndReturn(const FromType& input) \549 { \550 ToType output = 0; \551 ConvertValue(&output, input); \552 return output; \553 }554 555 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(void*)556 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(int)557 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(unsigned int)558 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(char)559 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(unsigned char)560 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(short)561 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(unsigned short)562 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(long)563 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(unsigned long)564 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(float)565 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(double)566 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(long double)567 CONVERT_VALUE_AND_RETURN_SPECIALIZATION(bool)568 569 543 #endif /* _Convert_H__ */ -
code/branches/core2/src/util/MultiTypeMath.cc
r947 r960 89 89 90 90 MultiTypeMath::operator void*() const 91 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeMath, void*>(*this ); }91 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeMath, void*>(*this, 0); } 92 92 MultiTypeMath::operator int() const 93 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this ); }93 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this, 0); } 94 94 MultiTypeMath::operator unsigned int() const 95 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeMath, unsigned int>(*this ); }95 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeMath, unsigned int>(*this, 0); } 96 96 MultiTypeMath::operator char() const 97 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeMath, char>(*this ); }97 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeMath, char>(*this, 0); } 98 98 MultiTypeMath::operator unsigned char() const 99 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeMath, unsigned char>(*this ); }99 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeMath, unsigned char>(*this, 0); } 100 100 MultiTypeMath::operator short() const 101 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeMath, short>(*this ); }101 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeMath, short>(*this, 0); } 102 102 MultiTypeMath::operator unsigned short() const 103 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeMath, unsigned short>(*this ); }103 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeMath, unsigned short>(*this, 0); } 104 104 MultiTypeMath::operator long() const 105 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeMath, long>(*this ); }105 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeMath, long>(*this, 0); } 106 106 MultiTypeMath::operator unsigned long() const 107 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeMath, unsigned long>(*this ); }107 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeMath, unsigned long>(*this, 0); } 108 108 MultiTypeMath::operator float() const 109 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeMath, float>(*this ); }109 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeMath, float>(*this, 0); } 110 110 MultiTypeMath::operator double() const 111 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeMath, double>(*this ); }111 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeMath, double>(*this, 0); } 112 112 MultiTypeMath::operator long double() const 113 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeMath, long double>(*this ); }113 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeMath, long double>(*this, 0); } 114 114 MultiTypeMath::operator bool() const 115 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeMath, bool>(*this ); }115 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeMath, bool>(*this, 0); } 116 116 MultiTypeMath::operator std::string() const 117 117 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this); } -
code/branches/core2/src/util/MultiTypePrimitive.cc
r947 r960 135 135 136 136 MultiTypePrimitive::operator void*() const 137 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypePrimitive, void*>(*this ); }137 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypePrimitive, void*>(*this, 0); } 138 138 MultiTypePrimitive::operator int() const 139 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this ); }139 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this, 0); } 140 140 MultiTypePrimitive::operator unsigned int() const 141 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this ); }141 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this, 0); } 142 142 MultiTypePrimitive::operator char() const 143 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this ); }143 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this, 0); } 144 144 MultiTypePrimitive::operator unsigned char() const 145 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this ); }145 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this, 0); } 146 146 MultiTypePrimitive::operator short() const 147 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this ); }147 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this, 0); } 148 148 MultiTypePrimitive::operator unsigned short() const 149 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this ); }149 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this, 0); } 150 150 MultiTypePrimitive::operator long() const 151 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this ); }151 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this, 0); } 152 152 MultiTypePrimitive::operator unsigned long() const 153 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this ); }153 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this, 0); } 154 154 MultiTypePrimitive::operator float() const 155 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this ); }155 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this, 0); } 156 156 MultiTypePrimitive::operator double() const 157 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this ); }157 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this, 0); } 158 158 MultiTypePrimitive::operator long double() const 159 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this ); }159 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this, 0); } 160 160 MultiTypePrimitive::operator bool() const 161 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this ); }161 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this, 0); } 162 162 163 163 void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp) -
code/branches/core2/src/util/MultiTypeString.cc
r947 r960 66 66 67 67 MultiTypeString::operator void*() const 68 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeString, void*>(*this ); }68 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeString, void*>(*this, 0); } 69 69 MultiTypeString::operator int() const 70 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this ); }70 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this, 0); } 71 71 MultiTypeString::operator unsigned int() const 72 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeString, unsigned int>(*this ); }72 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeString, unsigned int>(*this, 0); } 73 73 MultiTypeString::operator char() const 74 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeString, char>(*this ); }74 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeString, char>(*this, 0); } 75 75 MultiTypeString::operator unsigned char() const 76 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeString, unsigned char>(*this ); }76 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeString, unsigned char>(*this, 0); } 77 77 MultiTypeString::operator short() const 78 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeString, short>(*this ); }78 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeString, short>(*this, 0); } 79 79 MultiTypeString::operator unsigned short() const 80 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeString, unsigned short>(*this ); }80 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeString, unsigned short>(*this, 0); } 81 81 MultiTypeString::operator long() const 82 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeString, long>(*this ); }82 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeString, long>(*this, 0); } 83 83 MultiTypeString::operator unsigned long() const 84 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeString, unsigned long>(*this ); }84 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeString, unsigned long>(*this, 0); } 85 85 MultiTypeString::operator float() const 86 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeString, float>(*this ); }86 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeString, float>(*this, 0); } 87 87 MultiTypeString::operator double() const 88 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeString, double>(*this ); }88 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeString, double>(*this, 0); } 89 89 MultiTypeString::operator long double() const 90 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeString, long double>(*this ); }90 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeString, long double>(*this, 0); } 91 91 MultiTypeString::operator bool() const 92 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeString, bool>(*this ); }92 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeString, bool>(*this, 0); } 93 93 MultiTypeString::operator std::string() const 94 94 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this); }
Note: See TracChangeset
for help on using the changeset viewer.