From 76f2aba51ab609118ba863ee779a9c5bb302944c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 5 Apr 2021 17:24:16 -0400 Subject: [PATCH] Makes use of pretty names in descriptions optional. --- Reflection/Struct.cpp | 10 +++++----- Reflection/Struct.hpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Reflection/Struct.cpp b/Reflection/Struct.cpp index b27652301..3e2a6157c 100644 --- a/Reflection/Struct.cpp +++ b/Reflection/Struct.cpp @@ -159,7 +159,7 @@ bool Reflection::fuzzy_set(Struct &target, const std::string &name, const std::s // MARK: - Description -void Reflection::Struct::append(std::ostringstream &stream, const std::string &key, const std::type_info *const type, size_t offset) const { +void Reflection::Struct::append(std::ostringstream &stream, const std::string &key, const std::type_info *const type, size_t offset, bool use_pretty_names) const { // Output Bools as yes/no. if(*type == typeid(bool)) { stream << ::Reflection::get(*this, key, offset); @@ -198,12 +198,12 @@ void Reflection::Struct::append(std::ostringstream &stream, const std::string &k // Recurse to deal with embedded objects. if(*type == typeid(Reflection::Struct)) { const Reflection::Struct *const child = reinterpret_cast(get(key)); - stream << child->description(); + stream << child->description(use_pretty_names); return; } } -std::string Reflection::Struct::description() const { +std::string Reflection::Struct::description(bool use_pretty_names) const { std::ostringstream stream; const auto name_map = pretty_names(); @@ -216,7 +216,7 @@ std::string Reflection::Struct::description() const { // 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) << ": "; + stream << (use_pretty_names && mapped_key != name_map.end() ? mapped_key->second : key) << ": "; const auto count = count_of(key); const auto type = type_of(key); @@ -226,7 +226,7 @@ std::string Reflection::Struct::description() const { } for(size_t index = 0; index < count; ++index) { - append(stream, key, type, index); + append(stream, key, type, index, use_pretty_names); if(index != count-1) stream << ", "; } diff --git a/Reflection/Struct.hpp b/Reflection/Struct.hpp index 0e4cb3227..14026f0af 100644 --- a/Reflection/Struct.hpp +++ b/Reflection/Struct.hpp @@ -50,7 +50,7 @@ struct Struct { @returns A string describing this struct. This string has no guaranteed layout, may not be sufficiently formed for a formal language parser, etc. */ - std::string description() const; + std::string description(bool use_pretty_names = true) const; /*! Serialises this struct in BSON format. @@ -83,7 +83,7 @@ struct Struct { virtual bool should_serialise([[maybe_unused]] const std::string &key) const { return true; } private: - void append(std::ostringstream &stream, const std::string &key, const std::type_info *type, size_t offset) const; + void append(std::ostringstream &stream, const std::string &key, const std::type_info *type, size_t offset, bool use_pretty_names) const; bool deserialise(const uint8_t *bson, size_t size); };