27 #include <string_view> 40 inline uint64_t
parseUint(
const char*& buffer) noexcept {
42 while (!std::isdigit(*buffer))
44 while (std::isdigit(*buffer)) {
45 result = (result << 1) + (result << 3) + *buffer -
'0';
60 bool resetFile(std::ifstream& file, std::vector<char>& buffer,
const std::string_view& path);
71 bool readFile(std::ifstream& file, std::vector<char>& buffer,
const std::string_view& path);
82 constexpr
KeyUnit() : key(
""sv), unit(
""sv) { }
83 constexpr
KeyUnit(std::string_view aKey, std::string_view aUnit) : key(aKey), unit(aUnit) { }
96 std::string
findUnit(
const std::string& name,
const std::array<KeyUnit, N>& keyUnitAssociation,
const std::string_view& defaultUnit) {
97 for (
const auto& val : keyUnitAssociation) {
98 if (name.find(val.key) != std::string::npos)
99 return std::string(val.unit);
101 return std::string(defaultUnit);
Stuct to associate a field name containing a certain key with a unit.
bool readFile(std::ifstream &file, std::vector< char > &buffer, const std::string_view &path)
Attempts to read file into buffer.
Namespace for sources of metrics objects and operations.
uint64_t parseUint(const char *&buffer) noexcept
Fast and unsafe unsigned integer parser.
constexpr KeyUnit(std::string_view aKey, std::string_view aUnit)
int alphanumCompare(const char *l, const char *r)
Alphanumeric string comparison.
bool resetFile(std::ifstream &file, std::vector< char > &buffer, const std::string_view &path)
Attempts to open a file and set buffer size accordingly.
std::string findUnit(const std::string &name, const std::array< KeyUnit, N > &keyUnitAssociation, const std::string_view &defaultUnit)
Tries to associate a field name with a unit, falling back on the default unit if none matches...