stlab.adobe.com Adobe Systems Incorporated

conversion.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
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 // Under 64-bit Windows size_t and ptrdiff_t do not fall into the categories above,
00040 // and can cause bad cast failures in any_regular_t when one presumes it would, as
00041 // is the case in a 32-bit environment. By default, then, we emit an error when an
00042 // attempt is made to promote these types. You can turn off the error by defining
00043 // ADOBE_NO_MSVC64_PROMOTION_ERROR in your project.
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 } // namespace adobe
00091 
00092 /*************************************************************************************************/
00093 
00094 #endif
00095 
00096 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google