implement operator >>
This commit is contained in:
1 parent
c539ba6689
commit
d6c1f9aaed
2 files changed
+35
-3
No files matched your search
@@ -200,9 +200,40 @@ std::ostream& operator<< (std::ostream& os, const Mac48Address & address)
|
||||
return os;
|
||||
}
|
||||
|
||||
std::istream& operator>> (std::istream& is, const Mac48Address & address)
|
||||
static uint8_t
|
||||
AsInt (std::string v)
|
||||
{
|
||||
// XXX !
|
||||
std::istringstream iss;
|
||||
iss.str (v);
|
||||
uint32_t retval;
|
||||
iss >> std::hex >> retval >> std::dec;
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::istream& operator>> (std::istream& is, Mac48Address & address)
|
||||
{
|
||||
std::string v;
|
||||
is >> v;
|
||||
|
||||
std::string::size_type col = 0;
|
||||
for (uint8_t i = 0; i < 6; ++i)
|
||||
{
|
||||
std::string tmp;
|
||||
std::string::size_type next;
|
||||
next = v.find (":", col);
|
||||
if (next == std::string::npos)
|
||||
{
|
||||
tmp = v.substr (col, v.size ()-col);
|
||||
address.m_address[i] = AsInt (tmp);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = v.substr (col, next-col);
|
||||
address.m_address[i] = AsInt (tmp);
|
||||
col = next + 1;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ private:
|
||||
static uint8_t GetType (void);
|
||||
friend bool operator < (const Mac48Address &a, const Mac48Address &b);
|
||||
friend bool operator == (const Mac48Address &a, const Mac48Address &b);
|
||||
friend std::istream& operator>> (std::istream& is, Mac48Address & address);
|
||||
|
||||
uint8_t m_address[6];
|
||||
};
|
||||
@@ -117,7 +118,7 @@ bool operator == (const Mac48Address &a, const Mac48Address &b);
|
||||
bool operator != (const Mac48Address &a, const Mac48Address &b);
|
||||
bool operator < (const Mac48Address &a, const Mac48Address &b);
|
||||
std::ostream& operator<< (std::ostream& os, const Mac48Address & address);
|
||||
std::istream& operator>> (std::istream& is, const Mac48Address & address);
|
||||
std::istream& operator>> (std::istream& is, Mac48Address & address);
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
Reference in new issue
Block a user