Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:41

0001 // Boost.Signals2 library
0002 
0003 // Copyright Frank Mori Hess 2007-2008.
0004 // Copyright Timmo Stange 2007.
0005 // Copyright Douglas Gregor 2001-2004. Use, modification and
0006 // distribution is subject to the Boost Software License, Version
0007 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0008 // http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 // For more information, see http://www.boost.org
0011 
0012 // This file is included iteratively, and should not be protected from multiple inclusion
0013 
0014 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0015 #define BOOST_SIGNALS2_NUM_ARGS BOOST_PP_ITERATION()
0016 #else
0017 #define BOOST_SIGNALS2_NUM_ARGS 1
0018 #endif
0019 
0020 
0021 namespace boost
0022 {
0023   namespace signals2
0024   {
0025 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0026     template<typename Signature, typename SlotFunction> class slot;
0027 #else
0028     template<typename Signature, typename SlotFunction = boost::function<Signature> >
0029       class slot;
0030 
0031 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1900)
0032     template<typename Signature, typename SlotFunction> class slot{};
0033 #endif
0034 #endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
0035 
0036     template<BOOST_SIGNALS2_SLOT_TEMPLATE_SPECIALIZATION_DECL(BOOST_SIGNALS2_NUM_ARGS)>
0037       class BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS) BOOST_SIGNALS2_SLOT_TEMPLATE_SPECIALIZATION
0038       : public slot_base, public detail::BOOST_SIGNALS2_STD_FUNCTIONAL_BASE
0039 
0040     {
0041     public:
0042       template<BOOST_SIGNALS2_PREFIXED_SIGNATURE_TEMPLATE_DECL(BOOST_SIGNALS2_NUM_ARGS, Other), typename OtherSlotFunction>
0043       friend class BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS);
0044 
0045       typedef SlotFunction slot_function_type;
0046       typedef R result_type;
0047       typedef typename mpl::identity<BOOST_SIGNALS2_SIGNATURE_FUNCTION_TYPE(BOOST_SIGNALS2_NUM_ARGS)>::type signature_type;
0048 
0049 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0050 
0051 // typedef Tn argn_type;
0052 #define BOOST_SIGNALS2_MISC_STATEMENT(z, n, data) \
0053     typedef BOOST_PP_CAT(T, BOOST_PP_INC(n)) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type);
0054           BOOST_PP_REPEAT(BOOST_SIGNALS2_NUM_ARGS, BOOST_SIGNALS2_MISC_STATEMENT, ~)
0055 #undef BOOST_SIGNALS2_MISC_STATEMENT
0056 #if BOOST_SIGNALS2_NUM_ARGS == 1
0057       typedef arg1_type argument_type;
0058 #elif BOOST_SIGNALS2_NUM_ARGS == 2
0059       typedef arg1_type first_argument_type;
0060       typedef arg2_type second_argument_type;
0061 #endif
0062 
0063       template<unsigned n> class arg : public
0064         detail::BOOST_SIGNALS2_PREPROCESSED_ARG_N_TYPE_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)
0065         <n BOOST_SIGNALS2_PP_COMMA_IF(BOOST_SIGNALS2_NUM_ARGS)
0066         BOOST_SIGNALS2_ARGS_TEMPLATE_INSTANTIATION(BOOST_SIGNALS2_NUM_ARGS)>
0067       {};
0068 
0069       BOOST_STATIC_CONSTANT(int, arity = BOOST_SIGNALS2_NUM_ARGS);
0070 
0071 #else // BOOST_NO_CXX11_VARIADIC_TEMPLATES
0072 
0073       template<unsigned n> class arg
0074       {
0075       public:
0076         typedef typename detail::variadic_arg_type<n, Args...>::type type;
0077       };
0078       BOOST_STATIC_CONSTANT(int, arity = sizeof...(Args));
0079 
0080 #endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
0081 
0082       template<typename F>
0083       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)(const F& f)
0084       {
0085         init_slot_function(f);
0086       }
0087       // copy constructors
0088 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0089       template<BOOST_SIGNALS2_PREFIXED_SIGNATURE_TEMPLATE_DECL(BOOST_SIGNALS2_NUM_ARGS, Other), typename OtherSlotFunction>
0090       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)(const BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)
0091         <BOOST_SIGNALS2_PREFIXED_SIGNATURE_TEMPLATE_INSTANTIATION(BOOST_SIGNALS2_NUM_ARGS, Other), OtherSlotFunction> &other_slot):
0092         slot_base(other_slot), _slot_function(other_slot._slot_function)
0093       {
0094       }
0095 #endif
0096       template<typename Signature, typename OtherSlotFunction>
0097       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)(const slot<Signature, OtherSlotFunction> &other_slot):
0098         slot_base(other_slot), _slot_function(other_slot._slot_function)
0099       {
0100       }
0101       // bind syntactic sugar
0102       BOOST_SIGNALS2_SLOT_N_BINDING_CONSTRUCTORS
0103       // invocation
0104       R operator()(BOOST_SIGNALS2_SIGNATURE_FULL_ARGS(BOOST_SIGNALS2_NUM_ARGS))
0105       {
0106         locked_container_type locked_objects = lock();
0107         return _slot_function(BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(BOOST_SIGNALS2_NUM_ARGS));
0108       }
0109       R operator()(BOOST_SIGNALS2_SIGNATURE_FULL_ARGS(BOOST_SIGNALS2_NUM_ARGS)) const
0110       {
0111         locked_container_type locked_objects = lock();
0112         return _slot_function(BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(BOOST_SIGNALS2_NUM_ARGS));
0113       }
0114       // tracking
0115       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)& track(const weak_ptr<void> &tracked)      {
0116         _tracked_objects.push_back(tracked);
0117         return *this;
0118       }
0119       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)& track(const signal_base &signal)
0120       {
0121         track_signal(signal);
0122         return *this;
0123       }
0124       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)& track(const slot_base &slot)
0125       {
0126         tracked_container_type::const_iterator it;
0127         for(it = slot.tracked_objects().begin(); it != slot.tracked_objects().end(); ++it)
0128         {
0129           _tracked_objects.push_back(*it);
0130         }
0131         return *this;
0132       }
0133       template<typename ForeignWeakPtr>
0134       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)& track_foreign(const ForeignWeakPtr &tracked,
0135         typename weak_ptr_traits<ForeignWeakPtr>::shared_type * /*SFINAE*/ = 0)
0136       {
0137         _tracked_objects.push_back(detail::foreign_void_weak_ptr(tracked));
0138         return *this;
0139       }
0140       template<typename ForeignSharedPtr>
0141       BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)& track_foreign(const ForeignSharedPtr &tracked,
0142         typename shared_ptr_traits<ForeignSharedPtr>::weak_type * /*SFINAE*/ = 0)
0143       {
0144         _tracked_objects.push_back
0145         (
0146           detail::foreign_void_weak_ptr
0147           (
0148             typename shared_ptr_traits<ForeignSharedPtr>::weak_type(tracked)
0149           )
0150         );
0151         return *this;
0152       }
0153 
0154       const slot_function_type& slot_function() const {return _slot_function;}
0155       slot_function_type& slot_function() {return _slot_function;}
0156     private:
0157       template<typename F>
0158       void init_slot_function(const F& f)
0159       {
0160         _slot_function = detail::get_invocable_slot(f, detail::tag_type(f));
0161         signals2::detail::tracked_objects_visitor visitor(this);
0162         boost::visit_each(visitor, f);
0163       }
0164 
0165       SlotFunction _slot_function;
0166     };
0167 
0168 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0169     namespace detail
0170     {
0171       template<unsigned arity, typename Signature, typename SlotFunction>
0172       class slotN;
0173       // partial template specialization
0174       template<typename Signature, typename SlotFunction>
0175       class slotN<BOOST_SIGNALS2_NUM_ARGS, Signature, SlotFunction>
0176       {
0177       public:
0178         typedef BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)<
0179           BOOST_SIGNALS2_PORTABLE_SIGNATURE(BOOST_SIGNALS2_NUM_ARGS, Signature),
0180           SlotFunction> type;
0181       };
0182     }
0183 #endif
0184   } // end namespace signals2
0185 } // end namespace boost
0186 
0187 #undef BOOST_SIGNALS2_NUM_ARGS