Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JDATABASE::JMACAddress Struct Reference

MAC address. More...

#include <JMACAddress.hh>

Inheritance diagram for JDATABASE::JMACAddress:
std::vector< unsigned char > JLANG::JEquals< JFirst_t, JSecond_t >

Public Types

enum  { NUMBER_OF_BYTES = 6 }
 

Public Member Functions

 JMACAddress ()
 Default constructor.
 
bool equal (const JMACAddress &address) const
 Equal method.
 
 ClassDefNV (JMACAddress, 1)
 

Static Public Member Functions

static const char * get_separator ()
 Get list of allowed separators.
 
static bool is_separator (const int c)
 Check if given character is an allowed separator.
 

Friends

std::istream & operator>> (std::istream &in, JMACAddress &object)
 Read MAC address from input stream.
 
std::ostream & operator<< (std::ostream &out, const JMACAddress &object)
 Write MAC address to output stream.
 

Detailed Description

MAC address.

Definition at line 30 of file JMACAddress.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
NUMBER_OF_BYTES 

number of bytes

Definition at line 34 of file JMACAddress.hh.

34 {
35 NUMBER_OF_BYTES = 6 //!< number of bytes
36 };
@ NUMBER_OF_BYTES
number of bytes

Constructor & Destructor Documentation

◆ JMACAddress()

JDATABASE::JMACAddress::JMACAddress ( )
inline

Default constructor.

Definition at line 73 of file JMACAddress.hh.

Member Function Documentation

◆ get_separator()

static const char * JDATABASE::JMACAddress::get_separator ( )
inlinestatic

Get list of allowed separators.

Returns
allowed separators

Definition at line 44 of file JMACAddress.hh.

45 {
46 return ":.-";
47 }

◆ is_separator()

static bool JDATABASE::JMACAddress::is_separator ( const int c)
inlinestatic

Check if given character is an allowed separator.

Parameters
ccharacter
Returns
true if separator; else false

Definition at line 56 of file JMACAddress.hh.

57 {
58 const std::string buffer(JMACAddress::get_separator());
59
60 for (std::string::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
61 if ((int) *i == c) {
62 return true;
63 }
64 }
65
66 return false;
67 }
static const char * get_separator()
Get list of allowed separators.

◆ equal()

bool JDATABASE::JMACAddress::equal ( const JMACAddress & address) const
inline

Equal method.

Parameters
addressMAC address
Returns
true if this MAC address and given MAC address are equal; else false

Definition at line 84 of file JMACAddress.hh.

85 {
86 for (int i = 0; i != NUMBER_OF_BYTES; ++i) {
87 if ((*this)[i] != address[i]) {
88 return false;
89 }
90 }
91
92 return true;
93 }

◆ ClassDefNV()

JDATABASE::JMACAddress::ClassDefNV ( JMACAddress ,
1  )

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JMACAddress & object )
friend

Read MAC address from input stream.

Parameters
ininput stream
objectMAC address
Returns
input stream

Definition at line 103 of file JMACAddress.hh.

104 {
105 using namespace std;
106
107 object = JMACAddress();
108
109 int c;
110
111 if (in >> hex >> c) {
112
113 object[0] = (unsigned char) c;
114
115 for (int i = 1; i != NUMBER_OF_BYTES; ++i) {
116 if (is_separator(in.get()) && in >> hex >> c)
117 object[i] = (unsigned char) c;
118 else
119 in.setstate(ios::failbit);
120 }
121 }
122
123 return in >> dec;
124 }
static bool is_separator(const int c)
Check if given character is an allowed separator.
JMACAddress()
Default constructor.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JMACAddress & object )
friend

Write MAC address to output stream.

Parameters
outoutput stream
objectMAC address
Returns
output stream

Definition at line 135 of file JMACAddress.hh.

136 {
137 using namespace std;
138
139 out << setw(2) << setfill('0') << hex << (int) object[0];
140
141 for (int i = 1; i != NUMBER_OF_BYTES; ++i) {
142 out << setw(1) << JMACAddress::get_separator()[0]
143 << setw(2) << setfill('0') << hex << (int) object[i];
144 }
145
146 return out << setfill(' ') << dec;
147 }

The documentation for this struct was generated from the following file: