stlab.adobe.com Adobe Systems Incorporated

optional_connect.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_OPTIONAL_CONNECTION_HPP
00010 #define ADOBE_OPTIONAL_CONNECTION_HPP
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <boost/utility/enable_if.hpp>
00017 
00018 /*************************************************************************************************/
00019 
00020 #ifdef BOOST_MSVC
00021     #define ADOBE_OPTIONAL_CONNECT_TEST(p) &p != 0
00022 #else
00023     #define ADOBE_OPTIONAL_CONNECT_TEST(p) sizeof(p) != 0
00024 #endif
00025 
00026 /*************************************************************************************************/
00027 
00028 #define ADOBE_OPTIONAL_CONNECT1(ns, func)                                               \
00029 namespace adobe {                                                                       \
00030 namespace ns {                                                                          \
00031 namespace implementation {                                                              \
00032     template <class R, class T>                                                         \
00033     R func(T& t,                                                                        \
00034     typename boost::enable_if_c<ADOBE_OPTIONAL_CONNECT_TEST(T::##func)>::type* = 0)     \
00035         { return t.##func(); }                                                          \
00036     template <class R, class T>                                                         \
00037     R func(volatile T&, ...)                                                            \
00038         { return R(); }                                                                 \
00039 }                                                                                       \
00040 template <class R, class T>                                                             \
00041 R func(T& t)                                                                            \
00042     { return implementation::##func##<R>(t); }                                          \
00043 } }
00044 
00045 /*************************************************************************************************/
00046 
00047 #define ADOBE_OPTIONAL_CONNECT2(ns, func)                                                   \
00048 namespace adobe {                                                                           \
00049 namespace ns {                                                                              \
00050 namespace implementation {                                                                  \
00051     template <class R, class T, class U>                                                    \
00052     R func(T& t, U& u,                                                                      \
00053         typename boost::enable_if_c<ADOBE_OPTIONAL_CONNECT_TEST(T::##func)>::type* = 0)     \
00054         { return t.##func##(u); }                                                           \
00055     template <class R, class T, class U>                                                    \
00056     R func(volatile T&, volatile U&, ...)                                                   \
00057         { return R(); }                                                                     \
00058 }                                                                                           \
00059 template <class R, class T, class U>                                                        \
00060 R func(T& t, U& u)                                                                          \
00061     { return implementation::##func##<R>(t, u); }                                           \
00062 } }
00063 
00064 /*************************************************************************************************/
00065 
00066 #define ADOBE_OPTIONAL_CONNECT3(ns, func)                                                       \
00067 namespace adobe {                                                                               \
00068 namespace ns {                                                                                  \
00069 namespace implementation {                                                                      \
00070     template <class R, class T, class U, class V>                                               \
00071     R func(T& t, U& u, V& v,                                                                    \
00072         typename boost::enable_if_c<ADOBE_OPTIONAL_CONNECT_TEST(T::##func)>::type* = 0)         \
00073         { return t.##func(u, v); }                                                              \
00074     template <class R, class T, class U, class V>                                               \
00075     R func(volatile T&, volatile U&, volatile V&, ...)                                          \
00076         { return R(); }                                                                         \
00077 }                                                                                               \
00078 template <class R, class T, class U, class V>                                                   \
00079 R func(T& t, U& u, V& v)                                                                        \
00080     { return implementation::##func##<R>(t, u, v); }                                            \
00081 } }
00082 
00083 /*************************************************************************************************/
00084 
00085 #endif // ADOBE_OPTIONAL_CONNECTION_HPP
00086 
00087 /*************************************************************************************************/

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