Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
successor.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2021 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
29
******************************************************************************/
30
31
#ifndef ETL_SUCCESSOR_INCLUDED
32
#define ETL_SUCCESSOR_INCLUDED
33
34
#include "
platform.h
"
35
#include "
error_handler.h
"
36
#include "
exception.h
"
37
#include "
file_error_numbers.h
"
38
#include "
nullptr.h
"
39
40
namespace
etl
41
{
42
//***************************************************************************
44
//***************************************************************************
45
class
successor_exception :
public
etl::exception
46
{
47
public
:
48
49
successor_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
50
:
exception
(reason_, file_name_, line_number_)
51
{
52
}
53
};
54
55
//***************************************************************************
57
//***************************************************************************
58
class
successor_invalid :
public
etl::successor_exception
59
{
60
public
:
61
62
successor_invalid(string_type file_name_, numeric_type line_number_)
63
:
etl::successor_exception
(ETL_ERROR_TEXT(
"successor:invalid"
, ETL_SUCCESSOR_FILE_ID
"A"
), file_name_, line_number_)
64
{
65
}
66
};
67
68
//***************************************************************************
70
//***************************************************************************
71
template
<
typename
T>
72
class
successor
73
{
74
public
:
75
76
typedef
T successor_type;
77
78
//*************************************************************************
80
//*************************************************************************
81
successor
()
82
: p_successor(ETL_NULLPTR)
83
{
84
}
85
86
//*************************************************************************
88
//*************************************************************************
89
successor
(successor_type& s)
90
: p_successor(&s)
91
{
92
}
93
94
//*************************************************************************
96
//*************************************************************************
97
void
set_successor
(successor_type& s)
98
{
99
p_successor = &s;
100
}
101
102
#if ETL_CPP11_SUPPORTED
103
//*************************************************************************
105
//*************************************************************************
106
template
<
typename
... TSuccessors>
107
void
set_successor
(successor_type& s, TSuccessors&... rest)
108
{
109
set_successor
(s);
110
s.set_successor(rest...);
111
}
112
#endif
113
114
//*************************************************************************
116
//*************************************************************************
117
template
<
typename
TSuccessor>
118
void
append_successor
(TSuccessor& s)
119
{
120
if
(
has_successor
())
121
{
122
get_successor
().append_successor(s);
123
}
124
else
125
{
126
set_successor
(s);
127
}
128
}
129
130
#if ETL_CPP11_SUPPORTED
131
//*************************************************************************
133
//*************************************************************************
134
template
<
typename
TSuccessor,
typename
... TSuccessors>
135
void
append_successor
(TSuccessor& s, TSuccessors&... rest)
136
{
137
if
(
has_successor
())
138
{
139
get_successor
().append_successor(s);
140
get_successor
().append_successor(rest...);
141
}
142
else
143
{
144
set_successor
(s);
145
append_successor
(rest...);
146
}
147
}
148
#endif
149
150
//*************************************************************************
152
//*************************************************************************
153
void
clear_successor
()
154
{
155
p_successor = ETL_NULLPTR;
156
}
157
158
//*************************************************************************
160
//*************************************************************************
161
void
clear_successor_chain
()
162
{
163
if
(
has_successor
())
164
{
165
get_successor
().clear_successor_chain();
166
clear_successor
();
167
}
168
}
169
170
//*************************************************************************
173
//*************************************************************************
174
successor_type&
get_successor
()
const
175
{
176
ETL_ASSERT
(
has_successor
(), ETL_ERROR(
successor_invalid
));
177
178
return
*p_successor;
179
}
180
181
//*************************************************************************
183
//*************************************************************************
184
bool
has_successor
()
const
185
{
186
return
(p_successor != ETL_NULLPTR);
187
}
188
189
private
:
190
191
successor_type* p_successor;
192
};
193
}
// namespace etl
194
195
#endif
etl::successor_exception
Exception for the successor.
Definition
successor.h:46
etl::successor_invalid
Invalid exception for successor.
Definition
successor.h:59
etl::successor::clear_successor
void clear_successor()
Clear the successor.
Definition
successor.h:153
etl::successor::set_successor
void set_successor(successor_type &s)
Set the successor.
Definition
successor.h:97
etl::successor::has_successor
bool has_successor() const
Does this have a successor?
Definition
successor.h:184
etl::successor::clear_successor_chain
void clear_successor_chain()
Clear the successor chain.
Definition
successor.h:161
etl::successor::append_successor
void append_successor(TSuccessor &s)
Append a successor.
Definition
successor.h:118
etl::successor::get_successor
successor_type & get_successor() const
Definition
successor.h:174
etl::successor::successor
successor(successor_type &s)
Construct from a successor type.
Definition
successor.h:89
etl::successor::successor
successor()
Default constructor.
Definition
successor.h:81
error_handler.h
exception.h
file_error_numbers.h
ETL_ASSERT
#define ETL_ASSERT(b, e)
Definition
error_handler.h:511
etl::exception::exception
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition
exception.h:81
etl::exception
Definition
exception.h:59
etl
Definition
absolute.h:40
nullptr.h
platform.h
include
etl
successor.h
Generated on
for Embedded Template Library by
1.17.0