Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
int_wrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored By: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_INT_WRAPPER_H_
20 #define MIR_INT_WRAPPER_H_
21 
22 #include <iosfwd>
23 
24 namespace mir
25 {
26 template<typename Tag>
28 {
29 public:
30  typedef int ValueType;
31 
32  IntWrapper() : value(0) {}
33 
34  explicit IntWrapper(ValueType value) : value(value) {}
35  ValueType as_value() const { return value; }
36 
37 private:
38  ValueType value;
39 };
40 
41 template<typename Tag>
42 std::ostream& operator<<(std::ostream& out, IntWrapper<Tag> const& value)
43 {
44  out << value.as_value();
45  return out;
46 }
47 
48 template<typename Tag>
49 inline bool operator == (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
50 {
51  return lhs.as_value() == rhs.as_value();
52 }
53 
54 template<typename Tag>
55 inline bool operator != (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
56 {
57  return lhs.as_value() != rhs.as_value();
58 }
59 
60 template<typename Tag>
61 inline bool operator <= (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
62 {
63  return lhs.as_value() <= rhs.as_value();
64 }
65 
66 template<typename Tag>
67 inline bool operator >= (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
68 {
69  return lhs.as_value() >= rhs.as_value();
70 }
71 
72 template<typename Tag>
73 inline bool operator < (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
74 {
75  return lhs.as_value() < rhs.as_value();
76 }
77 }
78 
79 #include <functional>
80 namespace std
81 {
82 template<typename Tag>
83 struct hash< ::mir::IntWrapper<Tag> >
84 {
85  std::hash<int> self;
86  std::size_t operator()(::mir::IntWrapper<Tag> const& id) const
87  {
88  return self(id.as_value());
89  }
90 };
91 }
92 
93 #endif // MIR_INT_WRAPPER_H_

Copyright © 2012,2013 Canonical Ltd.
Generated on Wed Oct 30 18:52:19 UTC 2013