CatapultServer  v0.5.0.1 (Elephant)
FileSize.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "Casting.h"
23 #include <iosfwd>
24 #include <stdint.h>
25 
26 namespace catapult { namespace utils {
27 
29  class FileSize final {
30  private:
31  constexpr explicit FileSize(uint64_t bytes) : m_bytes(bytes)
32  {}
33 
34  public:
36  constexpr FileSize() : FileSize(0)
37  {}
38 
39  public:
41  static constexpr FileSize FromMegabytes(uint64_t megabytes) {
42  return FromKilobytes(megabytes * 1024);
43  }
44 
46  static constexpr FileSize FromKilobytes(uint64_t kilobytes) {
47  return FromBytes(kilobytes * 1024);
48  }
49 
51  static constexpr FileSize FromBytes(uint64_t bytes) {
52  return FileSize(bytes);
53  }
54 
55  public:
57  constexpr uint64_t megabytes() const {
58  return kilobytes() / 1024;
59  }
60 
62  constexpr uint64_t kilobytes() const {
63  return bytes() / 1024;
64  }
65 
67  constexpr uint64_t bytes() const {
68  return m_bytes;
69  }
70 
72  uint32_t bytes32() const {
73  return checked_cast<uint64_t, uint32_t>(m_bytes);
74  }
75 
76  public:
78  constexpr bool operator==(const FileSize& rhs) const {
79  return m_bytes == rhs.m_bytes;
80  }
81 
83  constexpr bool operator!=(const FileSize& rhs) const {
84  return !(*this == rhs);
85  }
86 
88  constexpr bool operator>=(const FileSize& rhs) const {
89  return m_bytes >= rhs.m_bytes;
90  }
91 
93  constexpr bool operator>(const FileSize& rhs) const {
94  return m_bytes > rhs.m_bytes;
95  }
96 
98  constexpr bool operator<=(const FileSize& rhs) const {
99  return m_bytes <= rhs.m_bytes;
100  }
101 
103  constexpr bool operator<(const FileSize& rhs) const {
104  return m_bytes < rhs.m_bytes;
105  }
106 
107  private:
108  uint64_t m_bytes;
109  };
110 
112  std::ostream& operator<<(std::ostream& out, const FileSize& fileSize);
113 }}
catapult::utils::FileSize::bytes
constexpr uint64_t bytes() const
Returns the number of bytes.
Definition: FileSize.h:67
catapult::utils::FileSize::m_bytes
uint64_t m_bytes
Definition: FileSize.h:108
FileSize.h
IntegerMath.h
catapult::utils::FileSize::kilobytes
constexpr uint64_t kilobytes() const
Returns the number of kilobytes.
Definition: FileSize.h:62
catapult::utils::FileSize::FileSize
constexpr FileSize()
Creates a default (zero) file size.
Definition: FileSize.h:36
catapult::utils::FileSize::bytes32
uint32_t bytes32() const
Returns the number of bytes as a uint32_t.
Definition: FileSize.h:72
catapult::utils::FileSize::FromMegabytes
static constexpr FileSize FromMegabytes(uint64_t megabytes)
Creates a file size from the given number of megabytes.
Definition: FileSize.h:41
catapult::utils::FileSize::megabytes
constexpr uint64_t megabytes() const
Returns the number of megabytes.
Definition: FileSize.h:57
catapult::utils::FileSize
Represents a file size.
Definition: FileSize.h:29
catapult::utils::FileSize::operator!=
constexpr bool operator!=(const FileSize &rhs) const
Returns true if this file size is not equal to rhs.
Definition: FileSize.h:83
catapult::utils::FileSize::operator<=
constexpr bool operator<=(const FileSize &rhs) const
Returns true if this file size is less than or equal to rhs.
Definition: FileSize.h:98
catapult::utils::FileSize::operator>=
constexpr bool operator>=(const FileSize &rhs) const
Returns true if this file size is greater than or equal to rhs.
Definition: FileSize.h:88
catapult::utils::operator<<
std::ostream & operator<<(std::ostream &out, const BlockSpan &blockSpan)
Insertion operator for outputting blockSpan to out.
Definition: BlockSpan.cpp:27
catapult::utils::FileSize::FromKilobytes
static constexpr FileSize FromKilobytes(uint64_t kilobytes)
Creates a file size from the given number of kilobytes.
Definition: FileSize.h:46
Casting.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::utils::FileSize::FromBytes
static constexpr FileSize FromBytes(uint64_t bytes)
Creates a file size from the given number of bytes.
Definition: FileSize.h:51
catapult::utils::FileSize::FileSize
constexpr FileSize(uint64_t bytes)
Definition: FileSize.h:31
m_hasOutput
bool m_hasOutput
Definition: FileSize.cpp:60
m_out
std::ostream & m_out
Definition: FileSize.cpp:59
catapult::utils::FileSize::operator>
constexpr bool operator>(const FileSize &rhs) const
Returns true if this file size is greater than rhs.
Definition: FileSize.h:93
catapult::utils::FileSize::operator==
constexpr bool operator==(const FileSize &rhs) const
Returns true if this file size is equal to rhs.
Definition: FileSize.h:78
catapult::utils::FileSize::operator<
constexpr bool operator<(const FileSize &rhs) const
Returns true if this file size is less than rhs.
Definition: FileSize.h:103