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 //***************************************************************************
56 {
57 public:
58
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
100 {
101 }
102
103 TReturnType operator()(const_pointer indirect_itr)
104 {
106 }
107
109 };
110
111 //*************************************************************************
112 template <typename TUnaryFunction>
114 {
115 public:
116
119 {
120 }
121
122 void operator()(const_pointer indirect_itr)
123 {
125 }
126
128 };
129
130 //*************************************************************************
132 //*************************************************************************
133 template <typename TBinaryFunction, typename TReturnType = void>
135 {
136 public:
137
140 {
141 }
142
143 TReturnType operator()(const_pointer indirect_itr_lhs,
144 const_pointer indirect_itr_rhs)
145 {
147 }
148
150 };
151
152 //*************************************************************************
153 template <typename TBinaryFunction>
155 {
156 public:
157
160 {
161 }
162
163 void operator()(const_pointer indirect_itr_lhs,
164 const_pointer indirect_itr_rhs)
165 {
167 }
168
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
315 : lookup_itr()
316 {
317 }
318
320 : lookup_itr(other.lookup_itr)
321 {
322 }
323
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#if defined(ETL_CHECK_PUSH_POP)
761 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
762#endif
763 T* p = storage.create<T>(value);
764 lookup.push_back(p);
765 }
766
767#if ETL_USING_CPP11
768 //*********************************************************************
772 //*********************************************************************
773 void push_back(rvalue_reference value)
774 {
775#if defined(ETL_CHECK_PUSH_POP)
776 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
777#endif
778 T* p = storage.create<T>(etl::move(value));
779 lookup.push_back(p);
780 }
781#endif
782
783#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION)
784 //*********************************************************************
788 //*********************************************************************
789 template <typename ... Args>
790 reference emplace_back(Args && ... args)
791 {
792 T* p = storage.create<T>(etl::forward<Args>(args)...);
793 lookup.push_back(p);
794 return back();
795 }
796#else
797 //*********************************************************************
801 //*********************************************************************
802 reference emplace_back()
803 {
804 T* p = storage.create<T>(T());
805 lookup.push_back(p);
806 return back();
807 }
808
809 //*********************************************************************
813 //*********************************************************************
814 template <typename T1>
815 reference emplace_back(const T1& value1)
816 {
817 T* p = storage.create<T>(T(value1));
818 lookup.push_back(p);
819 return back();
820 }
821
822 //*********************************************************************
826 //*********************************************************************
827 template <typename T1, typename T2>
828 reference emplace_back(const T1& value1, const T2& value2)
829 {
830 T* p = storage.create<T>(T(value1, value2));
831 lookup.push_back(p);
832 return back();
833 }
834
835 //*********************************************************************
839 //*********************************************************************
840 template <typename T1, typename T2, typename T3>
841 reference emplace_back(const T1& value1, const T2& value2, const T3& value3)
842 {
843 T* p = storage.create<T>(T(value1, value2, value3));
844 lookup.push_back(p);
845 return back();
846 }
847
848 //*********************************************************************
852 //*********************************************************************
853 template <typename T1, typename T2, typename T3, typename T4>
854 reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
855 {
856 T* p = storage.create<T>(T(value1, value2, value3, value4));
857 lookup.push_back(p);
858 return back();
859 }
860#endif
861
862 //*************************************************************************
864 //*************************************************************************
865 void pop_back()
866 {
867 ETL_ASSERT(!empty(), ETL_ERROR(vector_empty));
868
869 reference object = back();
870 storage.destroy<T>(etl::addressof(object));
871 lookup.pop_back();
872 }
873
874 //*********************************************************************
879 //*********************************************************************
880 iterator insert(const_iterator position, const_reference value)
881 {
882 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
883
884 T* p = storage.create<T>(T(value));
885 position = iterator(lookup.insert(position.lookup_itr, p));
886
887 return to_iterator(position);
888 }
889
890#if ETL_USING_CPP11
891 //*********************************************************************
896 //*********************************************************************
897 iterator insert(const_iterator position, rvalue_reference value)
898 {
899 ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
900
901 T* p = storage.create<T>(T(etl::move(value)));
902 position = iterator(lookup.insert(position.lookup_itr, p));
903
904 return to_iterator(position);
905 }
906#endif
907
908 //*************************************************************************
910 //*************************************************************************
911#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION)
912 template <typename ... Args>
913 iterator emplace(iterator position, Args && ... args)
914 {
915 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
916
917 T* p = storage.create<T>(T(etl::forward<Args>(args)...));
918 position = iterator(lookup.insert(position.lookup_itr, p));
919
920 return position;
921 }
922#else
924 {
925 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
926
927 T* p = storage.create<T>(T());
928 position = iterator(lookup.insert(position.lookup_itr, p));
929
930 return position;
931 }
932
933 template <typename T1>
934 iterator emplace(iterator position, const T1& value1)
935 {
936 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
937
938 T* p = storage.create<T>(T(value1));
939 position = iterator(lookup.insert(position.lookup_itr, p));
940
941 return position;
942 }
943
944 template <typename T1, typename T2>
945 iterator emplace(iterator position, const T1& value1, const T2& value2)
946 {
947 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
948
949 T* p = storage.create<T>(T(value1, value2));
950 position = iterator(lookup.insert(position.lookup_itr, p));
951
952 return position;
953 }
954
955 template <typename T1, typename T2, typename T3>
956 iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3)
957 {
958 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
959
960 T* p = storage.create<T>(T(value1, value2, value3));
961 position = iterator(lookup.insert(position.lookup_itr, p));
962
963 return position;
964 }
965
966 template <typename T1, typename T2, typename T3, typename T4>
967 iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
968 {
969 ETL_ASSERT(!full(), ETL_ERROR(vector_full));
970
971 T* p = storage.create<T>(T(value1, value2, value3, value4));
972 position = iterator(lookup.insert(position.lookup_itr, p));
973
974 return position;
975 }
976#endif
977
978 //*********************************************************************
984 //*********************************************************************
985 iterator insert(const_iterator position, size_t n, parameter_t value)
986 {
987 ETL_ASSERT((size() + n) <= capacity(), ETL_ERROR(vector_full));
988
989 iterator position_ = to_iterator(position);
990
991 // Make space for the new lookup pointers.
992 typename etl::ivector<T*>::iterator lookup_itr = position_.lookup_itr;
993 lookup.insert(lookup_itr, n, ETL_NULLPTR);
994
995 while (n-- != 0U)
996 {
997 T* p = storage.create<T>(value);
998 *lookup_itr++ = p;
999 }
1000
1001 return position_;
1002 }
1003
1004 //*********************************************************************
1010 //*********************************************************************
1011 template <class TIterator>
1013 {
1014 size_t count = size_t(etl::distance(first, last));
1015
1016 ETL_ASSERT((size() + count) <= capacity(), ETL_ERROR(vector_full));
1017
1018 // Make space for the new lookup pointers.
1019 typename etl::ivector<T*>::iterator lookup_itr = to_iterator(position).lookup_itr;
1020 lookup.insert(lookup_itr, count, ETL_NULLPTR);
1021
1022 while (first != last)
1023 {
1024 T* p = storage.create<T>(*first);
1025 *lookup_itr++ = p;
1026 ++first;
1027 }
1028
1029 return to_iterator(position);
1030 }
1031
1032 //*********************************************************************
1036 //*********************************************************************
1038 {
1039 storage.destroy<T>(etl::addressof(*i_element));
1040
1041 return iterator(lookup.erase(i_element.lookup_itr));
1042 }
1043
1044 //*********************************************************************
1048 //*********************************************************************
1050 {
1051 storage.destroy<T>(etl::addressof(*i_element));
1052
1053 return iterator(lookup.erase(i_element.lookup_itr));
1054 }
1055
1056 //*********************************************************************
1063 //*********************************************************************
1065 {
1066 iterator element = to_iterator(first);
1067
1068 while (element != last)
1069 {
1070 storage.destroy<T>(etl::addressof(*element));
1071 ++element;
1072 }
1073
1074 lookup.erase(first.lookup_itr, last.lookup_itr);
1075
1076 return to_iterator(last);
1077 }
1078
1079 //*************************************************************************
1081 //*************************************************************************
1083 {
1084 if (&rhs != this)
1085 {
1086 assign(rhs.cbegin(), rhs.cend());
1087 }
1088
1089 return *this;
1090 }
1091
1092#if ETL_USING_CPP11
1093 //*************************************************************************
1095 //*************************************************************************
1097 {
1098 if (&rhs != this)
1099 {
1100 clear();
1101 iterator itr = rhs.begin();
1102 while (itr != rhs.end())
1103 {
1104 push_back(etl::move(*itr));
1105 ++itr;
1106 }
1107
1108 rhs.initialise();
1109 }
1110
1111 return *this;
1112 }
1113#endif
1114
1115 //*************************************************************************
1118 //*************************************************************************
1119 size_type size() const
1120 {
1121 return lookup.size();
1122 }
1123
1124 //*************************************************************************
1127 //*************************************************************************
1128 size_type capacity() const
1129 {
1130 return lookup.capacity();
1131 }
1132
1133 //*************************************************************************
1136 //*************************************************************************
1137 bool empty() const
1138 {
1139 return lookup.empty();
1140 }
1141
1142 //*************************************************************************
1145 //*************************************************************************
1146 bool full() const
1147 {
1148 return lookup.full();
1149 }
1150
1151 //*************************************************************************
1154 //*************************************************************************
1155 size_type max_size() const
1156 {
1157 return lookup.max_size();
1158 }
1159
1160 //*************************************************************************
1163 //*************************************************************************
1164 size_type available() const
1165 {
1166 return lookup.available();
1167 }
1168
1169 protected:
1170
1171 //*********************************************************************
1173 //*********************************************************************
1175 : lookup(lookup_)
1176 , storage(storage_)
1177 {
1178 }
1179
1180 //*********************************************************************
1182 //*********************************************************************
1184 {
1185 if ETL_IF_CONSTEXPR(etl::is_trivially_destructible<T>::value)
1186 {
1187 storage.release_all();
1188 }
1189 else
1190 {
1191 iterator itr = begin();
1192
1193 while (itr != end())
1194 {
1195 storage.destroy<T>(etl::addressof(*itr));
1196 ++itr;
1197 }
1198 }
1199
1200 lookup.clear();
1201 }
1202
1203#if ETL_USING_CPP11
1204 //*********************************************************************
1206 //*********************************************************************
1208 {
1209 if (this != &other)
1210 {
1211 initialise();
1212
1213 typename iindirect_vector<T>::iterator itr = other.begin();
1214
1215 while (itr != other.end())
1216 {
1217 push_back(etl::move(*itr));
1218 ++itr;
1219 }
1220
1221 other.initialise();
1222 }
1223 }
1224#endif
1225
1226 etl::ivector<T*>& lookup;
1227 etl::ipool& storage;
1228
1229 private:
1230
1231 // Disable copy construction.
1232 iindirect_vector(const iindirect_vector&) ETL_DELETE;
1233
1234 //*************************************************************************
1236 //*************************************************************************
1237#if defined(ETL_POLYMORPHIC_INDIRECT_VECTOR) || defined(ETL_POLYMORPHIC_CONTAINERS)
1238 public:
1239 virtual
1240#else
1241 protected:
1242#endif
1244 {
1245 }
1246
1247 protected:
1248
1249 //*************************************************************************
1251 //*************************************************************************
1253 {
1254 return iterator(const_cast<indirect_iterator>(itr.lookup_itr));
1255 }
1256 };
1257
1258 //***************************************************************************
1264 //***************************************************************************
1265 template <typename T>
1267 {
1268 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1269 }
1270
1271 //***************************************************************************
1277 //***************************************************************************
1278 template <typename T>
1280 {
1281 return !(lhs == rhs);
1282 }
1283
1284 //***************************************************************************
1290 //***************************************************************************
1291 template <typename T>
1293 {
1294 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1295 }
1296
1297 //***************************************************************************
1303 //***************************************************************************
1304 template <typename T>
1306 {
1307 return (rhs < lhs);
1308 }
1309
1310 //***************************************************************************
1316 //***************************************************************************
1317 template <typename T>
1319 {
1320 return !(lhs > rhs);
1321 }
1322
1323 //***************************************************************************
1329 //***************************************************************************
1330 template <typename T>
1332 {
1333 return !(lhs < rhs);
1334 }
1335
1336 //***************************************************************************
1341 //***************************************************************************
1342 template <typename T, const size_t MAX_SIZE_>
1344 {
1345 public:
1346
1347 ETL_STATIC_ASSERT((MAX_SIZE_ > 0U), "Zero capacity etl::indirect_vector is not valid");
1348
1349 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1350
1351 //*************************************************************************
1353 //*************************************************************************
1355 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1356 {
1357 }
1358
1359 //*************************************************************************
1362 //*************************************************************************
1364 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1365 {
1366 this->resize(initial_size);
1367 }
1368
1369 //*************************************************************************
1373 //*************************************************************************
1374 indirect_vector(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value)
1375 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1376 {
1377 this->resize(initial_size, value);
1378 }
1379
1380 //*************************************************************************
1385 //*************************************************************************
1386 template <typename TIterator>
1388 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1389 {
1390 this->assign(first, last);
1391 }
1392
1393#if ETL_HAS_INITIALIZER_LIST
1394 //*************************************************************************
1396 //*************************************************************************
1397 indirect_vector(std::initializer_list<T> init)
1398 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1399 {
1400 this->assign(init.begin(), init.end());
1401 }
1402#endif
1403
1404 //*************************************************************************
1406 //*************************************************************************
1408 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1409 {
1410 this->assign(other.begin(), other.end());
1411 }
1412
1413 //*************************************************************************
1415 //*************************************************************************
1417 {
1418 if (&rhs != this)
1419 {
1420 this->assign(rhs.cbegin(), rhs.cend());
1421 }
1422
1423 return *this;
1424 }
1425
1426#if ETL_USING_CPP11
1427 //*************************************************************************
1429 //*************************************************************************
1431 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1432 {
1433 this->move_container(etl::move(other));
1434 }
1435
1436 //*************************************************************************
1438 //*************************************************************************
1440 {
1441 this->move_container(etl::move(rhs));
1442
1443 return *this;
1444 }
1445#endif
1446
1447 //*************************************************************************
1449 //*************************************************************************
1451 {
1452 this->clear();
1453 }
1454
1455 private:
1456
1457 etl::vector<T*, MAX_SIZE> lookup_vector;
1458 etl::pool<T, MAX_SIZE> storage_pool;
1459 };
1460
1461 template <typename T, const size_t MAX_SIZE_>
1462 ETL_CONSTANT size_t indirect_vector<T, MAX_SIZE_>::MAX_SIZE;
1463
1464 //*************************************************************************
1466 //*************************************************************************
1467#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1468 template <typename T, typename... Ts>
1469 indirect_vector(T, Ts...)
1470 ->indirect_vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
1471#endif
1472
1473 //*************************************************************************
1475 //*************************************************************************
1476#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1477 template <typename... T>
1478 constexpr auto make_indirect_vector(T&&... t) -> etl::indirect_vector<typename etl::common_type_t<T...>, sizeof...(T)>
1479 {
1480 return { etl::forward<T>(t)... };
1481 }
1482#endif
1483
1484 //***************************************************************************
1489 //***************************************************************************
1490 template <typename T>
1492 {
1493 public:
1494
1495 //*************************************************************************
1497 //*************************************************************************
1503
1504 //*************************************************************************
1507 //*************************************************************************
1510 {
1511 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1512 this->resize(initial_size);
1513 }
1514
1515 //*************************************************************************
1519 //*************************************************************************
1520 indirect_vector_ext(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1522 {
1523 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1524 this->resize(initial_size, value);
1525 }
1526
1527 //*************************************************************************
1532 //*************************************************************************
1533 template <typename TIterator>
1536 {
1537 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1538 this->assign(first, last);
1539 }
1540
1541#if ETL_HAS_INITIALIZER_LIST
1542 //*************************************************************************
1544 //*************************************************************************
1545 indirect_vector_ext(std::initializer_list<T> init, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1547 {
1548 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1549 this->assign(init.begin(), init.end());
1550 }
1551#endif
1552
1553 //*************************************************************************
1555 //*************************************************************************
1558 {
1559 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1560 this->assign(other.begin(), other.end());
1561 }
1562
1563 //*************************************************************************
1565 //*************************************************************************
1567
1568 //*************************************************************************
1570 //*************************************************************************
1572 {
1573 if (&rhs != this)
1574 {
1575 this->assign(rhs.cbegin(), rhs.cend());
1576 }
1577
1578 return *this;
1579 }
1580
1581#if ETL_USING_CPP11
1582 //*************************************************************************
1584 //*************************************************************************
1587 {
1588 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1589 this->move_container(etl::move(other));
1590 }
1591
1592 //*************************************************************************
1594 //*************************************************************************
1595 indirect_vector_ext(indirect_vector_ext&& other) ETL_DELETE;
1596
1597 //*************************************************************************
1599 //*************************************************************************
1600 indirect_vector_ext& operator = (indirect_vector_ext&& rhs)
1601 {
1602 this->move_container(etl::move(rhs));
1603
1604 return *this;
1605 }
1606#endif
1607
1608 //*************************************************************************
1610 //*************************************************************************
1612 {
1613 this->clear();
1614 }
1615 };
1616}
1617
1618#endif
1619
Binary function adaptor.
Definition indirect_vector.h:135
const_iterator.
Definition indirect_vector.h:309
iterator.
Definition indirect_vector.h:176
Unary function adaptor.
Definition indirect_vector.h:95
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:974
#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:1252
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:1571
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:1520
~indirect_vector()
Destructor.
Definition indirect_vector.h:1450
void assign(TIterator first, TIterator last)
Definition indirect_vector.h:699
size_type available() const
Definition indirect_vector.h:1164
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:1082
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:1508
bool empty() const
Definition indirect_vector.h:1137
indirect_vector(size_t initial_size, typename etl::iindirect_vector< T >::parameter_t value)
Definition indirect_vector.h:1374
reference emplace_back(const T1 &value1, const T2 &value2, const T3 &value3)
Definition indirect_vector.h:841
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:1556
reference emplace_back(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition indirect_vector.h:854
iterator erase(const_iterator i_element)
Definition indirect_vector.h:1049
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:865
bool full() const
Definition indirect_vector.h:1146
size_type size() const
Definition indirect_vector.h:1119
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:923
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:1407
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:1498
indirect_vector(size_t initial_size)
Definition indirect_vector.h:1363
~iindirect_vector()
Destructor.
Definition indirect_vector.h:1243
indirect_vector()
Constructor.
Definition indirect_vector.h:1354
size_type max_size() const
Definition indirect_vector.h:1155
const_iterator begin() const
Definition indirect_vector.h:461
void initialise()
Initialise the indirect_vector.
Definition indirect_vector.h:1183
~indirect_vector_ext()
Destructor.
Definition indirect_vector.h:1611
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:828
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:1012
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:1037
indirect_vector(TIterator first, TIterator last)
Definition indirect_vector.h:1387
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:1416
iterator erase(const_iterator first, const_iterator last)
Definition indirect_vector.h:1064
reference emplace_back(const T1 &value1)
Definition indirect_vector.h:815
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:1534
reference emplace_back()
Definition indirect_vector.h:802
size_type capacity() const
Definition indirect_vector.h:1128
iindirect_vector(etl::ivector< T * > &lookup_, etl::ipool &storage_)
Constructor.
Definition indirect_vector.h:1174
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:880
iterator insert(const_iterator position, size_t n, parameter_t value)
Definition indirect_vector.h:985
Definition indirect_vector.h:72
Definition indirect_vector.h:1344
Template deduction guides.
Definition indirect_vector.h:1492
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
void release_all()
Release all objects in the pool.
Definition ipool.h:451
T * create()
Definition ipool.h:333
void destroy(const T *const p_object)
Definition ipool.h:425
Definition ipool.h:103
Definition pool.h:54
is_same
Definition type_traits_generator.h:1080
remove_cv
Definition type_traits_generator.h:1007
bool full() const
Definition pvoidvector.h:705
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:380
bool empty() const
Definition pvoidvector.h:696
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:442
iterator end()
Definition ivectorpointer.h:96
iterator begin()
Definition ivectorpointer.h:78
iterator insert(const_iterator position, parameter_t value)
Definition ivectorpointer.h:391
size_t available() const
Definition pvoidvector.h:714
size_type size() const
Definition pvoidvector.h:687
void clear()
Clears the vector.
Definition ivectorpointer.h:337
Definition indirect_vector.h:56
Definition vector.h:71
Definition vector_base.h:80
Definition vector_base.h:52
Definition vector_base.h:66
Definition vector_base.h:94
bitset_ext
Definition absolute.h:38
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1148
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1160
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1109
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1097
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1121
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1136
binary_function
Definition functional.h:161
Definition type_traits_generator.h:2190
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
unary_function
Definition functional.h:151