29 #ifndef __ETL_IDEQUE__
30 #define __ETL_IDEQUE__
31 #define __ETL_IN_IDEQUE_H__
40 #ifndef ETL_THROW_EXCEPTIONS
57 typedef size_t size_type;
59 typedef const T& const_reference;
61 typedef const T* const_pointer;
62 typedef typename std::iterator_traits<pointer>::difference_type difference_type;
71 template <
typename TIterator>
81 struct iterator :
public std::iterator<std::random_access_iterator_tag, T>
96 p_deque(other.p_deque),
97 p_buffer(other.p_buffer)
104 index = (index == p_deque->
MAX_SIZE) ? 0 : index + 1;
113 index = (index == p_deque->
MAX_SIZE) ? 0 : index + 1;
119 iterator operator +=(difference_type offset)
124 index = (
static_cast<size_t>(index) > p_deque->
MAX_SIZE) ? index - p_deque->
BUFFER_SIZE : index;
128 operator -= (-offset);
135 iterator operator -=(difference_type offset)
140 index = (index < 0) ? index + p_deque->
BUFFER_SIZE : index;
144 operator += (-offset);
153 index = (index == 0) ? p_deque->
MAX_SIZE : index - 1;
162 index = (index == 0) ? p_deque->
MAX_SIZE : index - 1;
168 reference operator *()
170 return p_buffer[index];
174 const_reference operator *()
const
176 return p_buffer[index];
180 pointer operator ->()
182 return &p_buffer[index];
186 const_pointer operator ->()
const
188 return &p_buffer[index];
194 return ideque::distance(*
this, other) > 0;
216 return lhs.index == rhs.index;
222 return !(lhs == rhs);
226 difference_type get_index()
const
238 pointer get_buffer()
const
252 iterator(difference_type index,
ideque& the_deque, pointer p_buffer)
259 difference_type index;
267 struct const_iterator :
public std::iterator<std::random_access_iterator_tag, const T>
281 : index(other.index),
282 p_deque(other.p_deque),
283 p_buffer(other.p_buffer)
289 : index(other.index),
290 p_deque(other.p_deque),
291 p_buffer(other.p_buffer)
298 index = (index == p_deque->
MAX_SIZE) ? 0 : index + 1;
307 index = (index == p_deque->
MAX_SIZE) ? 0 : index + 1;
318 index = (
static_cast<size_t>(index) > p_deque->
MAX_SIZE) ? index - p_deque->
BUFFER_SIZE : index;
322 operator -= (-offset);
334 index = (index < 0) ? index + p_deque->
BUFFER_SIZE : index;
338 operator += (-offset);
347 index = (index == 0) ? p_deque->
MAX_SIZE : index - 1;
356 index = (index == 0) ? p_deque->
MAX_SIZE : index - 1;
362 const_reference operator *()
const
364 return p_buffer[index];
368 const_pointer operator ->()
const
370 return &p_buffer[index];
376 return ideque::distance(*
this, other) > 0;
398 return lhs.index == rhs.index;
404 return !(lhs == rhs);
408 difference_type get_index()
const
420 pointer get_buffer()
const
434 difference_type distance(difference_type firstIndex, difference_type index)
436 if (index < firstIndex)
442 return index - firstIndex;
454 difference_type index;
459 typedef std::reverse_iterator<iterator> reverse_iterator;
460 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
475 template<
typename TIterator>
477 assign(TIterator range_begin, TIterator range_end)
481 while (range_begin != range_end)
493 void assign(size_type n,
const value_type& value)
498 #ifdef ETL_THROW_EXCEPTIONS
520 reference
at(
size_t index)
524 #ifdef ETL_THROW_EXCEPTIONS
542 const_reference
at(
size_t index)
const
546 #ifdef ETL_THROW_EXCEPTIONS
672 return reverse_iterator(
end());
680 return const_reverse_iterator(
end());
688 return const_reverse_iterator(
cend());
696 return reverse_iterator(
begin());
702 const_reverse_iterator
rend()
const
704 return const_reverse_iterator(
begin());
710 const_reverse_iterator
crend()
const
712 return const_reverse_iterator(
cbegin());
737 if (insert_position ==
begin())
742 else if (insert_position ==
end())
750 if (std::distance(first, position) < std::distance(position,
last))
753 std::copy(first, position, first - 1);
756 *(--position) = value;
767 std::copy_backward(position,
last,
last + 1);
778 #ifdef ETL_THROW_EXCEPTIONS
801 if (insert_position ==
begin())
804 std::fill_n(first, n, value);
807 else if (insert_position ==
end())
810 std::fill_n(position, n, value);
819 if (distance(first, insert_position) < difference_type(
current_size / 2))
822 iterator new_position = position - n;
825 std::copy(first, position, new_first);
828 std::fill_n(new_position, n, value);
832 position = new_position;
839 std::copy_backward(position,
last + 1, new_last + 1);
842 std::fill_n(position, n, value);
853 #ifdef ETL_THROW_EXCEPTIONS
870 template<
typename TIterator>
877 size_t n = std::distance(range_begin, range_end);
881 if (insert_position ==
begin())
888 while (range_begin != range_end)
890 *destination++ = *range_begin++;
895 else if (insert_position ==
end())
899 while (range_begin != range_end)
901 *(++
last) = *range_begin++;
910 if (distance(first, insert_position) < difference_type(
current_size / 2))
913 iterator new_position = position - n;
916 std::copy(first, position, new_first);
919 std::copy(range_begin, range_end, new_position);
923 position = new_position;
930 std::copy_backward(position,
last + 1, new_last + 1);
933 std::copy(range_begin, range_end, position);
944 #ifdef ETL_THROW_EXCEPTIONS
963 if (distance(position) <= difference_type(
current_size))
965 if (position == first)
970 else if (position ==
last)
977 if (distance(first, position) < difference_type(
current_size / 2))
979 std::copy_backward(first, position, position + 1);
985 std::copy(position + 1,
last + 1, position);
994 #ifdef ETL_THROW_EXCEPTIONS
1014 if ((distance(range_begin) <= difference_type(
current_size)) &&
1015 (distance(range_end) <= difference_type(
current_size)))
1018 difference_type length = std::distance(range_begin, range_end);
1021 if (position == first)
1027 else if (position ==
last - length + 1)
1035 if (distance(first, position) < difference_type(
current_size / 2))
1038 std::copy_backward(first, position, position + length);
1046 std::copy(position + length,
last + 1, position);
1055 #ifdef ETL_THROW_EXCEPTIONS
1084 #ifdef ETL_THROW_EXCEPTIONS
1110 #ifdef ETL_THROW_EXCEPTIONS
1155 #ifdef ETL_THROW_EXCEPTIONS
1181 #ifdef ETL_THROW_EXCEPTIONS
1213 void resize(
size_t new_size,
const value_type& value = value_type())
1227 for (
size_t i = 0; i < count; ++i)
1238 #ifdef ETL_THROW_EXCEPTIONS
1251 return distance(rhs, lhs);
1259 return distance(rhs, lhs);
1265 friend difference_type
operator -(
const reverse_iterator& lhs,
const reverse_iterator& rhs)
1267 return distance(lhs.base(), rhs.base());
1273 friend difference_type
operator -(
const const_reverse_iterator& lhs,
const const_reverse_iterator& rhs)
1275 return distance(lhs.base(), rhs.base());
1299 template <
typename TIterator1,
typename TIterator2>
1300 static difference_type distance(
const TIterator1& range_begin,
const TIterator2& range_end)
1302 difference_type distance1 = distance(range_begin);
1303 difference_type distance2 = distance(range_end);
1305 return distance2 - distance1;
1311 template <
typename TIterator>
1312 static difference_type distance(
const TIterator& other)
1314 const difference_type index = other.get_index();
1315 const difference_type reference_index = other.get_deque().first.index;
1316 const size_t buffer_size = other.get_deque().BUFFER_SIZE;
1318 if (index < reference_index)
1320 return buffer_size + index - reference_index;
1324 return index - reference_index;
1337 template <
typename T>
1350 template <
typename T>
1353 return !(lhs == rhs);
1363 template <
typename T>
1366 return std::lexicographical_compare(lhs.begin(),
1379 template <
typename T>
1392 template <
typename T>
1395 return std::lexicographical_compare(lhs.
begin(),
1409 template <
typename T>
size_type size() const
Definition: deque_base.h:112
const_reverse_iterator crend() const
Gets a const reverse iterator to the beginning of the deque.
Definition: ideque.h:710
void push_back(parameter_t item)
Definition: ideque.h:1070
Const Iterator.
Definition: ideque.h:267
iterator last
Iterator to the first item in the deque.
Definition: ideque.h:1291
void pop_back()
Removes the oldest item from the deque.
Definition: ideque.h:1123
bool operator>(const etl::ideque< T > &lhs, const etl::ideque< T > &rhs)
Definition: ideque.h:1393
bool operator<(const etl::ideque< T > &lhs, const etl::ideque< T > &rhs)
Definition: ideque.h:1364
const_reverse_iterator rend() const
Gets a const reverse iterator to the beginning of the deque.
Definition: ideque.h:702
iterator insert(const_iterator insert_position, const value_type &value)
Definition: ideque.h:731
const_iterator begin() const
Gets a const iterator to the beginning of the deque.
Definition: ideque.h:630
reference at(size_t index)
Definition: ideque.h:520
void swap(etl::bitset< N > &lhs, etl::bitset< N > &rhs)
swap
Definition: bitset.h:1200
const_iterator cend() const
Gets a const iterator to the end of the deque.
Definition: ideque.h:662
Definition: deque_base.h:102
Determine how to pass parameters.
Definition: parameter_type.h:40
ideque & operator=(const ideque &other)
Assignment operator.
Definition: ideque.h:465
const_reference front() const
Definition: ideque.h:596
const size_type MAX_SIZE
The maximum number of elements in the deque.
Definition: deque_base.h:183
void pop_front()
Removes the oldest item from the deque.
Definition: ideque.h:1194
Definition: type_traits.h:268
enable_if< is_iterator< TIterator >::value, iterator >::type insert(const_iterator insert_position, TIterator range_begin, TIterator range_end)
Definition: ideque.h:872
iterator insert(const_iterator insert_position, size_type n, const value_type &value)
Definition: ideque.h:795
const_reverse_iterator crbegin() const
Gets a const reverse iterator to the end of the deque.
Definition: ideque.h:686
const_iterator end() const
Gets a const iterator to the end of the deque.
Definition: ideque.h:654
iterator erase(const_iterator erase_position)
Definition: ideque.h:959
reference push_back()
Definition: ideque.h:1097
reference operator[](size_t index)
Definition: ideque.h:563
bool operator!=(const etl::ideque< T > &lhs, const etl::ideque< T > &rhs)
Definition: ideque.h:1351
const_reverse_iterator rbegin() const
Gets a const reverse iterator to the end of the deque.
Definition: ideque.h:678
void clear()
Clears the deque.
Definition: ideque.h:718
const_iterator cbegin() const
Gets a const iterator to the beginning of the deque.
Definition: ideque.h:638
Definition: algorithm.h:43
pointer p_buffer
Iterator to the last item in the deque.
Definition: ideque.h:1292
bool full() const
Definition: deque_base.h:130
size_type max_size() const
Definition: deque_base.h:148
reference back()
Definition: ideque.h:605
iterator end()
Gets an iterator to the end of the deque.
Definition: ideque.h:646
Iterator.
Definition: ideque.h:81
const size_type BUFFER_SIZE
The of elements in the buffer.
Definition: deque_base.h:184
const_reference back() const
Definition: ideque.h:614
bool operator>=(const etl::ideque< T > &lhs, const etl::ideque< T > &rhs)
Definition: ideque.h:1410
void push_front(parameter_t item)
Definition: ideque.h:1141
iterator erase(const_iterator range_begin, const_iterator range_end)
Definition: ideque.h:1010
Test for an iterator.
Definition: ideque.h:72
iterator begin()
Gets an iterator to the beginning of the deque.
Definition: ideque.h:622
reference front()
Definition: ideque.h:587
bool operator==(const etl::ideque< T > &lhs, const etl::ideque< T > &rhs)
Definition: ideque.h:1338
size_type current_size
The current number of elements in the deque.
Definition: deque_base.h:182
static void error(const exception &e)
Definition: error_handler.cpp:50
Definition: type_traits.h:45
void assign(size_type n, const value_type &value)
Definition: ideque.h:493
etl::enable_if< is_iterator< TIterator >::value, void >::type assign(TIterator range_begin, TIterator range_end)
Assigns a range to the deque.
Definition: ideque.h:477
reverse_iterator rbegin()
Gets a reverse iterator to the end of the deque.
Definition: ideque.h:670
bool empty() const
Definition: deque_base.h:121
Definition: deque_base.h:88
const_reference at(size_t index) const
Definition: ideque.h:542
Definition: deque_base.h:60
reference push_front()
Definition: ideque.h:1168
reverse_iterator rend()
Gets a reverse iterator to the beginning of the deque.
Definition: ideque.h:694
void resize(size_t new_size, const value_type &value=value_type())
Definition: ideque.h:1213
ideque(pointer p_buffer, size_t max_size, size_t buffer_size)
Constructor.
Definition: ideque.h:1283
friend difference_type operator-(const iterator &lhs, const iterator &rhs)
Definition: ideque.h:1249