Added non-const get_message() member funtions in shared message framework.

This commit is contained in:
John Wellbelove 2021-02-14 11:42:36 +00:00
parent ae06e64177
commit f145b53e80
9 changed files with 52 additions and 5 deletions

View File

@ -47,6 +47,7 @@ namespace etl
public:
virtual ~ireference_counted_message() {}
ETL_NODISCARD virtual etl::imessage& get_message() = 0; ///< Get a reference to the message.
ETL_NODISCARD virtual const etl::imessage& get_message() const = 0; ///< Get a const reference to the message.
ETL_NODISCARD virtual etl::ireference_counter& get_reference_counter() = 0; ///< Get a reference to the reference counter.
ETL_NODISCARD virtual const etl::ireference_counter& get_reference_counter() const = 0; ///< Get a const reference to the reference counter.
@ -86,6 +87,15 @@ namespace etl
{
}
//***************************************************************************
/// Get a reference to the message.
/// \return A reference to the message.
//***************************************************************************
ETL_NODISCARD virtual TMessage& get_message() ETL_OVERRIDE
{
return rc_object.get_object();
}
//***************************************************************************
/// Get a const reference to the message.
/// \return A const reference to the message.
@ -150,6 +160,15 @@ namespace etl
{
}
//***************************************************************************
/// Get a reference to the message.
/// \return A reference to the message.
//***************************************************************************
ETL_NODISCARD virtual TMessage& get_message() ETL_OVERRIDE
{
return rc_object.get_object();
}
//***************************************************************************
/// Get a const reference to the message.
/// \return A const reference to the message.

View File

@ -194,6 +194,15 @@ namespace etl
{
}
//***************************************************************************
/// Get a reference to the counted object.
//***************************************************************************
ETL_NODISCARD value_type& get_object()
{
return object;
}
//***************************************************************************
/// Get a const reference to the counted object.
//***************************************************************************
@ -224,7 +233,7 @@ namespace etl
reference_counted_object(const reference_counted_object&) ETL_DELETE;
reference_counted_object& operator =(const reference_counted_object&) ETL_DELETE;
const TObject object; ///< The object being reference counted.
TObject object; ///< The object being reference counted.
etl::reference_counter<TCounter> reference_counter; ///< The reference counter.
};

View File

@ -153,6 +153,14 @@ namespace etl
}
}
//*************************************************************************
/// Get a reference to the contained message.
//***********************************************************************
ETL_NODISCARD etl::imessage& get_message()
{
return p_rcmessage->get_message();
}
//*************************************************************************
/// Get a const reference to the contained message.
//*************************************************************************

View File

@ -39,7 +39,7 @@ SOFTWARE.
#define ETL_VERSION_MAJOR 20
#define ETL_VERSION_MINOR 2
#define ETL_VERSION_PATCH 1
#define ETL_VERSION_PATCH 2
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH)

View File

@ -1,6 +1,6 @@
{
"name": "ETL Embedded Template Library",
"version": "20.2.1",
"version": "20.2.2",
"author s": {
"name": "John Wellbelove",
"email": "john.wellbelove@etlcpp.com"

View File

@ -1,5 +1,5 @@
name=Embedded Template Library ETL
version=20.2.1
version=20.2.2
author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
license=MIT

View File

@ -1,3 +1,7 @@
===============================================================================
20.2.2
Added non-const get_message() member funtions in shared message framework.
===============================================================================
20.2.1
Modified reference_counted_message_pool::allocate() return type.

View File

@ -1,4 +1,4 @@
#sudo ntpdate time.windows.com
sudo ntpdate ntp.ubuntu.com
cd build
echo "ETL Tests" > etl_test_log.txt
echo "********** GCC **********" >> etl_test_log.txt

View File

@ -191,7 +191,14 @@ namespace
{
etl::reference_counted_message<Message2, etl::atomic_int>* prcm = message_pool.allocate<Message2>();
Message2& m2 = prcm->get_message(); // Check that we can get a non-const reference to the message.
const Message2& cm2 = prcm->get_message(); // Check that we can get a const reference to the message.
etl::shared_message sm1(*prcm);
etl::imessage& im = sm1.get_message(); // Check that we can get a non-const reference to the message.
const etl::imessage& cim = sm1.get_message(); // Check that we can get a const reference to the message.
CHECK_EQUAL(1, sm1.get_reference_count());
CHECK(sm1.is_valid());
}