src/sysc/packages/boost/detail/ob_call_traits.hpp

Go to the documentation of this file.
00001 //  (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
00002 //  Permission to copy, use, modify, sell and
00003 //  distribute this software is granted provided this copyright notice appears
00004 //  in all copies. This software is provided "as is" without express or implied
00005 //  warranty, and with no claim as to its suitability for any purpose.
00006 
00007 //  See http://www.boost.org for most recent version including documentation.
00008 //
00009 //  Crippled version for crippled compilers:
00010 //  see libs/utility/call_traits.htm
00011 //
00012 
00013 /* Release notes:
00014    01st October 2000:
00015       Fixed call_traits on VC6, using "poor man's partial specialisation",
00016       using ideas taken from "Generative programming" by Krzysztof Czarnecki 
00017       & Ulrich Eisenecker.
00018 */
00019 
00020 #ifndef BOOST_OB_CALL_TRAITS_HPP
00021 #define BOOST_OB_CALL_TRAITS_HPP
00022 
00023 #ifndef BOOST_CONFIG_HPP
00024 #include <sysc/packages/boost/config.hpp>
00025 #endif
00026 
00027 #ifndef BOOST_ARITHMETIC_TYPE_TRAITS_HPP
00028 #include <sysc/packages/boost/type_traits/arithmetic_traits.hpp>
00029 #endif
00030 #ifndef BOOST_COMPOSITE_TYPE_TRAITS_HPP
00031 #include <sysc/packages/boost/type_traits/composite_traits.hpp>
00032 #endif
00033 
00034 namespace boost{
00035 
00036 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
00037 //
00038 // use member templates to emulate
00039 // partial specialisation:
00040 //
00041 namespace detail{
00042 
00043 template <class T>
00044 struct standard_call_traits
00045 {
00046    typedef T value_type;
00047    typedef T& reference;
00048    typedef const T& const_reference;
00049    typedef const T& param_type;
00050 };
00051 template <class T>
00052 struct simple_call_traits
00053 {
00054    typedef T value_type;
00055    typedef T& reference;
00056    typedef const T& const_reference;
00057    typedef const T param_type;
00058 };
00059 template <class T>
00060 struct reference_call_traits
00061 {
00062    typedef T value_type;
00063    typedef T reference;
00064    typedef T const_reference;
00065    typedef T param_type;
00066 };
00067 
00068 template <bool pointer, bool arithmetic, bool reference>
00069 struct call_traits_chooser
00070 {
00071    template <class T>
00072    struct rebind
00073    {
00074       typedef standard_call_traits<T> type;
00075    };
00076 };
00077 
00078 template <>
00079 struct call_traits_chooser<true, false, false>
00080 {
00081    template <class T>
00082    struct rebind
00083    {
00084       typedef simple_call_traits<T> type;
00085    };
00086 };
00087 
00088 template <>
00089 struct call_traits_chooser<false, false, true>
00090 {
00091    template <class T>
00092    struct rebind
00093    {
00094       typedef reference_call_traits<T> type;
00095    };
00096 };
00097 
00098 template <bool size_is_small> 
00099 struct call_traits_sizeof_chooser2
00100 {
00101    template <class T>
00102    struct small_rebind
00103    {
00104       typedef simple_call_traits<T> small_type;
00105    };
00106 };
00107 
00108 template<> 
00109 struct call_traits_sizeof_chooser2<false>
00110 {
00111    template <class T>
00112    struct small_rebind
00113    {
00114       typedef standard_call_traits<T> small_type;
00115    };
00116 };
00117 
00118 template <>
00119 struct call_traits_chooser<false, true, false>
00120 {
00121    template <class T>
00122    struct rebind
00123    {
00124       enum { sizeof_choice = (sizeof(T) <= sizeof(void*)) };
00125       typedef call_traits_sizeof_chooser2<(sizeof(T) <= sizeof(void*))> chooser;
00126       typedef typename chooser::template small_rebind<T> bound_type;
00127       typedef typename bound_type::small_type type;
00128    };
00129 };
00130 
00131 } // namespace detail
00132 template <typename T>
00133 struct call_traits
00134 {
00135 private:
00136     typedef detail::call_traits_chooser<
00137          ::boost::is_pointer<T>::value,
00138          ::boost::is_arithmetic<T>::value, 
00139          ::boost::is_reference<T>::value
00140       > chooser;
00141    typedef typename chooser::template rebind<T> bound_type;
00142    typedef typename bound_type::type call_traits_type;
00143 public:
00144    typedef typename call_traits_type::value_type       value_type;
00145    typedef typename call_traits_type::reference        reference;
00146    typedef typename call_traits_type::const_reference  const_reference;
00147    typedef typename call_traits_type::param_type       param_type;
00148 };
00149 
00150 #else
00151 //
00152 // sorry call_traits is completely non-functional
00153 // blame your broken compiler:
00154 //
00155 
00156 template <typename T>
00157 struct call_traits
00158 {
00159    typedef T value_type;
00160    typedef T& reference;
00161    typedef const T& const_reference;
00162    typedef const T& param_type;
00163 };
00164 
00165 #endif // member templates
00166 
00167 }
00168 
00169 #endif // BOOST_OB_CALL_TRAITS_HPP

Generated on Wed Apr 25 13:53:28 2007 for SystemC by  doxygen 1.5.1