aboutsummaryrefslogtreecommitdiff
path: root/lib/events/event.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-02-11 22:21:25 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-08 17:43:58 +0200
commitc42d268db0b40cdba06381fc64a6966a72c90709 (patch)
treecf61bf560deb441d032fe161088efd798a338e26 /lib/events/event.h
parent4b35dfd8af196ff9e8669499ea3ed7e4127f5901 (diff)
downloadlibquotient-c42d268db0b40cdba06381fc64a6966a72c90709.tar.gz
libquotient-c42d268db0b40cdba06381fc64a6966a72c90709.zip
QUO_CONTENT_GETTER
To streamline adding of simple getters of content parts.
Diffstat (limited to 'lib/events/event.h')
-rw-r--r--lib/events/event.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/events/event.h b/lib/events/event.h
index a27c0b96..ec21c6aa 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -258,6 +258,21 @@ template <typename EventT>
using EventsArray = std::vector<event_ptr_tt<EventT>>;
using Events = EventsArray<Event>;
+//! \brief Define an inline method obtaining a content part
+//!
+//! This macro adds a const method that extracts a JSON value at the key
+//! <tt>toSnakeCase(PartName_)</tt> (sic) and converts it to the type
+//! \p PartType_. Effectively, the generated method is an equivalent of
+//! \code
+//! contentPart<PartType_>(Quotient::toSnakeCase(#PartName_##_ls));
+//! \endcode
+#define QUO_CONTENT_GETTER(PartType_, PartName_) \
+ PartType_ PartName_() const \
+ { \
+ static const auto JsonKey = toSnakeCase(#PartName_##_ls); \
+ return contentPart<PartType_>(JsonKey); \
+ }
+
// === Facilities for event class definitions ===
// This macro should be used in a public section of an event class to