Cthulhu  0.2.10
Cthulhu compiler collection
memory.cpp
Go to the documentation of this file.
1 #include "stdafx.hpp"
2 
3 #include "editor/memory.hpp"
4 
5 std::string Memory::to_string() const
6 {
7  if (mBytes == 0) { return "0b"; }
8 
9  std::stringstream ss;
10  size_t total = mBytes;
11 
12  // seperate each part with a +
13 
14  for (int fmt = eLimit - 1; fmt >= 0; fmt--)
15  {
16  size_t size = total / kSizes[fmt];
17  if (size > 0)
18  {
19  ss << size << kNames[fmt];
20  total %= kSizes[fmt];
21 
22  if (total > 0)
23  ss << "+";
24  }
25  }
26 
27  return ss.str();
28 }
CT_NODISCARD size_t size
Definition: scan.h:128
CT_NODISCARD STA_FORMAT_STRING const char * fmt
Definition: str.h:68
@ eLimit
Definition: memory.hpp:12
std::string to_string() const
Definition: memory.cpp:5
static constexpr const char * kNames[eLimit]
Definition: memory.hpp:29
static constexpr size_t kSizes[eLimit]
Definition: memory.hpp:21