From 79e47c3cda6e61e9655295cc14fba92cbbbbe712 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sat, 10 Feb 2024 16:56:28 +0100 Subject: [PATCH] add FileSize::operator std::string() const --- Log.cpp | 6 ++++++ Log.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Log.cpp b/Log.cpp index 391f9fe..7520a46 100644 --- a/Log.cpp +++ b/Log.cpp @@ -297,6 +297,12 @@ std::ostream& operator<<(std::ostream& str, const PrintErrno&) { return str << strerror(errno) << " (" << errno << ')'; } +FileSize::operator std::string() const { + std::ostringstream str; + str << *this; + return str.str(); +} + std::ostream& operator<<(std::ostream& str, const FileSize& fs) { static const char PREFIX[] {' ', 'K', 'M', 'G', 'T', 'P', 'E'}; static const uint_fast8_t PREFIXCOUNT = 7; diff --git a/Log.h b/Log.h index b426a0e..54c518f 100644 --- a/Log.h +++ b/Log.h @@ -122,6 +122,7 @@ public: explicit FileSize(uint64_t fs) : fs(fs) {} FileSize(const FileSize&) = delete; FileSize& operator=(const FileSize&) = delete; + operator std::string() const; private: uint64_t fs; friend std::ostream& operator<<(std::ostream& str, const FileSize& fs);