OpFlex Framework  1.7.0
MAC.h
Go to the documentation of this file.
1 /* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
6 /*
7  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
8  *
9  * This program and the accompanying materials are made available under the
10  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
11  * and is available at http://www.eclipse.org/legal/epl-v10.html
12  */
13 
14 #ifndef MODB_MAC_H
15 #define MODB_MAC_H
16 
17 #include <string>
18 #include <vector>
19 
20 namespace opflex {
21 namespace modb {
22 
37 class MAC {
38 public:
42  MAC();
43 
50  explicit MAC(const std::string& mac);
51 
58  explicit MAC(uint8_t mac[6]);
59 
63  ~MAC();
64 
68  std::string toString() const;
69 
73  void toUIntArray(/* out */uint8_t mac[6]) const;
74 
75 private:
83  explicit MAC(uint64_t mac);
84 
89  uint64_t mac;
90 
91  friend bool operator==(const MAC& lhs, const MAC& rhs);
92  friend bool operator!=(const MAC& lhs, const MAC& rhs);
93  friend size_t hash_value(MAC const& mac);
94 };
95 
99 std::ostream & operator<<(std::ostream &os, const MAC& mac);
100 
104 bool operator==(const MAC& lhs, const MAC& rhs);
108 bool operator!=(const MAC& lhs, const MAC& rhs);
113 size_t hash_value(MAC const& mac);
114 
115 /* @} modb */
116 /* @} cpp */
117 
118 } /* namespace modb */
119 } /* namespace opflex */
120 
121 #if __cplusplus > 199711L
122 
123 namespace std {
128 template<> struct hash<opflex::modb::MAC> {
132  std::size_t operator()(const opflex::modb::MAC& m) const {
133  return opflex::modb::hash_value(m);
134  }
135 };
136 } /* namespace std */
137 
138 #endif
139 
140 #endif /* MODB_MAC_H */
void toUIntArray(uint8_t mac[6]) const
Get the MAC represented as an array of 6 bytes in network byte order.
bool operator==(const MAC &lhs, const MAC &rhs)
Check for MAC equality.
std::ostream & operator<<(std::ostream &os, const MAC &mac)
Stream insertion operator.
friend size_t hash_value(MAC const &mac)
Compute a hash value for the MAC, making MAC suitable as a key in a boost::unordered_map.
Definition: OFLogHandler.h:20
bool operator!=(const MAC &lhs, const MAC &rhs)
Check for MAC inequality.
~MAC()
Destroy the MAC.
friend bool operator!=(const MAC &lhs, const MAC &rhs)
Check for MAC inequality.
MAC()
Construct a MAC consisting of all zeroes.
std::string toString() const
Get the MAC represented as a string.
friend bool operator==(const MAC &lhs, const MAC &rhs)
Check for MAC equality.
A MAC address is used to identify devices on an ethernet network.
Definition: MAC.h:37
size_t hash_value(MAC const &mac)
Compute a hash value for the MAC, making MAC suitable as a key in a boost::unordered_map.