SignalTemplate.h

00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@hotmail.com */
00025 
00026 /* Note that this file intentionally has no include guards.  This is because it is intended to be included multiple
00027    times, as in SignalsAndSlots.h. */
00028 
00029 #if GG_SIGNALS_NUM_ARGS == 0
00030 #define GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00031 #else
00032 #define GG_SIGNALS_COMMA_IF_NONZERO_ARGS ,
00033 #endif
00034 
00035 #define GG_SIGNALS_FORWARDER_NAME BOOST_PP_CAT(GG_SIGNALS_FORWARDER_BASE_NAME, GG_SIGNALS_NUM_ARGS)
00036 
00037 namespace GG {
00038 
00039 namespace detail {
00040 template <class C, class R GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00041           GG_SIGNALS_SIGNAL_TEMPLATE_PARMS>
00042 struct GG_SIGNALS_FORWARDER_NAME
00043 {
00044     GG_SIGNALS_FORWARDER_NAME(boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig_) : sig(sig_) {}
00045     R operator()(GG_SIGNALS_SIGNAL_PARMS) {sig(GG_SIGNALS_SIGNAL_ARGS);}
00046     boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig;
00047 };
00048 } // namespace detail
00049 
00054 template <class C, class R, class T1, class T2 GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00055           GG_SIGNALS_SIGNAL_TEMPLATE_PARMS> inline
00056 boost::signals::connection 
00057 Connect(boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig, 
00058         R (T1::* fn) (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), 
00059         T2 obj, 
00060         boost::signals::connect_position at = boost::signals::at_back)
00061 {
00062     return sig.connect(boost::bind(fn, obj GG_SIGNALS_COMMA_IF_NONZERO_ARGS GG_SIGNALS_BIND_ARGS), at);
00063 }
00064 
00069 template <class C, class R, class T1, class T2 GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00070           GG_SIGNALS_SIGNAL_TEMPLATE_PARMS> inline
00071 boost::signals::connection 
00072 Connect(boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig, 
00073         R (T1::* fn) (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS) const, 
00074         T2 obj, 
00075         boost::signals::connect_position at = boost::signals::at_back)
00076 {
00077     return sig.connect(boost::bind(fn, obj GG_SIGNALS_COMMA_IF_NONZERO_ARGS GG_SIGNALS_BIND_ARGS), at);
00078 }
00079 
00084 template <class C, class R, class T1, class T2 GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00085           GG_SIGNALS_SIGNAL_TEMPLATE_PARMS> inline
00086 boost::signals::connection 
00087 Connect(boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig, 
00088         R (T1::* fn) (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), 
00089         T2 obj, 
00090         int grp, 
00091         boost::signals::connect_position at = boost::signals::at_back)
00092 {
00093     return sig.connect(grp, boost::bind(fn, obj GG_SIGNALS_COMMA_IF_NONZERO_ARGS GG_SIGNALS_BIND_ARGS), at);
00094 }
00095 
00100 template <class C, class R, class T1, class T2 GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00101           GG_SIGNALS_SIGNAL_TEMPLATE_PARMS> inline
00102 boost::signals::connection 
00103 Connect(boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig, 
00104         R (T1::* fn) (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS) const, 
00105         T2 obj, 
00106         int grp, 
00107         boost::signals::connect_position at = boost::signals::at_back)
00108 {
00109     return sig.connect(grp, boost::bind(fn, obj GG_SIGNALS_COMMA_IF_NONZERO_ARGS GG_SIGNALS_BIND_ARGS), at);
00110 }
00111 
00114 template <class C, class R GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00115           GG_SIGNALS_SIGNAL_TEMPLATE_PARMS> inline
00116 boost::signals::connection 
00117 Connect(boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig1, 
00118         boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig2, 
00119         boost::signals::connect_position at = boost::signals::at_back)
00120 {
00121     typedef typename detail::GG_SIGNALS_FORWARDER_NAME<C, R GG_SIGNALS_COMMA_IF_NONZERO_ARGS GG_SIGNALS_SIGNAL_TEMPLATE_ARGS> Forwarder;
00122     return sig1.connect(Forwarder(sig2), at);
00123 }
00124 
00127 template <class C, class R GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00128           GG_SIGNALS_SIGNAL_TEMPLATE_PARMS> inline
00129 boost::signals::connection 
00130 Connect(boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig1, 
00131         boost::signal<R (GG_SIGNALS_SIGNAL_TEMPLATE_ARGS), C>& sig2, 
00132         int grp, 
00133         boost::signals::connect_position at = boost::signals::at_back)
00134 {
00135     typedef typename detail::GG_SIGNALS_FORWARDER_NAME<C, R GG_SIGNALS_COMMA_IF_NONZERO_ARGS GG_SIGNALS_SIGNAL_TEMPLATE_ARGS> Forwarder;
00136     return sig1.connect(grp, Forwarder(sig2), at);
00137 }
00138 
00139 } //namespace GG
00140 
00141 #undef GG_SIGNALS_COMMA_IF_NONZERO_ARGS
00142 #undef GG_SIGNALS_FORWARDER_NAME

Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2