10 #ifndef EASTL_FIXED_LIST_H
11 #define EASTL_FIXED_LIST_H
14 #include <EASTL/list.h>
15 #include <EASTL/internal/fixed_pool.h>
17 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
31 #ifndef EASTL_FIXED_LIST_DEFAULT_NAME
32 #define EASTL_FIXED_LIST_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixed_list"
38 #ifndef EASTL_FIXED_LIST_DEFAULT_ALLOCATOR
39 #define EASTL_FIXED_LIST_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_LIST_DEFAULT_NAME)
65 template <
typename T,
size_t nodeCount,
bool bEnableOverflow = true,
typename OverflowAllocator = EASTLAllocatorType>
66 class fixed_list :
public list<T, fixed_node_allocator<sizeof(typename list<T>::node_type),
67 nodeCount, EASTL_ALIGN_OF(typename list<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;
80 enum { kMaxSize = nodeCount };
82 using base_type::assign;
83 using base_type::resize;
84 using base_type::insert;
85 using base_type::size;
86 using base_type::get_allocator;
89 char mBuffer[fixed_allocator_type::kBufferSize];
91 using base_type::internalAllocator;
95 explicit fixed_list(
const overflow_allocator_type& overflowAllocator);
97 fixed_list(size_type n,
const value_type& value);
103 template <
typename InputIterator>
104 fixed_list(InputIterator first, InputIterator last);
111 void reset_lose_memory();
112 size_type max_size()
const;
114 bool has_overflowed()
const;
115 bool can_overflow()
const;
118 const overflow_allocator_type& get_overflow_allocator()
const EA_NOEXCEPT;
119 overflow_allocator_type& get_overflow_allocator() EA_NOEXCEPT;
120 void set_overflow_allocator(
const overflow_allocator_type&
allocator);
129 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
131 : base_type(fixed_allocator_type(mBuffer))
133 #if EASTL_NAME_ENABLED
134 internalAllocator().set_name(EASTL_FIXED_LIST_DEFAULT_NAME);
139 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
140 inline fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(
const overflow_allocator_type& overflowAllocator)
141 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
143 #if EASTL_NAME_ENABLED
144 internalAllocator().set_name(EASTL_FIXED_LIST_DEFAULT_NAME);
149 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
150 inline fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(size_type n)
151 : base_type(fixed_allocator_type(mBuffer))
153 #if EASTL_NAME_ENABLED
154 internalAllocator().set_name(EASTL_FIXED_LIST_DEFAULT_NAME);
161 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
162 inline fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(size_type n,
const value_type& value)
163 : base_type(fixed_allocator_type(mBuffer))
165 #if EASTL_NAME_ENABLED
166 internalAllocator().set_name(EASTL_FIXED_LIST_DEFAULT_NAME);
173 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
174 inline fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(
const this_type& x)
175 : base_type(fixed_allocator_type(mBuffer))
177 internalAllocator().copy_overflow_allocator(x.internalAllocator());
179 #if EASTL_NAME_ENABLED
180 internalAllocator().set_name(x.internalAllocator().get_name());
183 assign(x.begin(), x.end());
187 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
188 inline fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(this_type&& x)
189 : base_type(fixed_allocator_type(mBuffer))
200 internalAllocator().copy_overflow_allocator(x.internalAllocator());
202 #if EASTL_NAME_ENABLED
203 internalAllocator().set_name(x.internalAllocator().get_name());
206 assign(x.begin(), x.end());
210 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
211 inline fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(this_type&& x,
const overflow_allocator_type& overflowAllocator)
212 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
215 internalAllocator().copy_overflow_allocator(x.internalAllocator());
217 #if EASTL_NAME_ENABLED
218 internalAllocator().set_name(x.internalAllocator().get_name());
221 assign(x.begin(), x.end());
225 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
226 inline fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(
std::initializer_list<value_type> ilist,
const overflow_allocator_type& overflowAllocator)
227 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
229 assign(ilist.begin(), ilist.end());
233 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
234 template <
typename InputIterator>
235 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::fixed_list(InputIterator first, InputIterator last)
236 : base_type(fixed_allocator_type(mBuffer))
238 #if EASTL_NAME_ENABLED
239 internalAllocator().set_name(EASTL_FIXED_LIST_DEFAULT_NAME);
246 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
247 inline typename fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::this_type&
248 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::operator=(
const this_type& x)
254 #if EASTL_ALLOCATOR_COPY_ENABLED
255 internalAllocator() = x.internalAllocator();
258 base_type::assign(x.begin(), x.end());
264 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
265 inline typename fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::this_type&
266 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::operator=(this_type&& x)
272 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
273 inline typename fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::this_type&
277 base_type::assign(ilist.begin(), ilist.end());
282 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
283 inline void fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::swap(this_type& x)
286 eastl::fixed_swap(*
this, x);
290 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
291 inline void fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::reset_lose_memory()
293 base_type::reset_lose_memory();
294 get_allocator().reset(mBuffer);
298 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
299 inline typename fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::size_type
300 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::max_size()
const
306 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
307 inline bool fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::full()
const
314 return !internalAllocator().can_allocate();
318 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
319 inline bool fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::has_overflowed()
const
321 #if EASTL_FIXED_SIZE_TRACKING_ENABLED
322 return (internalAllocator().mPool.mnPeakSize > kMaxSize);
324 return (size() > kMaxSize);
329 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
330 inline bool fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::can_overflow()
const
332 return bEnableOverflow;
336 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
337 inline const typename fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::overflow_allocator_type&
338 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::get_overflow_allocator() const EA_NOEXCEPT
340 return internalAllocator().get_overflow_allocator();
344 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
345 inline typename fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::overflow_allocator_type&
346 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::get_overflow_allocator() EA_NOEXCEPT
348 return internalAllocator().get_overflow_allocator();
352 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
354 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>::set_overflow_allocator(
const overflow_allocator_type& allocator)
356 internalAllocator().set_overflow_allocator(allocator);
364 template <
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename OverflowAllocator>
365 inline void swap(fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>& a,
366 fixed_list<T, nodeCount, bEnableOverflow, OverflowAllocator>& b)
369 eastl::fixed_swap(a, b);
Definition: allocator.h:52
Definition: fixed_list.h:68
Definition: fixed_pool.h:607
Definition: initializer_list.h:38
EA Standard Template Library.
Definition: algorithm.h:288