Embedded Template Library  1.0
indirect_vector.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2019 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
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 
42 #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
43  #include <initializer_list>
44 #endif
45 
46 #ifdef ETL_COMPILER_GCC
47 #pragma GCC diagnostic push
48 #pragma GCC diagnostic ignored "-Wunused-variable"
49 #endif
50 
51 #undef ETL_FILE
52 #define ETL_FILE "53"
53 
54 //*****************************************************************************
58 //*****************************************************************************
59 
60 namespace etl
61 {
62  //***************************************************************************
65  //***************************************************************************
67  {
68  public:
69 
70  indirect_vector_buffer_missmatch(string_type file_name_, numeric_type line_number_)
71  : vector_exception(ETL_ERROR_TEXT("indirect_vector:buffer_missmatch", ETL_FILE"A"), file_name_, line_number_)
72  {
73  }
74  };
75 
76  //***************************************************************************
80  //***************************************************************************
81  template <typename T>
83  {
84  public:
85 
86  typedef T value_type;
87  typedef T& reference;
88  typedef const T& const_reference;
89 #if ETL_CPP11_SUPPORTED
90  typedef T&& rvalue_reference;
91 #endif
92  typedef T* pointer;
93  typedef const T* const_pointer;
94 
95  typedef typename etl::ivector<T*>::iterator indirect_iterator;
96  typedef typename etl::ivector<T*>::const_iterator indirect_const_iterator;
97 
98  typedef typename etl::ivector<T*>::size_type size_type;
99  typedef typename etl::ivector<T*>::difference_type difference_type;
100 
101  //*************************************************************************
103  //*************************************************************************
104  template <typename TUnaryFunction, typename TReturnType = void>
106  {
107  public:
108 
109  unary_function_adaptor(TUnaryFunction unary_function_)
110  : unary_function(unary_function_)
111  {
112  }
113 
114  TReturnType operator()(const_pointer indirect_itr)
115  {
116  return unary_function(*indirect_itr);
117  }
118 
119  TUnaryFunction unary_function;
120  };
121 
122  //*************************************************************************
123  template <typename TUnaryFunction>
124  class unary_function_adaptor<TUnaryFunction, void>
125  {
126  public:
127 
128  unary_function_adaptor(TUnaryFunction unary_function_)
129  : unary_function(unary_function_)
130  {
131  }
132 
133  void operator()(const_pointer indirect_itr)
134  {
135  unary_function(*indirect_itr);
136  }
137 
138  TUnaryFunction unary_function;
139  };
140 
141  //*************************************************************************
143  //*************************************************************************
144  template <typename TBinaryFunction, typename TReturnType = void>
146  {
147  public:
148 
149  binary_function_adaptor(TBinaryFunction binary_function_)
150  : binary_function(binary_function_)
151  {
152  }
153 
154  TReturnType operator()(const_pointer indirect_itr_lhs,
155  const_pointer indirect_itr_rhs)
156  {
157  return binary_function(*indirect_itr_lhs, *indirect_itr_rhs);
158  }
159 
160  TBinaryFunction binary_function;
161  };
162 
163  //*************************************************************************
164  template <typename TBinaryFunction>
165  class binary_function_adaptor<TBinaryFunction, void>
166  {
167  public:
168 
169  binary_function_adaptor(TBinaryFunction binary_function_)
170  : binary_function(binary_function_)
171  {
172  }
173 
174  void operator()(const_pointer indirect_itr_lhs,
175  const_pointer indirect_itr_rhs)
176  {
177  binary_function(*indirect_itr_lhs, *indirect_itr_rhs);
178  }
179 
180  TBinaryFunction binary_function;
181  };
182 
183  //*************************************************************************
185  //*************************************************************************
186  class iterator : public etl::iterator<ETL_OR_STD::random_access_iterator_tag, T>
187  {
188  public:
189 
190  friend class iindirect_vector;
191  friend class const_iterator;
192 
193  iterator()
194  {
195  }
196 
197  iterator(const iterator& other)
198  : lookup_itr(other.lookup_itr)
199  {
200  }
201 
202  iterator& operator ++()
203  {
204  ++lookup_itr;
205  return *this;
206  }
207 
208  iterator operator ++(int)
209  {
210  iterator temp(*this);
211  ++lookup_itr;
212  return temp;
213  }
214 
215  iterator& operator --()
216  {
217  --lookup_itr;
218  return *this;
219  }
220 
221  iterator operator --(int)
222  {
223  iterator temp(*this);
224  --lookup_itr;
225  return temp;
226  }
227 
228  iterator& operator =(const iterator& other)
229  {
230  lookup_itr = other.lookup_itr;
231  return *this;
232  }
233 
234  iterator operator +=(size_type n)
235  {
236  lookup_itr += n;
237  return *this;
238  }
239 
240  iterator operator -=(size_type n)
241  {
242  lookup_itr -= n;
243  return *this;
244  }
245 
246  reference operator *()
247  {
248  return **lookup_itr;
249  }
250 
251  const_reference operator *() const
252  {
253  return **lookup_itr;
254  }
255 
256  pointer operator &()
257  {
258  return &(**lookup_itr);
259  }
260 
261  const_pointer operator &() const
262  {
263  return &(**lookup_itr);
264  }
265 
266  pointer operator ->()
267  {
268  return &(**lookup_itr);
269  }
270 
271  const_pointer operator ->() const
272  {
273  return &(**lookup_itr);
274  }
275 
276  friend iterator operator +(const iterator& lhs, difference_type offset)
277  {
278  iterator result(lhs);
279  result += offset;
280  return result;
281  }
282 
283  friend iterator operator -(const iterator& lhs, difference_type offset)
284  {
285  iterator result(lhs);
286  result -= offset;
287  return result;
288  }
289 
290  indirect_iterator indirection()
291  {
292  return lookup_itr;
293  }
294 
295  indirect_const_iterator indirection() const
296  {
297  return lookup_itr;
298  }
299 
300  friend difference_type operator -(const iterator& lhs, const iterator& rhs)
301  {
302  return lhs.lookup_itr - rhs.lookup_itr;
303  }
304 
305  friend bool operator == (const iterator& lhs, const iterator& rhs)
306  {
307  return lhs.lookup_itr == rhs.lookup_itr;
308  }
309 
310  friend bool operator != (const iterator& lhs, const iterator& rhs)
311  {
312  return !(lhs == rhs);
313  }
314 
315  friend bool operator < (const iterator& lhs, const iterator& rhs)
316  {
317  return lhs.lookup_itr < rhs.lookup_itr;
318  }
319 
320  private:
321 
322  iterator(indirect_iterator itr_)
323  : lookup_itr(itr_)
324  {
325  }
326 
327  indirect_iterator lookup_itr;
328  };
329 
330  //*************************************************************************
332  //*************************************************************************
333  class const_iterator : public etl::iterator<ETL_OR_STD::random_access_iterator_tag, const T>
334  {
335  public:
336 
337  friend class iindirect_vector;
338 
340  {
341  }
342 
343  const_iterator(const const_iterator& other)
344  : lookup_itr(other.lookup_itr)
345  {
346  }
347 
348  const_iterator(const typename iindirect_vector::iterator& other)
349  : lookup_itr(other.lookup_itr)
350  {
351  }
352 
353  const_iterator& operator ++()
354  {
355  ++lookup_itr;
356  return *this;
357  }
358 
359  const_iterator operator ++(int)
360  {
361  const_iterator temp(*this);
362  ++lookup_itr;
363  return temp;
364  }
365 
366  const_iterator& operator --()
367  {
368  --lookup_itr;
369  return *this;
370  }
371 
372  const_iterator operator --(int)
373  {
374  const_iterator temp(*this);
375  --lookup_itr;
376  return temp;
377  }
378 
379  const_iterator operator +=(size_type n)
380  {
381  lookup_itr += n;
382  return *this;
383  }
384 
385  const_iterator operator -=(size_type n)
386  {
387  lookup_itr -= n;
388  return *this;
389  }
390 
391  const_iterator& operator =(const const_iterator& other)
392  {
393  lookup_itr = other.lookup_itr;
394  return *this;
395  }
396 
397  const_reference operator *() const
398  {
399  return **lookup_itr;
400  }
401 
402  const_pointer operator &() const
403  {
404  return &(**lookup_itr);
405  }
406 
407  const_pointer operator ->() const
408  {
409  return &(**lookup_itr);
410  }
411 
412  indirect_const_iterator indirection() const
413  {
414  return lookup_itr;
415  }
416 
417  friend const_iterator operator +(const const_iterator& lhs, difference_type offset)
418  {
419  const_iterator result(lhs);
420  result += offset;
421  return result;
422  }
423 
424  friend const_iterator operator -(const const_iterator& lhs, difference_type offset)
425  {
426  const_iterator result(lhs);
427  result -= offset;
428  return result;
429  }
430 
431  friend difference_type operator -(const const_iterator& lhs, const const_iterator& rhs)
432  {
433  return lhs.lookup_itr - rhs.lookup_itr;
434  }
435 
436  friend bool operator == (const const_iterator& lhs, const const_iterator& rhs)
437  {
438  return lhs.lookup_itr == rhs.lookup_itr;
439  }
440 
441  friend bool operator != (const const_iterator& lhs, const const_iterator& rhs)
442  {
443  return !(lhs == rhs);
444  }
445 
446  friend bool operator < (const const_iterator& lhs, const const_iterator& rhs)
447  {
448  return lhs.lookup_itr < rhs.lookup_itr;
449  }
450 
451  private:
452 
453  typedef typename etl::ivector<T*>::const_iterator lookup_itr_t;
454 
455  const_iterator(indirect_const_iterator itr_)
456  : lookup_itr(itr_)
457  {
458  }
459 
460  indirect_const_iterator lookup_itr;
461  };
462 
463  typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
464  typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
465 
466  protected:
467 
468  typedef typename etl::parameter_type<T>::type parameter_t;
469 
470  public:
471 
472  //*********************************************************************
475  //*********************************************************************
477  {
478  return iterator(lookup.begin());
479  }
480 
481  //*********************************************************************
484  //*********************************************************************
486  {
487  return const_iterator(lookup.begin());
488  }
489 
490  //*********************************************************************
493  //*********************************************************************
495  {
496  return iterator(lookup.end());
497  }
498 
499  //*********************************************************************
502  //*********************************************************************
504  {
505  return const_iterator(lookup.end());
506  }
507 
508  //*********************************************************************
511  //*********************************************************************
513  {
514  return const_iterator(lookup.begin());
515  }
516 
517  //*********************************************************************
520  //*********************************************************************
522  {
523  return const_iterator(lookup.cend());
524  }
525 
526  //*********************************************************************
529  //*********************************************************************
530  reverse_iterator rbegin()
531  {
532  return reverse_iterator(end());
533  }
534 
535  //*********************************************************************
538  //*********************************************************************
539  const_reverse_iterator rbegin() const
540  {
541  return const_reverse_iterator(end());
542  }
543 
544  //*********************************************************************
547  //*********************************************************************
548  reverse_iterator rend()
549  {
550  return reverse_iterator(begin());
551  }
552 
553  //*********************************************************************
556  //*********************************************************************
557  const_reverse_iterator rend() const
558  {
559  return const_reverse_iterator(begin());
560  }
561 
562  //*********************************************************************
565  //*********************************************************************
566  const_reverse_iterator crbegin() const
567  {
568  return const_reverse_iterator(cend());
569  }
570 
571  //*********************************************************************
574  //*********************************************************************
575  const_reverse_iterator crend() const
576  {
577  return const_reverse_iterator(cbegin());
578  }
579 
580  //*********************************************************************
585  //*********************************************************************
586  void resize(size_t new_size)
587  {
588  resize(new_size, T());
589  }
590 
591  //*********************************************************************
597  //*********************************************************************
598  void resize(size_t new_size, T value)
599  {
600  ETL_ASSERT(new_size <= capacity(), ETL_ERROR(vector_full));
601 
602  if (new_size <= capacity())
603  {
604  if (new_size > size())
605  {
606  size_type n = new_size - size();
607 
608  while (n-- != 0U)
609  {
610  T* p = storage.create<T>(value);
611  lookup.push_back(p);
612  }
613  }
614  else
615  {
616  size_type n = size() - new_size;
617 
618  while (n-- != 0U)
619  {
620  pop_back();
621  }
622  }
623  }
624  }
625 
626  //*********************************************************************
628  //*********************************************************************
629  void reserve(size_t)
630  {
631  }
632 
633  //*********************************************************************
637  //*********************************************************************
638  reference operator [](size_t i)
639  {
640  return *lookup[i];
641  }
642 
643  //*********************************************************************
647  //*********************************************************************
648  const_reference operator [](size_t i) const
649  {
650  return *lookup[i];
651  }
652 
653  //*********************************************************************
658  //*********************************************************************
659  reference at(size_t i)
660  {
661  return *lookup.at(i);
662  }
663 
664  //*********************************************************************
669  //*********************************************************************
670  const_reference at(size_t i) const
671  {
672  return *lookup.at(i);
673  }
674 
675  //*********************************************************************
678  //*********************************************************************
679  reference front()
680  {
681  return *(lookup.front());
682  }
683 
684  //*********************************************************************
687  //*********************************************************************
688  const_reference front() const
689  {
690  return *(lookup.front());
691  }
692 
693  //*********************************************************************
696  //*********************************************************************
697  reference back()
698  {
699  return *(lookup.back());
700  }
701 
702  //*********************************************************************
705  //*********************************************************************
706  const_reference back() const
707  {
708  return *(lookup.back());
709  }
710 
711  //*********************************************************************
717  //*********************************************************************
718  template <typename TIterator>
719  void assign(TIterator first, TIterator last)
720  {
721  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");
722 
723 #if defined(ETL_DEBUG)
724  difference_type d = etl::distance(first, last);
725  ETL_ASSERT(static_cast<size_t>(d) <= capacity(), ETL_ERROR(vector_full));
726 #endif
727 
728  initialise();
729 
730  while (first != last)
731  {
732  T* p = storage.create<T>(*first);
733  lookup.push_back(p);
734  ++first;
735  }
736  }
737 
738  //*********************************************************************
743  //*********************************************************************
744  void assign(size_t n, parameter_t value)
745  {
746  ETL_ASSERT(n <= capacity(), ETL_ERROR(vector_full));
747 
748  initialise();
749 
750  while (n-- != 0U)
751  {
752  T* p = storage.create<T>(value);
753  lookup.push_back(p);
754  }
755  }
756 
757  //*************************************************************************
759  //*************************************************************************
760  void clear()
761  {
762  initialise();
763  }
764 
765  //*********************************************************************
769  //*********************************************************************
770  void push_back(const_reference value)
771  {
772 #if defined(ETL_CHECK_PUSH_POP)
773  ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
774 #endif
775  T* p = storage.create<T>(value);
776  lookup.push_back(p);
777  }
778 
779 #if ETL_CPP11_SUPPORTED
780  //*********************************************************************
784  //*********************************************************************
785  void push_back(rvalue_reference value)
786  {
787 #if defined(ETL_CHECK_PUSH_POP)
788  ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full));
789 #endif
790  T* p = storage.create<T>(etl::move(value));
791  lookup.push_back(p);
792  }
793 #endif
794 
795 #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03)
796  //*********************************************************************
800  //*********************************************************************
801  template <typename ... Args>
802  void emplace_back(Args && ... args)
803  {
804  T* p = storage.create<T>(etl::forward<Args>(args)...);
805  lookup.push_back(p);
806  }
807 #else
808  //*********************************************************************
812  //*********************************************************************
813  template <typename T1>
814  void emplace_back(const T1& value1)
815  {
816  T* p = storage.create<T>(T(value1));
817  lookup.push_back(p);
818  }
819 
820  //*********************************************************************
824  //*********************************************************************
825  template <typename T1, typename T2>
826  void emplace_back(const T1& value1, const T2& value2)
827  {
828  T* p = storage.create<T>(T(value1, value2));
829  lookup.push_back(p);
830  }
831 
832  //*********************************************************************
836  //*********************************************************************
837  template <typename T1, typename T2, typename T3>
838  void emplace_back(const T1& value1, const T2& value2, const T3& value3)
839  {
840  T* p = storage.create<T>(T(value1, value2, value3));
841  lookup.push_back(p);
842  }
843 
844  //*********************************************************************
848  //*********************************************************************
849  template <typename T1, typename T2, typename T3, typename T4>
850  void emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
851  {
852  T* p = storage.create<T>(T(value1, value2, value3, value4));
853  lookup.push_back(p);
854  }
855 #endif
856 
857  //*************************************************************************
859  //*************************************************************************
860  void pop_back()
861  {
862  ETL_ASSERT(!empty(), ETL_ERROR(vector_empty));
863 
864  reference object = back();
865  storage.destroy<T>(etl::addressof(object));
866  lookup.pop_back();
867  }
868 
869  //*********************************************************************
874  //*********************************************************************
875  iterator insert(iterator position, const_reference value)
876  {
877  ETL_ASSERT(size() + 1 <= capacity(), ETL_ERROR(vector_full));
878 
879  T* p = storage.create<T>(T(value));
880  position = iterator(lookup.insert(position.lookup_itr, p));
881 
882  return position;
883  }
884 
885 #if ETL_CPP11_SUPPORTED
886  //*********************************************************************
891  //*********************************************************************
892  iterator insert(iterator position, rvalue_reference value)
893  {
894  ETL_ASSERT(size() + 1 <= capacity(), ETL_ERROR(vector_full));
895 
896  T* p = storage.create<T>(T(etl::move(value)));
897  position = iterator(lookup.insert(position.lookup_itr, p));
898 
899  return position;
900  }
901 #endif
902 
903  //*************************************************************************
905  //*************************************************************************
906 #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT
907  template <typename ... Args>
908  iterator emplace(iterator position, Args && ... args)
909  {
910  ETL_ASSERT(!full(), ETL_ERROR(vector_full));
911 
912  T* p = storage.create<T>(T(etl::forward<Args>(args)...));
913  position = iterator(lookup.insert(position.lookup_itr, p));
914 
915  return position;
916  }
917 #else
918  template <typename T1>
919  iterator emplace(iterator position, const T1& value1)
920  {
921  ETL_ASSERT(!full(), ETL_ERROR(vector_full));
922 
923  T* p = storage.create<T>(T(value1));
924  position = iterator(lookup.insert(position.lookup_itr, p));
925 
926  return position;
927  }
928 
929  template <typename T1, typename T2>
930  iterator emplace(iterator position, const T1& value1, const T2& value2)
931  {
932  ETL_ASSERT(!full(), ETL_ERROR(vector_full));
933 
934  T* p = storage.create<T>(T(value1, value2));
935  position = iterator(lookup.insert(position.lookup_itr, p));
936 
937  return position;
938  }
939 
940  template <typename T1, typename T2, typename T3>
941  iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3)
942  {
943  ETL_ASSERT(!full(), ETL_ERROR(vector_full));
944 
945  T* p = storage.create<T>(T(value1, value2, value3));
946  position = iterator(lookup.insert(position.lookup_itr, p));
947 
948  return position;
949  }
950 
951  template <typename T1, typename T2, typename T3, typename T4>
952  iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
953  {
954  ETL_ASSERT(!full(), ETL_ERROR(vector_full));
955 
956  T* p = storage.create<T>(T(value1, value2, value3, value4));
957  position = iterator(lookup.insert(position.lookup_itr, p));
958 
959  return position;
960  }
961 #endif
962 
963  //*********************************************************************
969  //*********************************************************************
970  void insert(iterator position, size_t n, parameter_t value)
971  {
972  ETL_ASSERT((size() + n) <= capacity(), ETL_ERROR(vector_full));
973 
974  // Make space for the new lookup pointers.
975  typename etl::ivector<T*>::iterator lookup_itr = position.lookup_itr;
976  lookup.insert(lookup_itr, n, ETL_NULLPTR);
977 
978  while (n-- != 0U)
979  {
980  T* p = storage.create<T>(value);
981  *lookup_itr++ = p;
982  }
983  }
984 
985  //*********************************************************************
991  //*********************************************************************
992  template <class TIterator>
993  void insert(iterator position, TIterator first, TIterator last)
994  {
995  size_t count = size_t(etl::distance(first, last));
996 
997  ETL_ASSERT((size() + count) <= capacity(), ETL_ERROR(vector_full));
998 
999  // Make space for the new lookup pointers.
1000  typename etl::ivector<T*>::iterator lookup_itr = position.lookup_itr;
1001  lookup.insert(lookup_itr, count, ETL_NULLPTR);
1002 
1003  while (first != last)
1004  {
1005  T* p = storage.create<T>(*first);
1006  *lookup_itr++ = p;
1007  ++first;
1008  }
1009  }
1010 
1011  //*********************************************************************
1015  //*********************************************************************
1017  {
1018  storage.destroy<T>(etl::addressof(*i_element));
1019 
1020  return iterator(lookup.erase(i_element.lookup_itr));
1021  }
1022 
1023  //*********************************************************************
1030  //*********************************************************************
1032  {
1033  iterator element = first;
1034 
1035  while (element != last)
1036  {
1037  storage.destroy<T>(etl::addressof(*element));
1038  ++element;
1039  }
1040 
1041  lookup.erase(first.lookup_itr, last.lookup_itr);
1042 
1043  return last;
1044  }
1045 
1046  //*************************************************************************
1048  //*************************************************************************
1050  {
1051  if (&rhs != this)
1052  {
1053  assign(rhs.cbegin(), rhs.cend());
1054  }
1055 
1056  return *this;
1057  }
1058 
1059 #if ETL_CPP11_SUPPORTED
1060  //*************************************************************************
1062  //*************************************************************************
1064  {
1065  if (&rhs != this)
1066  {
1067  clear();
1068  iterator itr = rhs.begin();
1069  while (itr != rhs.end())
1070  {
1071  push_back(etl::move(*itr));
1072  ++itr;
1073  }
1074 
1075  rhs.initialise();
1076  }
1077 
1078  return *this;
1079  }
1080 #endif
1081 
1082  //*************************************************************************
1085  //*************************************************************************
1086  size_type size() const
1087  {
1088  return lookup.size();
1089  }
1090 
1091  //*************************************************************************
1094  //*************************************************************************
1095  size_type capacity() const
1096  {
1097  return lookup.capacity();
1098  }
1099 
1100  //*************************************************************************
1103  //*************************************************************************
1104  bool empty() const
1105  {
1106  return lookup.empty();
1107  }
1108 
1109  //*************************************************************************
1112  //*************************************************************************
1113  bool full() const
1114  {
1115  return lookup.full();
1116  }
1117 
1118  //*************************************************************************
1121  //*************************************************************************
1122  size_type max_size() const
1123  {
1124  return lookup.max_size();
1125  }
1126 
1127  //*************************************************************************
1130  //*************************************************************************
1131  size_type available() const
1132  {
1133  return lookup.available();
1134  }
1135 
1136  protected:
1137 
1138  //*********************************************************************
1140  //*********************************************************************
1142  : lookup(lookup_)
1143  , storage(storage_)
1144  {
1145  }
1146 
1147  //*********************************************************************
1149  //*********************************************************************
1150  void initialise()
1151  {
1152  iterator itr = begin();
1153 
1154  while (itr != end())
1155  {
1156  storage.destroy<T>(etl::addressof(*itr));
1157  ++itr;
1158  }
1159 
1160  lookup.clear();
1161  }
1162 
1163  //*********************************************************************
1165  //*********************************************************************
1167  {
1168  if (this != &other)
1169  {
1170  initialise();
1171 
1172  typename iindirect_vector<T>::iterator itr = other.begin();
1173 
1174  while (itr != other.end())
1175  {
1176  push_back(etl::move(*itr));
1177  ++itr;
1178  }
1179 
1180  other.initialise();
1181  }
1182  }
1183 
1184  etl::ivector<T*>& lookup;
1185  etl::ipool& storage;
1186 
1187  private:
1188 
1189  // Disable copy construction.
1190  iindirect_vector(const iindirect_vector&) ETL_DELETE;
1191 
1192  //*************************************************************************
1194  //*************************************************************************
1195 #if defined(ETL_POLYMORPHIC_INDIRECT_VECTOR) || defined(ETL_POLYMORPHIC_CONTAINERS)
1196  public:
1197  virtual
1198 #else
1199  protected:
1200 #endif
1202  {
1203  initialise();
1204  }
1205  };
1206 
1207  //***************************************************************************
1213  //***************************************************************************
1214  template <typename T>
1216  {
1217  return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
1218  }
1219 
1220  //***************************************************************************
1226  //***************************************************************************
1227  template <typename T>
1229  {
1230  return !(lhs == rhs);
1231  }
1232 
1233  //***************************************************************************
1239  //***************************************************************************
1240  template <typename T>
1242  {
1243  return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1244  }
1245 
1246  //***************************************************************************
1252  //***************************************************************************
1253  template <typename T>
1255  {
1256  return (rhs < lhs);
1257  }
1258 
1259  //***************************************************************************
1265  //***************************************************************************
1266  template <typename T>
1268  {
1269  return !(lhs > rhs);
1270  }
1271 
1272  //***************************************************************************
1278  //***************************************************************************
1279  template <typename T>
1281  {
1282  return !(lhs < rhs);
1283  }
1284 
1285  //***************************************************************************
1290  //***************************************************************************
1291  template <typename T, const size_t MAX_SIZE_>
1293  {
1294  public:
1295 
1296  ETL_STATIC_ASSERT((MAX_SIZE_ > 0U), "Zero capacity etl::indirect_vector is not valid");
1297 
1298  static const size_t MAX_SIZE = MAX_SIZE_;
1299 
1300  //*************************************************************************
1302  //*************************************************************************
1304  : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1305  {
1306  }
1307 
1308  //*************************************************************************
1311  //*************************************************************************
1312  explicit indirect_vector(size_t initial_size)
1313  : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1314  {
1315  this->resize(initial_size);
1316  }
1317 
1318  //*************************************************************************
1322  //*************************************************************************
1323  indirect_vector(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value)
1324  : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1325  {
1326  this->resize(initial_size, value);
1327  }
1328 
1329  //*************************************************************************
1334  //*************************************************************************
1335  template <typename TIterator>
1336  indirect_vector(TIterator first, TIterator last)
1337  : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1338  {
1339  this->assign(first, last);
1340  }
1341 
1342 #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
1343  //*************************************************************************
1345  //*************************************************************************
1346  indirect_vector(std::initializer_list<T> init)
1347  : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1348  {
1349  this->assign(init.begin(), init.end());
1350  }
1351 #endif
1352 
1353  //*************************************************************************
1355  //*************************************************************************
1357  : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1358  {
1359  this->assign(other.begin(), other.end());
1360  }
1361 
1362  //*************************************************************************
1364  //*************************************************************************
1366  {
1367  if (&rhs != this)
1368  {
1369  this->assign(rhs.cbegin(), rhs.cend());
1370  }
1371 
1372  return *this;
1373  }
1374 
1375 #if ETL_CPP11_SUPPORTED
1376  //*************************************************************************
1378  //*************************************************************************
1380  : etl::iindirect_vector<T>(lookup_vector, storage_pool)
1381  {
1382  this->move_container(etl::move(other));
1383  }
1384 
1385  //*************************************************************************
1387  //*************************************************************************
1389  {
1390  this->move_container(etl::move(rhs));
1391 
1392  return *this;
1393  }
1394 #endif
1395 
1396  //*************************************************************************
1398  //*************************************************************************
1400  {
1401  this->clear();
1402  }
1403 
1404  private:
1405 
1406  etl::vector<T*, MAX_SIZE> lookup_vector;
1407  etl::pool<T, MAX_SIZE> storage_pool;
1408  };
1409 
1410  //*************************************************************************
1412  //*************************************************************************
1413 #if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
1414  template <typename T, typename... Ts>
1415  indirect_vector(T, Ts...)
1416  ->indirect_vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
1417 #endif
1418 
1419  //***************************************************************************
1424  //***************************************************************************
1425  template <typename T>
1427  {
1428  public:
1429 
1430  //*************************************************************************
1432  //*************************************************************************
1434  : etl::iindirect_vector<T>(lookup_, pool_)
1435  {
1436  ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1437  }
1438 
1439  //*************************************************************************
1442  //*************************************************************************
1443  explicit indirect_vector_ext(size_t initial_size, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1444  : etl::iindirect_vector<T>(lookup_, pool_)
1445  {
1446  ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1447  this->resize(initial_size);
1448  }
1449 
1450  //*************************************************************************
1454  //*************************************************************************
1455  indirect_vector_ext(size_t initial_size, typename etl::iindirect_vector<T>::parameter_t value, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1456  : etl::iindirect_vector<T>(lookup_, pool_)
1457  {
1458  ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1459  this->resize(initial_size, value);
1460  }
1461 
1462  //*************************************************************************
1467  //*************************************************************************
1468  template <typename TIterator>
1469  indirect_vector_ext(TIterator first, TIterator last, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1470  : etl::iindirect_vector<T>(lookup_, pool_)
1471  {
1472  ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1473  this->assign(first, last);
1474  }
1475 
1476 #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
1477  //*************************************************************************
1479  //*************************************************************************
1480  indirect_vector_ext(std::initializer_list<T> init, etl::ivector<T*>& lookup_, etl::ipool& pool_)
1481  : etl::iindirect_vector<T>(lookup_, pool_)
1482  {
1483  ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1484  this->assign(init.begin(), init.end());
1485  }
1486 #endif
1487 
1488  //*************************************************************************
1490  //*************************************************************************
1492  : etl::iindirect_vector<T>(lookup_, pool_)
1493  {
1494  ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1495  this->assign(other.begin(), other.end());
1496  }
1497 
1498  //*************************************************************************
1500  //*************************************************************************
1502  {
1503  if (&rhs != this)
1504  {
1505  this->assign(rhs.cbegin(), rhs.cend());
1506  }
1507 
1508  return *this;
1509  }
1510 
1511 #if ETL_CPP11_SUPPORTED
1512  //*************************************************************************
1514  //*************************************************************************
1516  : etl::iindirect_vector<T>(lookup_, pool_)
1517  {
1518  ETL_ASSERT(lookup_.capacity() <= pool_.capacity(), ETL_ERROR(indirect_vector_buffer_missmatch));
1519  this->move_container(etl::move(other));
1520  }
1521 
1522  //*************************************************************************
1524  //*************************************************************************
1526  {
1527  this->move_container(etl::move(rhs));
1528 
1529  return *this;
1530  }
1531 #endif
1532 
1533  //*************************************************************************
1535  //*************************************************************************
1537  {
1538  this->clear();
1539  }
1540  };
1541 }
1542 
1543 #ifdef ETL_COMPILER_GCC
1544 #pragma GCC diagnostic pop
1545 #endif
1546 
1547 #undef ETL_FILE
1548 
1549 #endif
1550 
Binary function adaptor.
Definition: indirect_vector.h:146
const_iterator.
Definition: indirect_vector.h:334
iterator.
Definition: indirect_vector.h:187
Unary function adaptor.
Definition: indirect_vector.h:106
bitset< MAXN > operator&(const bitset< MAXN > &lhs, const bitset< MAXN > &rhs)
Definition: bitset.h:1157
#define ETL_ASSERT(b, e)
Definition: error_handler.h:290
reference at(size_t i)
Definition: indirect_vector.h:659
const_reverse_iterator crend() const
Definition: indirect_vector.h:575
void resize(size_t new_size)
Definition: indirect_vector.h:586
void clear()
Clears the indirect_vector.
Definition: indirect_vector.h:760
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:1455
~indirect_vector()
Destructor.
Definition: indirect_vector.h:1399
void assign(TIterator first, TIterator last)
Definition: indirect_vector.h:719
size_type available() const
Definition: indirect_vector.h:1131
indirect_vector & operator=(const indirect_vector &rhs)
Assignment operator.
Definition: indirect_vector.h:1365
reference back()
Definition: indirect_vector.h:697
iterator end()
Definition: indirect_vector.h:494
void insert(iterator position, TIterator first, TIterator last)
Definition: indirect_vector.h:993
const_iterator end() const
Definition: indirect_vector.h:503
iterator emplace(iterator position, const T1 &value1)
Emplaces a value to the vector at the specified position.
Definition: indirect_vector.h:919
indirect_vector_ext(size_t initial_size, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Definition: indirect_vector.h:1443
bool empty() const
Definition: indirect_vector.h:1104
indirect_vector(size_t initial_size, typename etl::iindirect_vector< T >::parameter_t value)
Definition: indirect_vector.h:1323
void emplace_back(const T1 &value1, const T2 &value2)
Definition: indirect_vector.h:826
reverse_iterator rend()
Definition: indirect_vector.h:548
void emplace_back(const T1 &value1, const T2 &value2, const T3 &value3)
Definition: indirect_vector.h:838
indirect_vector_ext(const indirect_vector_ext &other, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Copy constructor.
Definition: indirect_vector.h:1491
void resize(size_t new_size, T value)
Definition: indirect_vector.h:598
void emplace_back(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition: indirect_vector.h:850
void pop_back()
Removes an element from the end of the indirect_vector.
Definition: indirect_vector.h:860
bool full() const
Definition: indirect_vector.h:1113
size_type size() const
Definition: indirect_vector.h:1086
void reserve(size_t)
Does nothing.
Definition: indirect_vector.h:629
const_iterator cend() const
Definition: indirect_vector.h:521
void assign(size_t n, parameter_t value)
Definition: indirect_vector.h:744
indirect_vector(const indirect_vector &other)
Copy constructor.
Definition: indirect_vector.h:1356
const_iterator cbegin() const
Definition: indirect_vector.h:512
const_reference back() const
Definition: indirect_vector.h:706
const_reference front() const
Definition: indirect_vector.h:688
indirect_vector_ext(etl::ivector< T * > &lookup_, etl::ipool &pool_)
Constructor.
Definition: indirect_vector.h:1433
indirect_vector(size_t initial_size)
Definition: indirect_vector.h:1312
~iindirect_vector()
Destructor.
Definition: indirect_vector.h:1201
indirect_vector()
Constructor.
Definition: indirect_vector.h:1303
size_type max_size() const
Definition: indirect_vector.h:1122
const_iterator begin() const
Definition: indirect_vector.h:485
void emplace_back(const T1 &value1)
Definition: indirect_vector.h:814
void initialise()
Initialise the indirect_vector.
Definition: indirect_vector.h:1150
~indirect_vector_ext()
Destructor.
Definition: indirect_vector.h:1536
const_reference at(size_t i) const
Definition: indirect_vector.h:670
iterator begin()
Definition: indirect_vector.h:476
iterator insert(iterator position, const_reference value)
Definition: indirect_vector.h:875
void insert(iterator position, size_t n, parameter_t value)
Definition: indirect_vector.h:970
iindirect_vector & operator=(const iindirect_vector &rhs)
Assignment operator.
Definition: indirect_vector.h:1049
indirect_vector_ext & operator=(const indirect_vector_ext &rhs)
Assignment operator.
Definition: indirect_vector.h:1501
const_reverse_iterator rend() const
Definition: indirect_vector.h:557
const_reverse_iterator rbegin() const
Definition: indirect_vector.h:539
iterator erase(iterator i_element)
Definition: indirect_vector.h:1016
indirect_vector(TIterator first, TIterator last)
Definition: indirect_vector.h:1336
reverse_iterator rbegin()
Definition: indirect_vector.h:530
const_reverse_iterator crbegin() const
Definition: indirect_vector.h:566
reference front()
Definition: indirect_vector.h:679
indirect_vector_ext(TIterator first, TIterator last, etl::ivector< T * > &lookup_, etl::ipool &pool_)
Definition: indirect_vector.h:1469
size_type capacity() const
Definition: indirect_vector.h:1095
iindirect_vector(etl::ivector< T * > &lookup_, etl::ipool &storage_)
Constructor.
Definition: indirect_vector.h:1141
reference operator[](size_t i)
Definition: indirect_vector.h:638
void push_back(const_reference value)
Definition: indirect_vector.h:770
void move_container(iindirect_vector &&other)
Move from a container.
Definition: indirect_vector.h:1166
iterator erase(iterator first, iterator last)
Definition: indirect_vector.h:1031
Definition: indirect_vector.h:83
Definition: indirect_vector.h:1293
Template deduction guides.
Definition: indirect_vector.h:1427
bool operator==(const etl::iindirect_vector< T > &lhs, const etl::iindirect_vector< T > &rhs)
Definition: indirect_vector.h:1215
bool operator<(const etl::iindirect_vector< T > &lhs, const etl::iindirect_vector< T > &rhs)
Definition: indirect_vector.h:1241
bool operator!=(const etl::iindirect_vector< T > &lhs, const etl::iindirect_vector< T > &rhs)
Definition: indirect_vector.h:1228
T * addressof(T &t)
Definition: memory.h:61
size_t capacity() const
Returns the maximum number of items in the pool.
Definition: pool.h:293
T * create()
Definition: pool.h:146
void destroy(const T *const p_object)
Definition: pool.h:238
Definition: pool.h:118
is_same
Definition: type_traits_generator.h:981
remove_cv
Definition: type_traits_generator.h:921
bool full() const
Definition: pvoidvector.h:598
reference front()
Definition: ivectorpointer.h:251
void push_back(parameter_t value)
Definition: ivectorpointer.h:338
size_type max_size() const
Definition: vector_base.h:143
size_type capacity() const
Definition: vector_base.h:134
void pop_back()
Definition: ivectorpointer.h:357
bool empty() const
Definition: pvoidvector.h:589
reference back()
Definition: ivectorpointer.h:269
iterator insert(iterator position, parameter_t value)
Definition: ivectorpointer.h:368
const_iterator cend() const
Definition: ivectorpointer.h:123
reference at(size_t i)
Definition: ivectorpointer.h:231
iterator erase(iterator i_element)
Definition: ivectorpointer.h:411
iterator end()
Definition: ivectorpointer.h:96
iterator begin()
Definition: ivectorpointer.h:78
size_t available() const
Definition: pvoidvector.h:607
size_type size() const
Definition: pvoidvector.h:580
void clear()
Clears the vector.
Definition: ivectorpointer.h:328
Definition: indirect_vector.h:67
Definition: vector.h:80
Definition: ivectorpointer.h:49
Definition: vector_base.h:83
Definition: vector_base.h:55
Definition: vector_base.h:69
Definition: absolute.h:37
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
etl::fixed_iterator< TIterator > & operator-(etl::fixed_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type)
Definition: fixed_iterator.h:193
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:594
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:582
etl::fixed_iterator< TIterator > & operator+(etl::fixed_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type)
Definition: fixed_iterator.h:183
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:606
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:621
Definition: functional.h:170
iterator
Definition: iterator.h:422
etl::conditional< etl::is_fundamental< T >::value||etl::is_pointer< T >::value, T, const T & >::type type
By default fundamental and pointer types are passed by value.
Definition: parameter_type.h:48
Definition: functional.h:161