mirror of
https://github.com/TomHarte/CLK.git
synced 2025-03-25 06:30:38 +00:00
Makes use of pretty names in descriptions optional.
This commit is contained in:
parent
fd88071c0a
commit
76f2aba51a
Reflection
@ -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<bool>(*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<const Reflection::Struct *>(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 << ", ";
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user