10 #ifndef EASTL_FIXED_SLIST_H
11 #define EASTL_FIXED_SLIST_H
14 #include <EASTL/slist.h>
15 #include <EASTL/internal/fixed_pool.h>
17 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
31 #ifndef EASTL_FIXED_SLIST_DEFAULT_NAME
32 #define EASTL_FIXED_SLIST_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixed_slist"
38 #ifndef EASTL_FIXED_SLIST_DEFAULT_ALLOCATOR
39 #define EASTL_FIXED_SLIST_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_SLIST_DEFAULT_NAME)
65 template <
typename T,
size_t nodeCount,
bool bEnableOverflow = true,
typename OverflowAllocator = EASTLAllocatorType>
66 class fixed_slist :
public slist<T, fixed_node_allocator<sizeof(typename slist<T>::node_type),
67 nodeCount, EASTL_ALIGN_OF(typename slist<T>::node_type), 0, bEnableOverflow, OverflowAllocator> >
72 typedef OverflowAllocator overflow_allocator_type;
75 typedef typename base_type::size_type size_type;
76 typedef typename base_type::value_type value_type;
79 enum { kMaxSize = nodeCount };
81 using base_type::assign;
82 using base_type::resize;
83 using base_type::size;
86 char mBuffer[fixed_allocator_type::kBufferSize];
88 using base_type::internalAllocator;
92 explicit fixed_slist(
const overflow_allocator_type& overflowAllocator);
100 template <
typename InputIterator>
101 fixed_slist(InputIterator first, InputIterator last);
108 void reset_lose_memory();
109 size_type max_size()
const;
111 bool has_overflowed()
const;
112 bool can_overflow()
const;
115 const overflow_allocator_type& get_overflow_allocator()
const EA_NOEXCEPT;
116 overflow_allocator_type& get_overflow_allocator() EA_NOEXCEPT;
117 void set_overflow_allocator(
const overflow_allocator_type&
allocator);
127 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
129 : base_type(fixed_allocator_type(mBuffer))
131 #if EASTL_NAME_ENABLED
132 internalAllocator().set_name(EASTL_FIXED_SLIST_DEFAULT_NAME);
137 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
138 inline fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(
const overflow_allocator_type& overflowAllocator)
139 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
141 #if EASTL_NAME_ENABLED
142 internalAllocator().set_name(EASTL_FIXED_SLIST_DEFAULT_NAME);
147 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
148 inline fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(size_type n)
149 : base_type(fixed_allocator_type(mBuffer))
151 #if EASTL_NAME_ENABLED
152 internalAllocator().set_name(EASTL_FIXED_SLIST_DEFAULT_NAME);
159 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
160 inline fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(size_type n,
const value_type& value)
161 : base_type(fixed_allocator_type(mBuffer))
163 #if EASTL_NAME_ENABLED
164 internalAllocator().set_name(EASTL_FIXED_SLIST_DEFAULT_NAME);
171 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
172 inline fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(
const this_type& x)
173 : base_type(fixed_allocator_type(mBuffer))
175 internalAllocator().copy_overflow_allocator(x.internalAllocator());
177 #if EASTL_NAME_ENABLED
178 internalAllocator().set_name(x.internalAllocator().get_name());
181 assign(x.begin(), x.end());
185 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
186 inline fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(this_type&& x)
187 : base_type(fixed_allocator_type(mBuffer))
198 internalAllocator().copy_overflow_allocator(x.internalAllocator());
200 #if EASTL_NAME_ENABLED
201 internalAllocator().set_name(x.internalAllocator().get_name());
204 assign(x.begin(), x.end());
207 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
208 inline fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(this_type&& x,
const overflow_allocator_type& overflowAllocator)
209 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
212 internalAllocator().copy_overflow_allocator(x.internalAllocator());
214 #if EASTL_NAME_ENABLED
215 internalAllocator().set_name(x.internalAllocator().get_name());
218 assign(x.begin(), x.end());
222 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
223 inline fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(
std::initializer_list<value_type> ilist,
const overflow_allocator_type& overflowAllocator)
224 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
226 #if EASTL_NAME_ENABLED
227 internalAllocator().set_name(EASTL_FIXED_SLIST_DEFAULT_NAME);
230 assign(ilist.begin(), ilist.end());
234 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
235 template <
typename InputIterator>
236 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_slist(InputIterator first, InputIterator last)
237 : base_type(fixed_allocator_type(mBuffer))
239 #if EASTL_NAME_ENABLED
240 internalAllocator().set_name(EASTL_FIXED_SLIST_DEFAULT_NAME);
247 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
248 inline typename fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::this_type&
249 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::operator=(
const this_type& x)
255 #if EASTL_ALLOCATOR_COPY_ENABLED
256 internalAllocator() = x.internalAllocator();
259 base_type::assign(x.begin(), x.end());
265 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
266 inline typename fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::this_type&
267 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::operator=(this_type&& x)
273 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
274 inline typename fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::this_type&
278 base_type::assign(ilist.begin(), ilist.end());
283 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
284 inline void fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::swap(this_type& x)
287 eastl::fixed_swap(*
this, x);
291 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
292 inline void fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::reset_lose_memory()
294 base_type::reset_lose_memory();
295 base_type::get_allocator().reset(mBuffer);
299 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
300 inline typename fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::size_type
301 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::max_size()
const
307 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
308 inline bool fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::full()
const
313 return !internalAllocator().can_allocate();
317 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
318 inline bool fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::has_overflowed()
const
320 #if EASTL_FIXED_SIZE_TRACKING_ENABLED
321 return (internalAllocator().mPool.mnPeakSize > kMaxSize);
323 return (size() > kMaxSize);
328 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
329 inline bool fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::can_overflow()
const
331 return bEnableOverflow;
335 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
336 inline const typename fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::overflow_allocator_type&
337 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::get_overflow_allocator() const EA_NOEXCEPT
339 return internalAllocator().get_overflow_allocator();
343 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
344 inline typename fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::overflow_allocator_type&
345 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::get_overflow_allocator() EA_NOEXCEPT
347 return internalAllocator().get_overflow_allocator();
351 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
353 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>::set_overflow_allocator(
const overflow_allocator_type& allocator)
355 internalAllocator().set_overflow_allocator(allocator);
364 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
365 inline void swap(fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>& a,
366 fixed_slist<T, nodeCount, bEnableOverflow, OverflowAllocator>& b)
369 eastl::fixed_swap(a, b);
Definition: allocator.h:52
Definition: fixed_pool.h:607
Definition: fixed_slist.h:68
Definition: initializer_list.h:38
EA Standard Template Library.
Definition: algorithm.h:288