os/ossrv/ossrv_pub/boost_apis/boost/signals/slot.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/signals/slot.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,157 @@
     1.4 +// Boost.Signals library
     1.5 +
     1.6 +// Copyright Douglas Gregor 2001-2004. Use, modification and
     1.7 +// distribution is subject to the Boost Software License, Version
     1.8 +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     1.9 +// http://www.boost.org/LICENSE_1_0.txt)
    1.10 +
    1.11 +// For more information, see http://www.boost.org
    1.12 +
    1.13 +#ifndef BOOST_SIGNALS_SLOT_HEADER
    1.14 +#define BOOST_SIGNALS_SLOT_HEADER
    1.15 +
    1.16 +#include <boost/signals/detail/signals_common.hpp>
    1.17 +#include <boost/signals/connection.hpp>
    1.18 +#include <boost/signals/trackable.hpp>
    1.19 +#include <boost/visit_each.hpp>
    1.20 +#include <boost/shared_ptr.hpp>
    1.21 +#include <cassert>
    1.22 +
    1.23 +#ifdef BOOST_HAS_ABI_HEADERS
    1.24 +#  include BOOST_ABI_PREFIX
    1.25 +#endif
    1.26 +
    1.27 +namespace boost {
    1.28 +  namespace BOOST_SIGNALS_NAMESPACE {
    1.29 +    namespace detail {
    1.30 +      class BOOST_SIGNALS_DECL slot_base {
    1.31 +        // We would have to enumerate all of the signalN classes here as
    1.32 +        // friends to make this private (as it otherwise should be). We can't
    1.33 +        // name all of them because we don't know how many there are.
    1.34 +      public:
    1.35 +        struct data_t {
    1.36 +          std::vector<const trackable*> bound_objects;
    1.37 +          connection watch_bound_objects;
    1.38 +        };
    1.39 +        shared_ptr<data_t> get_data() const { return data; }
    1.40 +
    1.41 +        // Get the set of bound objects
    1.42 +        std::vector<const trackable*>& get_bound_objects() const
    1.43 +        { return data->bound_objects; }
    1.44 +
    1.45 +        // Determine if this slot is still "active", i.e., all of the bound
    1.46 +        // objects still exist
    1.47 +        bool is_active() const 
    1.48 +        { return data->watch_bound_objects.connected(); }
    1.49 +
    1.50 +      protected:
    1.51 +        // Create a connection for this slot
    1.52 +        void create_connection();
    1.53 +
    1.54 +        shared_ptr<data_t> data;
    1.55 +
    1.56 +      private:
    1.57 +        static void bound_object_destructed(void*, void*) {}
    1.58 +      };
    1.59 +    } // end namespace detail
    1.60 +
    1.61 +    // Get the slot so that it can be copied
    1.62 +    template<typename F>
    1.63 +    reference_wrapper<const F>
    1.64 +    get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::signal_tag)
    1.65 +      { return reference_wrapper<const F>(f); }
    1.66 +
    1.67 +    template<typename F>
    1.68 +    const F&
    1.69 +    get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::reference_tag)
    1.70 +      { return f; }
    1.71 +
    1.72 +    template<typename F>
    1.73 +    const F&
    1.74 +    get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::value_tag)
    1.75 +      { return f; }
    1.76 +
    1.77 +    // Get the slot so that it can be inspected for trackable objects
    1.78 +    template<typename F>
    1.79 +    const F&
    1.80 +    get_inspectable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::signal_tag)
    1.81 +      { return f; }
    1.82 +
    1.83 +    template<typename F>
    1.84 +    const F&
    1.85 +    get_inspectable_slot(const reference_wrapper<F>& f, BOOST_SIGNALS_NAMESPACE::detail::reference_tag)
    1.86 +      { return f.get(); }
    1.87 +
    1.88 +    template<typename F>
    1.89 +    const F&
    1.90 +    get_inspectable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::value_tag)
    1.91 +      { return f; }
    1.92 +
    1.93 +    // Determines the type of the slot - is it a signal, a reference to a
    1.94 +    // slot or just a normal slot.
    1.95 +    template<typename F>
    1.96 +    typename BOOST_SIGNALS_NAMESPACE::detail::get_slot_tag<F>::type
    1.97 +    tag_type(const F&)
    1.98 +    {
    1.99 +      typedef typename BOOST_SIGNALS_NAMESPACE::detail::get_slot_tag<F>::type
   1.100 +        the_tag_type;
   1.101 +      the_tag_type tag = the_tag_type();
   1.102 +      return tag;
   1.103 +    }
   1.104 +
   1.105 +  } // end namespace BOOST_SIGNALS_NAMESPACE
   1.106 +
   1.107 +  template<typename SlotFunction>
   1.108 +  class slot : public BOOST_SIGNALS_NAMESPACE::detail::slot_base {
   1.109 +    typedef BOOST_SIGNALS_NAMESPACE::detail::slot_base inherited;
   1.110 +    typedef typename inherited::data_t data_t;
   1.111 +
   1.112 +  public:
   1.113 +    template<typename F>
   1.114 +    slot(const F& f) : slot_function(BOOST_SIGNALS_NAMESPACE::get_invocable_slot(f, BOOST_SIGNALS_NAMESPACE::tag_type(f)))
   1.115 +    {
   1.116 +      this->data.reset(new data_t);
   1.117 +
   1.118 +      // Visit each of the bound objects and store them for later use
   1.119 +      // An exception thrown here will allow the basic_connection to be
   1.120 +      // destroyed when this goes out of scope, and no other connections
   1.121 +      // have been made.
   1.122 +      BOOST_SIGNALS_NAMESPACE::detail::bound_objects_visitor 
   1.123 +        do_bind(this->data->bound_objects);
   1.124 +      visit_each(do_bind, 
   1.125 +                 BOOST_SIGNALS_NAMESPACE::get_inspectable_slot
   1.126 +                   (f, BOOST_SIGNALS_NAMESPACE::tag_type(f)));
   1.127 +      create_connection();
   1.128 +    }
   1.129 +
   1.130 +#ifdef __BORLANDC__
   1.131 +    template<typename F>
   1.132 +    slot(F* f) : slot_function(f)
   1.133 +    {
   1.134 +      this->data.reset(new data_t);
   1.135 +      create_connection();
   1.136 +    }
   1.137 +#endif // __BORLANDC__
   1.138 +
   1.139 +    // We would have to enumerate all of the signalN classes here as friends
   1.140 +    // to make this private (as it otherwise should be). We can't name all of
   1.141 +    // them because we don't know how many there are.
   1.142 +  public:
   1.143 +    // Get the slot function to call the actual slot
   1.144 +    const SlotFunction& get_slot_function() const { return slot_function; }
   1.145 +
   1.146 +    void release() const { data->watch_bound_objects.set_controlling(false); }
   1.147 +
   1.148 +  private:
   1.149 +    slot(); // no default constructor
   1.150 +    slot& operator=(const slot&); // no assignment operator
   1.151 +
   1.152 +    SlotFunction slot_function;
   1.153 +  };
   1.154 +} // end namespace boost
   1.155 +
   1.156 +#ifdef BOOST_HAS_ABI_HEADERS
   1.157 +#  include BOOST_ABI_SUFFIX
   1.158 +#endif
   1.159 +
   1.160 +#endif // BOOST_SIGNALS_SLOT_HEADER