~ubuntu-branches/ubuntu/vivid/ardour/vivid-proposed

« back to all changes in this revision

Viewing changes to libs/sigc++2/sigc++/adaptors/lambda/macros/group.h.m4

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler, Jaromír Mikeš, Felipe Sateler
  • Date: 2014-05-22 14:39:25 UTC
  • mfrom: (29 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: package-import@ubuntu.com-20140522143925-vwqfo9287pmkrroe
Tags: 1:2.8.16+git20131003-3
* Team upload

[ Jaromír Mikeš ]
* Add -dbg package

[ Felipe Sateler ]
* Upload to experimental

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl Copyright 2002, The libsigc++ Development Team 
 
2
dnl 
 
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. 
 
7
dnl 
 
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. 
 
12
dnl 
 
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 
 
16
dnl
 
17
divert(-1)
 
18
include(template.macros.m4)
 
19
 
 
20
dnl
 
21
dnl  How to call the darn thing!
 
22
define([LAMBDA_GROUP_FACTORY],[dnl
 
23
template <class T_functor, LOOP(class T_type%1, $1)>
 
24
lambda<lambda_group$1<T_functor, LOOP(typename unwrap_reference<T_type%1>::type, $1)> >
 
25
group(const T_functor& _A_func, LOOP(T_type%1 _A_%1, $1))
 
26
{
 
27
  typedef lambda_group$1<T_functor, LOOP(typename unwrap_reference<T_type%1>::type, $1)> T_lambda;
 
28
  return lambda<T_lambda>(T_lambda(_A_func, LOOP(_A_%1, $1)));
 
29
}
 
30
 
 
31
])
 
32
dnl
 
33
dnl  How to call the darn thing!
 
34
define([LAMBDA_GROUP_DO],[dnl
 
35
define([_L_],[LOOP(_A_%1, $2)])dnl
 
36
define([_T_],[LOOP(T_arg%1, $2)])dnl
 
37
dnl Please someone get a gun!
 
38
  template <LOOP(class T_arg%1, $2)>
 
39
  typename deduce_result_type<LOOP(T_arg%1,$2)>::type
 
40
  operator() (LOOP(T_arg%1 _A_%1, $2)) const
 
41
    { return this->func_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
 
42
          typename value%1_type::template deduce_result_type<LOOP(T_arg%1,$2)>::type],$1)>(LOOP([
 
43
        this->value%1_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
 
44
          _P_(T_arg%1)],$2)>(_L_)],$1)); }
 
45
 
 
46
  #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
 
47
  template <LOOP(class T_arg%1, $2)>
 
48
  typename deduce_result_type<LOOP(T_arg%1,$2)>::type
 
49
  sun_forte_workaround (LOOP(T_arg%1 _A_%1, $2)) const
 
50
    { return this->func_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
 
51
          typename value%1_type::template deduce_result_type<LOOP(T_arg%1,$2)>::type],$1)>(LOOP([
 
52
        this->value%1_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
 
53
          _P_(T_arg%1)],$2)>(_L_)],$1)); }
 
54
  #endif //SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
 
55
 
 
56
])
 
57
dnl
 
58
dnl This really doesn't have much to do with lambda other than
 
59
dnl holding lambdas with in itself.
 
60
define([LAMBDA_GROUP],[dnl
 
61
template <class T_functor, LOOP(class T_type%1, $1)>
 
62
struct lambda_group$1 : public lambda_base
 
63
{
 
64
  typedef typename functor_trait<T_functor>::result_type result_type;dnl
 
65
FOR(1, $1,[
 
66
  typedef typename lambda<T_type%1>::lambda_type   value%1_type;])
 
67
  typedef typename adaptor_trait<T_functor>::adaptor_type functor_type;
 
68
 
 
69
  template <LOOP(class T_arg%1=void,$2)>
 
70
  struct deduce_result_type
 
71
    { typedef typename functor_type::template deduce_result_type<LOOP([
 
72
          typename value%1_type::template deduce_result_type<LOOP([
 
73
            _P_(T_arg%1)],$2)>::type],$1)
 
74
        >::type type; };
 
75
 
 
76
  result_type
 
77
  operator ()() const;
 
78
 
 
79
FOR(1,CALL_SIZE,[[LAMBDA_GROUP_DO($1,%1)]])dnl
 
80
  lambda_group$1(typename type_trait<T_functor>::take _A_func, LOOP(typename type_trait<T_type%1>::take _A_%1, $1))
 
81
    : LOOP(value%1_(_A_%1), $1), func_(_A_func) {}dnl
 
82
 
 
83
FOR(1, $1,[
 
84
  value%1_type value%1_;])
 
85
  mutable functor_type func_;
 
86
};
 
87
 
 
88
template <class T_functor, LOOP(class T_type%1, $1)>
 
89
typename lambda_group$1<T_functor, LOOP(T_type%1, $1)>::result_type
 
90
lambda_group$1<T_functor, LOOP(T_type%1, $1)>::operator ()() const
 
91
  { return func_(LOOP(value%1_(), $1)); }
 
92
 
 
93
 
 
94
//template specialization of visit_each<>(action, functor):
 
95
template <class T_action, class T_functor, LOOP(class T_type%1, $1)>
 
96
void visit_each(const T_action& _A_action,
 
97
                const lambda_group$1<T_functor, LOOP(T_type%1, $1)>& _A_target)
 
98
{dnl
 
99
FOR(1, $1,[
 
100
  visit_each(_A_action, _A_target.value%1_);])
 
101
  visit_each(_A_action, _A_target.func_);
 
102
}
 
103
 
 
104
 
 
105
])
 
