class for Ip and Mac

This commit is contained in:
Erik Frojdh
2019-04-02 15:24:25 +02:00
parent df2d67d90d
commit b198b50377
10 changed files with 204 additions and 138 deletions

View File

@ -16,29 +16,35 @@ class IpAddr {
uint32_t addr_{0};
public:
explicit IpAddr(uint32_t address);
IpAddr(uint32_t address);
IpAddr(const std::string &address);
IpAddr(const char *address);
std::string str() const;
std::string hex() const;
bool operator==(const IpAddr &other) const { return addr_ == other.addr_; }
bool operator!=(const IpAddr &other) const { return addr_ != other.addr_; }
bool operator==(const uint32_t other) const { return addr_ == other; }
bool operator!=(const uint32_t other) const { return addr_ != other; }
};
class MacAddr {
private:
uint64_t addr_{0};
std::string to_hex(const char delimiter = 0);
std::string to_hex(const char delimiter = 0) const;
public:
MacAddr(uint64_t mac);
MacAddr(std::string mac);
std::string str() { return to_hex(':'); }
std::string hex() { return to_hex(); }
MacAddr(const char *address);
std::string str() const { return to_hex(':'); }
std::string hex() const { return to_hex(); }
bool operator==(const MacAddr &other) const { return addr_ == other.addr_; }
bool operator!=(const MacAddr &other) const { return addr_ != other.addr_; }
bool operator==(const uint64_t other) const { return addr_ == other; }
bool operator!=(const uint64_t other) const { return addr_ != other; }
};
std::ostream &operator<<(std::ostream &out, const IpAddr &addr){
return out << addr.str();
}
std::ostream &operator<<(std::ostream &out, const IpAddr &addr);
std::ostream &operator<<(std::ostream &out, const MacAddr &addr);
} // namespace sls