From ecee02d41d75ecf6e62c5dd47809e1775e15b860 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 2 Jan 2021 14:09:36 +0000 Subject: [PATCH] reference_counted_object and reference_counted_message specialisations --- include/etl/reference_counted_message.h | 31 +++++++++++++++++++---- include/etl/reference_counted_object.h | 33 +++++++++++++++++++++---- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/include/etl/reference_counted_message.h b/include/etl/reference_counted_message.h index c2426e39..3706a2e2 100644 --- a/include/etl/reference_counted_message.h +++ b/include/etl/reference_counted_message.h @@ -54,7 +54,7 @@ namespace etl //*************************************************************************** // Reference counted message type. //*************************************************************************** - template + template class reference_counted_message : public etl::ireference_counted_message { public: @@ -110,7 +110,7 @@ namespace etl /// \tparam TMessage The type to be reference counted. //*************************************************************************** template - class atomic_counted_message : virtual public etl::reference_counted_message + class atomic_counted_message : virtual public etl::reference_counted_message { public: @@ -119,12 +119,12 @@ namespace etl /// \param msg The message to count. //*************************************************************************** atomic_counted_message(const TMessage& msg_) - : reference_counted_message(msg_) + : reference_counted_message(msg_) { } - typedef typename reference_counted_message::message_type message_type; - typedef typename reference_counted_message::counter_type counter_type; + typedef typename reference_counted_message::message_type message_type; + typedef typename reference_counted_message::counter_type counter_type; }; #endif @@ -180,6 +180,27 @@ namespace etl /// The reference counted object. etl::reference_counted_object rc_object; }; + + //*************************************************************************** + /// Synonym for reference_counted_message + /// \tparam TObject The type stored in the object. + //*************************************************************************** + template + class uncounted_message : public etl::reference_counted_message + { + public: + + //*************************************************************************** + /// Constructor. + //*************************************************************************** + uncounted_message(const TMessage& msg_) + : reference_counted_message(msg_) + { + } + + typedef typename reference_counted_message::message_type message_type; + typedef typename reference_counted_message::counter_type counter_type; + }; } #endif diff --git a/include/etl/reference_counted_object.h b/include/etl/reference_counted_object.h index 821ab449..868ccf8e 100644 --- a/include/etl/reference_counted_object.h +++ b/include/etl/reference_counted_object.h @@ -55,7 +55,7 @@ namespace etl /// \tparam TObject The type to be reference counted. /// \tparam TCounter The type to use as the counter. //*************************************************************************** - template + template class reference_counted_object : public etl::ireference_counted_object { public: @@ -101,6 +101,8 @@ namespace etl //*************************************************************************** ETL_NODISCARD virtual uint32_t decrement_reference_count() ETL_OVERRIDE { + assert(reference_count > 0); + return uint32_t(--reference_count); } @@ -129,7 +131,7 @@ namespace etl /// \tparam TObject The type to be reference counted. //*************************************************************************** template - class atomic_counted_object : public etl::reference_counted_object + class atomic_counted_object : public etl::reference_counted_object { public: @@ -137,12 +139,12 @@ namespace etl /// Constructor. //*************************************************************************** atomic_counted_object(const TObject& object_) - : reference_counted_object(object_) + : reference_counted_object(object_) { } - typedef typename reference_counted_object::value_type value_type; - typedef typename reference_counted_object::counter_type counter_type; + typedef typename reference_counted_object::value_type value_type; + typedef typename reference_counted_object::counter_type counter_type; }; #endif @@ -217,6 +219,27 @@ namespace etl TObject object; // The object being reference counted. }; + + //*************************************************************************** + /// Synonym for reference_counted_object + /// \tparam TObject The type stored in the object. + //*************************************************************************** + template + class uncounted_object : public etl::reference_counted_object + { + public: + + //*************************************************************************** + /// Constructor. + //*************************************************************************** + uncounted_object(const TObject& object_) + : reference_counted_object(object_) + { + } + + typedef typename reference_counted_object::value_type value_type; + typedef typename reference_counted_object::counter_type counter_type; + }; } #endif