diff options
author | YohanPipereau <ypiperea@cisco.com> | 2019-07-15 15:37:46 +0200 |
---|---|---|
committer | YohanPipereau <ypiperea@cisco.com> | 2019-07-26 15:29:05 +0200 |
commit | 18561adfde80d6665e24262d70d18f916e2662e5 (patch) | |
tree | 06683574ba18ee25012f77b18da7c0e35a5707aa /src/plugins/sys_util.cpp | |
parent | adc56bc5ddcdf947864d982cda809588b7ccd8bc (diff) |
vom: migration from scvpp to vom
Change-Id: I79609f0bee9b8307da0d9bf704babe8ba06dba4d
Signed-off-by: YohanPipereau <ypiperea@cisco.com>
Co-authored-by: Pavel Kotucek <pavel.kotucek@pantheon.tech>
Co-authored-by: Andrej Kozemcak <andrej.kozemcak@pantheon.tech>
Diffstat (limited to 'src/plugins/sys_util.cpp')
-rw-r--r-- | src/plugins/sys_util.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/plugins/sys_util.cpp b/src/plugins/sys_util.cpp new file mode 100644 index 0000000..f011825 --- /dev/null +++ b/src/plugins/sys_util.cpp @@ -0,0 +1,61 @@ +#include "sys_util.h" + +namespace utils { + +prefix::prefix() +{ +} + +prefix::prefix(const prefix &p) +{ + m_address = p.address(); + m_prefix_len = p.prefix_length(); +} + +prefix::prefix(std::string p) +{ + size_t found = p.find_last_of('/'); + + if (found == std::string::npos) //not found + throw std::runtime_error("missing '/' in " + p); + + m_address = boost::asio::ip::address::from_string(p.substr(0, found)); + m_prefix_len = std::stoi(p.substr(found+1, p.length())); +} + +prefix prefix::make_prefix(std::string str) +{ + prefix tmp(str); + return prefix(tmp); +} + +unsigned short prefix::prefix_length() const +{ + return m_prefix_len; +} + +boost::asio::ip::address prefix::address() const +{ + return m_address; +} + +std::string prefix::to_string() const +{ + ostringstream os; + os << m_address << "/" << m_prefix_len; + return os.str(); +} + +std::ostream& operator<<(std::ostream& os, const prefix& p) +{ + os << p.to_string(); + + return os; +} + +bool prefix::empty() const +{ + return to_string().empty(); +} + +} |