mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-24 05:18:36 +00:00
Makes provision for pretty-printed key names.
i.e. keys that don't fit C++ naming rules.
This commit is contained in:
@@ -205,6 +205,7 @@ void Reflection::Struct::append(std::ostringstream &stream, const std::string &k
|
||||
|
||||
std::string Reflection::Struct::description() const {
|
||||
std::ostringstream stream;
|
||||
const auto name_map = pretty_names();
|
||||
|
||||
stream << "{";
|
||||
|
||||
@@ -212,7 +213,10 @@ std::string Reflection::Struct::description() const {
|
||||
for(const auto &key: all_keys()) {
|
||||
if(!is_first) stream << ", ";
|
||||
is_first = false;
|
||||
stream << key << ": ";
|
||||
|
||||
// Use the pretty name for this key, if defined.
|
||||
const auto mapped_key = name_map.find(key);
|
||||
stream << (mapped_key != name_map.end() ? mapped_key->second : key) << ": ";
|
||||
|
||||
const auto count = count_of(key);
|
||||
const auto type = type_of(key);
|
||||
|
||||
@@ -27,6 +27,14 @@ namespace Reflection {
|
||||
#define DeclareField(Name) declare(&Name, #Name)
|
||||
|
||||
struct Struct {
|
||||
/*!
|
||||
Maps from internal key names to more human-friendly ones; e.g. might contain
|
||||
a mapping from afDash to af'.
|
||||
*/
|
||||
virtual std::unordered_map<std::string, std::string> pretty_names() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual std::vector<std::string> all_keys() const = 0;
|
||||
virtual const std::type_info *type_of(const std::string &name) const = 0;
|
||||
virtual size_t count_of(const std::string &name) const = 0;
|
||||
|
||||
Reference in New Issue
Block a user