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 template <> struct promote<const char*>     { typedef version_1::string_t type; };
00040 template <> struct promote<std::string>     { typedef version_1::string_t type; };
00041 
00042 /*************************************************************************************************/
00043 
00044 template <typename lht, typename rht>
00045 inline lht explicit_cast(const rht& rhs)
00046 { return static_cast<lht>(rhs); }
00047 
00048 /*************************************************************************************************/
00049 
00050 template <typename R, typename T>
00051 struct runtime_cast_t {
00052     R operator()(T& x) const { return dynamic_cast<R>(x); }
00053 };
00054 
00055 template <typename R, typename T>
00056 inline R runtime_cast(T& x)
00057 { return runtime_cast_t<R, T>()(x); }
00058 
00059 template <typename R, typename T>
00060 inline R runtime_cast(T* x)
00061 { return runtime_cast_t<R, T*>()(x); }
00062 
00063 template <typename R, typename T>
00064 inline bool runtime_cast(const T& x, R& r)
00065 {
00066     const R* p = runtime_cast<const R*>(&x);
00067     if (!p) return false;
00068     r = *p;
00069     return true;
00070 }
00071 
00072 /*************************************************************************************************/
00073 
00074 template <typename T>
00075 inline T& remove_const(const T& x)
00076 { return const_cast<T&>(x); }
00077 
00078 /*************************************************************************************************/
00079 
00080 } // namespace adobe
00081 
00082 /*************************************************************************************************/
00083 
00084 #endif
00085 
00086 /*************************************************************************************************/

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