< prev index next >

src/share/vm/metaprogramming/integerTypes.hpp

Print this page
rev 13265 : imported patch IntegerTypes
rev 13268 : [mq]: Atomic_polishing_v2


 207 
 208 // Cast integral value to some different type of integral value.
 209 template<typename T, typename U>
 210 struct IntegerTypes::Cast<T, U, true, false, false> VALUE_OBJ_CLASS_SPEC {
 211   T operator()(U x) const {
 212     // Canonicalization verifies T is integral.
 213     typedef typename Canonical<T>::type canonical_type;
 214     return static_cast<T>(cast_integral<canonical_type>(x));
 215   }
 216 };
 217 
 218 // Cast integral value to floating point.
 219 template<typename T, typename U>
 220 struct IntegerTypes::Cast<T, U, true, false, true> VALUE_OBJ_CLASS_SPEC {
 221   T operator()(U x) const { return cast_floating_point<T>(x); }
 222 };
 223 
 224 // Cast integral value to pointer.
 225 template<typename T, typename U>
 226 struct IntegerTypes::Cast<T, U, true, true, false> VALUE_OBJ_CLASS_SPEC {
 227   T operator()(U x) const { return (T)((void*)x); }
 228 };
 229 
 230 // Same integral type is identity conversion.
 231 template<typename T>
 232 struct IntegerTypes::Cast<T, T, true, false, false> VALUE_OBJ_CLASS_SPEC {
 233   T operator()(T x) const { return x; }
 234 };
 235 
 236 // Give an informative error if the sizes differ.
 237 template<typename T, typename U, bool to_pointer, bool to_float>
 238 struct IntegerTypes::Cast<T, U, false, to_pointer, to_float> VALUE_OBJ_CLASS_SPEC {
 239   STATIC_ASSERT(sizeof(T) == sizeof(U));
 240 };
 241 
 242 template<typename T, typename U>
 243 inline T IntegerTypes::cast(U x) {
 244   // Canonicalization verifies U is integral.
 245   typedef typename Canonical<U>::type parameter_type;
 246   return Cast<T, parameter_type>()(static_cast<parameter_type>(x));
 247 }




 207 
 208 // Cast integral value to some different type of integral value.
 209 template<typename T, typename U>
 210 struct IntegerTypes::Cast<T, U, true, false, false> VALUE_OBJ_CLASS_SPEC {
 211   T operator()(U x) const {
 212     // Canonicalization verifies T is integral.
 213     typedef typename Canonical<T>::type canonical_type;
 214     return static_cast<T>(cast_integral<canonical_type>(x));
 215   }
 216 };
 217 
 218 // Cast integral value to floating point.
 219 template<typename T, typename U>
 220 struct IntegerTypes::Cast<T, U, true, false, true> VALUE_OBJ_CLASS_SPEC {
 221   T operator()(U x) const { return cast_floating_point<T>(x); }
 222 };
 223 
 224 // Cast integral value to pointer.
 225 template<typename T, typename U>
 226 struct IntegerTypes::Cast<T, U, true, true, false> VALUE_OBJ_CLASS_SPEC {
 227   T operator()(U x) const { return reinterpret_cast<T>(x); }
 228 };
 229 
 230 // Same integral type is identity conversion.
 231 template<typename T>
 232 struct IntegerTypes::Cast<T, T, true, false, false> VALUE_OBJ_CLASS_SPEC {
 233   T operator()(T x) const { return x; }
 234 };
 235 
 236 // Give an informative error if the sizes differ.
 237 template<typename T, typename U, bool to_pointer, bool to_float>
 238 struct IntegerTypes::Cast<T, U, false, to_pointer, to_float> VALUE_OBJ_CLASS_SPEC {
 239   STATIC_ASSERT(sizeof(T) == sizeof(U));
 240 };
 241 
 242 template<typename T, typename U>
 243 inline T IntegerTypes::cast(U x) {
 244   // Canonicalization verifies U is integral.
 245   typedef typename Canonical<U>::type parameter_type;
 246   return Cast<T, parameter_type>()(static_cast<parameter_type>(x));
 247 }


< prev index next >