Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
variant_pool.h
1
/******************************************************************************
2
The MIT License(MIT)
3
4
Embedded Template Library.
5
https://github.com/ETLCPP/etl
6
https://www.etlcpp.com
7
8
Copyright(c) 2017 John Wellbelove
9
10
Permission is hereby granted, free of charge, to any person obtaining a copy
11
of this software and associated documentation files(the "Software"), to deal
12
in the Software without restriction, including without limitation the rights
13
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14
copies of the Software, and to permit persons to whom the Software is
15
furnished to do so, subject to the following conditions :
16
17
The above copyright notice and this permission notice shall be included in all
18
copies or substantial portions of the Software.
19
20
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
SOFTWARE.
27
******************************************************************************/
28
29
#ifndef ETL_VARIANT_POOL_INCLUDED
30
#define ETL_VARIANT_POOL_INCLUDED
31
32
#include "
platform.h
"
33
#include "
largest.h
"
34
#include "
pool.h
"
35
#include "static_assert.h"
36
#include "
type_traits.h
"
37
38
#include <stddef.h>
39
40
namespace
etl
41
{
42
#if ETL_USING_CPP11 && !defined(ETL_VARIANT_POOL_FORCE_CPP03_IMPLEMENTATION)
43
//***************************************************************************
44
template
<
size_t
MAX_SIZE_,
typename
... Ts>
45
class
variant_pool
:
public
etl::generic_pool<etl::largest<Ts...>::size, etl::largest<Ts...>::alignment, MAX_SIZE_>
46
{
47
public
:
48
49
typedef
etl::generic_pool<etl::largest<Ts...>
::size
, etl::largest<Ts...>::alignment, MAX_SIZE_> base_t;
50
51
static
const
size_t
MAX_SIZE = MAX_SIZE_;
52
53
//*************************************************************************
55
//*************************************************************************
56
variant_pool
() {}
57
58
//*************************************************************************
60
//*************************************************************************
61
template
<
typename
T,
typename
... Args>
62
T*
create
(Args&&... args)
63
{
64
ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value),
"Unsupported type"
);
65
66
return
base_t::template
create<T>
(etl::forward<Args>(args)...);
67
}
68
69
//*************************************************************************
71
//*************************************************************************
72
template
<
typename
T>
73
void
destroy
(
const
T*
const
p)
74
{
75
ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value || etl::is_base_of_any<T, Ts...>::value),
"Invalid type"
);
76
77
base_t::destroy(p);
78
}
79
80
//*************************************************************************
82
//*************************************************************************
83
size_t
max_size
()
const
84
{
85
return
MAX_SIZE;
86
}
87
88
private
:
89
90
variant_pool
(
const
variant_pool
&) ETL_DELETE;
91
variant_pool
& operator=(
const
variant_pool
&) ETL_DELETE;
92
};
93
94
//***************************************************************************
95
template
<
typename
... Ts>
96
class
variant_pool_ext
:
public
etl::generic_pool_ext
<etl::largest<Ts...>::size, etl::largest<Ts...>::alignment>
97
{
98
public
:
99
100
typedef
etl::generic_pool_ext
<
etl::largest
<Ts...>
::size
,
etl::largest
<Ts...>::alignment> base_t;
101
102
//*************************************************************************
104
//*************************************************************************
105
variant_pool_ext
(
typename
base_t::element* buffer,
size_t
size
)
106
: base_t(buffer,
size
)
107
{
108
}
109
110
//*************************************************************************
112
//*************************************************************************
113
template
<
typename
T,
typename
... Args>
114
T*
create
(Args&&... args)
115
{
116
ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value),
"Unsupported type"
);
117
118
return
base_t::template
create<T>
(etl::forward<Args>(args)...);
119
}
120
121
//*************************************************************************
123
//*************************************************************************
124
template
<
typename
T>
125
void
destroy
(
const
T*
const
p)
126
{
127
ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value || etl::is_base_of_any<T, Ts...>::value),
"Invalid type"
);
128
129
base_t::destroy(p);
130
}
131
132
//*************************************************************************
134
//*************************************************************************
135
size_t
max_size
()
const
136
{
137
return
base_t::max_size();
138
}
139
140
private
:
141
142
variant_pool_ext
(
const
variant_pool_ext
&) ETL_DELETE;
143
variant_pool_ext
& operator=(
const
variant_pool_ext
&) ETL_DELETE;
144
};
145
#else
146
#include "private/variant_pool_cpp03.h"
147
#endif
148
}
// namespace etl
149
150
#endif
etl::variant_pool_ext
Definition
variant_pool.h:201
etl::variant_pool_ext::create
T * create()
Creates the object. Default constructor.
Definition
variant_pool.h:220
etl::variant_pool_ext::destroy
void destroy(const T *const p)
Destroys the object.
Definition
variant_pool.h:287
etl::variant_pool_ext::variant_pool_ext
variant_pool_ext(typename base_t::element *buffer, size_t size)
Default constructor.
Definition
variant_pool.h:210
etl::variant_pool_ext::max_size
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition
variant_pool.h:313
etl::variant_pool
Definition
variant_pool.h:56
etl::variant_pool::max_size
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition
variant_pool.h:170
etl::variant_pool::destroy
void destroy(const T *const p)
Destroys the object.
Definition
variant_pool.h:144
etl::variant_pool::create
T * create()
Creates the object. Default constructor.
Definition
variant_pool.h:77
etl::variant_pool::variant_pool
variant_pool()
Default constructor.
Definition
variant_pool.h:68
variant_pool_ext
Definition
variant_pool_cpp03.h:200
etl::largest
Definition
largest.h:45
etl::ipool::size
size_t size() const
Returns the number of allocated items in the pool.
Definition
ipool.h:523
etl::generic_pool_ext
Definition
generic_pool.h:216
largest.h
etl
Definition
absolute.h:40
platform.h
pool.h
type_traits.h
include
etl
variant_pool.h
Generated on
for Embedded Template Library by
1.17.0