Embedded Template Library 1.0
Loading...
Searching...
No Matches
indirect_vector.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2019 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_INDIRECT_VECTOR_INCLUDED
32#define ETL_INDIRECT_VECTOR_INCLUDED
33
34#include "platform.h"
35#include "vector.h"
36#include "pool.h"
37#include "iterator.h"
38#include "utility.h"
39#include "functional.h"
40#include "static_assert.h"
41#include "initializer_list.h"
42
43//*****************************************************************************
47//*****************************************************************************
48
49namespace etl
50{
51 //***************************************************************************
54 //***************************************************************************
55 class indirect_vector_buffer_missmatch : public vector_exception
56 {
57 public:
58
59 indirect_vector_buffer_missmatch(string_type file_name_, numeric_type line_number_)
60 : vector_exception(ETL_ERROR_TEXT("indirect_vector:buffer_missmatch", ETL_INDIRECT_VECTOR_FILE_ID"A"), file_name_, line_number_)
61 {
62 }
63 };
64
65 //***************************************************************************
69 //***************************************************************************
70 template <typename T>
72 {
73 public:
74
75 typedef T value_type;
76 typedef T& reference;
77 typedef const T& const_reference;
78#if ETL_USING_CPP11
79 typedef T&& rvalue_reference;
80#endif
81 typedef T* pointer;
82 typedef const T* const_pointer;
83
84 typedef typename etl::ivector<T*>::iterator indirect_iterator;
85 typedef typename etl::ivector<T*>::const_iterator indirect_const_iterator;
86
87 typedef typename etl::ivector<T*>::size_type size_type;
88 typedef typename etl::ivector<T*>::difference_type difference_type;
89
90 //*************************************************************************
92 //*************************************************************************
93 template <typename TUnaryFunction, typename TReturnType = void>
94 class unary_function_adaptor
95 {
96 public:
97
98 unary_function_adaptor(TUnaryFunction unary_function_)
99 : unary_function(unary_function_)
100 {
101 }
102
103 TReturnType operator()(const_pointer indirect_itr)
104 {
105 return unary_function(*indirect_itr);
106 }
107
108 TUnaryFunction unary_function;
109 };
110
111 //*************************************************************************
112 template <typename TUnaryFunction>
113 class unary_function_adaptor<TUnaryFunction, void>
114 {
115 public:
116
117 unary_function_adaptor(TUnaryFunction unary_function_)
118 : unary_function(unary_function_)
119 {
120 }
121
122 void operator()(const_pointer indirect_itr)
123 {
124 unary_function(*indirect_itr);
125 }
126
127 TUnaryFunction unary_function;
128 };
129
130 //*************************************************************************
132 //*************************************************************************
133 template <typename TBinaryFunction, typename TReturnType = void>
134 class binary_function_adaptor
135 {
136 public:
137
138 binary_function_adaptor(TBinaryFunction binary_function_)
139 : binary_function(binary_function_)
140 {
141 }
142
143 TReturnType operator()(const_pointer indirect_itr_lhs,
144 const_pointer indirect_itr_rhs)
145 {
146 return binary_function(*indirect_itr_lhs, *indirect_itr_rhs);
147 }
148
149 TBinaryFunction binary_function;
150 };
151
152 //*************************************************************************
153 template <typename TBinaryFunction>
154 class binary_function_adaptor<TBinaryFunction, void>
155 {
156 public:
157
158 binary_function_adaptor(TBinaryFunction binary_function_)
159 : binary_function(binary_function_)
160 {
161 }
162
163 void operator()(const_pointer indirect_itr_lhs,
164 const_pointer indirect_itr_rhs)
165 {
166 binary_function(*indirect_itr_lhs, *indirect_itr_rhs);
167 }
168
169 TBinaryFunction binary_function;
170 };
171
172 //*************************************************************************
174 //*************************************************************************
175 class iterator : public etl::iterator<ETL_OR_STD::random_access_iterator_tag, T>
176 {
177 public:
178
179 friend class iindirect_vector;
180 friend class const_iterator;
181
182 iterator()
183 : lookup_itr()
184 {
185 }
186
187 iterator(const iterator& other)
188 : lookup_itr(other.lookup_itr)
189 {
190 }
191
192 iterator& operator ++()
193 {
194 ++lookup_itr;
195 return *this;
196 }
197
198 iterator operator ++(int)
199 {
200 iterator temp(*this);
201 ++lookup_itr;
202 return temp;
203 }
204
205 iterator& operator --()
206 {
207 --lookup_itr;
208 return *this;
209 }
210
211 iterator operator --(int)
212 {
213 iterator temp(*this);
214 --lookup_itr;
215 return temp;
216 }
217
218 iterator& operator =(const iterator& other)
219 {
220 lookup_itr = other.lookup_itr;
221 return *this;
222 }
223
224 iterator operator +=(size_type n)
225 {
226 lookup_itr += n;
227 return *this;
228 }
229
230 iterator operator -=(size_type n)
231 {
232 lookup_itr -= n;
233 return *this;
234 }
235
236 reference operator *() const
237 {
238 return **lookup_itr;
239 }
240
241 pointer operator &() const
242 {
243 return &(**lookup_itr);
244 }
245
246 pointer operator ->() const
247 {
248 return &(**lookup_itr);
249 }
250
251 friend iterator operator +(const iterator& lhs, difference_type offset)
252 {
253 iterator result(lhs);
254 result += offset;
255 return result;
256 }
257
258 friend iterator operator -(const iterator& lhs, difference_type offset)
259 {
260 iterator result(lhs);
261 result -= offset;
262 return result;
263 }
264
265 indirect_iterator indirection()
266 {
267 return lookup_itr;
268 }
269
270 indirect_const_iterator indirection() const
271 {
272 return lookup_itr;
273 }
274
275 friend difference_type operator -(const iterator& lhs, const iterator& rhs)
276 {
277 return lhs.lookup_itr - rhs.lookup_itr;
278 }
279
280 friend bool operator == (const iterator& lhs, const iterator& rhs)
281 {
282 return lhs.lookup_itr == rhs.lookup_itr;
283 }
284
285 friend bool operator != (const iterator& lhs, const iterator& rhs)
286 {
287 return !(lhs == rhs);
288 }
289
290 friend bool operator < (const iterator& lhs, const iterator& rhs)
291 {
292 return lhs.lookup_itr < rhs.lookup_itr;
293 }
294
295 private:
296
297 iterator(indirect_iterator itr_)
298 : lookup_itr(itr_)
299 {
300 }
301
302 indirect_iterator lookup_itr;
303 };
304
305 //*************************************************************************
307 //*************************************************************************
308 class const_iterator : public etl::iterator<ETL_OR_STD::random_access_iterator_tag, const T>
309 {
310 public:
311
312 friend class iindirect_vector;
313
314 const_iterator()
315 : lookup_itr()
316 {
317 }
318
319 const_iterator(const const_iterator& other)
320 : lookup_itr(other.lookup_itr)
321 {
322 }
323
324 const_iterator(const typename iindirect_vector::iterator& other)
325 : lookup_itr(other.lookup_itr)
326 {
327 }
328
329 const_iterator& operator ++()
330 {
331 ++lookup_itr;
332 return *this;
333 }
334
335 const_iterator operator ++(int)
336 {
337 const_iterator temp(*this);
338 ++lookup_itr;
339 return temp;
340 }
341
342 const_iterator& operator --()
343 {
344 --lookup_itr;
345 return *this;
346 }
347
348 const_iterator operator --(int)
349 {
350 const_iterator temp(*this);
351 --lookup_itr;
352 return temp;
353 }
354
355 const_iterator operator +=(size_type n)
356 {
357 lookup_itr += n;
358 return *this;
359 }
360
361 const_iterator operator -=(size_type n)
362 {
363 lookup_itr -= n;
364 return *this;
365 }
366
367 const_iterator& operator =(const const_iterator& other)
368 {
369 lookup_itr = other.lookup_itr;
370 return *this;
371 }
372
373 const_reference operator *() const
374 {
375 return **lookup_itr;
376 }
377
378 const_pointer operator &() const
379 {
380 return &(**lookup_itr);
381 }
382
383 const_pointer operator ->() const
384 {
385 return &(**lookup_itr);
386 }
387
388 indirect_const_iterator indirection() const
389 {
390 return lookup_itr;
391 }
392
393 friend const_iterator operator +(const const_iterator& lhs, difference_type offset)
394 {
395 const_iterator result(lhs);
396 result += offset;
397 return result;
398 }
399
400 friend const_iterator operator -(const const_iterator& lhs, difference_type offset)
401 {
402 const_iterator result(lhs);
403 result -= offset;
404 return result;
405 }
406
407 friend difference_type operator -(const const_iterator& lhs, const const_iterator& rhs)
408 {
409 return lhs.lookup_itr - rhs.lookup_itr;
410 }
411
412 friend bool operator == (const const_iterator& lhs, const const_iterator& rhs)
413 {
414 return lhs.lookup_itr == rhs.lookup_itr;
415 }
416
417 friend bool operator != (const const_iterator& lhs, const const_iterator& rhs)
418 {
419 return !(lhs == rhs);
420 }
421
422 friend bool operator < (const const_iterator& lhs, const const_iterator& rhs)
423 {
424 return lhs.lookup_itr < rhs.lookup_itr;
425 }
426
427 private:
428
429 typedef typename etl::ivector<T*>::const_iterator lookup_itr_t;
430
431 const_iterator(indirect_const_iterator itr_)
432 : lookup_itr(itr_)
433 {
434 }
435
436 indirect_const_iterator lookup_itr;
437 };
438
439 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
440 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
441
442 protected:
443
444 typedef typename etl::parameter_type<T>::type parameter_t;
445
446 public:
447
448 //*********************************************************************
451 //*********************************************************************
453 {
454 return iterator(lookup.begin());
455 }
456
457 //*********************************************************************
460 //*********************************************************************
462 {
463 return const_iterator(lookup.begin());
464 }
465
466 //*********************************************************************
469 //*********************************************************************
471 {
472 return iterator(lookup.end());
473 }
474
475 //*********************************************************************
478 //*********************************************************************
480 {
481 return const_iterator(lookup.end());
482 }
483
484 //*********************************************************************
487 //*********************************************************************
489 {
490 return const_iterator(lookup.begin());
491 }
492
493 //*********************************************************************
496 //*********************************************************************
498 {
499 return const_iterator(lookup.cend());
500 }
501
502 //*********************************************************************
505 //*********************************************************************
506 reverse_iterator rbegin()
507 {
508 return reverse_iterator(end());
509 }
510
511 //*********************************************************************
514 //*********************************************************************
515 const_reverse_iterator rbegin() const
516 {
517 return const_reverse_iterator(end());
518 }
519
520 //*********************************************************************
523 //*********************************************************************
524 reverse_iterator rend()
525 {
526 return reverse_iterator(begin());
527 }
528
529 //*********************************************************************
532 //*********************************************************************
533 const_reverse_iterator rend() const
534 {
535 return const_reverse_iterator(begin());
536 }
537
538 //*********************************************************************
541 //*********************************************************************
542 const_reverse_iterator crbegin() const
543 {
544 return const_reverse_iterator(cend());
545 }
546
547 //*********************************************************************
550 //*********************************************************************
551 const_reverse_iterator crend() const
552 {
553 return const_reverse_iterator(cbegin());
554 }
555
556 //*********************************************************************
561 //*********************************************************************
562 void resize(size_t new_size)
563 {
564 resize(new_size, T());
565 }
566
567 //*********************************************************************
573 //*********************************************************************
574 void resize(size_t new_size, const_reference value)
575 {
576 ETL_ASSERT(new_size <= capacity(), ETL_ERROR(vector_full));
577
578 if (new_size <= capacity())
579 {
580 if (new_size > size())
581 {
582 size_type n = new_size - size();
583
584 while (n-- != 0U)
585 {
586 T* p = storage.create<T>(value);
587 lookup.push_back(p);
588 }
589 }
590 else
591 {
592 size_type n = size() - new_size;
593
594 while (n-- != 0U)
595 {
596 pop_back();
597 }
598 }
599 }
600 }
601
602 //*********************************************************************
606 //*********************************************************************
607 void reserve(size_t n)
608 {
609 (void)n; // Stop 'unused parameter' warning in release mode.
610 ETL_ASSERT(n <= capacity(), ETL_ERROR(vector_out_of_bounds));
611 }
612
613 //*********************************************************************
617 //*********************************************************************
618 reference operator [](size_t i)
619 {
620 return *lookup[i];
621 }
622
623 //*********************************************************************
627 //*********************************************************************
628 const_reference operator [](size_t i) const
629 {
630 return *lookup[i];
631 }
632
633 //*********************************************************************
638 //*********************************************************************
639 reference at(size_t i)
640 {
641 return *lookup.at(i);
642 }
643
644 //*********************************************************************
649 //*********************************************************************
650 const_reference at(size_t i) const
651 {
652 return *lookup.at(i);
653 }
654
655 //*********************************************************************
658 //*********************************************************************
659 reference front()
660 {
661 return *(lookup.front());
662 }
663
664 //*********************************************************************
667 //*********************************************************************
668 const_reference front() const
669 {
670 return *(lookup.front());
671 }
672
673 //*********************************************************************
676 //*********************************************************************
677 reference back()
678 {
679 return *(lookup.back());
680 }
681
682 //*********************************************************************
685 //*********************************************************************
686 const_reference back() const
687 {
688 return *(lookup.back());
689 }
690
691 //*********************************************************************
697 //*********************************************************************
698 template <typename TIterator>
699 void assign(TIterator first, TIterator last)
700 {
701 ETL_STATIC_ASSERT((etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::iterator_traits<TIterator>::value_type>::type>::value), "Iterator type does not match container type");
702
703#if ETL_IS_DEBUG_BUILD
704 difference_type d = etl::distance(first, last);
705 ETL_ASSERT(static_cast<size_t>(d) <= capacity(), ETL_ERROR(vector_full));
706#endif
707
708 initialise();
709
710 while (first != last)
711 {
712 T* p = storage.create<T>(*first);
713 lookup.push_back(p);
714 ++first;
715 }
716 }
717
718 //*********************************************************************
723 //*********************************************************************
724 void assign(size_t n, parameter_t value)
725 {
726 ETL_ASSERT(n <= capacity(), ETL_ERROR(vector_full));
727
728 initialise();
729
730 while (n-- != 0U)
731 {
732 T* p = storage.create<T>(value);
733 lookup.push_back(p);
734 }
735 }
736
737 //*************************************************************************
739 //*************************************************************************
740 void clear()
741 {
742 initialise();
743 }
744
745 //*************************************************************************
747 //*************************************************************************
748 void fill(const T& value)
749 {
750 etl::fill(begin(), end(), value);
751 }
752
753 //*********************************************************************
757 //*********************************************************************
758 void push_back(const_reference value)
759 {
760 ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(size() != capacity(), ETL_ERROR(vector_full));
761
762 T* p = storage.create<T>(value);
763 lookup.push_back(p);
764 }
765
766#if ETL_USING_CPP11
767 //*********************************************************************
771 //*********************************************************************
772 void push_back(rvalue_reference value)
773 {
774 ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(size() != capacity(), ETL_ERROR(vector_full));
775
776 T* p = storage.create<T>(etl::move(value));
777 lookup.push_back(p);
778 }
779#endif
780
781#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION)
782 //*********************************************************************
786 //*********************************************************************
787 template <typename ... Args>
788 reference emplace_back(Args && ... args)
789 {
790 T* p = storage.create<T>(etl::forward<Args>(args)...);
791 lookup.push_back(p);
792 return back();
793 }
794#else
795 //*********************************************************************
799 //*********************************************************************
800 reference emplace_back()
801 {
802 T* p = storage.create<T>(T());
803 lookup.push_back(p);
804 return back();
805 }
806
807 //*********************************************************************
811 //*********************************************************************
812 template <typename T1>
813 reference emplace_back(const T1& value1)
814 {
815 T* p = storage.create<T>(T(value1));
816 lookup.push_back(p);
817 return back();
818 }
819
820 //*********************************************************************
824 //*********************************************************************
825 template <typename T1, typename T2>
826 reference emplace_back(const T1& value1, const T2& value2)
827 {
828 T* p = storage.create<T>(T(value1, value2));
829 lookup.push_back(p);
830 return back();
831 }
832
833 //*********************************************************************
837 //*********************************************************************
838 template <typename T1, typename T2, typename T3>
839 reference emplace_back(const T1& value1, const T2& value2, const T3& value3)
840 {
841 T* p = storage.create<T>(T(value1, value2, value3));
842 lookup.push_back(p);
843 return back();
844 }
845
846 //*********************************************************************
850 //*********************************************************************
851 template <typename T1, typename T2, typename T3, typename T4>
852 reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
853 {
854 T* p = storage.create<T>(T(value1, value2, value3, value4));
855 lookup.push_back(p);
856 return back();
857 }
858#endif
859
860 //*************************************************************************
862 //*************************************************************************
863 void pop_back()
864 {
865 ETL_ASSERT(!empty(), ETL_ERROR(vector_empty));
866
867 reference object = back();
868 storage.destroy<T>(etl::addressof(object));
869 lookup.pop_back();
870 }
871
872 //*********************************************************************
877 //*********************************************************************
878 iterator insert(const_iterator position, const_reference value)
879 {
880 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
881
882 T* p = storage.create<T>(T(value));
883 position = iterator(lookup.insert(position.lookup_itr, p));
884
885 return to_iterator(position);
886 }
887
888#if ETL_USING_CPP11
889 //*********************************************************************
894 //*********************************************************************
895 iterator insert(const_iterator position, rvalue_reference value)
896 {
897 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
898
899 T* p = storage.create<T>(T(etl::move(value)));
900 position = iterator(lookup.insert(position.lookup_itr, p));
901
902 return to_iterator(position);
903 }
904#endif
905
906 //*************************************************************************
908 //*************************************************************************
909#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION)
910 template <typename ... Args>
911 iterator emplace(iterator position, Args && ... args)
912 {
913 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
914
915 T* p = storage.create<T>(T(etl::forward<Args>(args)...));
916 position = iterator(lookup.insert(position.lookup_itr, p));
917
918 return position;
919 }
920#else
922 {
923 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
924
925 T* p = storage.create<T>(T());
926 position = iterator(lookup.insert(position.lookup_itr, p));
927
928 return position;
929 }
930
931 template <typename T1>
932 iterator emplace(iterator position, const T1& value1)
933 {
934 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
935
936 T* p = storage.create<T>(T(value1));
937 position = iterator(lookup.insert(position.lookup_itr, p));
938
939 return position;
940 }
941
942 template <typename T1, typename T2>
943 iterator emplace(iterator position, const T1& value1, const T2& value2)
944 {
945 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
946
947 T* p = storage.create<T>(T(value1, value2));
948 position = iterator(lookup.insert(position.lookup_itr, p));
949
950 return position;
951 }
952
953 template <typename T1, typename T2, typename T3>
954 iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3)
955 {
956 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
957
958 T* p = storage.create<T>(T(value1, value2, value3));
959 position = iterator(lookup.insert(position.lookup_itr, p));
960
961 return position;
962 }
963
964 template <typename T1, typename T2, typename T3, typename T4>
965 iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
966 {
967 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
968
969 T* p = storage.create<T>(T(value1, value2, value3, value4));
970 position = iterator(lookup.insert(position.lookup_itr, p));
971
972 return position;
973 }
974#endif
975
976 //*********************************************************************
982 //*********************************************************************
983 iterator insert(const_iterator position, size_t n, parameter_t value)
984 {
985 ETL_ASSERT((size() + n) <= capacity(), ETL_ERROR(vector_full));
986
987 iterator position_ = to_iterator(position);
988
989 // Make space for the new lookup pointers.
990 typename etl::ivector<T*>::iterator lookup_itr = position_.lookup_itr;
991 lookup.insert(lookup_itr, n, ETL_NULLPTR);
992
993 while (n-- != 0U)
994 {
995 T* p = storage.create<T>(value);
996 *lookup_itr++ = p;
997 }
998
999 return position_;
1000 }
1001
1002 //*********************************************************************
1008 //*********************************************************************
1009 template <class TIterator>
1010 iterator insert(const_iterator position, TIterator first, TIterator last)
1011 {
1012 size_t count = size_t(etl::distance(first, last));
1013
1014 ETL_ASSERT((size() + count) <= capacity(), ETL_ERROR(vector_full));
1015
1016 // Make space for the new lookup pointers.
1017 typename etl::ivector<T*>::iterator lookup_itr = to_iterator(position).lookup_itr;
1018 lookup.insert(lookup_itr, count, ETL_NULLPTR);
1019
1020 while (first != last)
1021 {
1022 T* p = storage.create<T>(*first);
1023 *lookup_itr++ = p;
1024 ++first;
1025 }
1026
1027 return to_iterator(position);
1028 }
1029
1030 //*********************************************************************
1034 //*********************************************************************
1036 {
1037 storage.destroy<T>(etl::addressof(*i_element));
1038
1039 return iterator(lookup.erase(i_element.lookup_itr));
1040 }
1041
1042 //*********************************************************************
1046 //*********************************************************************
1048 {
1049 storage.destroy<T>(etl::addressof(*i_element));
1050
1051 return iterator(lookup.erase(i_element.lookup_itr));
1052 }
1053
1054 //*********************************************************************
1061 //*********************************************************************
1063 {
1064 iterator element = to_iterator(first);
1065
1066 while (element != last)
1067 {
1068 storage.destroy<T>(etl::addressof(*element));
1069 ++element;
1070 }
1071
1072 lookup.erase(first.lookup_itr, last.lookup_itr);
1073
1074 return to_iterator(last);
1075 }
1076
1077 //*************************************************************************
1079 //*************************************************************************
1081 {
1082 if (&rhs != this)
1083 {
1084 assign(rhs.cbegin(), rhs.cend());
1085 }
1086
1087 return *this;
1088 }
1089
1090#if ETL_USING_CPP11
1091 //*************************************************************************
1093 //*************************************************************************
1095 {
1096 if (&rhs != this)
1097 {
1098 clear();
1099 iterator itr = rhs.begin();
1100 while (itr != rhs.end())
1101 {
1102 push_back(etl::move(*itr));
1103 ++itr;
1104 }
1105
1106 rhs.initialise();
1107 }
1108
1109 return *this;
1110 }
1111#endif
1112
1113 //*************************************************************************
1116 //*************************************************************************
1117 size_type size() const
1118 {
1119 return lookup.size();
1120 }
1121
1122 //*************************************************************************
1125 //*************************************************************************
1126 size_type capacity() const
1127 {
1128 return lookup.capacity();
1129 }
1130
1131 //*************************************************************************
1134 //*************************************************************************
1135 bool empty() const
1136 {
1137 return lookup.empty();
1138 }
1139
1140 //*************************************************************************
1143 //*************************************************************************
1144 bool full() const
1145 {
1146 return lookup.full();
1147 }
1148
1149 //*************************************************************************
1152 //*************************************************************************
1153 size_type max_size() const
1154 {
1155 return lookup.max_size();
1156 }
1157
1158 //*************************************************************************
1161 //*************************************************************************
1162 size_type available() const
1163 {
1164 return lookup.available();
1165 }
1166
1167 protected:
1168
1169 //*********************************************************************
1171 //*********************************************************************
1173 : lookup(lookup_)
1174 , storage(storage_)
1175 {
1176 }
1177
1178 //*********************************************************************
1180 //*********************************************************************
1182 {
1183 if ETL_IF_CONSTEXPR(etl::is_trivially_destructible<T>::value)
1184 {
1185 storage.release_all();
1186 }
1187 else
1188 {
1189 iterator itr = begin();
1190
1191 while (itr != end())
1192 {
1193 storage.destroy<T>(etl::addressof(*itr));
1194 ++itr;
1195 }
1196 }
1197
1198 lookup.clear();
1199 }
1200
1201#if ETL_USING_CPP11
1202 //*********************************************************************
1204 //*********************************************************************
1205 void move_container(iindirect_vector&& other)
1206 {
1207 if (this != &other)
1208 {
1209 initialise();
1210
1211 typename iindirect_vector<T>::iterator itr = other.begin();
1212
1213 while (itr != other.end())
1214 {
1215 push_back(etl::move(*itr));
1216 ++itr;
1217 }
1218
1219 other.initialise();
1220 }
1221 }
1222#endif
1223
1224 etl::ivector<T*>& lookup;
1225 etl::ipool& storage;
1226
1227 private:
1228
1229 // Disable copy construction.
1230 iindirect_vector(const iindirect_vector&) ETL_DELETE;
1231
1232 //*************************************************************************
1234 //*************************************************************************
1235#if defined(ETL_POLYMORPHIC_INDIRECT_VECTOR) || defined(ETL_POLYMORPHIC_CONTAINERS)
1236 public:
1237 virtual
1238#else
1239 protected:
1240#endif
1242 {
1243 }
1244
1245 protected:
1246
1247 //*************************************************************************
1249 //*************************************************************************
1251 {
1252 return iterator(const_cast<indirect_iterator>(itr.lookup_itr));
1253 }
1254 };
1255
1256 //***************************************************************************
1262 //***************************************************************************
1263 template <typename T>
1265 {
1266 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1267 }
1268
1269 //***************************************************************************
1275 //***************************************************************************
1276 template <typename T>
1278 {
1279 return !(lhs == rhs);
1280 }
1281
1282 //***************************************************************************
1288 //***************************************************************************
1289 template <typename T>
1291 {
1292 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1293 }
1294
1295 //***************************************************************************
1301 //***************************************************************************
1302 template <typename T>
1304 {
1305 return (rhs < lhs);
1306 }
1307
1308 //***************************************************************************
1314 //***************************************************************************
1315 template <typename T>
1317 {
1318 return !(lhs > rhs);
1319 }
1320
1321 //***************************************************************************
1327 //***************************************************************************
1328 template <typename T>
1330 {
1331 return !(lhs < rhs);
1332 }
1333
1334 //***************************************************************************
1339 //***************************************************************************
1340 template <typename T, const size_t MAX_SIZE_>
1342 {
1343 public:
1344
1345 ETL_STATIC_ASSERT((MAX_SIZE_ > 0U), "Zero capacity etl::indirect_vector is not valid");
1346
1347 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1348
1349 //*************************************************************************
1351 //*************************************************************************
1353 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1354 {
1355 }
1356
1357 //*************************************************************************
1360 //*************************************************************************
1361 explicit indirect_vector(size_t initial_size)
1362 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1363 {
1364 this->resize(initial_size);
1365 }
1366
1367 //*************************************************************************
1371 //*************************************************************************
1372 indirect_vector(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value)
1373 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1374 {
1375 this->resize(initial_size, value);
1376 }
1377
1378 //*************************************************************************
1383 //*************************************************************************
1384 template <typename TIterator>
1385 indirect_vector(TIterator first, TIterator last)
1386 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1387 {
1388 this->assign(first, last);
1389 }
1390
1391#if ETL_HAS_INITIALIZER_LIST
1392 //*************************************************************************
1394 //*************************************************************************
1395 indirect_vector(std::initializer_list<T> init)
1396 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1397 {
1398 this->assign(init.begin(), init.end());
1399 }
1400#endif
1401
1402 //*************************************************************************
1404 //*************************************************************************
1406 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1407 {
1408 this->assign(other.begin(), other.end());
1409 }
1410
1411 //*************************************************************************
1413 //*************************************************************************
1415 {
1416 if (&rhs != this)
1417 {
1418 this->assign(rhs.cbegin(), rhs.cend());
1419 }
1420
1421 return *this;
1422 }
1423
1424#if ETL_USING_CPP11
1425 //*************************************************************************
1427 //*************************************************************************
1429 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1430 {
1431 this->move_container(etl::move(other));
1432 }
1433
1434 //*************************************************************************
1436 //*************************************************************************
1438 {
1439 this->move_container(etl::move(rhs));
1440
1441 return *this;
1442 }
1443#endif
1444
1445 //*************************************************************************
1447 //*************************************************************************
1449 {
1450 this->clear();
1451 }
1452
1453 private:
1454
1455 etl::vector<T*, MAX_SIZE> lookup_vector;
1456 etl::pool<T, MAX_SIZE> storage_pool;
1457 };
1458
1459 template <typename T, const size_t MAX_SIZE_>
1460 ETL_CONSTANT size_t indirect_vector<T, MAX_SIZE_>::MAX_SIZE;
1461
1462 //*************************************************************************
1464 //*************************************************************************
1465#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1466 template <typename T, typename... Ts>
1467 indirect_vector(T, Ts...)
1468 ->indirect_vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
1469#endif
1470
1471 //*************************************************************************
1473 //*************************************************************************
1474#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1475 template <typename... T>
1476 constexpr auto make_indirect_vector(T&&... t) -> etl::indirect_vector<typename etl::common_type_t<T...>, sizeof...(T)>
1477 {
1478 return { etl::forward<T>(t)... };
1479 }
1480#endif
1481
1482 //***************************************************************************
1487 //***************************************************************************
1488 template <typename T>
1490 {
1491 public:
1492
1493 //*************************************************************************
1495 //*************************************************************************
1497 : etl::iindirect_vector<T>(lookup_, pool_)
1498 {
1499 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1500 }
1501
1502 //*************************************************************************
1505 //*************************************************************************
1506 explicit indirect_vector_ext(size_t initial_size, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1507 : etl::iindirect_vector<T>(lookup_, pool_)
1508 {
1509 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1510 this->resize(initial_size);
1511 }
1512
1513 //*************************************************************************
1517 //*************************************************************************
1518 indirect_vector_ext(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1519 : etl::iindirect_vector<T>(lookup_, pool_)
1520 {
1521 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1522 this->resize(initial_size, value);
1523 }
1524
1525 //*************************************************************************
1530 //*************************************************************************
1531 template <typename TIterator>
1532 indirect_vector_ext(TIterator first, TIterator last, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1533 : etl::iindirect_vector<T>(lookup_, pool_)
1534 {
1535 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1536 this->assign(first, last);
1537 }
1538
1539#if ETL_HAS_INITIALIZER_LIST
1540 //*************************************************************************
1542 //*************************************************************************
1543 indirect_vector_ext(std::initializer_list<T> init, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1544 : etl::iindirect_vector<T>(lookup_, pool_)
1545 {
1546 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1547 this->assign(init.begin(), init.end());
1548 }
1549#endif
1550
1551 //*************************************************************************
1553 //*************************************************************************
1555 : etl::iindirect_vector<T>(lookup_, pool_)
1556 {
1557 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1558 this->assign(other.begin(), other.end());
1559 }
1560
1561 //*************************************************************************
1563 //*************************************************************************
1565
1566 //*************************************************************************
1568 //*************************************************************************
1570 {
1571 if (&rhs != this)
1572 {
1573 this->assign(rhs.cbegin(), rhs.cend());
1574 }
1575
1576 return *this;
1577 }
1578
1579#if ETL_USING_CPP11
1580 //*************************************************************************
1582 //*************************************************************************
1584 : etl::iindirect_vector<T>(lookup_, pool_)
1585 {
1586 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1587 this->move_container(etl::move(other));
1588 }
1589
1590 //*************************************************************************
1592 //*************************************************************************
1593 indirect_vector_ext(indirect_vector_ext&& other) ETL_DELETE;
1594
1595 //*************************************************************************
1597 //*************************************************************************
1599 {
1600 this->move_container(etl::move(rhs));
1601
1602 return *this;
1603 }
1604#endif
1605
1606 //*************************************************************************
1608 //*************************************************************************
1610 {
1611 this->clear();
1612 }
1613 };
1614}
1615
1616#endif
1617
const_iterator.
Definition indirect_vector.h:309
iterator.
Definition indirect_vector.h:176
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:962
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
reference at(size_t i)
Definition indirect_vector.h:639
const_reverse_iterator crend() const
Definition indirect_vector.h:551
void resize(size_t new_size)
Definition indirect_vector.h:562
iterator to_iterator(const_iterator itr) const
Convert from const_iterator to iterator.
Definition indirect_vector.h:1250
void clear()
Clears the indirect_vector.
Definition indirect_vector.h:740
indirect_vector_ext & operator=(const indirect_vector_ext &rhs)
Assignment operator.
Definition indirect_vector.h:1569
indirect_vector_ext(size_t initial_size, typename etl::iindirect_vector< T >::parameter_t value, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Definition indirect_vector.h:1518
~indirect_vector()
Destructor.
Definition indirect_vector.h:1448
void assign(TIterator first, TIterator last)
Definition indirect_vector.h:699
size_type available() const
Definition indirect_vector.h:1162
indirect_vector_ext(const indirect_vector_ext &other) ETL_DELETE
Copy constructor (Deleted).
reference back()
Definition indirect_vector.h:677
iindirect_vector & operator=(const iindirect_vector &rhs)
Assignment operator.
Definition indirect_vector.h:1080
iterator end()
Definition indirect_vector.h:470
const_iterator end() const
Definition indirect_vector.h:479
indirect_vector_ext(size_t initial_size, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Definition indirect_vector.h:1506
bool empty() const
Definition indirect_vector.h:1135
indirect_vector(size_t initial_size, typename etl::iindirect_vector< T >::parameter_t value)
Definition indirect_vector.h:1372
reference emplace_back(const T1 &value1, const T2 &value2, const T3 &value3)
Definition indirect_vector.h:839
reverse_iterator rend()
Definition indirect_vector.h:524
indirect_vector_ext(const indirect_vector_ext &other, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Construct a copy.
Definition indirect_vector.h:1554
reference emplace_back(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition indirect_vector.h:852
iterator erase(const_iterator i_element)
Definition indirect_vector.h:1047
void reserve(size_t n)
Definition indirect_vector.h:607
void pop_back()
Removes an element from the end of the indirect_vector.
Definition indirect_vector.h:863
bool full() const
Definition indirect_vector.h:1144
size_type size() const
Definition indirect_vector.h:1117
const_iterator cend() const
Definition indirect_vector.h:497
iterator emplace(iterator position)
Emplaces a value to the vector at the specified position.
Definition indirect_vector.h:921
void assign(size_t n, parameter_t value)
Definition indirect_vector.h:724
indirect_vector(const indirect_vector &other)
Copy constructor.
Definition indirect_vector.h:1405
const_iterator cbegin() const
Definition indirect_vector.h:488
const_reference back() const
Definition indirect_vector.h:686
const_reference front() const
Definition indirect_vector.h:668
indirect_vector_ext(etl::ivector< T * > &lookup_, etl::ipool &pool_)
Constructor.
Definition indirect_vector.h:1496
indirect_vector(size_t initial_size)
Definition indirect_vector.h:1361
~iindirect_vector()
Destructor.
Definition indirect_vector.h:1241
indirect_vector()
Constructor.
Definition indirect_vector.h:1352
size_type max_size() const
Definition indirect_vector.h:1153
const_iterator begin() const
Definition indirect_vector.h:461
void initialise()
Initialise the indirect_vector.
Definition indirect_vector.h:1181
~indirect_vector_ext()
Destructor.
Definition indirect_vector.h:1609
const_reference at(size_t i) const
Definition indirect_vector.h:650
reference emplace_back(const T1 &value1, const T2 &value2)
Definition indirect_vector.h:826
iterator begin()
Definition indirect_vector.h:452
void fill(const T &value)
Fills the buffer.
Definition indirect_vector.h:748
iterator insert(const_iterator position, TIterator first, TIterator last)
Definition indirect_vector.h:1010
const_reverse_iterator rend() const
Definition indirect_vector.h:533
const_reverse_iterator rbegin() const
Definition indirect_vector.h:515
void resize(size_t new_size, const_reference value)
Definition indirect_vector.h:574
iterator erase(iterator i_element)
Definition indirect_vector.h:1035
indirect_vector(TIterator first, TIterator last)
Definition indirect_vector.h:1385
reverse_iterator rbegin()
Definition indirect_vector.h:506
const_reverse_iterator crbegin() const
Definition indirect_vector.h:542
indirect_vector & operator=(const indirect_vector &rhs)
Assignment operator.
Definition indirect_vector.h:1414
iterator erase(const_iterator first, const_iterator last)
Definition indirect_vector.h:1062
reference emplace_back(const T1 &value1)
Definition indirect_vector.h:813
reference front()
Definition indirect_vector.h:659
indirect_vector_ext(TIterator first, TIterator last, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Definition indirect_vector.h:1532
reference emplace_back()
Definition indirect_vector.h:800
size_type capacity() const
Definition indirect_vector.h:1126
iindirect_vector(etl::ivector< T * > &lookup_, etl::ipool &storage_)
Constructor.
Definition indirect_vector.h:1172
reference operator[](size_t i)
Definition indirect_vector.h:618
void push_back(const_reference value)
Definition indirect_vector.h:758
iterator insert(const_iterator position, const_reference value)
Definition indirect_vector.h:878
iterator insert(const_iterator position, size_t n, parameter_t value)
Definition indirect_vector.h:983
Definition indirect_vector.h:72
Definition indirect_vector.h:1342
Template deduction guides.
Definition indirect_vector.h:1490
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
size_t capacity() const
Returns the maximum number of items in the pool.
Definition ipool.h:488
T * create()
Definition ipool.h:333
Definition ipool.h:103
Definition pool.h:54
is_same
Definition type_traits_generator.h:1104
remove_cv
Definition type_traits_generator.h:1031
void push_back(parameter_t value)
Definition ivectorpointer.h:347
size_type capacity() const
Definition vector_base.h:131
iterator insert(const_iterator position, parameter_t value)
Definition ivectorpointer.h:391
Definition indirect_vector.h:56
Definition vector.h:71
Definition vector.h:1225
Definition vector_base.h:80
Definition vector_base.h:66
Definition vector_base.h:94
bitset_ext
Definition absolute.h:39
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178
iterator
Definition iterator.h:399
etl::conditional< etl::is_fundamental< T >::value||etl::is_pointer< T >::value, T, constT & >::type type
By default fundamental and pointer types are passed by value.
Definition parameter_type.h:48