sigx++ 2.0.1
|
00001 // -*- c++ -*- 00002 /* Do not edit! -- generated file */ 00003 00004 00005 #ifndef _SIGXMACROS_INTERNAL_TYPES_H_ 00006 #define _SIGXMACROS_INTERNAL_TYPES_H_ 00007 00008 00009 /* 00010 * Copyright 2007 Klaus Triendl 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Library General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2 of the License, or (at your option) any later version. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Library General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Library General Public 00023 * License along with this library; if not, write to the Free 00024 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 */ 00026 00027 #include <sigc++/type_traits.h> // sigc::is_base_and_derived 00028 #include <sigc++/functors/functor_trait.h> // sigc::nil 00029 #include <sigc++/adaptors/deduce_result_type.h> // sigc::adaptor_base 00030 #include <sigc++/adaptors/adaptor_trait.h> // sigc::adaptor_functor 00031 #include <sigc++/adaptors/bind.h> // sigc::bind_functor 00032 #include <sigc++/adaptors/hide.h> // sigc::hide_functor 00033 #include <sigc++/functors/slot_base.h> // sigc::slot_base 00034 #include <sigx/fwddecl.h> 00035 #include <sigx/types.h> 00036 #include <sigx/static_assert.h> 00037 00038 00039 // functor attaching a shared_dispatchable to another functor by binding 00040 // the shared_dispatchable and hiding it 00041 #define SIGX_DISPATCH_WITH_FUNCTOR(T_functor)\ 00042 sigc::bind_functor<-1, sigc::hide_functor<-1, T_functor>, shared_dispatchable> 00043 00044 00045 namespace sigx 00046 { 00047 00048 namespace internal 00049 { 00050 00051 00055 template <typename T_arg1 = sigc::nil, typename T_arg2 = sigc::nil, typename T_arg3 = sigc::nil, typename T_arg4 = sigc::nil, typename T_arg5 = sigc::nil, typename T_arg6 = sigc::nil, typename T_arg7 = sigc::nil> 00056 struct count_arguments 00057 { static const int value = 7; }; 00058 00059 template <> 00060 struct count_arguments<> 00061 { static const int value = 0; }; 00062 template <typename T_arg1> 00063 struct count_arguments<T_arg1> 00064 { static const int value = 1; }; 00065 template <typename T_arg1, typename T_arg2> 00066 struct count_arguments<T_arg1, T_arg2> 00067 { static const int value = 2; }; 00068 template <typename T_arg1, typename T_arg2, typename T_arg3> 00069 struct count_arguments<T_arg1, T_arg2, T_arg3> 00070 { static const int value = 3; }; 00071 template <typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4> 00072 struct count_arguments<T_arg1, T_arg2, T_arg3, T_arg4> 00073 { static const int value = 4; }; 00074 template <typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5> 00075 struct count_arguments<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5> 00076 { static const int value = 5; }; 00077 template <typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6> 00078 struct count_arguments<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6> 00079 { static const int value = 6; }; 00080 00081 00082 00094 template<typename T_functor, 00095 bool I_istunnel = 00096 sigc::is_base_and_derived<sigx::tunnel_base, T_functor>::value, 00097 bool I_isadaptor = 00098 sigc::is_base_and_derived<sigc::adaptor_base, T_functor>::value> 00099 struct is_functor_tunneled; 00100 00101 00105 template<typename T_functor> 00106 struct is_functor_tunneled<T_functor, true, true> 00107 { 00108 static const bool value = true; 00109 }; 00110 00114 template<typename T_functor> 00115 struct is_functor_tunneled<T_functor, true, false> 00116 { 00117 static const bool value = true; 00118 }; 00119 00124 template<typename T_functor> 00125 struct is_functor_tunneled<T_functor, false, false> 00126 { 00127 // no chance to investigate further, probably a static or member function 00128 // pointer 00129 static const bool value = false; 00130 }; 00131 00135 template<typename T_functor> 00136 struct is_functor_tunneled<T_functor, false, true> 00137 { 00138 // investigate further by cascading the functor chain 00139 // functor must define adaptor_type; 00140 // T_functor is probably derived from sigc::adapts<T_functor>; defines 00141 // adaptor_type 00142 typedef typename T_functor::adaptor_type adaptor_type; 00143 static const bool value = is_functor_tunneled<adaptor_type>::value; 00144 }; 00145 00152 template<typename T_functor> 00153 struct is_functor_tunneled<sigc::adaptor_functor<T_functor>, false, true> 00154 { 00155 static const bool value = is_functor_tunneled<T_functor>::value; 00156 }; 00157 00158 00159 00160 00172 template< 00173 typename T_functor, 00174 bool I_isslot = sigc::is_base_and_derived<sigc::slot_base, T_functor>::value, 00175 bool I_isadaptor = sigc::is_base_and_derived<sigc::adaptor_base, T_functor>::value> 00176 struct is_or_adapts_slot; 00177 00178 00182 template<typename T_functor> 00183 struct is_or_adapts_slot<T_functor, true, false> 00184 { 00185 static const bool value = true; 00186 }; 00187 00192 template<typename T_functor> 00193 struct is_or_adapts_slot<T_functor, false, false> 00194 { 00195 // no chance to investigate further, probably a static or member function 00196 // pointer 00197 static const bool value = false; 00198 }; 00199 00203 template<typename T_functor> 00204 struct is_or_adapts_slot<T_functor, false, true> 00205 { 00206 // investigate further by cascading the functor chain 00207 // functor must define adaptor_type; 00208 // T_functor is probably derived from sigc::adapts<T_functor>; defines 00209 // adaptor_type 00210 typedef typename T_functor::adaptor_type adaptor_type; 00211 static const bool value = is_or_adapts_slot<adaptor_type>::value; 00212 }; 00213 00220 template<typename T_functor> 00221 struct is_or_adapts_slot<sigc::adaptor_functor<T_functor>, false, true> 00222 { 00223 static const bool value = is_or_adapts_slot<T_functor>::value; 00224 }; 00225 00226 00227 00228 00239 template<typename T_functor, bool I_isadapter = sigc::is_base_and_derived<sigc::adaptor_base, T_functor>::value> 00240 struct dispatchable_constraint; 00241 00242 00243 template<typename T_functor> 00244 struct dispatchable_constraint<T_functor, false> 00245 { 00246 static const dispatchable& find_dispatchable(typename sigc::type_trait<T_functor>::take _A_func) 00247 { 00248 // if the compiler reports an error there are only 2 possibilities: 00249 // 1) you connected a static function to a signal or opened a tunnel on a 00250 // static signal without specifying the dispatchable to operate on. 00251 // 2) you connected a member function to a signal or opened a tunnel on a 00252 // member function where the member function is not from a dispatchable 00253 // solution: call 'open_tunnel_with' or 'open_sync_tunnel_with' and specify the dispatachable! 00254 00255 // access obj_ of the functor; 00256 // this issues a compile time error if _A_func is not a functor 00257 // on an object's member function (only sigc member functors have this) 00258 // obj_ is a (const_)limit_reference type; must call invoke() to 00259 // ensure that we get the bound member type instead of a sigc::trackable 00260 return _A_func.obj_.invoke(); 00261 } 00262 }; 00263 00264 // walks down the adaptor chain 00265 template<typename T_functor> 00266 struct dispatchable_constraint<T_functor, true> 00267 { 00268 static const dispatchable& find_dispatchable(typename sigc::type_trait<T_functor>::take _A_func) 00269 { 00270 return is_adaptor_dispatchable(_A_func); 00271 } 00272 00273 private: 00274 // takes T_functor and matches it again to find 00275 // special types and walk down the adaptor chain 00276 template<typename T_adapted_functor> 00277 static const dispatchable& is_adaptor_dispatchable(const sigc::adaptor_functor<T_adapted_functor>& _A_func) 00278 { 00279 return dispatchable_constraint<T_adapted_functor>::find_dispatchable(_A_func.functor_); 00280 } 00281 00282 // match the sigx special dispatchable adaptor chain 00283 template<typename T_adapted_functor> 00284 static const dispatchable& is_adaptor_dispatchable(const SIGX_DISPATCH_WITH_FUNCTOR(T_adapted_functor)& _A_func) 00285 { 00286 // no need to proceed as we found out that the functor is dispatchable 00287 return _A_func.bound1_.visit(); 00288 } 00289 00290 // match all other apaptors, must define adaptor_type 00291 template<typename T_adapted_functor> 00292 static const dispatchable& is_adaptor_dispatchable(const T_adapted_functor& _A_func) 00293 { 00294 // T_adapted_functor must define adaptor_type; 00295 typedef typename T_adapted_functor::adaptor_type adaptor_type; 00296 // _A_func.functor_ is always an adaptor_type 00297 return is_adaptor_dispatchable(_A_func.functor_); 00298 } 00299 }; 00300 00301 00302 } // namespace internal 00303 00304 } // namespace sigx 00305 #endif /* _SIGXMACROS_INTERNAL_TYPES_H_ */