31#ifndef ETL_MULTI_SPAN_INCLUDED
32#define ETL_MULTI_SPAN_INCLUDED
51 typedef T element_type;
52 typedef typename etl::remove_cv<T>::type value_type;
53 typedef size_t size_type;
55 typedef const T& const_reference;
57 typedef const T* const_pointer;
65 class iterator :
public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, element_type>
69 friend class multi_span;
70 friend class const_iterator;
73 ETL_CONSTEXPR14 iterator()
74 : p_span_list(ETL_NULLPTR)
75 , p_current_span(ETL_NULLPTR)
76 , p_value(ETL_NULLPTR)
81 ETL_CONSTEXPR14 iterator(
const iterator& other)
82 : p_span_list(other.p_span_list)
83 , p_current_span(other.p_current_span)
84 , p_value(other.p_value)
89 ETL_CONSTEXPR14 iterator& operator=(
const iterator& rhs)
91 p_span_list = rhs.p_span_list;
92 p_current_span = rhs.p_current_span;
93 p_value = rhs.p_value;
99 ETL_CONSTEXPR14 iterator& operator++()
101 if (p_current_span != p_span_list->end())
105 if (p_value == p_current_span->end())
109 }
while ((p_current_span != p_span_list->end()) && p_current_span->empty());
111 if (p_current_span != p_span_list->end())
113 p_value = p_current_span->begin();
117 p_value = ETL_NULLPTR;
126 ETL_CONSTEXPR14 iterator operator++(
int)
128 iterator temp = *
this;
136 ETL_CONSTEXPR14 iterator& operator--()
138 if (p_current_span == p_span_list->end())
141 p_value = p_current_span->end();
144 else if ((p_current_span != p_span_list->begin()) || (p_value != p_current_span->begin()))
146 if (p_value == p_current_span->begin())
150 }
while ((p_current_span != p_span_list->begin()) && p_current_span->empty());
152 p_value = p_current_span->end();
162 p_value = ETL_NULLPTR;
169 ETL_CONSTEXPR14 iterator operator--(
int)
171 iterator temp = *
this;
213 ETL_CONSTEXPR14
friend bool operator==(
const iterator& lhs,
const iterator& rhs)
215 return (lhs.p_current_span == rhs.p_current_span) && (lhs.p_value == rhs.p_value);
221 ETL_CONSTEXPR14
friend bool operator!=(
const iterator& lhs,
const iterator& rhs)
223 return !(lhs == rhs);
228 typedef const span_type* span_pointer;
229 typedef const span_list_type* span_list_pointer;
230 typedef typename span_list_type::iterator span_list_iterator;
233 ETL_CONSTEXPR14
iterator(
const span_list_type& span_list_, span_list_iterator p_current_span_)
234 : p_span_list(&span_list_)
235 , p_current_span(p_current_span_)
236 , p_value(ETL_NULLPTR)
238 if (p_current_span != p_span_list->
end())
240 while ((p_current_span != p_span_list->end()) && p_current_span->empty())
245 if (p_current_span != p_span_list->
end())
247 p_value = p_current_span->begin();
251 p_value = ETL_NULLPTR;
256 span_list_pointer p_span_list;
257 span_pointer p_current_span;
264 class const_iterator :
public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, const element_type>
268 friend class multi_span;
271 ETL_CONSTEXPR14 const_iterator()
272 : p_span_list(ETL_NULLPTR)
273 , p_current_span(ETL_NULLPTR)
274 , p_value(ETL_NULLPTR)
279 ETL_CONSTEXPR14 const_iterator(
const const_iterator& other)
280 : p_span_list(other.p_span_list)
281 , p_current_span(other.p_current_span)
282 , p_value(other.p_value)
287 ETL_CONSTEXPR14 const_iterator& operator=(
const const_iterator& rhs)
289 p_span_list = rhs.p_span_list;
290 p_current_span = rhs.p_current_span;
291 p_value = rhs.p_value;
298 : p_span_list(other.p_span_list)
299 , p_current_span(other.p_current_span)
300 , p_value(other.p_value)
307 p_span_list = rhs.p_span_list;
308 p_current_span = rhs.p_current_span;
309 p_value = rhs.p_value;
315 ETL_CONSTEXPR14 const_iterator& operator++()
317 if (p_current_span != p_span_list->end())
321 if (p_value == p_current_span->end())
325 }
while ((p_current_span != p_span_list->end()) && p_current_span->empty());
327 if (p_current_span != p_span_list->end())
329 p_value = p_current_span->begin();
333 p_value = ETL_NULLPTR;
342 ETL_CONSTEXPR14 const_iterator operator++(
int)
344 const_iterator temp = *
this;
352 ETL_CONSTEXPR14 const_iterator& operator--()
354 if (p_current_span == p_span_list->end())
357 p_value = p_current_span->end();
360 else if ((p_current_span != p_span_list->begin()) || (p_value != p_current_span->begin()))
362 if (p_value == p_current_span->begin())
366 }
while ((p_current_span != p_span_list->begin()) && p_current_span->empty());
368 p_value = p_current_span->end();
378 p_value = ETL_NULLPTR;
385 ETL_CONSTEXPR14 const_iterator operator--(
int)
387 const_iterator temp = *
this;
413 ETL_CONSTEXPR14
friend bool operator==(
const const_iterator& lhs,
const const_iterator& rhs)
415 return (lhs.p_current_span == rhs.p_current_span) && (lhs.p_value == rhs.p_value);
421 ETL_CONSTEXPR14
friend bool operator!=(
const const_iterator& lhs,
const const_iterator& rhs)
423 return !(lhs == rhs);
428 typedef const span_type* span_pointer;
429 typedef const span_list_type* span_list_pointer;
430 typedef const typename span_list_type::iterator span_list_iterator;
433 ETL_CONSTEXPR14
const_iterator(
const span_list_type& span_list_, span_list_iterator p_current_span_)
434 : p_span_list(&span_list_)
435 , p_current_span(p_current_span_)
436 , p_value(ETL_NULLPTR)
438 if (p_current_span != p_span_list->end())
440 while ((p_current_span != p_span_list->end()) && p_current_span->empty())
445 if (p_current_span != p_span_list->end())
447 p_value = p_current_span->begin();
451 p_value = ETL_NULLPTR;
456 span_list_pointer p_span_list;
457 span_pointer p_current_span;
458 const_pointer p_value;
461 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
462 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
468 : span_list(span_list_)
476 template <
typename TContainer>
478 : span_list(a.data(), a.data() + a.size())
486 template <
typename TContainer>
488 : span_list(a.data(), a.data() + a.size())
495 template <
typename TIterator>
504 template <
typename TIterator>
514 : span_list(other.span_list)
523 span_list = other.span_list;
533 return iterator(span_list, span_list.begin());
539 ETL_CONSTEXPR14 const_iterator cbegin()
const
541 return const_iterator(span_list, span_list.cbegin());
547 ETL_CONSTEXPR14 iterator
end()
const
549 return iterator(span_list, span_list.end());
555 ETL_CONSTEXPR14 const_iterator
cend()
const
557 return const_iterator(span_list, span_list.cend());
563 ETL_CONSTEXPR14 reverse_iterator
rbegin()
const
565 return reverse_iterator(
end());
571 ETL_CONSTEXPR14 reverse_iterator
crbegin()
const
573 return const_reverse_iterator(
cend());
579 ETL_CONSTEXPR14 reverse_iterator
rend()
const
581 return reverse_iterator(
begin());
587 ETL_CONSTEXPR14 const_reverse_iterator
crend()
const
589 return const_reverse_iterator(
cbegin());
598 size_t number_of_spans = span_list.size();
602 while ((i >= span_list[index].
size()) && (index < number_of_spans))
604 i -= span_list[index].size();
608 return span_list[index][i];
614 ETL_CONSTEXPR14
size_t size() const ETL_NOEXCEPT
616 size_t total_n_spans = 0U;
618 for (
typename span_list_type::iterator itr = span_list.begin(); itr != span_list.end(); ++itr)
620 total_n_spans += itr->size();
623 return total_n_spans;
629 ETL_CONSTEXPR14
bool empty() const ETL_NOEXCEPT
631 if (span_list.empty())
646 size_t total_n_spans_bytes = 0U;
648 for (
typename span_list_type::iterator itr = span_list.begin(); itr != span_list.end(); ++itr)
650 total_n_spans_bytes += itr->size_bytes();
653 return total_n_spans_bytes;
661 return span_list.size();
666 span_list_type span_list;
Const Iterator.
Definition multi_span.h:265
ETL_CONSTEXPR14 friend bool operator==(const const_iterator &lhs, const const_iterator &rhs)
== operator
Definition multi_span.h:413
ETL_CONSTEXPR14 friend bool operator!=(const const_iterator &lhs, const const_iterator &rhs)
!= operator
Definition multi_span.h:421
ETL_CONSTEXPR14 const_reference operator*() const
Definition multi_span.h:397
ETL_CONSTEXPR14 const_pointer operator->() const
-> operator
Definition multi_span.h:405
Iterator.
Definition multi_span.h:66
ETL_CONSTEXPR14 reference operator*()
Definition multi_span.h:181
ETL_CONSTEXPR14 friend bool operator==(const iterator &lhs, const iterator &rhs)
== operator
Definition multi_span.h:213
ETL_CONSTEXPR14 const_reference operator*() const
Definition multi_span.h:189
ETL_CONSTEXPR14 pointer operator->()
-> operator
Definition multi_span.h:197
ETL_CONSTEXPR14 const_pointer operator->() const
-> operator
Definition multi_span.h:205
ETL_CONSTEXPR14 friend bool operator!=(const iterator &lhs, const iterator &rhs)
!= operator
Definition multi_span.h:221
ETL_CONSTEXPR14 multi_span(TIterator begin_, size_t length_)
Constructor.
Definition multi_span.h:505
ETL_CONSTEXPR14 multi_span(const multi_span &other)
Copy Constructor.
Definition multi_span.h:513
ETL_CONSTEXPR14 size_t size_spans() const ETL_NOEXCEPT
Returns the number of spans in the multi_span.
Definition multi_span.h:659
ETL_CONSTEXPR14 reference operator[](size_t i) const
Returns a reference to the indexed value.
Definition multi_span.h:595
ETL_CONSTEXPR14 size_t size() const ETL_NOEXCEPT
Returns the number of elements in the multi_span.
Definition multi_span.h:614
ETL_CONSTEXPR14 multi_span & operator=(const multi_span &other)
Assignment operator.
Definition multi_span.h:521
ETL_CONSTEXPR14 multi_span(const TContainer &a) ETL_NOEXCEPT
Definition multi_span.h:487
ETL_CONSTEXPR14 multi_span(TIterator begin_, TIterator end_)
Constructor.
Definition multi_span.h:496
ETL_CONSTEXPR14 multi_span(span_list_type span_list_)
Constructor.
Definition multi_span.h:467
ETL_CONSTEXPR14 size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the multi_span.
Definition multi_span.h:644
ETL_CONSTEXPR14 multi_span(TContainer &a) ETL_NOEXCEPT
Definition multi_span.h:477
ETL_CONSTEXPR14 bool empty() const ETL_NOEXCEPT
Returns true if the multi_span size is zero.
Definition multi_span.h:629
Span - Fixed Extent.
Definition span.h:208
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:508
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR TContainer::reverse_iterator rend(TContainer &container)
Definition iterator.h:1119
ETL_CONSTEXPR TContainer::const_reverse_iterator crbegin(const TContainer &container)
Definition iterator.h:1109
ETL_CONSTEXPR TContainer::reverse_iterator rbegin(TContainer &container)
Definition iterator.h:1089
ETL_CONSTEXPR TContainer::const_iterator cbegin(const TContainer &container)
Definition iterator.h:987
ETL_CONSTEXPR T * to_address(T *p) ETL_NOEXCEPT
Definition memory.h:62
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition iterator.h:967
ETL_CONSTEXPR TContainer::const_reverse_iterator crend(const TContainer &container)
Definition iterator.h:1139
ETL_CONSTEXPR TContainer::const_iterator cend(const TContainer &container)
Definition iterator.h:1017
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:997
iterator
Definition iterator.h:424