mem_fn.hpp

Go to the documentation of this file.
00001 #ifndef BOOST_MEM_FN_HPP_INCLUDED
00002 #define BOOST_MEM_FN_HPP_INCLUDED
00003 
00004 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 //
00011 //  mem_fn.hpp - a generalization of std::mem_fun[_ref]
00012 //
00013 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
00014 //  Copyright (c) 2001 David Abrahams
00015 //  Copyright (c) 2003-2005 Peter Dimov
00016 //
00017 // Distributed under the Boost Software License, Version 1.0. (See
00018 // accompanying file LICENSE_1_0.txt or copy at
00019 // http://www.boost.org/LICENSE_1_0.txt)
00020 //
00021 //  See http://www.boost.org/libs/bind/mem_fn.html for documentation.
00022 //
00023 
00024 #include <sysc/packages/boost/config.hpp>
00025 #include <sysc/packages/boost/get_pointer.hpp>
00026 #include <sysc/packages/boost/detail/workaround.hpp>
00027 
00028 namespace boost
00029 {
00030 
00031 #if defined(BOOST_NO_VOID_RETURNS)
00032 
00033 #define BOOST_MEM_FN_CLASS_F , class F
00034 #define BOOST_MEM_FN_TYPEDEF(X)
00035 
00036 namespace _mfi // mem_fun_impl
00037 {
00038 
00039 template<class V> struct mf
00040 {
00041 
00042 #define BOOST_MEM_FN_RETURN return
00043 
00044 #define BOOST_MEM_FN_NAME(X) inner_##X
00045 #define BOOST_MEM_FN_CC
00046 
00047 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00048 
00049 #undef BOOST_MEM_FN_CC
00050 #undef BOOST_MEM_FN_NAME
00051 
00052 #ifdef BOOST_MEM_FN_ENABLE_CDECL
00053 
00054 #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
00055 #define BOOST_MEM_FN_CC __cdecl
00056 
00057 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00058 
00059 #undef BOOST_MEM_FN_CC
00060 #undef BOOST_MEM_FN_NAME
00061 
00062 #endif
00063 
00064 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
00065 
00066 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
00067 #define BOOST_MEM_FN_CC __stdcall
00068 
00069 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00070 
00071 #undef BOOST_MEM_FN_CC
00072 #undef BOOST_MEM_FN_NAME
00073 
00074 #endif
00075 
00076 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
00077 
00078 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
00079 #define BOOST_MEM_FN_CC __fastcall
00080 
00081 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00082 
00083 #undef BOOST_MEM_FN_CC
00084 #undef BOOST_MEM_FN_NAME
00085 
00086 #endif
00087 
00088 #undef BOOST_MEM_FN_RETURN
00089 
00090 }; // struct mf<V>
00091 
00092 template<> struct mf<void>
00093 {
00094 
00095 #define BOOST_MEM_FN_RETURN
00096 
00097 #define BOOST_MEM_FN_NAME(X) inner_##X
00098 #define BOOST_MEM_FN_CC
00099 
00100 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00101 
00102 #undef BOOST_MEM_FN_CC
00103 #undef BOOST_MEM_FN_NAME
00104 
00105 #ifdef BOOST_MEM_FN_ENABLE_CDECL
00106 
00107 #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
00108 #define BOOST_MEM_FN_CC __cdecl
00109 
00110 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00111 
00112 #undef BOOST_MEM_FN_CC
00113 #undef BOOST_MEM_FN_NAME
00114 
00115 #endif
00116 
00117 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
00118 
00119 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
00120 #define BOOST_MEM_FN_CC __stdcall
00121 
00122 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00123 
00124 #undef BOOST_MEM_FN_CC
00125 #undef BOOST_MEM_FN_NAME
00126 
00127 #endif
00128 
00129 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
00130 
00131 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
00132 #define BOOST_MEM_FN_CC __fastcall
00133 
00134 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00135 
00136 #undef BOOST_MEM_FN_CC
00137 #undef BOOST_MEM_FN_NAME
00138 
00139 #endif
00140 
00141 #undef BOOST_MEM_FN_RETURN
00142 
00143 }; // struct mf<void>
00144 
00145 #undef BOOST_MEM_FN_CLASS_F
00146 #undef BOOST_MEM_FN_TYPEDEF_F
00147 
00148 #define BOOST_MEM_FN_NAME(X) X
00149 #define BOOST_MEM_FN_NAME2(X) inner_##X
00150 #define BOOST_MEM_FN_CC
00151 
00152 #include <sysc/packages/boost/bind/mem_fn_vw.hpp>
00153 
00154 #undef BOOST_MEM_FN_NAME
00155 #undef BOOST_MEM_FN_NAME2
00156 #undef BOOST_MEM_FN_CC
00157 
00158 #ifdef BOOST_MEM_FN_ENABLE_CDECL
00159 
00160 #define BOOST_MEM_FN_NAME(X) X##_cdecl
00161 #define BOOST_MEM_FN_NAME2(X) inner_##X##_cdecl
00162 #define BOOST_MEM_FN_CC __cdecl
00163 
00164 #include <sysc/packages/boost/bind/mem_fn_vw.hpp>
00165 
00166 #undef BOOST_MEM_FN_NAME
00167 #undef BOOST_MEM_FN_NAME2
00168 #undef BOOST_MEM_FN_CC
00169 
00170 #endif
00171 
00172 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
00173 
00174 #define BOOST_MEM_FN_NAME(X) X##_stdcall
00175 #define BOOST_MEM_FN_NAME2(X) inner_##X##_stdcall
00176 #define BOOST_MEM_FN_CC __stdcall
00177 
00178 #include <sysc/packages/boost/bind/mem_fn_vw.hpp>
00179 
00180 #undef BOOST_MEM_FN_NAME
00181 #undef BOOST_MEM_FN_NAME2
00182 #undef BOOST_MEM_FN_CC
00183 
00184 #endif
00185 
00186 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
00187 
00188 #define BOOST_MEM_FN_NAME(X) X##_fastcall
00189 #define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall
00190 #define BOOST_MEM_FN_CC __fastcall
00191 
00192 #include <sysc/packages/boost/bind/mem_fn_vw.hpp>
00193 
00194 #undef BOOST_MEM_FN_NAME
00195 #undef BOOST_MEM_FN_NAME2
00196 #undef BOOST_MEM_FN_CC
00197 
00198 #endif
00199 
00200 } // namespace _mfi
00201 
00202 #else // #ifdef BOOST_NO_VOID_RETURNS
00203 
00204 #define BOOST_MEM_FN_CLASS_F
00205 #define BOOST_MEM_FN_TYPEDEF(X) typedef X;
00206 
00207 namespace _mfi
00208 {
00209 
00210 #define BOOST_MEM_FN_RETURN return
00211 
00212 #define BOOST_MEM_FN_NAME(X) X
00213 #define BOOST_MEM_FN_CC
00214 
00215 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00216 
00217 #undef BOOST_MEM_FN_CC
00218 #undef BOOST_MEM_FN_NAME
00219 
00220 #ifdef BOOST_MEM_FN_ENABLE_CDECL
00221 
00222 #define BOOST_MEM_FN_NAME(X) X##_cdecl
00223 #define BOOST_MEM_FN_CC __cdecl
00224 
00225 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00226 
00227 #undef BOOST_MEM_FN_CC
00228 #undef BOOST_MEM_FN_NAME
00229 
00230 #endif
00231 
00232 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
00233 
00234 #define BOOST_MEM_FN_NAME(X) X##_stdcall
00235 #define BOOST_MEM_FN_CC __stdcall
00236 
00237 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00238 
00239 #undef BOOST_MEM_FN_CC
00240 #undef BOOST_MEM_FN_NAME
00241 
00242 #endif
00243 
00244 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
00245 
00246 #define BOOST_MEM_FN_NAME(X) X##_fastcall
00247 #define BOOST_MEM_FN_CC __fastcall
00248 
00249 #include <sysc/packages/boost/bind/mem_fn_template.hpp>
00250 
00251 #undef BOOST_MEM_FN_CC
00252 #undef BOOST_MEM_FN_NAME
00253 
00254 #endif
00255 
00256 #undef BOOST_MEM_FN_RETURN
00257 
00258 } // namespace _mfi
00259 
00260 #undef BOOST_MEM_FN_CLASS_F
00261 #undef BOOST_MEM_FN_TYPEDEF
00262 
00263 #endif // #ifdef BOOST_NO_VOID_RETURNS
00264 
00265 #define BOOST_MEM_FN_NAME(X) X
00266 #define BOOST_MEM_FN_CC
00267 
00268 #include <sysc/packages/boost/bind/mem_fn_cc.hpp>
00269 
00270 #undef BOOST_MEM_FN_NAME
00271 #undef BOOST_MEM_FN_CC
00272 
00273 #ifdef BOOST_MEM_FN_ENABLE_CDECL
00274 
00275 #define BOOST_MEM_FN_NAME(X) X##_cdecl
00276 #define BOOST_MEM_FN_CC __cdecl
00277 
00278 #include <sysc/packages/boost/bind/mem_fn_cc.hpp>
00279 
00280 #undef BOOST_MEM_FN_NAME
00281 #undef BOOST_MEM_FN_CC
00282 
00283 #endif
00284 
00285 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
00286 
00287 #define BOOST_MEM_FN_NAME(X) X##_stdcall
00288 #define BOOST_MEM_FN_CC __stdcall
00289 
00290 #include <sysc/packages/boost/bind/mem_fn_cc.hpp>
00291 
00292 #undef BOOST_MEM_FN_NAME
00293 #undef BOOST_MEM_FN_CC
00294 
00295 #endif
00296 
00297 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
00298 
00299 #define BOOST_MEM_FN_NAME(X) X##_fastcall
00300 #define BOOST_MEM_FN_CC __fastcall
00301 
00302 #include <sysc/packages/boost/bind/mem_fn_cc.hpp>
00303 
00304 #undef BOOST_MEM_FN_NAME
00305 #undef BOOST_MEM_FN_CC
00306 
00307 #endif
00308 
00309 // data member support
00310 
00311 namespace _mfi
00312 {
00313 
00314 template<class R, class T> class dm
00315 {
00316 public:
00317 
00318     typedef R const & result_type;
00319     typedef T const * argument_type;
00320 
00321 private:
00322     
00323     typedef R (T::*F);
00324     F f_;
00325 
00326     template<class U> R const & call(U & u, T const *) const
00327     {
00328         return (u.*f_);
00329     }
00330 
00331     template<class U> R & call(U & u, T *) const
00332     {
00333         return (u.*f_);
00334     }
00335 
00336     template<class U> R const & call(U & u, void const *) const
00337     {
00338         return (get_pointer(u)->*f_);
00339     }
00340 
00341 public:
00342     
00343     explicit dm(F f): f_(f) {}
00344 
00345     R & operator()(T * p) const
00346     {
00347         return (p->*f_);
00348     }
00349 
00350     R const & operator()(T const * p) const
00351     {
00352         return (p->*f_);
00353     }
00354 
00355     template<class U> R const & operator()(U & u) const
00356     {
00357         return call(u, &u);
00358     }
00359 
00360 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200)
00361 
00362     R & operator()(T & t) const
00363     {
00364         return (t.*f_);
00365     }
00366 
00367 #endif
00368 
00369     R const & operator()(T const & t) const
00370     {
00371         return (t.*f_);
00372     }
00373 
00374     bool operator==(dm const & rhs) const
00375     {
00376         return f_ == rhs.f_;
00377     }
00378 
00379     bool operator!=(dm const & rhs) const
00380     {
00381         return f_ != rhs.f_;
00382     }
00383 };
00384 
00385 } // namespace _mfi
00386 
00387 template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
00388 {
00389     return _mfi::dm<R, T>(f);
00390 }
00391 
00392 } // namespace boost
00393 
00394 #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED

Generated on Wed Jan 21 15:32:10 2009 for SystemC by  doxygen 1.5.5