From 18561adfde80d6665e24262d70d18f916e2662e5 Mon Sep 17 00:00:00 2001 From: YohanPipereau Date: Mon, 15 Jul 2019 15:37:46 +0200 Subject: vom: migration from scvpp to vom Change-Id: I79609f0bee9b8307da0d9bf704babe8ba06dba4d Signed-off-by: YohanPipereau Co-authored-by: Pavel Kotucek Co-authored-by: Andrej Kozemcak --- src/plugins/sys_util.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/plugins/sys_util.cpp (limited to 'src/plugins/sys_util.cpp') 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(); +} + +} -- cgit 1.2.3-korg