add FileSize::operator std::string() const

This commit is contained in:
mrbesen 2024-02-10 16:56:28 +01:00
parent feac7be191
commit 79e47c3cda
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 7 additions and 0 deletions

View File

@ -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;

1
Log.h
View File

@ -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);