Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Equiv.h
1 /*
2  * $Id$
3  * Equiv class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2008, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_UTIL_EQUIV_H_
23 #define ELM_UTIL_EQUIV_H_
24 
25 #include <elm/string.h>
26 #include <elm/util/Pair.h>
27 
28 namespace elm {
29 
30 // Equiv class
31 template <class T>
32 class Equiv {
33 public:
34  static inline bool equals(const T& v1, const T& v2) { return v1 == v2; }
35 };
36 
37 // EqualsEquiv class
38 template <class T>
39 class EqualsEquiv {
40 public:
41  static inline int compare(const T& v1, const T& v2)
42  { return v1.equals(v2); }
43 };
44 
45 
46 // AssocEquiv class
47 template <class K, class T, class E = Equiv<K> >
48 class AssocEquiv {
49 public:
50  typedef Pair<K, T> pair_t;
51  static inline bool equals(const pair_t& v1, const pair_t& v2)
52  { return E::equals(v1.fst, v2. fst); }
53 };
54 template <class K, class T> class Equiv<Pair<K, T> >
55  : public AssocEquiv<K, T> { };
56 
57 } // elm
58 
59 #endif /* ELM_UTIL_EQUIV_H_ */
static int compare(const T &v1, const T &v2)
Definition: Equiv.h:41
static bool equals(const pair_t &v1, const pair_t &v2)
Definition: Equiv.h:51
static bool equals(const T &v1, const T &v2)
Definition: Equiv.h:34
T1 fst
Definition: Pair.h:18
Definition: Equiv.h:48
Definition: Equiv.h:32
Definition: Pair.h:16
Definition: Equiv.h:39
Pair< K, T > pair_t
Definition: Equiv.h:50