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
86
88 typedef typename etl::ivector<T*>::difference_type difference_type;
89
90 //*************************************************************************
92 //*************************************************************************
93 template <typename TUnaryFunction, typename TReturnType = void>
110
111 //*************************************************************************
112 template <typename TUnaryFunction>
129
130 //*************************************************************************
132 //*************************************************************************
133 template <typename TBinaryFunction, typename TReturnType = void>
151
152 //*************************************************************************
153 template <typename TBinaryFunction>
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
193 {
194 ++lookup_itr;
195 return *this;
196 }
197
199 {
200 iterator temp(*this);
201 ++lookup_itr;
202 return temp;
203 }
204
206 {
207 --lookup_itr;
208 return *this;
209 }
210
212 {
213 iterator temp(*this);
214 --lookup_itr;
215 return temp;
216 }
217
219 {
220 lookup_itr = other.lookup_itr;
221 return *this;
222 }
223
225 {
226 lookup_itr += n;
227 return *this;
228 }
229
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
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
330 {
331 ++lookup_itr;
332 return *this;
333 }
334
336 {
337 const_iterator temp(*this);
338 ++lookup_itr;
339 return temp;
340 }
341
343 {
344 --lookup_itr;
345 return *this;
346 }
347
349 {
350 const_iterator temp(*this);
351 --lookup_itr;
352 return temp;
353 }
354
356 {
357 lookup_itr += n;
358 return *this;
359 }
360
362 {
363 lookup_itr -= n;
364 return *this;
365 }
366
368 {
369 lookup_itr = other.lookup_itr;
370 return *this;
371 }
372
374 {
375 return **lookup_itr;
376 }
377
379 {
380 return &(**lookup_itr);
381 }
382
384 {
385 return &(**lookup_itr);
386 }
387
388 indirect_const_iterator indirection() const
389 {
390 return lookup_itr;
391 }
392
394 {
395 const_iterator result(lhs);
396 result += offset;
397 return result;
398 }
399
401 {
402 const_iterator result(lhs);
403 result -= offset;
404 return result;
405 }
406
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
430
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
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 //*********************************************************************
619 {
620 return *lookup[i];
621 }
622
623 //*********************************************************************
627 //*********************************************************************
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 //*********************************************************************
660 {
661 return *(lookup.front());
662 }
663
664 //*********************************************************************
667 //*********************************************************************
669 {
670 return *(lookup.front());
671 }
672
673 //*********************************************************************
676 //*********************************************************************
678 {
679 return *(lookup.back());
680 }
681
682 //*********************************************************************
685 //*********************************************************************
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 //*********************************************************************
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 //*********************************************************************
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 //*********************************************************************
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 //*************************************************************************
1120 {
1121 return lookup.size();
1122 }
1123
1124 //*************************************************************************
1127 //*************************************************************************
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 //*************************************************************************
1156 {
1157 return lookup.max_size();
1158 }
1159
1160 //*************************************************************************
1163 //*************************************************************************
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 iterator itr = begin();
1186
1187 while (itr != end())
1188 {
1189 storage.destroy<T>(etl::addressof(*itr));
1190 ++itr;
1191 }
1192
1193 lookup.clear();
1194 }
1195
1196#if ETL_USING_CPP11
1197 //*********************************************************************
1199 //*********************************************************************
1201 {
1202 if (this != &other)
1203 {
1204 initialise();
1205
1206 typename iindirect_vector<T>::iterator itr = other.begin();
1207
1208 while (itr != other.end())
1209 {
1210 push_back(etl::move(*itr));
1211 ++itr;
1212 }
1213
1214 other.initialise();
1215 }
1216 }
1217#endif
1218
1219 etl::ivector<T*>& lookup;
1220 etl::ipool& storage;
1221
1222 private:
1223
1224 // Disable copy construction.
1225 iindirect_vector(const iindirect_vector&) ETL_DELETE;
1226
1227 //*************************************************************************
1229 //*************************************************************************
1230#if defined(ETL_POLYMORPHIC_INDIRECT_VECTOR) || defined(ETL_POLYMORPHIC_CONTAINERS)
1231 public:
1232 virtual
1233#else
1234 protected:
1235#endif
1237 {
1238 }
1239
1240 protected:
1241
1242 //*************************************************************************
1244 //*************************************************************************
1246 {
1247 return iterator(const_cast<indirect_iterator>(itr.lookup_itr));
1248 }
1249 };
1250
1251 //***************************************************************************
1257 //***************************************************************************
1258 template <typename T>
1260 {
1261 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1262 }
1263
1264 //***************************************************************************
1270 //***************************************************************************
1271 template <typename T>
1273 {
1274 return !(lhs == rhs);
1275 }
1276
1277 //***************************************************************************
1283 //***************************************************************************
1284 template <typename T>
1286 {
1287 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1288 }
1289
1290 //***************************************************************************
1296 //***************************************************************************
1297 template <typename T>
1299 {
1300 return (rhs < lhs);
1301 }
1302
1303 //***************************************************************************
1309 //***************************************************************************
1310 template <typename T>
1312 {
1313 return !(lhs > rhs);
1314 }
1315
1316 //***************************************************************************
1322 //***************************************************************************
1323 template <typename T>
1325 {
1326 return !(lhs < rhs);
1327 }
1328
1329 //***************************************************************************
1334 //***************************************************************************
1335 template <typename T, const size_t MAX_SIZE_>
1337 {
1338 public:
1339
1340 ETL_STATIC_ASSERT((MAX_SIZE_ > 0U), "Zero capacity etl::indirect_vector is not valid");
1341
1342 static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_;
1343
1344 //*************************************************************************
1346 //*************************************************************************
1348 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1349 {
1350 }
1351
1352 //*************************************************************************
1355 //*************************************************************************
1357 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1358 {
1359 this->resize(initial_size);
1360 }
1361
1362 //*************************************************************************
1366 //*************************************************************************
1368 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1369 {
1370 this->resize(initial_size, value);
1371 }
1372
1373 //*************************************************************************
1378 //*************************************************************************
1379 template <typename TIterator>
1381 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1382 {
1383 this->assign(first, last);
1384 }
1385
1386#if ETL_HAS_INITIALIZER_LIST
1387 //*************************************************************************
1389 //*************************************************************************
1390 indirect_vector(std::initializer_list<T> init)
1391 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1392 {
1393 this->assign(init.begin(), init.end());
1394 }
1395#endif
1396
1397 //*************************************************************************
1399 //*************************************************************************
1401 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1402 {
1403 this->assign(other.begin(), other.end());
1404 }
1405
1406 //*************************************************************************
1408 //*************************************************************************
1410 {
1411 if (&rhs != this)
1412 {
1413 this->assign(rhs.cbegin(), rhs.cend());
1414 }
1415
1416 return *this;
1417 }
1418
1419#if ETL_USING_CPP11
1420 //*************************************************************************
1422 //*************************************************************************
1424 : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1425 {
1426 this->move_container(etl::move(other));
1427 }
1428
1429 //*************************************************************************
1431 //*************************************************************************
1433 {
1434 this->move_container(etl::move(rhs));
1435
1436 return *this;
1437 }
1438#endif
1439
1440 //*************************************************************************
1442 //*************************************************************************
1444 {
1445 this->clear();
1446 }
1447
1448 private:
1449
1450 etl::vector<T*, MAX_SIZE> lookup_vector;
1451 etl::pool<T, MAX_SIZE> storage_pool;
1452 };
1453
1454 template <typename T, const size_t MAX_SIZE_>
1455 ETL_CONSTANT size_t indirect_vector<T, MAX_SIZE_>::MAX_SIZE;
1456
1457 //*************************************************************************
1459 //*************************************************************************
1460#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1461 template <typename T, typename... Ts>
1462 indirect_vector(T, Ts...)
1463 ->indirect_vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
1464#endif
1465
1466 //*************************************************************************
1468 //*************************************************************************
1469#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1470 template <typename... T>
1471 constexpr auto make_indirect_vector(T&&... t) -> etl::indirect_vector<typename etl::common_type_t<T...>, sizeof...(T)>
1472 {
1473 return { etl::forward<T>(t)... };
1474 }
1475#endif
1476
1477 //***************************************************************************
1482 //***************************************************************************
1483 template <typename T>
1485 {
1486 public:
1487
1488 //*************************************************************************
1490 //*************************************************************************
1496
1497 //*************************************************************************
1500 //*************************************************************************
1503 {
1504 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1505 this->resize(initial_size);
1506 }
1507
1508 //*************************************************************************
1512 //*************************************************************************
1515 {
1516 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1517 this->resize(initial_size, value);
1518 }
1519
1520 //*************************************************************************
1525 //*************************************************************************
1526 template <typename TIterator>
1529 {
1530 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1531 this->assign(first, last);
1532 }
1533
1534#if ETL_HAS_INITIALIZER_LIST
1535 //*************************************************************************
1537 //*************************************************************************
1538 indirect_vector_ext(std::initializer_list<T> init, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1540 {
1541 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1542 this->assign(init.begin(), init.end());
1543 }
1544#endif
1545
1546 //*************************************************************************
1548 //*************************************************************************
1551 {
1552 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1553 this->assign(other.begin(), other.end());
1554 }
1555
1556 //*************************************************************************
1558 //*************************************************************************
1560
1561 //*************************************************************************
1563 //*************************************************************************
1565 {
1566 if (&rhs != this)
1567 {
1568 this->assign(rhs.cbegin(), rhs.cend());
1569 }
1570
1571 return *this;
1572 }
1573
1574#if ETL_USING_CPP11
1575 //*************************************************************************
1577 //*************************************************************************
1580 {
1581 ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1582 this->move_container(etl::move(other));
1583 }
1584
1585 //*************************************************************************
1587 //*************************************************************************
1588 indirect_vector_ext(indirect_vector_ext&& other) ETL_DELETE;
1589
1590 //*************************************************************************
1592 //*************************************************************************
1593 indirect_vector_ext& operator = (indirect_vector_ext&& rhs)
1594 {
1595 this->move_container(etl::move(rhs));
1596
1597 return *this;
1598 }
1599#endif
1600
1601 //*************************************************************************
1603 //*************************************************************************
1605 {
1606 this->clear();
1607 }
1608 };
1609}
1610
1611#endif
1612
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:968
#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:1245
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:1564
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:1513
~indirect_vector()
Destructor.
Definition indirect_vector.h:1443
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:1501
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:1367
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:1549
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:1400
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:1491
indirect_vector(size_t initial_size)
Definition indirect_vector.h:1356
~iindirect_vector()
Destructor.
Definition indirect_vector.h:1236
indirect_vector()
Constructor.
Definition indirect_vector.h:1347
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:1604
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:1380
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:1409
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:1527
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:1337
Template deduction guides.
Definition indirect_vector.h:1485
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
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:1036
remove_cv
Definition type_traits_generator.h:963
bool full() const
Definition pvoidvector.h:681
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:672
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:690
size_type size() const
Definition pvoidvector.h:663
void clear()
Clears the vector.
Definition ivectorpointer.h:337
Definition indirect_vector.h:56
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:693
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:705
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:642
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:666
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:681
Definition functional.h:126
iterator
Definition iterator.h:399
pair holds two objects of arbitrary type
Definition utility.h:164
Definition functional.h:118