From c7e1dcb60a87b00a98c35cd53d63dba83da9e9c1 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 21 Oct 2018 11:36:16 -0700 Subject: [PATCH] Allow checking if an Event is valid --- include/cppkafka/event.h | 7 +++++++ src/event.cpp | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/include/cppkafka/event.h b/include/cppkafka/event.h index 235d70e..a48175c 100644 --- a/include/cppkafka/event.h +++ b/include/cppkafka/event.h @@ -143,6 +143,13 @@ public: * * RD_KAFKA_EVENT_OFFSET_COMMIT */ TopicPartitionList get_topic_partition_list() const; + + /** + * Check whether this event is valid + * + * /return true iff this event has a valid (non-null) handle inside + */ + operator bool() const; private: using HandlePtr = std::unique_ptr; diff --git a/src/event.cpp b/src/event.cpp index 4f2fc5d..1c82d3d 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -90,4 +90,8 @@ TopicPartitionList Event::get_topic_partition_list() const { return convert(toppars_handle); } +Event::operator bool() const { + return !!handle_; +} + } // cppkafka