libUTL++
Bytes.h
1 #pragma once
2 
4 
5 #include <libutl/Uint.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
20 
22 class Bytes : public Uint
23 {
26 
27 public:
32  Bytes(uint64_t bytes)
33  {
34  set(bytes);
35  }
36 
41  Bytes(const String& str)
42  {
43  set(str);
44  }
45 
46  String toString() const;
47 
48  double
49  kilobytes() const
50  {
51  return ((double)_n / KB(1));
52  }
53 
54  double
55  megabytes() const
56  {
57  return ((double)_n / MB(1));
58  }
59 
60  double
61  gigabytes() const
62  {
63  return ((double)_n / MB(1024));
64  }
65 
66 public:
68  static const Bytes oneKilobyte;
70  static const Bytes oneMegabyte;
72  static const Bytes oneGigabyte;
73 };
74 
76 
77 UTL_NS_END;
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
constexpr size_t MB(size_t n)
Convert size in megabytes to size in bytes.
Definition: util_inl.h:1023
static const Bytes oneMegabyte
One megabyte.
Definition: Bytes.h:70
Bytes(const String &str)
Constructor.
Definition: Bytes.h:41
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Character string.
Definition: String.h:31
static const Bytes oneKilobyte
One kilobyte.
Definition: Bytes.h:68
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
64-bit unsigned integer.
Definition: Uint.h:27
Number of bytes.
Definition: Bytes.h:22
constexpr size_t KB(size_t n)
Convert size in kilobytes to size in bytes.
Definition: util_inl.h:1008
static const Bytes oneGigabyte
One gigabyte.
Definition: Bytes.h:72
Bytes(uint64_t bytes)
Constructor.
Definition: Bytes.h:32