-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.h
44 lines (39 loc) · 1.17 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#define KILO 1024
#define MEGA (KILO * KILO)
#define GIGA (KILO * MEGA)
extern std::string StringInt(uint64_t val, uint32_t width = 0, char padding = ' ')
{
std::ostringstream ostr;
ostr.setf(std::ios::fixed, std::ios::floatfield);
ostr.fill(padding);
ostr << std::setw(width) << val;
return ostr.str();
}
extern std::string StringFlt(long double val, uint32_t width = 0, char padding = ' ')
{
std::ostringstream ostr;
ostr.setf(std::ios::fixed, std::ios::floatfield);
ostr.fill(padding);
ostr << std::setw(width) << val;
return ostr.str();
}
extern std::string StringHex(uint64_t val, uint32_t width = 0, char padding = ' ')
{
std::ostringstream ostr;
ostr.setf(std::ios::fixed, std::ios::floatfield);
ostr.fill(padding);
ostr << std::setw(width) << std::hex << "0x" << val;
return ostr.str();
}
extern std::string StringString(std::string val, uint32_t width = 0, char padding = ' ')
{
std::ostringstream ostr;
ostr.setf(std::ios::fixed, std::ios::floatfield);
ostr.fill(padding);
ostr << std::setw(width) << val;
return ostr.str();
}