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
20namespace opflex {
21namespace modb {
22
29
37class MAC {
38public:
42 MAC();
43
50 explicit MAC(const std::string& mac);
51
58 explicit MAC(uint8_t mac[6]);
59
64
68 std::string toString() const;
69
73 void toUIntArray(/* out */uint8_t mac[6]) const;
74
75private:
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
99std::ostream & operator<<(std::ostream &os, const MAC& mac);
100
104bool operator==(const MAC& lhs, const MAC& rhs);
108bool operator!=(const MAC& lhs, const MAC& rhs);
113size_t hash_value(MAC const& mac);
114
115/* @} modb */
116/* @} cpp */
117
118} /* namespace modb */
119} /* namespace opflex */
120
121#if __cplusplus > 199711L
122
123namespace std {
128template<> 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 */
A MAC address is used to identify devices on an ethernet network.
Definition MAC.h:37
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.
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.
~MAC()
Destroy the MAC.
friend bool operator!=(const MAC &lhs, const MAC &rhs)
Check for MAC inequality.
std::ostream & operator<<(std::ostream &os, const MAC &mac)
Stream insertion operator.
bool operator!=(const MAC &lhs, const MAC &rhs)
Check for MAC inequality.
void toUIntArray(uint8_t mac[6]) const
Get the MAC represented as an array of 6 bytes in network byte order.
MAC(uint8_t mac[6])
Construct a MAC using an array of 6 bytes, in network byte order.
std::string toString() const
Get the MAC represented as a string.
friend bool operator==(const MAC &lhs, const MAC &rhs)
Check for MAC equality.
bool operator==(const MAC &lhs, const MAC &rhs)
Check for MAC equality.
MAC(const std::string &mac)
Construct a MAC using the given string representation.
MAC()
Construct a MAC consisting of all zeroes.