From 89ed21e0c533174e26cf434055e4dd2f5467f97c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 9 Sep 2023 11:59:00 +0300 Subject: [PATCH] lib: improve printability for some types A little fmt pixie dust --- lib/message/mu-fields.hh | 20 ++++---------------- lib/mu-store.hh | 7 +++++++ lib/mu-xapian-db.cc | 2 ++ lib/mu-xapian-db.hh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/lib/message/mu-fields.hh b/lib/message/mu-fields.hh index 24279de8..abd0e1c8 100644 --- a/lib/message/mu-fields.hh +++ b/lib/message/mu-fields.hh @@ -207,7 +207,10 @@ struct Field { } }; -static inline bool operator==(const Field& f1, const Field& f2) { return f1.id == f2.id; } +// equality +static inline constexpr bool operator==(const Field& f1, const Field& f2) { return f1.id == f2.id; } +static inline constexpr bool operator==(const Field& f1, const Field::Id id) { return f1.id == id; } + MU_ENABLE_BITOPS(Field::Flag); @@ -594,20 +597,5 @@ Option 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 #endif /* MU_FIELDS_HH__ */ diff --git a/lib/mu-store.hh b/lib/mu-store.hh index 0ae0d2ef..e67005e4 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -467,6 +467,13 @@ private: MU_ENABLE_BITOPS(Store::Options); MU_ENABLE_BITOPS(Store::MoveOptions); +static inline std::string +format_as(const Store& store) +{ + return mu_format("store ({}/{})", format_as(store.xapian_db()), + store.root_maildir()); +} + } // namespace Mu #endif /* __MU_STORE_HH__ */ diff --git a/lib/mu-xapian-db.cc b/lib/mu-xapian-db.cc index ccda245b..1d5a864a 100644 --- a/lib/mu-xapian-db.cc +++ b/lib/mu-xapian-db.cc @@ -101,4 +101,6 @@ XapianDb::XapianDb(const std::string& db_path, Flavor flavor) : if (flavor == Flavor::CreateOverwrite) set_timestamp(MetadataIface::created_key); + + mu_debug("created {} / {}", flavor, *this); } diff --git a/lib/mu-xapian-db.hh b/lib/mu-xapian-db.hh index 49b00ed1..64a24f90 100644 --- a/lib/mu-xapian-db.hh +++ b/lib/mu-xapian-db.hh @@ -192,6 +192,16 @@ public: */ const std::string& path() const; + /** + * Get a description of the Xapian database + * + * @return description + */ + const std::string description() const { + return db().get_description(); + } + + /** * Get the number of documents (messages) in the database * @@ -399,6 +409,27 @@ private: DbType db_; }; +constexpr std::string_view +format_as(XapianDb::Flavor flavor) +{ + switch(flavor) { + case XapianDb::Flavor::CreateOverwrite: + return "create-overwrite"; + case XapianDb::Flavor::Open: + return "open"; + case XapianDb::Flavor::ReadOnly: + return "read-only"; + default: + return "??"; + } +} + +static inline std::string +format_as(const XapianDb& db) +{ + return mu_format("{} @ {}", db.description(), db.path()); +} + } // namespace Mu #endif /* MU_XAPIAN_DB_HH__ */