aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Compose.hh60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/FbTk/Compose.hh b/src/FbTk/Compose.hh
new file mode 100644
index 0000000..697023c
--- /dev/null
+++ b/src/FbTk/Compose.hh
@@ -0,0 +1,60 @@
1// Composer.hh
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
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// $Id: Compose.hh,v 1.1 2003/08/24 10:37:31 fluxgen Exp $
23
24#ifndef FBTK_COMPOSE_HH
25#define FBTK_COMPOSE_HH
26
27#include <functional>
28
29namespace FbTk {
30
31/// Composes two functions into one.
32/// Uses Arg for type B and then calls type A
33template <class A, class B>
34class Compose_base: public std::unary_function<typename B::argument_type, typename A::result_type> {
35public:
36 typedef typename A::result_type ResultTypeA;
37 typedef typename A::argument_type ArgumentTypeA;
38 typedef typename B::result_type ResultTypeB;
39 typedef typename B::argument_type ArgumentTypeB;
40
41 Compose_base(const A &a, const B &b):m_a(a), m_b(b) { }
42 ResultTypeA operator () (const ArgumentTypeB &arg) const {
43 return m_a(m_b(arg));
44 }
45
46private:
47 A m_a;
48 B m_b;
49};
50
51// helper that creates a Compose_base
52template <typename A, typename B>
53inline Compose_base<A, B>
54Compose(const A& a, const B& b) {
55 return Compose_base<A, B>(a, b);
56}
57
58}; // namespace FbTk
59
60#endif // FBTK_COMPOSE_HH