1 dnl Copyright 2002, The libsigc++ Development Team
3 dnl This library is free software; you can redistribute it and/or
4 dnl modify it under the terms of the GNU Lesser General Public
5 dnl License as published by the Free Software Foundation; either
6 dnl version 2.1 of the License, or (at your option) any later version.
8 dnl This library is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 dnl Lesser General Public License for more details.
13 dnl You should have received a copy of the GNU Lesser General Public
14 dnl License along with this library; if not, write to the Free Software
15 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 include(template.macros.m4)
21 define([LIMIT_REFERENCE],[dnl
22 /** A [$1]limit_reference<Foo> object stores a reference (Foo&), but make sure that,
23 * if Foo inherits from sigc::trackable, then visit_each<>() will "limit" itself to the
24 * sigc::trackable reference instead of the derived reference. This avoids use of
25 * a reference to the derived type when the derived destructor has run. That can be
26 * a problem when using virtual inheritance.
28 * If Foo inherits from trackable then both the derived reference and the
29 * sigc::trackable reference are stored, so we can later retrieve the sigc::trackable
30 * reference without doing an implicit conversion. To retrieve the derived reference
31 * (so that you invoke methods or members of it), use invoke(). To retrieve the trackable
32 * reference (so that you can call visit_each() on it), you use visit().
34 * If Foo does not inherit from sigc::trackable then invoke() and visit() just return the
37 * This is used for bound (sigc::bind) slot parameters (via bound_argument), bound return values,
38 * and, with mem_fun(), the reference to the handling object.
40 * - @e T_type The type of the reference.
42 template <class T_type,
43 bool I_derives_trackable =
44 std::is_base_of<trackable, T_type>::value>
45 class [$1]limit_reference
49 * @param _A_target The reference to limit.
51 [$1]limit_reference([$2]T_type& _A_target)
55 /** Retrieve the entity to visit for visit_each().
56 * Depending on the template specialization, this is either a derived reference, or sigc::trackable& if T_type derives from sigc::trackable.
57 * @return The reference.
59 inline const T_type& visit() const
62 /** Retrieve the reference.
63 * This is always a reference to the derived instance.
64 * @return The reference.
66 inline [$3]T_type& invoke() const
75 /** [$1]limit_reference object for a class that derives from trackable.
76 * - @e T_type The type of the reference.
78 template <class T_type>
79 class [$1]limit_reference<T_type, true>
83 * @param _A_target The reference to limit.
85 [$1]limit_reference([$2]T_type& _A_target)
90 /** Retrieve the entity to visit for visit_each().
91 * Depending on the template specialization, this is either a derived reference, or sigc::trackable& if T_type derives from sigc::trackable.
92 * @return The reference.
94 inline const trackable& visit() const
97 /** Retrieve the reference.
98 * This is always a reference to the derived instance.
99 * @return The reference.
101 inline [$3]T_type& invoke() const
105 /** The trackable reference.
107 [$2]trackable& visited;
114 #ifndef DOXYGEN_SHOULD_SKIP_THIS
115 /** Implementation of visitor specialized for the [$1]limit_reference
116 * class, to call visit_each() on the entity returned by the [$1]limit_reference's
118 * @tparam T_type The type of the reference.
119 * @tparam T_action The type of functor to invoke.
120 * @param _A_action The functor to invoke.
121 * @param _A_target The visited instance.
123 template <class T_type, bool I_derives_trackable>
124 struct visitor<[$1]limit_reference<T_type, I_derives_trackable> >
126 template <class T_action>
127 static void do_visit_each(const T_action& _A_action,
128 const [$1]limit_reference<T_type, I_derives_trackable>& _A_target)
130 sigc::visit_each(_A_action, _A_target.visit());
133 #endif // DOXYGEN_SHOULD_SKIP_THIS
138 _FIREWALL([LIMIT_REFERENCE])
140 #include <sigc++/visit_each.h>
141 #include <sigc++/type_traits.h>
142 #include <sigc++/trackable.h>
146 LIMIT_REFERENCE([],[],[])dnl
149 LIMIT_REFERENCE([const_],[const ],[const ])dnl
152 LIMIT_REFERENCE([volatile_],[],[volatile ])dnl
155 LIMIT_REFERENCE([const_volatile_],[const ],[const volatile ])dnl
157 } /* namespace sigc */