0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::stats: Add buffer-based stringifier to interface; simplify.

This commit is contained in:
Jason Volk 2020-06-17 20:28:05 -07:00
parent 1ff8217682
commit 4b20747e06
2 changed files with 27 additions and 5 deletions

View file

@ -56,6 +56,7 @@ namespace ircd::stats
extern const size_t NAME_MAX_LEN;
extern std::map<string_view, item<void> *> items;
string_view string(const mutable_buffer &, const item<void> &);
std::ostream &operator<<(std::ostream &, const item<void> &);
}

View file

@ -21,6 +21,15 @@ ircd::stats::items
std::ostream &
ircd::stats::operator<<(std::ostream &s,
const item<void> &item_)
{
thread_local char tmp[256];
s << string(tmp, item_);
return s;
}
ircd::string_view
ircd::stats::string(const mutable_buffer &buf,
const item<void> &item_)
{
if(item_.type == typeid(uint64_t *))
{
@ -30,7 +39,10 @@ ircd::stats::operator<<(std::ostream &s,
};
assert(item.val);
s << *item.val;
return fmt::sprintf
{
buf, "%lu", *item.val
};
}
else if(item_.type == typeid(uint32_t *))
{
@ -40,7 +52,10 @@ ircd::stats::operator<<(std::ostream &s,
};
assert(item.val);
s << *item.val;
return fmt::sprintf
{
buf, "%u", *item.val
};
}
else if(item_.type == typeid(uint16_t *))
{
@ -50,10 +65,16 @@ ircd::stats::operator<<(std::ostream &s,
};
assert(item.val);
s << *item.val;
return fmt::sprintf
{
buf, "%u", *item.val
};
}
return s;
else throw error
{
"Unsupported value type '%s'",
item_.type.name(),
};
}
//