Containers (STL-compatible) StateMachines MessageBus and more for Embedded Systems. See www.etlcpp.com
private/ivectorpointer.h@0:b47c2a7920c2, 2018-03-16 (annotated)
- Committer:
- bobbery
- Date:
- Fri Mar 16 16:34:18 2018 +0000
- Revision:
- 0:b47c2a7920c2
Works after using gcc_generic undef CAPACITY and replacing nullptr by std::nullptr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bobbery | 0:b47c2a7920c2 | 1 | ///\file |
bobbery | 0:b47c2a7920c2 | 2 | |
bobbery | 0:b47c2a7920c2 | 3 | /****************************************************************************** |
bobbery | 0:b47c2a7920c2 | 4 | The MIT License(MIT) |
bobbery | 0:b47c2a7920c2 | 5 | |
bobbery | 0:b47c2a7920c2 | 6 | Embedded Template Library. |
bobbery | 0:b47c2a7920c2 | 7 | https://github.com/ETLCPP/etl |
bobbery | 0:b47c2a7920c2 | 8 | http://www.etlcpp.com |
bobbery | 0:b47c2a7920c2 | 9 | |
bobbery | 0:b47c2a7920c2 | 10 | Copyright(c) 2016 jwellbelove |
bobbery | 0:b47c2a7920c2 | 11 | |
bobbery | 0:b47c2a7920c2 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy |
bobbery | 0:b47c2a7920c2 | 13 | of this software and associated documentation files(the "Software"), to deal |
bobbery | 0:b47c2a7920c2 | 14 | in the Software without restriction, including without limitation the rights |
bobbery | 0:b47c2a7920c2 | 15 | to use, copy, modify, merge, publish, distribute, sublicense, and / or sell |
bobbery | 0:b47c2a7920c2 | 16 | copies of the Software, and to permit persons to whom the Software is |
bobbery | 0:b47c2a7920c2 | 17 | furnished to do so, subject to the following conditions : |
bobbery | 0:b47c2a7920c2 | 18 | |
bobbery | 0:b47c2a7920c2 | 19 | The above copyright notice and this permission notice shall be included in all |
bobbery | 0:b47c2a7920c2 | 20 | copies or substantial portions of the Software. |
bobbery | 0:b47c2a7920c2 | 21 | |
bobbery | 0:b47c2a7920c2 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
bobbery | 0:b47c2a7920c2 | 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
bobbery | 0:b47c2a7920c2 | 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE |
bobbery | 0:b47c2a7920c2 | 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
bobbery | 0:b47c2a7920c2 | 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
bobbery | 0:b47c2a7920c2 | 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
bobbery | 0:b47c2a7920c2 | 28 | SOFTWARE. |
bobbery | 0:b47c2a7920c2 | 29 | ******************************************************************************/ |
bobbery | 0:b47c2a7920c2 | 30 | |
bobbery | 0:b47c2a7920c2 | 31 | #ifndef __ETL_IVECTOR_POINTER__ |
bobbery | 0:b47c2a7920c2 | 32 | #define __ETL_IVECTOR_POINTER__ |
bobbery | 0:b47c2a7920c2 | 33 | |
bobbery | 0:b47c2a7920c2 | 34 | #ifndef __ETL_IN_VECTOR_H__ |
bobbery | 0:b47c2a7920c2 | 35 | #error This header is a private element of etl::ivector |
bobbery | 0:b47c2a7920c2 | 36 | #endif |
bobbery | 0:b47c2a7920c2 | 37 | |
bobbery | 0:b47c2a7920c2 | 38 | #include "pvoidvector.h" |
bobbery | 0:b47c2a7920c2 | 39 | |
bobbery | 0:b47c2a7920c2 | 40 | namespace etl |
bobbery | 0:b47c2a7920c2 | 41 | { |
bobbery | 0:b47c2a7920c2 | 42 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 43 | /// The base class for specifically sized vectors. |
bobbery | 0:b47c2a7920c2 | 44 | /// Can be used as a reference type for all vectors containing a specific pointer type. |
bobbery | 0:b47c2a7920c2 | 45 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 46 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 47 | template <typename T> |
bobbery | 0:b47c2a7920c2 | 48 | class ivector<T*> : public pvoidvector |
bobbery | 0:b47c2a7920c2 | 49 | { |
bobbery | 0:b47c2a7920c2 | 50 | public: |
bobbery | 0:b47c2a7920c2 | 51 | |
bobbery | 0:b47c2a7920c2 | 52 | typedef T* value_type; |
bobbery | 0:b47c2a7920c2 | 53 | typedef T*& reference; |
bobbery | 0:b47c2a7920c2 | 54 | typedef const T* const & const_reference; |
bobbery | 0:b47c2a7920c2 | 55 | typedef T** pointer; |
bobbery | 0:b47c2a7920c2 | 56 | typedef const T* const * const_pointer; |
bobbery | 0:b47c2a7920c2 | 57 | typedef T** iterator; |
bobbery | 0:b47c2a7920c2 | 58 | typedef const T* const * const_iterator; |
bobbery | 0:b47c2a7920c2 | 59 | typedef std::reverse_iterator<iterator> reverse_iterator; |
bobbery | 0:b47c2a7920c2 | 60 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
bobbery | 0:b47c2a7920c2 | 61 | typedef size_t size_type; |
bobbery | 0:b47c2a7920c2 | 62 | typedef typename std::iterator_traits<iterator>::difference_type difference_type; |
bobbery | 0:b47c2a7920c2 | 63 | |
bobbery | 0:b47c2a7920c2 | 64 | protected: |
bobbery | 0:b47c2a7920c2 | 65 | |
bobbery | 0:b47c2a7920c2 | 66 | typedef value_type parameter_t; |
bobbery | 0:b47c2a7920c2 | 67 | |
bobbery | 0:b47c2a7920c2 | 68 | private: |
bobbery | 0:b47c2a7920c2 | 69 | |
bobbery | 0:b47c2a7920c2 | 70 | typedef pvoidvector base_t; |
bobbery | 0:b47c2a7920c2 | 71 | |
bobbery | 0:b47c2a7920c2 | 72 | public: |
bobbery | 0:b47c2a7920c2 | 73 | |
bobbery | 0:b47c2a7920c2 | 74 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 75 | /// Returns an iterator to the beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 76 | ///\return An iterator to the beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 77 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 78 | iterator begin() |
bobbery | 0:b47c2a7920c2 | 79 | { |
bobbery | 0:b47c2a7920c2 | 80 | return iterator(base_t::begin()); |
bobbery | 0:b47c2a7920c2 | 81 | } |
bobbery | 0:b47c2a7920c2 | 82 | |
bobbery | 0:b47c2a7920c2 | 83 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 84 | /// Returns a const_iterator to the beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 85 | ///\return A const iterator to the beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 86 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 87 | const_iterator begin() const |
bobbery | 0:b47c2a7920c2 | 88 | { |
bobbery | 0:b47c2a7920c2 | 89 | return const_iterator(base_t::begin()); |
bobbery | 0:b47c2a7920c2 | 90 | } |
bobbery | 0:b47c2a7920c2 | 91 | |
bobbery | 0:b47c2a7920c2 | 92 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 93 | /// Returns an iterator to the end of the vector. |
bobbery | 0:b47c2a7920c2 | 94 | ///\return An iterator to the end of the vector. |
bobbery | 0:b47c2a7920c2 | 95 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 96 | iterator end() |
bobbery | 0:b47c2a7920c2 | 97 | { |
bobbery | 0:b47c2a7920c2 | 98 | return iterator(base_t::end()); |
bobbery | 0:b47c2a7920c2 | 99 | } |
bobbery | 0:b47c2a7920c2 | 100 | |
bobbery | 0:b47c2a7920c2 | 101 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 102 | /// Returns a const_iterator to the end of the vector. |
bobbery | 0:b47c2a7920c2 | 103 | ///\return A const iterator to the end of the vector. |
bobbery | 0:b47c2a7920c2 | 104 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 105 | const_iterator end() const |
bobbery | 0:b47c2a7920c2 | 106 | { |
bobbery | 0:b47c2a7920c2 | 107 | return const_iterator(base_t::end()); |
bobbery | 0:b47c2a7920c2 | 108 | } |
bobbery | 0:b47c2a7920c2 | 109 | |
bobbery | 0:b47c2a7920c2 | 110 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 111 | /// Returns a const_iterator to the beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 112 | ///\return A const iterator to the beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 113 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 114 | const_iterator cbegin() const |
bobbery | 0:b47c2a7920c2 | 115 | { |
bobbery | 0:b47c2a7920c2 | 116 | return const_iterator(base_t::cbegin()); |
bobbery | 0:b47c2a7920c2 | 117 | } |
bobbery | 0:b47c2a7920c2 | 118 | |
bobbery | 0:b47c2a7920c2 | 119 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 120 | /// Returns a const_iterator to the end of the vector. |
bobbery | 0:b47c2a7920c2 | 121 | ///\return A const iterator to the end of the vector. |
bobbery | 0:b47c2a7920c2 | 122 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 123 | const_iterator cend() const |
bobbery | 0:b47c2a7920c2 | 124 | { |
bobbery | 0:b47c2a7920c2 | 125 | return const_iterator(base_t::cend()); |
bobbery | 0:b47c2a7920c2 | 126 | } |
bobbery | 0:b47c2a7920c2 | 127 | |
bobbery | 0:b47c2a7920c2 | 128 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 129 | /// Returns an reverse iterator to the reverse beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 130 | ///\return Iterator to the reverse beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 131 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 132 | reverse_iterator rbegin() |
bobbery | 0:b47c2a7920c2 | 133 | { |
bobbery | 0:b47c2a7920c2 | 134 | return reverse_iterator(iterator(base_t::end())); |
bobbery | 0:b47c2a7920c2 | 135 | } |
bobbery | 0:b47c2a7920c2 | 136 | |
bobbery | 0:b47c2a7920c2 | 137 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 138 | /// Returns a const reverse iterator to the reverse beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 139 | ///\return Const iterator to the reverse beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 140 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 141 | const_reverse_iterator rbegin() const |
bobbery | 0:b47c2a7920c2 | 142 | { |
bobbery | 0:b47c2a7920c2 | 143 | return const_reverse_iterator(const_iterator(base_t::end())); |
bobbery | 0:b47c2a7920c2 | 144 | } |
bobbery | 0:b47c2a7920c2 | 145 | |
bobbery | 0:b47c2a7920c2 | 146 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 147 | /// Returns a reverse iterator to the end + 1 of the vector. |
bobbery | 0:b47c2a7920c2 | 148 | ///\return Reverse iterator to the end + 1 of the vector. |
bobbery | 0:b47c2a7920c2 | 149 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 150 | reverse_iterator rend() |
bobbery | 0:b47c2a7920c2 | 151 | { |
bobbery | 0:b47c2a7920c2 | 152 | return reverse_iterator(iterator(base_t::begin())); |
bobbery | 0:b47c2a7920c2 | 153 | } |
bobbery | 0:b47c2a7920c2 | 154 | |
bobbery | 0:b47c2a7920c2 | 155 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 156 | /// Returns a const reverse iterator to the end + 1 of the vector. |
bobbery | 0:b47c2a7920c2 | 157 | ///\return Const reverse iterator to the end + 1 of the vector. |
bobbery | 0:b47c2a7920c2 | 158 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 159 | const_reverse_iterator rend() const |
bobbery | 0:b47c2a7920c2 | 160 | { |
bobbery | 0:b47c2a7920c2 | 161 | return const_reverse_iterator(const_iterator(base_t::begin())); |
bobbery | 0:b47c2a7920c2 | 162 | } |
bobbery | 0:b47c2a7920c2 | 163 | |
bobbery | 0:b47c2a7920c2 | 164 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 165 | /// Returns a const reverse iterator to the reverse beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 166 | ///\return Const reverse iterator to the reverse beginning of the vector. |
bobbery | 0:b47c2a7920c2 | 167 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 168 | const_reverse_iterator crbegin() const |
bobbery | 0:b47c2a7920c2 | 169 | { |
bobbery | 0:b47c2a7920c2 | 170 | return const_reverse_iterator(const_iterator(base_t::cend())); |
bobbery | 0:b47c2a7920c2 | 171 | } |
bobbery | 0:b47c2a7920c2 | 172 | |
bobbery | 0:b47c2a7920c2 | 173 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 174 | /// Returns a const reverse iterator to the end + 1 of the vector. |
bobbery | 0:b47c2a7920c2 | 175 | ///\return Const reverse iterator to the end + 1 of the vector. |
bobbery | 0:b47c2a7920c2 | 176 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 177 | const_reverse_iterator crend() const |
bobbery | 0:b47c2a7920c2 | 178 | { |
bobbery | 0:b47c2a7920c2 | 179 | return const_reverse_iterator(const_iterator(base_t::cbegin())); |
bobbery | 0:b47c2a7920c2 | 180 | } |
bobbery | 0:b47c2a7920c2 | 181 | |
bobbery | 0:b47c2a7920c2 | 182 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 183 | /// Resizes the vector. |
bobbery | 0:b47c2a7920c2 | 184 | /// If asserts or exceptions are enabled and the new size is larger than the |
bobbery | 0:b47c2a7920c2 | 185 | /// maximum then a vector_full is thrown. |
bobbery | 0:b47c2a7920c2 | 186 | ///\param new_size The new size. |
bobbery | 0:b47c2a7920c2 | 187 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 188 | void resize(size_t new_size) |
bobbery | 0:b47c2a7920c2 | 189 | { |
bobbery | 0:b47c2a7920c2 | 190 | base_t::resize(new_size); |
bobbery | 0:b47c2a7920c2 | 191 | } |
bobbery | 0:b47c2a7920c2 | 192 | |
bobbery | 0:b47c2a7920c2 | 193 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 194 | /// Resizes the vector. |
bobbery | 0:b47c2a7920c2 | 195 | /// If asserts or exceptions are enabled and the new size is larger than the |
bobbery | 0:b47c2a7920c2 | 196 | /// maximum then a vector_full is thrown. |
bobbery | 0:b47c2a7920c2 | 197 | ///\param new_size The new size. |
bobbery | 0:b47c2a7920c2 | 198 | ///\param value The value to fill new elements with. Default = default constructed value. |
bobbery | 0:b47c2a7920c2 | 199 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 200 | void resize(size_t new_size, value_type value) |
bobbery | 0:b47c2a7920c2 | 201 | { |
bobbery | 0:b47c2a7920c2 | 202 | base_t::resize(new_size, value); |
bobbery | 0:b47c2a7920c2 | 203 | } |
bobbery | 0:b47c2a7920c2 | 204 | |
bobbery | 0:b47c2a7920c2 | 205 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 206 | /// Returns a reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 207 | ///\param i The index. |
bobbery | 0:b47c2a7920c2 | 208 | ///\return A reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 209 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 210 | reference operator [](size_t i) |
bobbery | 0:b47c2a7920c2 | 211 | { |
bobbery | 0:b47c2a7920c2 | 212 | return reference(base_t::operator[](i)); |
bobbery | 0:b47c2a7920c2 | 213 | } |
bobbery | 0:b47c2a7920c2 | 214 | |
bobbery | 0:b47c2a7920c2 | 215 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 216 | /// Returns a const reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 217 | ///\param i The index. |
bobbery | 0:b47c2a7920c2 | 218 | ///\return A const reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 219 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 220 | const_reference operator [](size_t i) const |
bobbery | 0:b47c2a7920c2 | 221 | { |
bobbery | 0:b47c2a7920c2 | 222 | return const_reference(base_t::operator[](i)); |
bobbery | 0:b47c2a7920c2 | 223 | } |
bobbery | 0:b47c2a7920c2 | 224 | |
bobbery | 0:b47c2a7920c2 | 225 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 226 | /// Returns a reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 227 | /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. |
bobbery | 0:b47c2a7920c2 | 228 | ///\param i The index. |
bobbery | 0:b47c2a7920c2 | 229 | ///\return A reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 230 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 231 | reference at(size_t i) |
bobbery | 0:b47c2a7920c2 | 232 | { |
bobbery | 0:b47c2a7920c2 | 233 | return reference(base_t::at(i)); |
bobbery | 0:b47c2a7920c2 | 234 | } |
bobbery | 0:b47c2a7920c2 | 235 | |
bobbery | 0:b47c2a7920c2 | 236 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 237 | /// Returns a const reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 238 | /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. |
bobbery | 0:b47c2a7920c2 | 239 | ///\param i The index. |
bobbery | 0:b47c2a7920c2 | 240 | ///\return A const reference to the value at index 'i' |
bobbery | 0:b47c2a7920c2 | 241 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 242 | const_reference at(size_t i) const |
bobbery | 0:b47c2a7920c2 | 243 | { |
bobbery | 0:b47c2a7920c2 | 244 | return const_reference(base_t::at(i)); |
bobbery | 0:b47c2a7920c2 | 245 | } |
bobbery | 0:b47c2a7920c2 | 246 | |
bobbery | 0:b47c2a7920c2 | 247 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 248 | /// Returns a reference to the first element. |
bobbery | 0:b47c2a7920c2 | 249 | ///\return A reference to the first element. |
bobbery | 0:b47c2a7920c2 | 250 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 251 | reference front() |
bobbery | 0:b47c2a7920c2 | 252 | { |
bobbery | 0:b47c2a7920c2 | 253 | return reference(base_t::front()); |
bobbery | 0:b47c2a7920c2 | 254 | } |
bobbery | 0:b47c2a7920c2 | 255 | |
bobbery | 0:b47c2a7920c2 | 256 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 257 | /// Returns a const reference to the first element. |
bobbery | 0:b47c2a7920c2 | 258 | ///\return A const reference to the first element. |
bobbery | 0:b47c2a7920c2 | 259 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 260 | const_reference front() const |
bobbery | 0:b47c2a7920c2 | 261 | { |
bobbery | 0:b47c2a7920c2 | 262 | return const_reference(base_t::front()); |
bobbery | 0:b47c2a7920c2 | 263 | } |
bobbery | 0:b47c2a7920c2 | 264 | |
bobbery | 0:b47c2a7920c2 | 265 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 266 | /// Returns a reference to the last element. |
bobbery | 0:b47c2a7920c2 | 267 | ///\return A reference to the last element. |
bobbery | 0:b47c2a7920c2 | 268 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 269 | reference back() |
bobbery | 0:b47c2a7920c2 | 270 | { |
bobbery | 0:b47c2a7920c2 | 271 | return reference(base_t::back()); |
bobbery | 0:b47c2a7920c2 | 272 | } |
bobbery | 0:b47c2a7920c2 | 273 | |
bobbery | 0:b47c2a7920c2 | 274 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 275 | /// Returns a const reference to the last element. |
bobbery | 0:b47c2a7920c2 | 276 | ///\return A const reference to the last element. |
bobbery | 0:b47c2a7920c2 | 277 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 278 | const_reference back() const |
bobbery | 0:b47c2a7920c2 | 279 | { |
bobbery | 0:b47c2a7920c2 | 280 | return const_reference(base_t::back()); |
bobbery | 0:b47c2a7920c2 | 281 | } |
bobbery | 0:b47c2a7920c2 | 282 | |
bobbery | 0:b47c2a7920c2 | 283 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 284 | /// Returns a pointer to the beginning of the vector data. |
bobbery | 0:b47c2a7920c2 | 285 | ///\return A pointer to the beginning of the vector data. |
bobbery | 0:b47c2a7920c2 | 286 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 287 | pointer data() |
bobbery | 0:b47c2a7920c2 | 288 | { |
bobbery | 0:b47c2a7920c2 | 289 | return pointer(base_t::data()); |
bobbery | 0:b47c2a7920c2 | 290 | } |
bobbery | 0:b47c2a7920c2 | 291 | |
bobbery | 0:b47c2a7920c2 | 292 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 293 | /// Returns a const pointer to the beginning of the vector data. |
bobbery | 0:b47c2a7920c2 | 294 | ///\return A const pointer to the beginning of the vector data. |
bobbery | 0:b47c2a7920c2 | 295 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 296 | const_pointer data() const |
bobbery | 0:b47c2a7920c2 | 297 | { |
bobbery | 0:b47c2a7920c2 | 298 | return const_pointer(base_t::data()); |
bobbery | 0:b47c2a7920c2 | 299 | } |
bobbery | 0:b47c2a7920c2 | 300 | |
bobbery | 0:b47c2a7920c2 | 301 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 302 | /// Assigns values to the vector. |
bobbery | 0:b47c2a7920c2 | 303 | /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. |
bobbery | 0:b47c2a7920c2 | 304 | /// If asserts or exceptions are enabled, emits vector_iterator if the iterators are reversed. |
bobbery | 0:b47c2a7920c2 | 305 | ///\param first The iterator to the first element. |
bobbery | 0:b47c2a7920c2 | 306 | ///\param last The iterator to the last element + 1. |
bobbery | 0:b47c2a7920c2 | 307 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 308 | template <typename TIterator> |
bobbery | 0:b47c2a7920c2 | 309 | void assign(TIterator first, TIterator last) |
bobbery | 0:b47c2a7920c2 | 310 | { |
bobbery | 0:b47c2a7920c2 | 311 | base_t::initialise(); |
bobbery | 0:b47c2a7920c2 | 312 | |
bobbery | 0:b47c2a7920c2 | 313 | while (first != last) |
bobbery | 0:b47c2a7920c2 | 314 | { |
bobbery | 0:b47c2a7920c2 | 315 | *p_end++ = (void*)*first++; |
bobbery | 0:b47c2a7920c2 | 316 | } |
bobbery | 0:b47c2a7920c2 | 317 | } |
bobbery | 0:b47c2a7920c2 | 318 | |
bobbery | 0:b47c2a7920c2 | 319 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 320 | /// Assigns values to the vector. |
bobbery | 0:b47c2a7920c2 | 321 | /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. |
bobbery | 0:b47c2a7920c2 | 322 | ///\param n The number of elements to add. |
bobbery | 0:b47c2a7920c2 | 323 | ///\param value The value to insert for each element. |
bobbery | 0:b47c2a7920c2 | 324 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 325 | void assign(size_t n, parameter_t value) |
bobbery | 0:b47c2a7920c2 | 326 | { |
bobbery | 0:b47c2a7920c2 | 327 | base_t::assign(n, value); |
bobbery | 0:b47c2a7920c2 | 328 | } |
bobbery | 0:b47c2a7920c2 | 329 | |
bobbery | 0:b47c2a7920c2 | 330 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 331 | /// Clears the vector. |
bobbery | 0:b47c2a7920c2 | 332 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 333 | void clear() |
bobbery | 0:b47c2a7920c2 | 334 | { |
bobbery | 0:b47c2a7920c2 | 335 | base_t::clear(); |
bobbery | 0:b47c2a7920c2 | 336 | } |
bobbery | 0:b47c2a7920c2 | 337 | |
bobbery | 0:b47c2a7920c2 | 338 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 339 | /// Increases the size of the vector by one, but does not initialise the new element. |
bobbery | 0:b47c2a7920c2 | 340 | /// If asserts or exceptions are enabled, throws a vector_full if the vector is already full. |
bobbery | 0:b47c2a7920c2 | 341 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 342 | void push_back() |
bobbery | 0:b47c2a7920c2 | 343 | { |
bobbery | 0:b47c2a7920c2 | 344 | base_t::push_back(); |
bobbery | 0:b47c2a7920c2 | 345 | } |
bobbery | 0:b47c2a7920c2 | 346 | |
bobbery | 0:b47c2a7920c2 | 347 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 348 | /// Inserts a value at the end of the vector. |
bobbery | 0:b47c2a7920c2 | 349 | /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. |
bobbery | 0:b47c2a7920c2 | 350 | ///\param value The value to add. |
bobbery | 0:b47c2a7920c2 | 351 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 352 | void push_back(parameter_t value) |
bobbery | 0:b47c2a7920c2 | 353 | { |
bobbery | 0:b47c2a7920c2 | 354 | base_t::push_back(value); |
bobbery | 0:b47c2a7920c2 | 355 | } |
bobbery | 0:b47c2a7920c2 | 356 | |
bobbery | 0:b47c2a7920c2 | 357 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 358 | /// Removes an element from the end of the vector. |
bobbery | 0:b47c2a7920c2 | 359 | /// Does nothing if the vector is empty. |
bobbery | 0:b47c2a7920c2 | 360 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 361 | void pop_back() |
bobbery | 0:b47c2a7920c2 | 362 | { |
bobbery | 0:b47c2a7920c2 | 363 | base_t::pop_back(); |
bobbery | 0:b47c2a7920c2 | 364 | } |
bobbery | 0:b47c2a7920c2 | 365 | |
bobbery | 0:b47c2a7920c2 | 366 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 367 | /// Inserts a value to the vector. |
bobbery | 0:b47c2a7920c2 | 368 | /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. |
bobbery | 0:b47c2a7920c2 | 369 | ///\param position The position to insert before. |
bobbery | 0:b47c2a7920c2 | 370 | ///\param value The value to insert. |
bobbery | 0:b47c2a7920c2 | 371 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 372 | iterator insert(iterator position, parameter_t value) |
bobbery | 0:b47c2a7920c2 | 373 | { |
bobbery | 0:b47c2a7920c2 | 374 | return iterator(base_t::insert(base_t::iterator(position), value)); |
bobbery | 0:b47c2a7920c2 | 375 | } |
bobbery | 0:b47c2a7920c2 | 376 | |
bobbery | 0:b47c2a7920c2 | 377 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 378 | /// Inserts 'n' values to the vector. |
bobbery | 0:b47c2a7920c2 | 379 | /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. |
bobbery | 0:b47c2a7920c2 | 380 | ///\param position The position to insert before. |
bobbery | 0:b47c2a7920c2 | 381 | ///\param n The number of elements to add. |
bobbery | 0:b47c2a7920c2 | 382 | ///\param value The value to insert. |
bobbery | 0:b47c2a7920c2 | 383 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 384 | void insert(iterator position, size_t n, parameter_t value) |
bobbery | 0:b47c2a7920c2 | 385 | { |
bobbery | 0:b47c2a7920c2 | 386 | base_t::insert(base_t::iterator(position), n, value); |
bobbery | 0:b47c2a7920c2 | 387 | } |
bobbery | 0:b47c2a7920c2 | 388 | |
bobbery | 0:b47c2a7920c2 | 389 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 390 | /// Inserts a range of values to the vector. |
bobbery | 0:b47c2a7920c2 | 391 | /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. |
bobbery | 0:b47c2a7920c2 | 392 | ///\param position The position to insert before. |
bobbery | 0:b47c2a7920c2 | 393 | ///\param first The first element to add. |
bobbery | 0:b47c2a7920c2 | 394 | ///\param last The last + 1 element to add. |
bobbery | 0:b47c2a7920c2 | 395 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 396 | template <class TIterator> |
bobbery | 0:b47c2a7920c2 | 397 | void insert(iterator position, TIterator first, TIterator last) |
bobbery | 0:b47c2a7920c2 | 398 | { |
bobbery | 0:b47c2a7920c2 | 399 | base_t::insert(base_t::iterator(position), first, last); |
bobbery | 0:b47c2a7920c2 | 400 | } |
bobbery | 0:b47c2a7920c2 | 401 | |
bobbery | 0:b47c2a7920c2 | 402 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 403 | /// Erases an element. |
bobbery | 0:b47c2a7920c2 | 404 | ///\param i_element Iterator to the element. |
bobbery | 0:b47c2a7920c2 | 405 | ///\return An iterator pointing to the element that followed the erased element. |
bobbery | 0:b47c2a7920c2 | 406 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 407 | iterator erase(iterator i_element) |
bobbery | 0:b47c2a7920c2 | 408 | { |
bobbery | 0:b47c2a7920c2 | 409 | return iterator(base_t::erase(base_t::iterator(i_element))); |
bobbery | 0:b47c2a7920c2 | 410 | } |
bobbery | 0:b47c2a7920c2 | 411 | |
bobbery | 0:b47c2a7920c2 | 412 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 413 | /// Erases a range of elements. |
bobbery | 0:b47c2a7920c2 | 414 | /// The range includes all the elements between first and last, including the |
bobbery | 0:b47c2a7920c2 | 415 | /// element pointed by first, but not the one pointed by last. |
bobbery | 0:b47c2a7920c2 | 416 | ///\param first Iterator to the first element. |
bobbery | 0:b47c2a7920c2 | 417 | ///\param last Iterator to the last element. |
bobbery | 0:b47c2a7920c2 | 418 | ///\return An iterator pointing to the element that followed the erased element. |
bobbery | 0:b47c2a7920c2 | 419 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 420 | iterator erase(iterator first, iterator last) |
bobbery | 0:b47c2a7920c2 | 421 | { |
bobbery | 0:b47c2a7920c2 | 422 | return iterator(base_t::erase(base_t::iterator(first), base_t::iterator(last))); |
bobbery | 0:b47c2a7920c2 | 423 | } |
bobbery | 0:b47c2a7920c2 | 424 | |
bobbery | 0:b47c2a7920c2 | 425 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 426 | /// Assignment operator. |
bobbery | 0:b47c2a7920c2 | 427 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 428 | ivector& operator = (const ivector& rhs) |
bobbery | 0:b47c2a7920c2 | 429 | { |
bobbery | 0:b47c2a7920c2 | 430 | if (&rhs != this) |
bobbery | 0:b47c2a7920c2 | 431 | { |
bobbery | 0:b47c2a7920c2 | 432 | assign(rhs.cbegin(), rhs.cend()); |
bobbery | 0:b47c2a7920c2 | 433 | } |
bobbery | 0:b47c2a7920c2 | 434 | |
bobbery | 0:b47c2a7920c2 | 435 | return *this; |
bobbery | 0:b47c2a7920c2 | 436 | } |
bobbery | 0:b47c2a7920c2 | 437 | |
bobbery | 0:b47c2a7920c2 | 438 | protected: |
bobbery | 0:b47c2a7920c2 | 439 | |
bobbery | 0:b47c2a7920c2 | 440 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 441 | /// Constructor. |
bobbery | 0:b47c2a7920c2 | 442 | //********************************************************************* |
bobbery | 0:b47c2a7920c2 | 443 | ivector(T** p_buffer_, size_t MAX_SIZE_) |
bobbery | 0:b47c2a7920c2 | 444 | : pvoidvector(reinterpret_cast<void**>(p_buffer_), MAX_SIZE_) |
bobbery | 0:b47c2a7920c2 | 445 | { |
bobbery | 0:b47c2a7920c2 | 446 | } |
bobbery | 0:b47c2a7920c2 | 447 | }; |
bobbery | 0:b47c2a7920c2 | 448 | |
bobbery | 0:b47c2a7920c2 | 449 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 450 | /// Equal operator. |
bobbery | 0:b47c2a7920c2 | 451 | ///\param lhs Reference to the first vector. |
bobbery | 0:b47c2a7920c2 | 452 | ///\param rhs Reference to the second vector. |
bobbery | 0:b47c2a7920c2 | 453 | ///\return <b>true</b> if the arrays are equal, otherwise <b>false</b> |
bobbery | 0:b47c2a7920c2 | 454 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 455 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 456 | template <typename T> |
bobbery | 0:b47c2a7920c2 | 457 | bool operator ==(const etl::ivector<T*>& lhs, const etl::ivector<T*>& rhs) |
bobbery | 0:b47c2a7920c2 | 458 | { |
bobbery | 0:b47c2a7920c2 | 459 | return pvoidvector_equal(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 460 | } |
bobbery | 0:b47c2a7920c2 | 461 | |
bobbery | 0:b47c2a7920c2 | 462 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 463 | /// Not equal operator. |
bobbery | 0:b47c2a7920c2 | 464 | ///\param lhs Reference to the first vector. |
bobbery | 0:b47c2a7920c2 | 465 | ///\param rhs Reference to the second vector. |
bobbery | 0:b47c2a7920c2 | 466 | ///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b> |
bobbery | 0:b47c2a7920c2 | 467 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 468 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 469 | template <typename T> |
bobbery | 0:b47c2a7920c2 | 470 | bool operator !=(const etl::ivector<T*>& lhs, const etl::ivector<T*>& rhs) |
bobbery | 0:b47c2a7920c2 | 471 | { |
bobbery | 0:b47c2a7920c2 | 472 | return pvoidvector_not_equal(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 473 | } |
bobbery | 0:b47c2a7920c2 | 474 | |
bobbery | 0:b47c2a7920c2 | 475 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 476 | /// Less than operator. |
bobbery | 0:b47c2a7920c2 | 477 | ///\param lhs Reference to the first vector. |
bobbery | 0:b47c2a7920c2 | 478 | ///\param rhs Reference to the second vector. |
bobbery | 0:b47c2a7920c2 | 479 | ///\return <b>true</b> if the first vector is lexicographically less than the second, otherwise <b>false</b> |
bobbery | 0:b47c2a7920c2 | 480 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 481 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 482 | template <typename T> |
bobbery | 0:b47c2a7920c2 | 483 | bool operator <(const etl::ivector<T*>& lhs, const etl::ivector<T*>& rhs) |
bobbery | 0:b47c2a7920c2 | 484 | { |
bobbery | 0:b47c2a7920c2 | 485 | return pvoidvector_less_than(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 486 | } |
bobbery | 0:b47c2a7920c2 | 487 | |
bobbery | 0:b47c2a7920c2 | 488 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 489 | /// Greater than operator. |
bobbery | 0:b47c2a7920c2 | 490 | ///\param lhs Reference to the first vector. |
bobbery | 0:b47c2a7920c2 | 491 | ///\param rhs Reference to the second vector. |
bobbery | 0:b47c2a7920c2 | 492 | ///\return <b>true</b> if the first vector is lexicographically greater than the second, otherwise <b>false</b> |
bobbery | 0:b47c2a7920c2 | 493 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 494 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 495 | template <typename T> |
bobbery | 0:b47c2a7920c2 | 496 | bool operator >(const etl::ivector<T*>& lhs, const etl::ivector<T*>& rhs) |
bobbery | 0:b47c2a7920c2 | 497 | { |
bobbery | 0:b47c2a7920c2 | 498 | return pvoidvector_greater_than(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 499 | } |
bobbery | 0:b47c2a7920c2 | 500 | |
bobbery | 0:b47c2a7920c2 | 501 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 502 | /// Less than or equal operator. |
bobbery | 0:b47c2a7920c2 | 503 | ///\param lhs Reference to the first vector. |
bobbery | 0:b47c2a7920c2 | 504 | ///\param rhs Reference to the second vector. |
bobbery | 0:b47c2a7920c2 | 505 | ///\return <b>true</b> if the first vector is lexigraphically less than or equal to the second, otherwise <b>false</b> |
bobbery | 0:b47c2a7920c2 | 506 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 507 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 508 | template <typename T> |
bobbery | 0:b47c2a7920c2 | 509 | bool operator <=(const etl::ivector<T*>& lhs, const etl::ivector<T*>& rhs) |
bobbery | 0:b47c2a7920c2 | 510 | { |
bobbery | 0:b47c2a7920c2 | 511 | return pvoidvector_less_than_equal(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 512 | } |
bobbery | 0:b47c2a7920c2 | 513 | |
bobbery | 0:b47c2a7920c2 | 514 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 515 | /// Greater than or equal operator. |
bobbery | 0:b47c2a7920c2 | 516 | ///\param lhs Reference to the first vector. |
bobbery | 0:b47c2a7920c2 | 517 | ///\param rhs Reference to the second vector. |
bobbery | 0:b47c2a7920c2 | 518 | ///\return <b>true</b> if the first vector is lexigraphically greater than or equal to the second, otherwise <b>false</b> |
bobbery | 0:b47c2a7920c2 | 519 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 520 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 521 | template <typename T> |
bobbery | 0:b47c2a7920c2 | 522 | bool operator >=(const etl::ivector<T*>& lhs, const etl::ivector<T*>& rhs) |
bobbery | 0:b47c2a7920c2 | 523 | { |
bobbery | 0:b47c2a7920c2 | 524 | return pvoidvector_greater_than_equal(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 525 | } |
bobbery | 0:b47c2a7920c2 | 526 | |
bobbery | 0:b47c2a7920c2 | 527 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 528 | // Helper functions |
bobbery | 0:b47c2a7920c2 | 529 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 530 | inline bool pvoidvector_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) |
bobbery | 0:b47c2a7920c2 | 531 | { |
bobbery | 0:b47c2a7920c2 | 532 | return operator ==(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 533 | } |
bobbery | 0:b47c2a7920c2 | 534 | |
bobbery | 0:b47c2a7920c2 | 535 | inline bool pvoidvector_not_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) |
bobbery | 0:b47c2a7920c2 | 536 | { |
bobbery | 0:b47c2a7920c2 | 537 | return operator !=(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 538 | } |
bobbery | 0:b47c2a7920c2 | 539 | |
bobbery | 0:b47c2a7920c2 | 540 | inline bool pvoidvector_less_than(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) |
bobbery | 0:b47c2a7920c2 | 541 | { |
bobbery | 0:b47c2a7920c2 | 542 | return operator <(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 543 | } |
bobbery | 0:b47c2a7920c2 | 544 | |
bobbery | 0:b47c2a7920c2 | 545 | inline bool pvoidvector_greater_than(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) |
bobbery | 0:b47c2a7920c2 | 546 | { |
bobbery | 0:b47c2a7920c2 | 547 | return operator >(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 548 | } |
bobbery | 0:b47c2a7920c2 | 549 | |
bobbery | 0:b47c2a7920c2 | 550 | inline bool pvoidvector_less_than_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) |
bobbery | 0:b47c2a7920c2 | 551 | { |
bobbery | 0:b47c2a7920c2 | 552 | return operator <=(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 553 | } |
bobbery | 0:b47c2a7920c2 | 554 | |
bobbery | 0:b47c2a7920c2 | 555 | inline bool pvoidvector_greater_than_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) |
bobbery | 0:b47c2a7920c2 | 556 | { |
bobbery | 0:b47c2a7920c2 | 557 | return operator >=(lhs, rhs); |
bobbery | 0:b47c2a7920c2 | 558 | } |
bobbery | 0:b47c2a7920c2 | 559 | } |
bobbery | 0:b47c2a7920c2 | 560 | |
bobbery | 0:b47c2a7920c2 | 561 | #endif |
bobbery | 0:b47c2a7920c2 | 562 |