mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added the option to derive etl::message<> from a custom parent class
This commit is contained in:
parent
38d8452e70
commit
7bb438bf1b
@ -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<etl::imessage, TParent>::value), "TParent is not derived from etl::imessage");
|
||||
|
||||
public:
|
||||
|
||||
enum
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library ETL
|
||||
version=20.11.5
|
||||
version=20.12.0
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -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'
|
||||
)
|
||||
|
||||
######################
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -39,6 +39,7 @@ namespace
|
||||
{
|
||||
enum
|
||||
{
|
||||
MESSAGE0,
|
||||
MESSAGE1,
|
||||
MESSAGE2,
|
||||
MESSAGE3,
|
||||
@ -53,16 +54,41 @@ namespace
|
||||
ROUTER3
|
||||
};
|
||||
|
||||
struct Message1 : public etl::message<MESSAGE1>
|
||||
//***********************************
|
||||
struct NotInterface
|
||||
{
|
||||
virtual int VirtualFunction() const = 0;
|
||||
};
|
||||
|
||||
////***********************************
|
||||
// Uncomment to demonstrate static assert
|
||||
//struct Message0 : public etl::message<MESSAGE0, NotInterface>
|
||||
//{
|
||||
//};
|
||||
|
||||
//***********************************
|
||||
struct Interface : public etl::imessage
|
||||
{
|
||||
virtual int VirtualFunction() const = 0;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Message1 : public etl::message<MESSAGE1, Interface>
|
||||
{
|
||||
Message1(etl::imessage_router& callback_)
|
||||
: callback(callback_)
|
||||
{
|
||||
}
|
||||
|
||||
int VirtualFunction() const override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
etl::imessage_router& callback;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Message2 : public etl::message<MESSAGE2>
|
||||
{
|
||||
Message2(etl::imessage_router& callback_)
|
||||
@ -73,6 +99,7 @@ namespace
|
||||
etl::imessage_router& callback;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Message3 : public etl::message<MESSAGE3>
|
||||
{
|
||||
Message3(etl::imessage_router& callback_)
|
||||
@ -84,6 +111,7 @@ namespace
|
||||
int value[10];
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Message4 : public etl::message<MESSAGE4>
|
||||
{
|
||||
Message4(etl::imessage_router& callback_)
|
||||
@ -94,6 +122,7 @@ namespace
|
||||
etl::imessage_router& callback;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Message5 : public etl::message<MESSAGE5>
|
||||
{
|
||||
};
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user