conversion.hppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ADOBE_CONVERSION_HPP
00010 #define ADOBE_CONVERSION_HPP
00011
00012 #include <adobe/config.hpp>
00013 #include <string>
00014
00015 #include <adobe/string_fwd.hpp>
00016
00017
00018
00019 namespace adobe {
00020
00021
00022
00023 template <typename T>
00024 struct promote
00025 {
00026 typedef T type;
00027 };
00028
00029 template <> struct promote<short> { typedef double type; };
00030 template <> struct promote<int> { typedef double type; };
00031 template <> struct promote<long> { typedef double type; };
00032
00033 template <> struct promote<unsigned short> { typedef double type; };
00034 template <> struct promote<unsigned int> { typedef double type; };
00035 template <> struct promote<unsigned long> { typedef double type; };
00036
00037 template <> struct promote<float> { typedef double type; };
00038
00039
00040
00041
00042
00043
00044 #if defined(BOOST_MSVC) && defined(_M_X64) && !defined(ADOBE_NO_MSVC64_PROMOTION_ERROR)
00045 template <> struct promote<std::size_t> { };
00046 template <> struct promote<std::ptrdiff_t> { };
00047 #endif
00048
00049 template <> struct promote<const char*> { typedef version_1::string_t type; };
00050 template <> struct promote<std::string> { typedef version_1::string_t type; };
00051
00052
00053
00054 template <typename lht, typename rht>
00055 inline lht explicit_cast(const rht& rhs)
00056 { return static_cast<lht>(rhs); }
00057
00058
00059
00060 template <typename R, typename T>
00061 struct runtime_cast_t {
00062 R operator()(T& x) const { return dynamic_cast<R>(x); }
00063 };
00064
00065 template <typename R, typename T>
00066 inline R runtime_cast(T& x)
00067 { return runtime_cast_t<R, T>()(x); }
00068
00069 template <typename R, typename T>
00070 inline R runtime_cast(T* x)
00071 { return runtime_cast_t<R, T*>()(x); }
00072
00073 template <typename R, typename T>
00074 inline bool runtime_cast(const T& x, R& r)
00075 {
00076 const R* p = runtime_cast<const R*>(&x);
00077 if (!p) return false;
00078 r = *p;
00079 return true;
00080 }
00081
00082
00083
00084 template <typename T>
00085 inline T& remove_const(const T& x)
00086 { return const_cast<T&>(x); }
00087
00088
00089
00090 }
00091
00092
00093
00094 #endif
00095
00096
|