0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SockAddrMap.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef SOCKADDRMAP_H
28 #define SOCKADDRMAP_H
29 
30 #include <Common/InetAddr.h>
31 
32 #include <unordered_map>
33 
34 namespace Hypertable {
35 
38 
40  class SockAddrHash {
41  public:
42  size_t operator () (const InetAddr &addr) const {
43  return (size_t)(addr.sin_addr.s_addr ^ addr.sin_port);
44  }
45  };
46 
48  struct SockAddrEqual {
49  bool operator()(const InetAddr &addr1, const InetAddr &addr2) const {
50  return (addr1.sin_addr.s_addr == addr2.sin_addr.s_addr)
51  && (addr1.sin_port == addr2.sin_port);
52  }
53  };
54 
56  template<typename TypeT, typename addr = InetAddr>
57  class SockAddrMap : public std::unordered_map<addr, TypeT, SockAddrHash, SockAddrEqual> {
58  };
59 
61 
62 } // namespace Hypertable
63 
64 #endif // SOCKADDRMAP_H
Equality predicate functor class for InetAddr.
Definition: SockAddrMap.h:48
Hash functor class for InetAddr.
Definition: SockAddrMap.h:40
Unordered map specialization for InetAddr keys.
Definition: SockAddrMap.h:57
Encapsulate an internet address.
Definition: InetAddr.h:66
Hypertable definitions
size_t operator()(const InetAddr &addr) const
Definition: SockAddrMap.h:42
Internet address wrapper classes and utility functions.
bool operator()(const InetAddr &addr1, const InetAddr &addr2) const
Definition: SockAddrMap.h:49