~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/FbTk/MemFun.hh

  • Committer: Package Import Robot
  • Author(s): Paul Tagliamonte
  • Date: 2010-08-12 21:16:02 UTC
  • mfrom: (0.1.1) (1.1.10)
  • Revision ID: package-import@ubuntu.com-20100812211602-3tsmzl9in5nmwz7z
Tags: 1.1.1+git20100807.0cc08f9-1
* debian/ dir has been cleaned out, complete repackage
  of most files.
* pulled new archive from git.fluxbox.org HEAD, saved as
  tar.gz.
* Added in fluxbox.* files from the old dfsg tree.
* Added in system.fluxbox-menu file from the old dfsg tree
* Added the source/format file to bump package source
  version from 1.0 to 3.0 (quilt). 
* Changed rules file to match the old dfsg setup so that
  fluxbox behaves nicely.
* Removed entries from copyright that no longer apply.
* Added theme based on Denis Brand ( naran )'s old theme.
* Added a background I whipped up.
* Changed compile flags to point to debian theme by default
* Adding a patch to have fluxbox use x-terminal-emulator
  over xterm. Closes: #591694 (LP: #580485)
* Adding a patch to allow titlebar-window dragging.
* Changed the flags in rules to pull from a script. This script
  lets us un-hardcode what theme is default. Be sure there
  is a theme pack!
* Added comments to my patches.
* Removing debian/docs, empty file.
* Fixing fluxbox.desktop to remove all the warnings from
  desktop-file-validate
* Fixing libtool issue by running an update before
  configure in the rules script.
* Added a compile flag script to auto-detect what platform
  we are running on, and apply the correct theme. This
  should solve Ubuntnu issues later on.
* adding in a get-orig-source rule
* fixing the upstream version number to pinpoint
  the commit ( thanks, lfaraone ).
* adding a rule for get-orig-source. ( thanks again,
  lfaraone ).
* Updated rules to actually allow us to do a build from it
* Removed Denis from the uploaders ( as per an email
  conversation )
* Removing madduck from the uploaders ( thanks for asking,
  lfaraone. ). Thanks for your hard work, madduck.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// MemFun.hh for FbTk, Fluxbox Toolkit
 
2
// Copyright (c) 2008 Henrik Kinnunen (fluxgen at fluxbox dot org)
 
3
//
 
4
// Permission is hereby granted, free of charge, to any person obtaining a
 
5
// copy of this software and associated documentation files (the "Software"),
 
6
// to deal in the Software without restriction, including without limitation
 
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
8
// and/or sell copies of the Software, and to permit persons to whom the
 
9
// Software is furnished to do so, subject to the following conditions:
 
10
//
 
11
// The above copyright notice and this permission notice shall be included in
 
12
// all copies or substantial portions of the Software.
 
13
//
 
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
20
// DEALINGS IN THE SOFTWARE.
 
21
 
 
22
#ifndef FBTK_MEM_FUN_HH
 
23
#define FBTK_MEM_FUN_HH
 
24
 
 
25
#include "SelectArg.hh"
 