106
divert(0)dnl
 
107
__FIREWALL__
 
108
#include <sigc++/adaptors/lambda/base.h>
 
109
 
 
110
/** @defgroup group_ group()
 
111
 * sigc::group() alters an arbitrary functor by rebuilding its arguments from one or more lambda expressions.
 
112
 * For each parameter that should be passed to the wrapped functor one lambda expression
 
113
 * has to be passed into group(). Lambda selectors can be used as placeholders for the
 
114
 * arguments passed into the new functor. Arguments that don't have a placeholder in one
 
115
 * of the lambda expressions are dropped.
 
116
 *
 
117
 * @par Examples:
 
118
 *   @code
 
119
 *   void foo(int, int);
 
120
 *   int bar(int);
 
121
 *   // argument binding ...
 
122
 *   sigc::group(&foo,10,sigc::_1)(20); //fixes the first argument and calls foo(10,20)
 
123
 *   sigc::group(&foo,sigc::_1,30)(40); //fixes the second argument and calls foo(40,30)
 
124
 *   // argument reordering ...
 
125
 *   sigc::group(&foo,sigc::_2,sigc::_1)(1,2); //calls foo(2,1)
 
126
 *   // argument hiding ...
 
127
 *   sigc::group(&foo,sigc::_1,sigc::_2)(1,2,3); //calls foo(1,2)
 
128
 *   // functor composition ...
 
129
 *   sigc::group(&foo,sigc::_1,sigc::group(&bar,sigc::_2))(1,2); //calls foo(1,bar(2))
 
130
 *   // algebraic expressions ...
 
131
 *   sigc::group(&foo,sigc::_1*sigc::_2,sigc::_1/sigc::_2)(6,3); //calls foo(6*3,6/3)
 
132
 *   @endcode
 
133
 *
 
134
 * The functor sigc::group() returns can be passed into
 
135
 * sigc::signal::connect() directly.
 
136
 *
 
137
 * @par Example:
 
138
 *   @code
 
139
 *   sigc::signal<void,int,int> some_signal;
 
140
 *   void foo(int);
 
141
 *   some_signal.connect(sigc::group(&foo,sigc::_2));
 
142
 *   @endcode
 
143
 *
 
144
 * Like in sigc::bind() you can bind references to functors by passing the objects
 
145
 * through the sigc::ref() helper function.
 
146
 *
 
147
 * @par Example:
 
148
 *   @code
 
149
 *   int some_int;
 
150
 *   sigc::signal<void> some_signal;
 
151
 *   void foo(int&);
 
152
 *   some_signal.connect(sigc::group(&foo,sigc::ref(some_int)));
 
153
 *   @endcode
 
154
 *
 
155
 * If you bind an object of a sigc::trackable derived type to a functor
 
156
 * by reference, a slot assigned to the group adaptor is cleared automatically
 
157
 * when the object goes out of scope.
 
158
 *
 
159
 * @par Example:
 
160
 *   @code
 
161
 *   struct bar : public sigc::trackable {} some_bar;
 
162
 *   sigc::signal<void> some_signal;
 
163
 *   void foo(bar&);
 
164
 *   some_signal.connect(sigc::group(&foo,sigc::ref(some_bar)));
 
165
 *     // disconnected automatically if some_bar goes out of scope
 
166
 *   @endcode
 
167
 *
 
168
 * @ingroup adaptors, lambdas
 
169
 */
 
170
 
 
171
namespace sigc {
 
172
 
 
173
FOR(1,3,[[LAMBDA_GROUP(%1, CALL_SIZE)]])
 
174
FOR(1,3,[[LAMBDA_GROUP_FACTORY(%1)]])
 
175
 
 
176
} /* namespace sigc */