All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
ids.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
16 #ifndef PAAL_IDS_HPP
17 #define PAAL_IDS_HPP
18 
19 #include <functional>
20 
21 namespace paal {
22 namespace lp {
23 
27 class Id {
28  protected:
30  Id() {}
32  explicit Id(int id) : m_id(id) {}
33 
34  public:
36  int get() const { return m_id; }
37 
39  bool operator<(Id id) const { return m_id < id.m_id; }
40 
42  bool operator==(Id id) const { return m_id == id.m_id; }
43 
44  private:
45  int m_id;
46 };
47 
51 struct col_id : Id {
52  col_id() {}
54  explicit col_id(int id) : Id(id) {}
55 };
56 
60 struct row_id : Id {
61  row_id() {}
63  explicit row_id(int id) : Id(id) {}
64 };
65 
66 } // lp
67 } // paal
68 
69 namespace std {
70 
74 template <> struct hash<paal::lp::Id> {
78  std::size_t operator()(const paal::lp::Id &x) const {
79  return hash<int>()(x.get());
80  }
81 };
82 
83 template <> struct hash<paal::lp::row_id> : public hash<paal::lp::Id> {};
84 
85 template <> struct hash<paal::lp::col_id> : public hash<paal::lp::Id> {};
86 
87 } // std
88 
89 #endif // PAAL_IDS_HPP
Id(int id)
Constructor.
Definition: ids.hpp:32
bool operator<(Id id) const
Less operator.
Definition: ids.hpp:39
col_id(int id)
Constructor.
Definition: ids.hpp:54
row_id(int id)
Constructor.
Definition: ids.hpp:63
std::size_t operator()(const paal::lp::Id &x) const
Definition: ids.hpp:78
int get() const
Returns the id number.
Definition: ids.hpp:36
bool operator==(Id id) const
Equality operator.
Definition: ids.hpp:42
Id()
Constructor.
Definition: ids.hpp:30