19#ifndef HEADER_HARDWARE_STATS_HPP
20#define HEADER_HARDWARE_STATS_HPP
26#include "utils/no_copy.hpp"
27#include "utils/string_utils.hpp"
29namespace HardwareStats
45 const std::string sanitize(std::string value)
52 for (
size_t i = 0; i < value.size(); i++)
54 uint8_t codepoint = value[i];
55 if (codepoint <= 0x1f)
57 sprintf(temp,
"\\u%04x", codepoint);
58 std::string suffix = value.substr(i + 1);
59 value = value.substr(0, i);
64 else if (codepoint ==
'"' || codepoint ==
'\\')
66 std::string suffix = value.substr(i + 1);
67 value = value.substr(0, i);
68 value.push_back(
'\\');
69 value.push_back((
char)codepoint);
80 void add(
const std::string &key,
const C&value)
84 m_data +=
"\""+sanitize(key)+
"\":"+StringUtils::toString(value);
89 void add(
const std::string &key,
const std::string &value)
93 m_data +=
"\""+sanitize(key)+
"\":\""+sanitize(value)+
"\"";
98 void add(
const std::string &key,
const char *s)
102 m_data +=
"\""+sanitize(key)+
"\":\""+sanitize(s)+
"\"";
115 void reportHardwareStats();
116 const std::string& getOSVersion();
117 int getNumProcessors();
A class to manage json data.
Definition: hardware_stats.hpp:33
std::string toString()
Returns the json data as one string.
Definition: hardware_stats.hpp:111
Json()
Constructor.
Definition: hardware_stats.hpp:39
void add(const std::string &key, const std::string &value)
Specialisation for adding string values.
Definition: hardware_stats.hpp:89
std::string m_data
The accumulated json data.
Definition: hardware_stats.hpp:36
void add(const std::string &key, const char *s)
Specialisation for adding character pointers.
Definition: hardware_stats.hpp:98
void add(const std::string &key, const C &value)
Adds a key-value pair to the json string.
Definition: hardware_stats.hpp:80
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26