From 7bb438bf1b5cfcec742d5c01425dcafb65e48e7e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 30 Jun 2021 20:57:42 +0100 Subject: [PATCH] Added the option to derive etl::message<> from a custom parent class --- include/etl/message.h | 2 ++ include/etl/version.h | 4 ++-- library.json | 2 +- library.properties | 2 +- meson.build | 2 +- support/Release notes.txt | 5 +++++ test/test_message_router.cpp | 33 ++++++++++++++++++++++++++++++++- 7 files changed, 44 insertions(+), 6 deletions(-) diff --git a/include/etl/message.h b/include/etl/message.h index 179655c1..cae10650 100644 --- a/include/etl/message.h +++ b/include/etl/message.h @@ -36,6 +36,7 @@ SOFTWARE. #include "exception.h" #include "message_types.h" #include "type_traits.h" +#include "static_assert.h" namespace etl { @@ -82,6 +83,7 @@ namespace etl class message : public TParent { ETL_STATIC_ASSERT((etl::is_base_of::value), "TParent is not derived from etl::imessage"); + public: enum diff --git a/include/etl/version.h b/include/etl/version.h index b520b1be..a763d4fc 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 20 -#define ETL_VERSION_MINOR 11 -#define ETL_VERSION_PATCH 5 +#define ETL_VERSION_MINOR 12 +#define ETL_VERSION_PATCH 0 #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) diff --git a/library.json b/library.json index 7091254c..6a2af629 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ETL Embedded Template Library", - "version": "20.11.5", + "version": "20.12.0", "author s": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index a0b702f4..aa7cb1c7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=20.11.5 +version=20.12.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/meson.build b/meson.build index 2de4988c..aa473f82 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,7 @@ project('PROJECT_NAME', 'cpp_std=c++17', 'build.cpp_std=c++17', ], meson_version: '>=0.54.0', - version: '20.11.5' + version: '20.12.0' ) ###################### diff --git a/support/Release notes.txt b/support/Release notes.txt index 7ad972a8..ab82c5b0 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +20.12.0 +Added the option to derived etl::message<> from a parent class other than etl::imessage. +The parent class must ultimately be derived from etl::imessage. + =============================================================================== 20.11.5 Added Arduino examples. diff --git a/test/test_message_router.cpp b/test/test_message_router.cpp index dd5dbd9b..cd943e62 100644 --- a/test/test_message_router.cpp +++ b/test/test_message_router.cpp @@ -39,6 +39,7 @@ namespace { enum { + MESSAGE0, MESSAGE1, MESSAGE2, MESSAGE3, @@ -53,16 +54,41 @@ namespace ROUTER3 }; - struct Message1 : public etl::message + //*********************************** + struct NotInterface + { + virtual int VirtualFunction() const = 0; + }; + + ////*********************************** + // Uncomment to demonstrate static assert + //struct Message0 : public etl::message + //{ + //}; + + //*********************************** + struct Interface : public etl::imessage + { + virtual int VirtualFunction() const = 0; + }; + + //*********************************** + struct Message1 : public etl::message { Message1(etl::imessage_router& callback_) : callback(callback_) { } + int VirtualFunction() const override + { + return 1; + } + etl::imessage_router& callback; }; + //*********************************** struct Message2 : public etl::message { Message2(etl::imessage_router& callback_) @@ -73,6 +99,7 @@ namespace etl::imessage_router& callback; }; + //*********************************** struct Message3 : public etl::message { Message3(etl::imessage_router& callback_) @@ -84,6 +111,7 @@ namespace int value[10]; }; + //*********************************** struct Message4 : public etl::message { Message4(etl::imessage_router& callback_) @@ -94,6 +122,7 @@ namespace etl::imessage_router& callback; }; + //*********************************** struct Message5 : public etl::message { }; @@ -123,6 +152,7 @@ namespace { ++message1_count; etl::send_message(msg.callback, message5); + CHECK_EQUAL(1, msg.VirtualFunction()); } void on_receive(const Message2& msg) @@ -185,6 +215,7 @@ namespace ++message1_count; sender_id = msg.callback.get_message_router_id(); etl::send_message(msg.callback, message5); + CHECK_EQUAL(1, msg.VirtualFunction()); } void on_receive(const Message2& msg)