aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2004-02-27 12:11:05 (GMT)
committerfluxgen <fluxgen>2004-02-27 12:11:05 (GMT)
commit217e4a0ee0d15ab823d7351512c8a9e7563d10ad (patch)
treed4fc4d01b6d2cb15cd3e3122d547cf956ba9515a
parent635e30e9157d5bee3beb337569262dd28989765d (diff)
downloadfluxbox-217e4a0ee0d15ab823d7351512c8a9e7563d10ad.zip
fluxbox-217e4a0ee0d15ab823d7351512c8a9e7563d10ad.tar.bz2
compare equal helper for containers
-rw-r--r--src/FbTk/CompareEqual.hh53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/FbTk/CompareEqual.hh b/src/FbTk/CompareEqual.hh
new file mode 100644
index 0000000..2894eac
--- /dev/null
+++ b/src/FbTk/CompareEqual.hh
@@ -0,0 +1,53 @@
1// CompareEqual.hh
2// Copyright (c) 2004 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: CompareEqual.hh,v 1.1 2004/02/27 12:11:05 fluxgen Exp $
23
24#ifndef FBTK_COMPAREEQUAL_HH
25#define FBTK_COMPAREEQUAL_HH
26
27#include <functional>
28namespace FbTk {
29
30/// @brief compares one class function with a value type
31template <typename ClassType, typename ValueType>
32class CompareEqual_base: public std::unary_function<ClassType, bool> {
33public:
34 typedef ValueType (ClassType::* Action)() const;
35 typedef ValueType Value;
36 CompareEqual_base(Action a, ValueType v):m_action(a), m_value(v) { }
37 bool operator ()(const ClassType *instance) const {
38 return (instance->*m_action)() == m_value;
39 }
40private:
41 Action m_action;
42 Value m_value;
43};
44
45// creates an CompareEqual_base object
46template <typename A, typename B>
47inline CompareEqual_base<A, B>
48CompareEqual(typename CompareEqual_base<A, B>::Action action, B b) {
49 return CompareEqual_base<A, B>(action, b);
50}
51} // end namespace FbTk
52
53#endif // FBTK_COMPAREEQUAL_HH