Embedded Template Library 1.0
message.h
1/******************************************************************************
2The MIT License(MIT)
3
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7
8Copyright(c) 2017 John Wellbelove
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files(the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions :
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27******************************************************************************/
28
29#ifndef ETL_MESSAGE_INCLUDED
30#define ETL_MESSAGE_INCLUDED
31
32#include "platform.h"
33#include "error_handler.h"
34#include "exception.h"
35#include "message_types.h"
36#include "type_traits.h"
37#include "static_assert.h"
38
39#include <stdint.h>
40
41namespace etl
42{
43 //***************************************************************************
45 {
46 public:
47
48 message_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
49 : exception(reason_, file_name_, line_number_)
50 {
51 }
52 };
53
54 //***************************************************************************
56 {
57 public:
58
59 unhandled_message_exception(string_type file_name_, numeric_type line_number_)
60 : message_exception(ETL_ERROR_TEXT("message:unknown", ETL_MESSAGE_FILE_ID"A"), file_name_, line_number_)
61 {
62 }
63 };
64
65 //***************************************************************************
66 // Message interface.
67 //***************************************************************************
69 {
70 public:
71
72 virtual ~imessage()
73 {
74 }
75
76 ETL_NODISCARD virtual etl::message_id_t get_message_id() const ETL_NOEXCEPT = 0;
77 };
78
79 //***************************************************************************
80 // Message type.
81 //***************************************************************************
82 template <etl::message_id_t ID_, typename TParent = etl::imessage>
83 class message : public TParent
84 {
85 ETL_STATIC_ASSERT((etl::is_base_of<etl::imessage, TParent>::value), "TParent is not derived from etl::imessage");
86
87 public:
88
89 static ETL_CONSTANT etl::message_id_t ID = ID_;
90
91 ETL_NODISCARD etl::message_id_t get_message_id() const ETL_NOEXCEPT ETL_OVERRIDE
92 {
93 return ID;
94 }
95 };
96
97 template <etl::message_id_t ID_, typename TParent>
99}
100
101#endif
Definition: message.h:69
Definition: message.h:45
Definition: message.h:84
Definition: message.h:56
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition: exception.h:69
Definition: exception.h:47
is_base_of
Definition: type_traits_generator.h:1252
bitset_ext
Definition: absolute.h:38
uint_least8_t message_id_t
Allow alternative type for message id.
Definition: message_types.h:40