implement operator >>

This commit is contained in:
Mathieu Lacage committed 2008-04-11 16:51:58 -07:00
1 parent c539ba6689
commit d6c1f9aaed
2 files changed
+35 -3

No files matched your search

+33 -2
View File
@@ -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;
}
+2 -1
View File
@@ -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