Embedded Template Library 1.0
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 //***************************************************************************
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>
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>
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 {
184 }
185
186 iterator(const iterator& other)
187 : lookup_itr(other.lookup_itr)
188 {
189 }
190
191 iterator& operator ++()
192 {
193 ++lookup_itr;
194 return *this;
195 }
196
197 iterator operator ++(int)
198 {
199 iterator temp(*this);
200 ++lookup_itr;
201 return temp;
202 }
203
204 iterator& operator --()
205 {
206 --lookup_itr;
207 return *this;
208 }
209
210 iterator operator --(int)
211 {
212 iterator temp(*this);
213 --lookup_itr;
214 return temp;
215 }
216
217 iterator& operator =(const iterator& other)
218 {
219 lookup_itr = other.lookup_itr;
220 return *this;
221 }
222
223 iterator operator +=(size_type n)
224 {
225 lookup_itr += n;
226 return *this;
227 }
228
229 iterator operator -=(size_type n)
230 {
231 lookup_itr -= n;
232 return *this;
233 }
234
235 reference operator *() const
236 {
237 return **lookup_itr;
238 }
239
240 pointer operator &() const
241 {
242 return &(**lookup_itr);
243 }
244
245 pointer operator ->() const
246 {
247 return &(**lookup_itr);
248 }
249
250 friend iterator operator +(const iterator& lhs, difference_type offset)
251 {
252 iterator result(lhs);
253 result += offset;
254 return result;
255 }
256
257 friend iterator operator -(const iterator& lhs, difference_type offset)
258 {
259 iterator result(lhs);
260 result -= offset;
261 return result;
262 }
263
264 indirect_iterator indirection()
265 {
266 return lookup_itr;
267 }
268
269 indirect_const_iterator indirection() const
270 {
271 return lookup_itr;
272 }
273
274 friend difference_type operator -(const iterator& lhs, const iterator& rhs)
275 {
276 return lhs.lookup_itr - rhs.lookup_itr;
277 }
278
279 friend bool operator == (const iterator& lhs, const iterator& rhs)
280 {
281 return lhs.lookup_itr == rhs.lookup_itr;
282 }
283
284 friend bool operator != (const iterator& lhs, const iterator& rhs)
285 {
286 return !(lhs == rhs);
287 }
288
289 friend bool operator < (const iterator& lhs, const iterator& rhs)
290 {
291 return lhs.lookup_itr < rhs.lookup_itr;
292 }
293
294 private:
295
296 iterator(indirect_iterator itr_)
297 : lookup_itr(itr_)
298 {
299 }
300
301 indirect_iterator lookup_itr;
302 };
303
304 //*************************************************************************
306 //*************************************************************************
307 class const_iterator : public etl::iterator<ETL_OR_STD::random_access_iterator_tag, const T>
308 {
309 public:
310
311 friend class iindirect_vector;
312
314 {
315 }
316
317 const_iterator(const const_iterator& other)
318 : lookup_itr(other.lookup_itr)
319 {
320 }
321
322 const_iterator(const typename iindirect_vector::iterator& other)
323 : lookup_itr(other.lookup_itr)
324 {
325 }
326
327 const_iterator& operator ++()
328 {
329 ++lookup_itr;
330 return *this;
331 }
332
333 const_iterator operator ++(int)
334 {
335 const_iterator temp(*this);
336 ++lookup_itr;
337 return temp;
338 }
339
340 const_iterator& operator --()
341 {
342 --lookup_itr;
343 return *this;
344 }
345
346 const_iterator operator --(int)
347 {
348 const_iterator temp(*this);
349 --lookup_itr;
350 return temp;
351 }
352
353 const_iterator operator +=(size_type n)
354 {
355 lookup_itr += n;
356 return *this;
357 }
358
359 const_iterator operator -=(size_type n)
360 {
361 lookup_itr -= n;
362 return *this;
363 }
364
365 const_iterator& operator =(const const_iterator& other)
366 {
367 lookup_itr = other.lookup_itr;
368 return *this;
369 }
370
371 const_reference operator *() const
372 {
373 return **lookup_itr;
374 }
375
376 const_pointer operator &() const
377 {
378 return &(**lookup_itr);
379 }
380
381 const_pointer operator ->() const
382 {
383 return &(**lookup_itr);
384 }
385
386 indirect_const_iterator indirection() const
387 {
388 return lookup_itr;
389 }
390
391 friend const_iterator operator +(const const_iterator& lhs, difference_type offset)
392 {
393 const_iterator result(lhs);
394 result += offset;
395 return result;
396 }
397
398 friend const_iterator operator -(const const_iterator& lhs, difference_type offset)
399 {
400 const_iterator result(lhs);
401 result -= offset;
402 return result;
403 }
404
405 friend difference_type operator -(const const_iterator& lhs, const const_iterator& rhs)
406 {
407 return lhs.lookup_itr - rhs.lookup_itr;
408 }
409
410 friend bool operator == (const const_iterator& lhs, const const_iterator& rhs)
411 {
412 return lhs.lookup_itr == rhs.lookup_itr;
413 }
414
415 friend bool operator != (const const_iterator& lhs, const const_iterator& rhs)
416 {
417 return !(lhs == rhs);
418 }
419
420 friend bool operator < (const const_iterator& lhs, const const_iterator& rhs)
421 {
422 return lhs.lookup_itr < rhs.lookup_itr;
423 }
424
425 private:
426
427 typedef typename etl::ivector<T*>::const_iterator lookup_itr_t;
428
429 const_iterator(indirect_const_iterator itr_)
430 : lookup_itr(itr_)
431 {
432 }
433
434 indirect_const_iterator lookup_itr;
435 };
436
437 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
438 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
439
440 protected:
441
442 typedef typename etl::parameter_type<T>::type parameter_t;
443
444 public:
445
446 //*********************************************************************
449 //*********************************************************************
451 {
452 return iterator(lookup.begin());
453 }
454
455 //*********************************************************************
458 //*********************************************************************
460 {
461 return const_iterator(lookup.begin());
462 }
463
464 //*********************************************************************
467 //*********************************************************************
469 {
470 return iterator(lookup.end());
471 }
472
473 //*********************************************************************
476 //*********************************************************************
478 {
479 return const_iterator(lookup.end());
480 }
481
482 //*********************************************************************
485 //*********************************************************************
487 {
488 return const_iterator(lookup.begin());
489 }
490
491 //*********************************************************************
494 //*********************************************************************
496 {
497 return const_iterator(lookup.cend());
498 }
499
500 //*********************************************************************
503 //*********************************************************************
504 reverse_iterator rbegin()
505 {
506 return reverse_iterator(end());
507 }
508
509 //*********************************************************************
512 //*********************************************************************
513 const_reverse_iterator rbegin() const
514 {
515 return const_reverse_iterator(end());
516 }
517
518 //*********************************************************************
521 //*********************************************************************
522 reverse_iterator rend()
523 {
524 return reverse_iterator(begin());
525 }
526
527 //*********************************************************************
530 //*********************************************************************
531 const_reverse_iterator rend() const
532 {
533 return const_reverse_iterator(begin());
534 }
535
536 //*********************************************************************
539 //*********************************************************************
540 const_reverse_iterator crbegin() const
541 {
542 return const_reverse_iterator(cend());
543 }
544
545 //*********************************************************************
548 //*********************************************************************
549 const_reverse_iterator crend() const
550 {
551 return const_reverse_iterator(cbegin());
552 }
553
554 //*********************************************************************
559 //*********************************************************************
560 void resize(size_t new_size)
561 {
562 resize(new_size, T());
563 }
564
565 //*********************************************************************
571 //*********************************************************************
572 void resize(size_t new_size, const_reference value)
573 {
574 ETL_ASSERT(new_size <= capacity(), ETL_ERROR(vector_full));
575
576 if (new_size <= capacity())
577 {
578 if (new_size > size())
579 {
580 size_type n = new_size - size();
581
582 while (n-- != 0U)
583 {
584 T* p = storage.create<T>(value);
585 lookup.push_back(p);
586 }
587 }
588 else
589 {
590 size_type n = size() - new_size;
591
592 while (n-- != 0U)
593 {
594 pop_back();
595 }
596 }
597 }
598 }
599
600 //*********************************************************************
603 //*********************************************************************
604 void reserve(size_t)
605 {
606 }
607
608 //*********************************************************************
612 //*********************************************************************
613 reference operator [](size_t i)
614 {
615 return *lookup[i];
616 }
617
618 //*********************************************************************
622 //*********************************************************************
623 const_reference operator [](size_t i) const
624 {
625 return *lookup[i];
626 }
627
628 //*********************************************************************
633 //*********************************************************************
634 reference at(size_t i)
635 {
636 return *lookup.at(i);
637 }
638
639 //*********************************************************************
644 //*********************************************************************
645 const_reference at(size_t i) const
646 {
647 return *lookup.at(i);
648 }
649
650 //*********************************************************************
653 //*********************************************************************
654 reference front()
655 {
656 return *(lookup.front());
657 }
658
659 //*********************************************************************
662 //*********************************************************************
663 const_reference front() const
664 {
665 return *(lookup.front());
666 }
667
668 //*********************************************************************
671 //*********************************************************************
672 reference back()
673 {
674 return *(lookup.back());
675 }
676
677 //*********************************************************************
680 //*********************************************************************
681 const_reference back() const
682 {
683 return *(lookup.back());
684 }
685
686 //*********************************************************************
692 //*********************************************************************
693 template <typename TIterator>
694 void assign(TIterator first, TIterator last)
695 {
696 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");
697
698#if ETL_IS_DEBUG_BUILD
699 difference_type d = etl::distance(first, last);
700 ETL_ASSERT(static_cast<size_t>(d) <= capacity(), ETL_ERROR(vector_full));
701#endif
702
703 initialise();
704
705 while (first != last)
706 {
707 T* p = storage.create<T>(*first);
708 lookup.push_back(p);
709 ++first;
710 }
711 }
712
713 //*********************************************************************
718 //*********************************************************************
719 void assign(size_t n, parameter_t value)
720 {
721 ETL_ASSERT(n <= capacity(), ETL_ERROR(vector_full));
722
723 initialise();
724
725 while (n-- != 0U)
726 {
727 T* p = storage.create<T>(value);
728 lookup.push_back(p);
729 }
730 }
731
732 //*************************************************************************
734 //*************************************************************************
735 void clear()
736 {
737 initialise();
738 }
739
740 //*************************************************************************
742 //*************************************************************************
743 void fill(const T& value)
744 {
745 etl::fill(begin(), end(), value);
746 }
747
748 //*********************************************************************
752 //*********************************************************************
753 void push_back(const_reference value)
754 {
755#if defined(ETL_CHECK_PUSH_POP)
756 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
757#endif
758 T* p = storage.create<T>(value);
759 lookup.push_back(p);
760 }
761
762#if ETL_USING_CPP11
763 //*********************************************************************
767 //*********************************************************************
768 void push_back(rvalue_reference value)
769 {
770#if defined(ETL_CHECK_PUSH_POP)
771 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
772#endif
773 T* p = storage.create<T>(etl::move(value));
774 lookup.push_back(p);
775 }
776#endif
777
778#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION)
779 //*********************************************************************
783 //*********************************************************************
784 template <typename ... Args>
785 reference emplace_back(Args && ... args)
786 {
787 T* p = storage.create<T>(etl::forward<Args>(args)...);
788 lookup.push_back(p);
789 return back();
790 }
791#else
792 //*********************************************************************
796 //*********************************************************************
797 template <typename T1>
798 reference emplace_back(const T1& value1)
799 {
800 T* p = storage.create<T>(T(value1));
801 lookup.push_back(p);
802 return back();
803 }
804
805 //*********************************************************************
809 //*********************************************************************
810 template <typename T1, typename T2>
811 reference emplace_back(const T1& value1, const T2& value2)
812 {
813 T* p = storage.create<T>(T(value1, value2));
814 lookup.push_back(p);
815 return back();
816 }
817
818 //*********************************************************************
822 //*********************************************************************
823 template <typename T1, typename T2, typename T3>
824 reference emplace_back(const T1& value1, const T2& value2, const T3& value3)
825 {
826 T* p = storage.create<T>(T(value1, value2, value3));
827 lookup.push_back(p);
828 return back();
829 }
830
831 //*********************************************************************
835 //*********************************************************************
836 template <typename T1, typename T2, typename T3, typename T4>
837 reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
838 {
839 T* p = storage.create<T>(T(value1, value2, value3, value4));
840 lookup.push_back(p);
841 return back();
842 }
843#endif
844
845 //*************************************************************************
847 //*************************************************************************
848 void pop_back()
849 {
850 ETL_ASSERT(!empty(), ETL_ERROR(vector_empty));
851
852 reference object = back();
853 storage.destroy<T>(etl::addressof(object));
854 lookup.pop_back();
855 }
856
857 //*********************************************************************
862 //*********************************************************************
863 iterator insert(const_iterator position, const_reference value)
864 {
865 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
866
867 T* p = storage.create<T>(T(value));
868 position = iterator(lookup.insert(position.lookup_itr, p));
869
870 return to_iterator(position);
871 }
872
873#if ETL_USING_CPP11
874 //*********************************************************************
879 //*********************************************************************
880 iterator insert(const_iterator position, rvalue_reference value)
881 {
882 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
883
884 T* p = storage.create<T>(T(etl::move(value)));
885 position = iterator(lookup.insert(position.lookup_itr, p));
886
887 return to_iterator(position);
888 }
889#endif
890
891 //*************************************************************************
893 //*************************************************************************
894#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
895 template <typename ... Args>
896 iterator emplace(iterator position, Args && ... args)
897 {
898 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
899
900 T* p = storage.create<T>(T(etl::forward<Args>(args)...));
901 position = iterator(lookup.insert(position.lookup_itr, p));
902
903 return position;
904 }
905#else
906 template <typename T1>
907 iterator emplace(iterator position, const T1& value1)
908 {
909 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
910
911 T* p = storage.create<T>(T(value1));
912 position = iterator(lookup.insert(position.lookup_itr, p));
913
914 return position;
915 }
916
917 template <typename T1, typename T2>
918 iterator emplace(iterator position, const T1& value1, const T2& value2)
919 {
920 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
921
922 T* p = storage.create<T>(T(value1, value2));
923 position = iterator(lookup.insert(position.lookup_itr, p));
924
925 return position;
926 }
927
928 template <typename T1, typename T2, typename T3>
929 iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3)
930 {
931 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
932
933 T* p = storage.create<T>(T(value1, value2, value3));
934 position = iterator(lookup.insert(position.lookup_itr, p));
935
936 return position;
937 }
938
939 template <typename T1, typename T2, typename T3, typename T4>
940 iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
941 {
942 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
943
944 T* p = storage.create<T>(T(value1, value2, value3, value4));
945 position = iterator(lookup.insert(position.lookup_itr, p));
946
947 return position;
948 }
949#endif
950
951 //*********************************************************************
957 //*********************************************************************
958 iterator insert(const_iterator position, size_t n, parameter_t value)
959 {
960 ETL_ASSERT((size() + n) <= capacity(), ETL_ERROR(vector_full));
961
962 iterator position_ = to_iterator(position);
963
964 // Make space for the new lookup pointers.
965 typename etl::ivector<T*>::iterator lookup_itr = position_.lookup_itr;
966 lookup.insert(lookup_itr, n, ETL_NULLPTR);
967
968 while (n-- != 0U)
969 {
970 T* p = storage.create<T>(value);
971 *lookup_itr++ = p;
972 }
973
974 return position_;
975 }
976
977 //*********************************************************************
983 //*********************************************************************
984 template <class TIterator>
985 iterator insert(const_iterator position, TIterator first, TIterator last)
986 {
987 size_t count = size_t(etl::distance(first, last));
988
989 ETL_ASSERT((size() + count) <= capacity(), ETL_ERROR(vector_full));
990
991 // Make space for the new lookup pointers.
992 typename etl::ivector<T*>::iterator lookup_itr = to_iterator(position).lookup_itr;
993 lookup.insert(lookup_itr, count, ETL_NULLPTR);
994
995 while (first != last)
996 {
997 T* p = storage.create<T>(*first);
998 *lookup_itr++ = p;
999 ++first;
1000 }
1001
1002 return to_iterator(position);
1003 }
1004
1005 //*********************************************************************
1009 //*********************************************************************
1011 {
1012 storage.destroy<T>(etl::addressof(*i_element));
1013
1014 return iterator(lookup.erase(i_element.lookup_itr));
1015 }
1016
1017 //*********************************************************************
1021 //*********************************************************************
1023 {
1024 storage.destroy<T>(etl::addressof(*i_element));
1025
1026 return iterator(lookup.erase(i_element.lookup_itr));
1027 }
1028
1029 //*********************************************************************
1036 //*********************************************************************
1038 {
1039 iterator element = to_iterator(first);
1040
1041 while (element != last)
1042 {
1043 storage.destroy<T>(etl::addressof(*element));
1044 ++element;
1045 }
1046
1047 lookup.erase(first.lookup_itr, last.lookup_itr);
1048
1049 return to_iterator(last);
1050 }
1051
1052 //*************************************************************************
1054 //*************************************************************************
1056 {
1057 if (&rhs != this)
1058 {
1059 assign(rhs.cbegin(), rhs.cend());
1060 }
1061
1062 return *this;
1063 }
1064
1065#if ETL_USING_CPP11
1066 //*************************************************************************
1068 //*************************************************************************
1070 {
1071 if (&rhs != this)
1072 {
1073 clear();
1074 iterator itr = rhs.begin();
1075 while (itr != rhs.end())
1076 {
1077 push_back(etl::move(*itr));
1078 ++itr;
1079 }
1080
1081 rhs.initialise();
1082 }
1083
1084 return *this;
1085 }
1086#endif
1087
1088 //*************************************************************************
1091 //*************************************************************************
1092 size_type size() const
1093 {
1094 return lookup.size();
1095 }
1096
1097 //*************************************************************************
1100 //*************************************************************************
1101 size_type capacity() const
1102 {
1103 return lookup.capacity();
1104 }
1105
1106 //*************************************************************************
1109 //*************************************************************************
1110 bool empty() const
1111 {
1112 return lookup.empty();
1113 }
1114
1115 //*************************************************************************
1118 //*************************************************************************
1119 bool full() const
1120 {
1121 return lookup.full();
1122 }
1123
1124 //*************************************************************************
1127 //*************************************************************************
1128 size_type max_size() const
1129 {
1130 return lookup.max_size();
1131 }
1132
1133 //*************************************************************************
1136 //*************************************************************************
1137 size_type available() const
1138 {
1139 return lookup.available();
1140 }
1141
1142 protected:
1143
1144 //*********************************************************************
1146 //*********************************************************************
1148 : lookup(lookup_)
1149 , storage(storage_)
1150 {
1151 }
1152
1153 //*********************************************************************
1155 //*********************************************************************
1157 {
1158 iterator itr = begin();
1159
1160 while (itr != end())
1161 {
1162 storage.destroy<T>(etl::addressof(*itr));
1163 ++itr;
1164 }
1165
1166 lookup.clear();
1167 }
1168
1169#if ETL_USING_CPP11
1170 //*********************************************************************
1172 //*********************************************************************
1173 void move_container(iindirect_vector&& other)
1174 {
1175 if (this != &other)
1176 {
1177 initialise();
1178
1179 typename iindirect_vector<T>::iterator itr = other.begin();
1180
1181 while (itr != other.end())
1182 {
1183 push_back(etl::move(*itr));
1184 ++itr;
1185 }
1186
1187 other.initialise();
1188 }
1189 }
1190#endif
1191
1192 etl::ivector<T*>& lookup;
1193 etl::ipool& storage;
1194
1195 private:
1196
1197 // Disable copy construction.
1198 iindirect_vector(const iindirect_vector&) ETL_DELETE;
1199
1200 //*************************************************************************
1202 //*************************************************************************
1203#if defined(ETL_POLYMORPHIC_INDIRECT_VECTOR) || defined(ETL_POLYMORPHIC_CONTAINERS)
1204 public:
1205 virtual
1206#else
1207 protected:
1208#endif
1210 {
1211 }
1212
1213 protected:
1214
1215 //*************************************************************************
1217 //*************************************************************************
1219 {
1220 return iterator(const_cast<indirect_iterator>(itr.lookup_itr));
1221 }
1222 };
1223
1224 //***************************************************************************
1230 //***************************************************************************
1231 template <typename T>
1233 {
1234 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1235 }
1236
1237 //***************************************************************************
1243 //***************************************************************************
1244 template <typename T>
1246 {
1247 return !(lhs == rhs);
1248 }
1249
1250 //***************************************************************************
1256 //***************************************************************************
1257 template <typename T>
1259 {
1260 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1261 }
1262
1263 //***************************************************************************
1269 //***************************************************************************
1270 template <typename T>
1272 {
1273 return (rhs < lhs);
1274 }
1275
1276 //***************************************************************************
1282 //***************************************************************************
1283 template <typename T>
1285 {
1286 return !(lhs > rhs);
1287 }
1288
1289 //***************************************************************************
1295 //***************************************************************************
1296 template <typename T>
1298 {
1299 return !(lhs < rhs);
1300 }
1301
1302 //***************************************************************************
1307 //***************************************************************************
1308 template <typename T, const size_t MAX_SIZE_>
1310 {
1311 public:
1312
1313 ETL_STATIC_ASSERT((MAX_SIZE_ > 0U), "Zero capacity etl::indirect_vector is not valid");
1314
1315 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1316
1317 //*************************************************************************
1319 //*************************************************************************
1321 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1322 {
1323 }
1324
1325 //*************************************************************************
1328 //*************************************************************************
1329 explicit indirect_vector(size_t initial_size)
1330 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1331 {
1332 this->resize(initial_size);
1333 }
1334
1335 //*************************************************************************
1339 //*************************************************************************
1340 indirect_vector(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value)
1341 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1342 {
1343 this->resize(initial_size, value);
1344 }
1345
1346 //*************************************************************************
1351 //*************************************************************************
1352 template <typename TIterator>
1353 indirect_vector(TIterator first, TIterator last)
1354 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1355 {
1356 this->assign(first, last);
1357 }
1358
1359#if ETL_HAS_INITIALIZER_LIST
1360 //*************************************************************************
1362 //*************************************************************************
1363 indirect_vector(std::initializer_list<T> init)
1364 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1365 {
1366 this->assign(init.begin(), init.end());
1367 }
1368#endif
1369
1370 //*************************************************************************
1372 //*************************************************************************
1374 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1375 {
1376 this->assign(other.begin(), other.end());
1377 }
1378
1379 //*************************************************************************
1381 //*************************************************************************
1383 {
1384 if (&rhs != this)
1385 {
1386 this->assign(rhs.cbegin(), rhs.cend());
1387 }
1388
1389 return *this;
1390 }
1391
1392#if ETL_USING_CPP11
1393 //*************************************************************************
1395 //*************************************************************************
1397 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1398 {
1399 this->move_container(etl::move(other));
1400 }
1401
1402 //*************************************************************************
1404 //*************************************************************************
1406 {
1407 this->move_container(etl::move(rhs));
1408
1409 return *this;
1410 }
1411#endif
1412
1413 //*************************************************************************
1415 //*************************************************************************
1417 {
1418 this->clear();
1419 }
1420
1421 private:
1422
1423 etl::vector<T*, MAX_SIZE> lookup_vector;
1424 etl::pool<T, MAX_SIZE> storage_pool;
1425 };
1426
1427 template <typename T, const size_t MAX_SIZE_>
1428 ETL_CONSTANT size_t indirect_vector<T, MAX_SIZE_>::MAX_SIZE;
1429
1430 //*************************************************************************
1432 //*************************************************************************
1433#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1434 template <typename T, typename... Ts>
1435 indirect_vector(T, Ts...)
1436 ->indirect_vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
1437#endif
1438
1439 //*************************************************************************
1441 //*************************************************************************
1442#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1443 template <typename... T>
1444 constexpr auto make_indirect_vector(T&&... t) -> etl::indirect_vector<typename etl::common_type_t<T...>, sizeof...(T)>
1445 {
1446 return { { etl::forward<T>(t)... } };
1447 }
1448#endif
1449
1450 //***************************************************************************
1455 //***************************************************************************
1456 template <typename T>
1458 {
1459 public:
1460
1461 //*************************************************************************
1463 //*************************************************************************
1465 : etl::iindirect_vector<T>(lookup_, pool_)
1466 {
1467 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1468 }
1469
1470 //*************************************************************************
1473 //*************************************************************************
1474 explicit indirect_vector_ext(size_t initial_size, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1475 : etl::iindirect_vector<T>(lookup_, pool_)
1476 {
1477 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1478 this->resize(initial_size);
1479 }
1480
1481 //*************************************************************************
1485 //*************************************************************************
1486 indirect_vector_ext(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1487 : etl::iindirect_vector<T>(lookup_, pool_)
1488 {
1489 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1490 this->resize(initial_size, value);
1491 }
1492
1493 //*************************************************************************
1498 //*************************************************************************
1499 template <typename TIterator>
1500 indirect_vector_ext(TIterator first, TIterator last, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1501 : etl::iindirect_vector<T>(lookup_, pool_)
1502 {
1503 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1504 this->assign(first, last);
1505 }
1506
1507#if ETL_HAS_INITIALIZER_LIST
1508 //*************************************************************************
1510 //*************************************************************************
1511 indirect_vector_ext(std::initializer_list<T> init, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1512 : etl::iindirect_vector<T>(lookup_, pool_)
1513 {
1514 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1515 this->assign(init.begin(), init.end());
1516 }
1517#endif
1518
1519 //*************************************************************************
1521 //*************************************************************************
1523 : etl::iindirect_vector<T>(lookup_, pool_)
1524 {
1525 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1526 this->assign(other.begin(), other.end());
1527 }
1528
1529 //*************************************************************************
1531 //*************************************************************************
1533
1534 //*************************************************************************
1536 //*************************************************************************
1538 {
1539 if (&rhs != this)
1540 {
1541 this->assign(rhs.cbegin(), rhs.cend());
1542 }
1543
1544 return *this;
1545 }
1546
1547#if ETL_USING_CPP11
1548 //*************************************************************************
1550 //*************************************************************************
1552 : etl::iindirect_vector<T>(lookup_, pool_)
1553 {
1554 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1555 this->move_container(etl::move(other));
1556 }
1557
1558 //*************************************************************************
1560 //*************************************************************************
1561 indirect_vector_ext(indirect_vector_ext&& other) ETL_DELETE;
1562
1563 //*************************************************************************
1565 //*************************************************************************
1567 {
1568 this->move_container(etl::move(rhs));
1569
1570 return *this;
1571 }
1572#endif
1573
1574 //*************************************************************************
1576 //*************************************************************************
1578 {
1579 this->clear();
1580 }
1581 };
1582}
1583
1584#endif
1585
Binary function adaptor.
Definition: indirect_vector.h:135
const_iterator.
Definition: indirect_vector.h:308
iterator.
Definition: indirect_vector.h:176
Unary function adaptor.
Definition: indirect_vector.h:95
#define ETL_ASSERT(b, e)
Definition: error_handler.h:316
reference at(size_t i)
Definition: indirect_vector.h:634
const_reverse_iterator crend() const
Definition: indirect_vector.h:549
void resize(size_t new_size)
Definition: indirect_vector.h:560
iterator to_iterator(const_iterator itr) const
Convert from const_iterator to iterator.
Definition: indirect_vector.h:1218
void clear()
Clears the indirect_vector.
Definition: indirect_vector.h:735
indirect_vector_ext & operator=(const indirect_vector_ext &rhs)
Assignment operator.
Definition: indirect_vector.h:1537
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:1486
~indirect_vector()
Destructor.
Definition: indirect_vector.h:1416
void assign(TIterator first, TIterator last)
Definition: indirect_vector.h:694
size_type available() const
Definition: indirect_vector.h:1137
indirect_vector_ext(const indirect_vector_ext &other) ETL_DELETE
Copy constructor (Deleted)
reference back()
Definition: indirect_vector.h:672
iindirect_vector & operator=(const iindirect_vector &rhs)
Assignment operator.
Definition: indirect_vector.h:1055
iterator end()
Definition: indirect_vector.h:468
const_iterator end() const
Definition: indirect_vector.h:477
iterator emplace(iterator position, const T1 &value1)
Emplaces a value to the vector at the specified position.
Definition: indirect_vector.h:907
indirect_vector_ext(size_t initial_size, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Definition: indirect_vector.h:1474
bool empty() const
Definition: indirect_vector.h:1110
indirect_vector(size_t initial_size, typename etl::iindirect_vector< T >::parameter_t value)
Definition: indirect_vector.h:1340
reference emplace_back(const T1 &value1, const T2 &value2, const T3 &value3)
Definition: indirect_vector.h:824
reverse_iterator rend()
Definition: indirect_vector.h:522
indirect_vector_ext(const indirect_vector_ext &other, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Construct a copy.
Definition: indirect_vector.h:1522
reference emplace_back(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition: indirect_vector.h:837
iterator erase(const_iterator i_element)
Definition: indirect_vector.h:1022
void pop_back()
Removes an element from the end of the indirect_vector.
Definition: indirect_vector.h:848
bool full() const
Definition: indirect_vector.h:1119
size_type size() const
Definition: indirect_vector.h:1092
void reserve(size_t)
Definition: indirect_vector.h:604
const_iterator cend() const
Definition: indirect_vector.h:495
void assign(size_t n, parameter_t value)
Definition: indirect_vector.h:719
indirect_vector(const indirect_vector &other)
Copy constructor.
Definition: indirect_vector.h:1373
const_iterator cbegin() const
Definition: indirect_vector.h:486
const_reference back() const
Definition: indirect_vector.h:681
const_reference front() const
Definition: indirect_vector.h:663
indirect_vector_ext(etl::ivector< T * > &lookup_, etl::ipool &pool_)
Constructor.
Definition: indirect_vector.h:1464
indirect_vector(size_t initial_size)
Definition: indirect_vector.h:1329
~iindirect_vector()
Destructor.
Definition: indirect_vector.h:1209
indirect_vector()
Constructor.
Definition: indirect_vector.h:1320
size_type max_size() const
Definition: indirect_vector.h:1128
const_iterator begin() const
Definition: indirect_vector.h:459
void initialise()
Initialise the indirect_vector.
Definition: indirect_vector.h:1156
~indirect_vector_ext()
Destructor.
Definition: indirect_vector.h:1577
const_reference at(size_t i) const
Definition: indirect_vector.h:645
reference emplace_back(const T1 &value1, const T2 &value2)
Definition: indirect_vector.h:811
iterator begin()
Definition: indirect_vector.h:450
void fill(const T &value)
Fills the buffer.
Definition: indirect_vector.h:743
iterator insert(const_iterator position, TIterator first, TIterator last)
Definition: indirect_vector.h:985
const_reverse_iterator rend() const
Definition: indirect_vector.h:531
const_reverse_iterator rbegin() const
Definition: indirect_vector.h:513
void resize(size_t new_size, const_reference value)
Definition: indirect_vector.h:572
iterator erase(iterator i_element)
Definition: indirect_vector.h:1010
indirect_vector(TIterator first, TIterator last)
Definition: indirect_vector.h:1353
reverse_iterator rbegin()
Definition: indirect_vector.h:504
const_reverse_iterator crbegin() const
Definition: indirect_vector.h:540
indirect_vector & operator=(const indirect_vector &rhs)
Assignment operator.
Definition: indirect_vector.h:1382
iterator erase(const_iterator first, const_iterator last)
Definition: indirect_vector.h:1037
reference emplace_back(const T1 &value1)
Definition: indirect_vector.h:798
reference front()
Definition: indirect_vector.h:654
indirect_vector_ext(TIterator first, TIterator last, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Definition: indirect_vector.h:1500
size_type capacity() const
Definition: indirect_vector.h:1101
iindirect_vector(etl::ivector< T * > &lookup_, etl::ipool &storage_)
Constructor.
Definition: indirect_vector.h:1147
reference operator[](size_t i)
Definition: indirect_vector.h:613
void push_back(const_reference value)
Definition: indirect_vector.h:753
iterator insert(const_iterator position, const_reference value)
Definition: indirect_vector.h:863
iterator insert(const_iterator position, size_t n, parameter_t value)
Definition: indirect_vector.h:958
Definition: indirect_vector.h:72
Definition: indirect_vector.h:1310
Template deduction guides.
Definition: indirect_vector.h:1458
bool operator==(const etl::iindirect_vector< T > &lhs, const etl::iindirect_vector< T > &rhs)
Definition: indirect_vector.h:1232
bool operator<(const etl::iindirect_vector< T > &lhs, const etl::iindirect_vector< T > &rhs)
Definition: indirect_vector.h:1258
bool operator!=(const etl::iindirect_vector< T > &lhs, const etl::iindirect_vector< T > &rhs)
Definition: indirect_vector.h:1245
ETL_CONSTEXPR17 T * addressof(T &t)
Definition: addressof.h:51
size_t capacity() const
Returns the maximum number of items in the pool.
Definition: ipool.h:277
T * create()
Definition: ipool.h:130
void destroy(const T *const p_object)
Definition: ipool.h:222
Definition: ipool.h:102
is_same
Definition: type_traits_generator.h:1041
remove_cv
Definition: type_traits_generator.h:968
bool full() const
Definition: pvoidvector.h:636
reference front()
Definition: ivectorpointer.h:260
void push_back(parameter_t value)
Definition: ivectorpointer.h:347
size_type max_size() const
Definition: vector_base.h:140
size_type capacity() const
Definition: vector_base.h:131
void pop_back()
Definition: ivectorpointer.h:368
bool empty() const
Definition: pvoidvector.h:627
reference back()
Definition: ivectorpointer.h:278
const_iterator cend() const
Definition: ivectorpointer.h:123
reference at(size_t i)
Definition: ivectorpointer.h:240
iterator erase(iterator i_element)
Definition: ivectorpointer.h:422
iterator end()
Definition: ivectorpointer.h:96
iterator begin()
Definition: ivectorpointer.h:78
iterator insert(const_iterator position, parameter_t value)
Definition: ivectorpointer.h:379
size_t available() const
Definition: pvoidvector.h:645
size_type size() const
Definition: pvoidvector.h:618
void clear()
Clears the vector.
Definition: ivectorpointer.h:337
Definition: indirect_vector.h:56
Definition: vector.h:72
Definition: ivectorpointer.h:49
Definition: vector_base.h:80
Definition: vector_base.h:52
Definition: vector_base.h:66
bitset_ext
Definition: absolute.h:38
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator-(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition: circular_iterator.h:672
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:684
etl::byte operator&(etl::byte lhs, etl::byte rhs)
And.
Definition: byte.h:273
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:696
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator+(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition: circular_iterator.h:659
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:657
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:672
Definition: functional.h:125
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
Definition: functional.h:117