message & friends: make formattable

So we can easily debug-print them.
This commit is contained in:
Dirk-Jan C. Binnema 2023-08-09 20:06:03 +03:00
parent 4dcd457b7f
commit 04219b55f7
4 changed files with 38 additions and 9 deletions

View File

@ -594,5 +594,20 @@ Option<Field> field_from_number(size_t id)
} }
/**
* Get a fmt-printable representation of Field for fmt
*
* @param field a Field
*
* @return a printable representation
*/
static inline constexpr auto format_as(const Field& field) {
return field.name;
}
static inline constexpr auto format_as(const Field::Id id) {
return format_as(field_from_id(id));
}
} // namespace Mu } // namespace Mu
#endif /* MU_FIELDS_HH__ */ #endif /* MU_FIELDS_HH__ */

View File

@ -387,6 +387,18 @@ flags_keep_unmutable(Flags old_flags, Flags new_flags, Flags unmutable_flag)
*/ */
std::string to_string(Flags flags); std::string to_string(Flags flags);
/**
* Get a string representation of Flags for fmt
*
* @param flags flags
*
* @return string as a sequence of message-flag shortcuts
*/
static inline auto format_as(const Flags& flags) {
return to_string(flags);
}
} // namespace Mu } // namespace Mu
#endif /* MU_FLAGS_HH__ */ #endif /* MU_FLAGS_HH__ */

View File

@ -460,15 +460,10 @@ private:
}; // Message }; // Message
MU_ENABLE_BITOPS(Message::Options); MU_ENABLE_BITOPS(Message::Options);
static inline auto
format_as(const Message& msg) {
static inline std::ostream& return msg.path();
operator<<(std::ostream& os, const Message& msg)
{
os << msg.sexp();
return os;
} }
} // Mu } // Mu
#endif /* MU_MESSAGE_HH__ */ #endif /* MU_MESSAGE_HH__ */

View File

@ -109,7 +109,7 @@ QueryMatch::has_flag(QueryMatch::Flags flag) const
return any_of(flags & flag); return any_of(flags & flag);
} }
inline std::ostream& static inline std::ostream&
operator<<(std::ostream& os, QueryMatch::Flags mflags) operator<<(std::ostream& os, QueryMatch::Flags mflags)
{ {
if (mflags == QueryMatch::Flags::None) { if (mflags == QueryMatch::Flags::None) {
@ -348,6 +348,13 @@ private:
QueryMatches& query_matches_; QueryMatches& query_matches_;
}; };
static inline auto
format_as(const QueryResultsIterator& it)
{
return it.path().value_or("<no path>");
}
constexpr auto MaxQueryResultsSize = std::numeric_limits<size_t>::max(); constexpr auto MaxQueryResultsSize = std::numeric_limits<size_t>::max();
class QueryResults { class QueryResults {