Jpp  19.1.0
the software that should make you happy
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
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. More...
 
bool equal (const JMACAddress &address) const
 Equal method. More...
 
 ClassDefNV (JMACAddress, 1)
 

Static Public Member Functions

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

Friends

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

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
Definition: JMACAddress.hh:35

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.
Definition: JMACAddress.hh:44

◆ 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  ,
 
)

Friends And Related Function 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  }
Definition: JSTDTypes.hh:14
static bool is_separator(const int c)
Check if given character is an allowed separator.
Definition: JMACAddress.hh:56
JMACAddress()
Default constructor.
Definition: JMACAddress.hh:73

◆ 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: