Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Pair.h
1 /*
2  * Pair class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2006, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_UTIL_PAIR_H
22 #define ELM_UTIL_PAIR_H
23 
24 namespace elm {
25 
26 namespace io {
27  class Output;
28  class Input;
29 }
30 
31 // Pair class
32 template <class T1, class T2>
33 class Pair {
34 public:
35  T1 fst;
36  T2 snd;
37  inline Pair(void) { }
38  inline Pair(const T1& _fst, const T2& _snd): fst(_fst), snd(_snd) { }
39  inline Pair(const Pair<T1, T2>& pair): fst(pair.fst), snd(pair.snd) { }
40  inline Pair<T1, T2>& operator=(const Pair<T1, T2>& pair) { fst = pair.fst; snd = pair.snd; return *this; }
41  inline bool operator==(const Pair<T1, T2>& pair) const { return ((fst== pair.fst) && (snd == pair.snd)); }
42  inline bool operator!=(const Pair<T1, T2>& pair) const { return !operator==(pair); }
43  inline bool operator<(const Pair<T1, T1>& pair) const { return fst < fst.pair || (fst == fst.pair && snd < snd.pair); }
44  inline bool operator<=(const Pair<T1, T1>& pair) const { return fst <= fst.pair || (fst == fst.pair && snd <= snd.pair); }
45  inline bool operator>(const Pair<T1, T1>& pair) const { return !operator<=(pair); }
46  inline bool operator>=(const Pair<T1, T1>& pair) const { return !operator<(pair); }
47 };
48 
49 
50 // RefPair class
51 template <class T1, class T2>
52 class RefPair {
53 public:
54  inline RefPair(T1& r1, T2& r2): v1(r1), v2(r2) { }
55  RefPair<T1, T2>& operator=(const Pair<T1, T2>& p) { v1 = p.fst; v2 = p.snd; return *this; }
56 private:
57  T1& v1;
58  T2& v2;
59 };
60 
61 
62 // Shortcuts
63 template <class T1, class T2> inline Pair<T1, T2> pair(const T1& v1, const T2& v2) { return Pair<T1, T2>(v1, v2); }
64 template <class T1, class T2> io::Output& operator<<(io::Output& out, const Pair<T1, T2>& p) { out << p.fst << " " << p.snd; return out; }
65 template <class T1, class T2> inline RefPair<T1, T2> let(T1& v1, T2& v2) { return RefPair<T1, T2>(v1, v2); }
66 template <class T1, class T2> io::Input& operator>>(io::Input& in, Pair<T1, T2>& p) { in >> p.fst >> p.snd; return in; }
67 
68 } // elm
69 
70 #endif /* ELM_UTIL_PAIR_H */
elm::t::out
typename type_info< T >::out_t out
Definition: type_info.h:284
elm::io::p
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
elm::RefPair::operator=
RefPair< T1, T2 > & operator=(const Pair< T1, T2 > &p)
Definition: Pair.h:55
elm::operator<<
AutoString & operator<<(CString str, const T &value)
Definition: AutoString.h:75
elm::pair
Pair< T1, T2 > pair(const T1 &v1, const T2 &v2)
Definition: Pair.h:63
elm::Pair::snd
T2 snd
Definition: Pair.h:36
elm::Pair
Definition: Pair.h:33
elm::Pair::operator>
bool operator>(const Pair< T1, T1 > &pair) const
Definition: Pair.h:45
elm::Pair::Pair
Pair(const T1 &_fst, const T2 &_snd)
Definition: Pair.h:38
elm::t::in
typename type_info< T >::in_t in
Definition: type_info.h:283
elm
Definition: adapter.h:26
elm::RefPair
Definition: Pair.h:52
elm::let
RefPair< T1, T2 > let(T1 &v1, T2 &v2)
Definition: Pair.h:65
elm::RefPair::RefPair
RefPair(T1 &r1, T2 &r2)
Definition: Pair.h:54
elm::Pair::Pair
Pair(void)
Definition: Pair.h:37
elm::Pair::operator!=
bool operator!=(const Pair< T1, T2 > &pair) const
Definition: Pair.h:42
elm::io::Input
Definition: Input.h:34
elm::Pair::Pair
Pair(const Pair< T1, T2 > &pair)
Definition: Pair.h:39
elm::Pair::operator==
bool operator==(const Pair< T1, T2 > &pair) const
Definition: Pair.h:41
elm::Pair::operator<
bool operator<(const Pair< T1, T1 > &pair) const
Definition: Pair.h:43
elm::Pair::operator=
Pair< T1, T2 > & operator=(const Pair< T1, T2 > &pair)
Definition: Pair.h:40
elm::Pair::operator<=
bool operator<=(const Pair< T1, T1 > &pair) const
Definition: Pair.h:44
elm::operator>>
io::StringInput operator>>(const string &str, T &val)
Definition: AutoString.h:82
elm::Pair::operator>=
bool operator>=(const Pair< T1, T1 > &pair) const
Definition: Pair.h:46
elm::io::Output
Definition: Output.h:179
elm::Pair::fst
T1 fst
Definition: Pair.h:35