26
 
 
27
namespace FbTk {
 
28
 
 
29
/// No argument functor
 
30
template <typename ReturnType, typename Object>
 
31
class MemFun0 {
 
32
public:
 
33
    typedef ReturnType (Object:: *Action)();
 
34
 
 
35
    MemFun0(Object& obj, Action action):
 
36
        m_obj(obj),
 
37
        m_action(action) {
 
38
    }
 
39
 
 
40
    void operator ()() {
 
41
        (m_obj.*m_action)();
 
42
    }
 
43
 
 
44
private:
 
45
    Object& m_obj;
 
46
    Action m_action;
 
47
};
 
48
 
 
49
 
 
50
template <typename ReturnType, typename Object>
 
51
MemFun0<ReturnType, Object>
 
52
MemFun( Object& obj, ReturnType (Object:: *action)() ) {
 
53
    return MemFun0<ReturnType, Object>(obj, action);
 
54
}
 
55
 
 
56
/// One argument functor
 
57
template <typename ReturnType, typename Object, typename Arg1>
 
58
class MemFun1 {
 
59
public:
 
60
    typedef ReturnType (Object:: *Action)(Arg1);
 
61
 
 
62
    MemFun1(Object& obj, Action action):
 
63
        m_obj(obj),
 
64
        m_action(action) {
 
65
    }
 
66
 
 
67
    void operator ()(Arg1 arg1) {
 
68
        (m_obj.*m_action)(arg1);
 
69
    }
 
70
 
 
71
private:
 
72
    Object& m_obj;
 
73
    Action m_action;
 
74
};
 
75
 
 
76
/// One argument functor helper function
 
77
template <typename ReturnType, typename Object, typename Arg1>
 
78
MemFun1<ReturnType, Object, Arg1>
 
79
MemFun( Object& obj, ReturnType (Object:: *action)(Arg1) ) {
 
80
    return MemFun1<ReturnType, Object, Arg1>(obj, action);
 
81
}
 
82
 
 
83
/// Two argument functor
 
84
template <typename ReturnType, typename Object, typename Arg1, typename Arg2>
 
85
class MemFun2 {
 
86
public:
 
87
    typedef ReturnType (Object:: *Action)(Arg1,Arg2);
 
88
 
 
89
    MemFun2(Object& obj, Action action):
 
90
        m_obj(obj),
 
91
        m_action(action) {
 
92
    }
 
93
    
 
94
    void operator ()(Arg1 arg1, Arg2 arg2) {
 
95
        (m_obj.*m_action)(arg1, arg2);
 
96
    }
 
97
 
 
98
private:
 
99
    Object& m_obj;
 
100
    Action m_action;
 
101
};
 
102
 
 
103
/// Two argument functor helper function
 
104
template <typename ReturnType, typename Object, typename Arg1, typename Arg2>
 
105
MemFun2<ReturnType, Object, Arg1, Arg2> 
 
106
MemFun( Object& obj, ReturnType (Object:: *action)(Arg1,Arg2) ) {
 
107
    return MemFun2<ReturnType, Object, Arg1, Arg2>(obj, action);
 
108
}
 
109
 
 
110
/// Three argument functor
 
111
template <typename ReturnType, typename Object,
 
112
          typename Arg1, typename Arg2, typename Arg3>
 
113
class MemFun3 {
 
114
public:
 
115
    typedef ReturnType (Object:: *Action)(Arg1,Arg2,Arg3);
 
116
 
 
117
    MemFun3(Object& obj, Action action):
 
118
        m_obj(obj),
 
119
        m_action(action) {
 
120
    }
 
121
 
 
122
    void operator ()(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
 
123
        (m_obj.*m_action)(arg1, arg2, arg3);
 
124
    }
 
125
 
 
126
private:
 
127
    Object& m_obj;
 
128
    Action m_action;
 
129
};
 
130
 
 
131
/// Three argument functor helper
 
132
template <typename ReturnType, typename Object, typename Arg1, typename Arg2, typename Arg3>
 
133
MemFun3<ReturnType, Object, Arg1, Arg2, Arg3>
 
134
MemFun( Object& obj, ReturnType (Object:: *action)(Arg1, Arg2, Arg3) ) {
 
135
    return MemFun3<ReturnType, Object, Arg1, Arg2, Arg3>(obj, action);
 
136
}
 
137
 
 
138
/// Ignores all arguments
 
139
template <typename ReturnType, typename Object>
 
140
class MemFun0IgnoreArgs: public MemFun0<ReturnType, Object> {
 
141
public:
 
142
    typedef MemFun0<ReturnType, Object> BaseType;
 
143
 
 
144
    MemFun0IgnoreArgs(Object& obj,
 
145
                      typename BaseType::Action action):
 
146
        BaseType(obj, action) {
 
147
    }
 
148
 
 
149
    template <typename IgnoreType1, typename IgnoreType2, typename IgnoreType3>
 
150
    void operator ()(IgnoreType1&, IgnoreType2&, IgnoreType3&) {
 
151
        BaseType::operator ()();
 
152
    }
 
153
 
 
154
    template <typename IgnoreType1, typename IgnoreType2>
 
155
    void operator ()(IgnoreType1&, IgnoreType2&) {
 
156
        BaseType::operator ()();
 
157
    }
 
158
 
 
159
    template <typename IgnoreType1>
 
160
    void operator ()(IgnoreType1&) {
 
161
        BaseType::operator ()();
 
162
    }
 
163
};
 
164
 
 
165
/// Ignores second and third argument
 
166
template <typename ReturnType, typename Object, typename Arg1>
 
167
class MemFun1IgnoreArgs: public MemFun1<ReturnType, Object, Arg1> {
 
168
public:
 
169
    typedef MemFun1<ReturnType, Object, Arg1> BaseType;
 
170
 
 
171
    MemFun1IgnoreArgs(Object& obj, typename BaseType::Action& action):
 
172
        BaseType(obj, action) {
 
173
    }
 
174
 
 
175
    template <typename IgnoreType1, typename IgnoreType2>
 
176
    void operator ()(Arg1 arg1, IgnoreType1&, IgnoreType2&) {
 
177
        BaseType::operator ()(arg1);
 
178
    }
 
179
 
 
180
    template <typename IgnoreType>
 
181
    void operator ()(Arg1 arg1, IgnoreType&) {
 
182
        BaseType::operator ()(arg1);
 
183
    }
 
184
};
 
185
 
 
186
/// Takes two arguments but ignores the third
 
187
template <typename ReturnType, typename Object, typename Arg1, typename Arg2>
 
188
class MemFun2IgnoreArgs: public MemFun2<ReturnType, Object, Arg1, Arg2> {
 
189
public:
 
190
    typedef MemFun2<ReturnType, Object, Arg1, Arg2> BaseType;
 
191
 
 
192
    MemFun2IgnoreArgs(Object& obj, typename BaseType::Action& action):
 
193
        BaseType(obj, action) {
 
194
    }
 
195
 
 
196
    template < typename IgnoreType >
 
197
    void operator ()(Arg1 arg1, Arg2 arg2, IgnoreType&) {
 
198
        BaseType::operator ()(arg1, arg2);
 
199
    }
 
200
};
 
201
 
 
202
/// Creates functor that ignores all arguments.
 
203
template <typename ReturnType, typename Object>
 
204
MemFun0IgnoreArgs<ReturnType, Object>
 
205
MemFunIgnoreArgs( Object& obj, ReturnType (Object:: *action)() ) {
 
206
    return MemFun0IgnoreArgs<ReturnType, Object>(obj, action);
 
207
}
 
208
 
 
209
/// Creates functor that ignores second and third argument.
 
210
template <typename ReturnType, typename Object, typename Arg1>
 
211
MemFun1IgnoreArgs<ReturnType, Object, Arg1>
 
212
MemFunIgnoreArgs( Object& obj, ReturnType (Object:: *action)(Arg1) ) {
 
213
    return MemFun1IgnoreArgs<ReturnType, Object, Arg1>(obj, action);
 
214
}
 
215
 
 
216
/// Creates functor that ignores third argument.
 
217
template <typename ReturnType, typename Object, typename Arg1, typename Arg2>
 
218
MemFun2IgnoreArgs<ReturnType, Object, Arg1, Arg2>
 
219
MemFunIgnoreArgs( Object& obj, ReturnType (Object:: *action)(Arg1,Arg2) ) {
 
220
    return MemFun2IgnoreArgs<ReturnType, Object, Arg1, Arg2>(obj, action);
 
221
}
 
222
 
 
223
/**
 
224
 * Creates a functor that selects a specific argument of three possible ones
 
225
 * and uses it for the single argument operator.
 
226
 */
 
227
template < int ArgNum, typename Functor>
 
228
class MemFunSelectArgImpl {
 
229
public:
 
230
 
 
231
    MemFunSelectArgImpl(Functor func):
 
232
        m_func(func) {
 
233
    }
 
234
 
 
235
    template <typename Type1, typename Type2, typename Type3>
 
236
    void operator ()(Type1& a, Type2& b, Type3& c) {
 
237
        m_func(STLUtil::SelectArg<ArgNum>()(a, b, c));
 
238
    }
 
239
 
 
240
    template <typename Type1, typename Type2>
 
241
    void operator ()(Type1& a, Type2& b) {
 
242
        m_func(STLUtil::SelectArg<ArgNum>()(a, b));
 
243
    }
 
244
 
 
245
    template <typename Type1>
 
246
    void operator ()(Type1& a) {
 
247
        m_func(a);
 
248
    }
 
249
 
 
250
private:
 
251
    Functor m_func;
 
252
};
 
253
 
 
254
/// Creates a functor that selects the first argument of three possible ones
 
255
/// and uses it for the single argument operator.
 
256
template <typename ReturnType, typename Object, typename Arg1>
 
257
MemFunSelectArgImpl<0, MemFun1<ReturnType, Object, Arg1> >
 
258
MemFunSelectArg0(Object& obj, ReturnType (Object:: *action)(Arg1)) {
 
259
    return MemFunSelectArgImpl<0, MemFun1<ReturnType, Object, Arg1> >(MemFun(obj, action));
 
260
}
 
261
 
 
262
/// Creates a functor that selects the second argument (or first if there is
 
263
/// only one) of three possible onesand uses it for the single argument operator.
 
264
template <typename ReturnType, typename Object, typename Arg1>
 
265
MemFunSelectArgImpl<1, MemFun1<ReturnType, Object, Arg1> >
 
266
MemFunSelectArg1(Object& obj, ReturnType (Object:: *action)(Arg1)) {
 
267
    return MemFunSelectArgImpl<1, MemFun1<ReturnType, Object, Arg1> >(MemFun(obj, action));
 
268
}
 
269
 
 
270
/// Creates a functor that selects the third argument (or the last argument if there is
 
271
/// less than three arguments) of three possible onesand uses it for the single argument operator.
 
272
template <typename ReturnType, typename Object, typename Arg1>
 
273
MemFunSelectArgImpl<2, MemFun1<ReturnType, Object, Arg1> >
 
274
MemFunSelectArg2(Object& obj, ReturnType (Object:: *action)(Arg1)) {
 
275
    return MemFunSelectArgImpl<2, MemFun1<ReturnType, Object, Arg1> >(MemFun(obj, action));
 
276
}
 
277
 
 
278
} // namespace FbTk
 
279
 
 
280
#endif // FBTK_MEM_FUN_HH
 
281