Containers (STL-compatible) StateMachines MessageBus and more for Embedded Systems. See www.etlcpp.com
private/vector_base.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) 2014 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 | #if !defined(__ETL_IN_VECTOR_H__) && !defined(__ETL_IN_PVOIDVECTOR__) |
bobbery | 0:b47c2a7920c2 | 32 | #error This header is a private element of etl::vector & etl::pvoidvector |
bobbery | 0:b47c2a7920c2 | 33 | #endif |
bobbery | 0:b47c2a7920c2 | 34 | |
bobbery | 0:b47c2a7920c2 | 35 | #ifndef __ETL_VECTOR_BASE__ |
bobbery | 0:b47c2a7920c2 | 36 | #define __ETL_VECTOR_BASE__ |
bobbery | 0:b47c2a7920c2 | 37 | |
bobbery | 0:b47c2a7920c2 | 38 | #include <stddef.h> |
bobbery | 0:b47c2a7920c2 | 39 | |
bobbery | 0:b47c2a7920c2 | 40 | #include "../platform.h" |
bobbery | 0:b47c2a7920c2 | 41 | #include "../exception.h" |
bobbery | 0:b47c2a7920c2 | 42 | #include "../error_handler.h" |
bobbery | 0:b47c2a7920c2 | 43 | #include "../debug_count.h" |
bobbery | 0:b47c2a7920c2 | 44 | |
bobbery | 0:b47c2a7920c2 | 45 | #define ETL_FILE "17" |
bobbery | 0:b47c2a7920c2 | 46 | |
bobbery | 0:b47c2a7920c2 | 47 | namespace etl |
bobbery | 0:b47c2a7920c2 | 48 | { |
bobbery | 0:b47c2a7920c2 | 49 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 50 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 51 | /// Exception base for vectors |
bobbery | 0:b47c2a7920c2 | 52 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 53 | class vector_exception : public exception |
bobbery | 0:b47c2a7920c2 | 54 | { |
bobbery | 0:b47c2a7920c2 | 55 | public: |
bobbery | 0:b47c2a7920c2 | 56 | |
bobbery | 0:b47c2a7920c2 | 57 | vector_exception(string_type reason_, string_type file_name_, numeric_type line_number_) |
bobbery | 0:b47c2a7920c2 | 58 | : exception(reason_, file_name_, line_number_) |
bobbery | 0:b47c2a7920c2 | 59 | { |
bobbery | 0:b47c2a7920c2 | 60 | } |
bobbery | 0:b47c2a7920c2 | 61 | }; |
bobbery | 0:b47c2a7920c2 | 62 | |
bobbery | 0:b47c2a7920c2 | 63 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 64 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 65 | /// Vector full exception. |
bobbery | 0:b47c2a7920c2 | 66 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 67 | class vector_full : public vector_exception |
bobbery | 0:b47c2a7920c2 | 68 | { |
bobbery | 0:b47c2a7920c2 | 69 | public: |
bobbery | 0:b47c2a7920c2 | 70 | |
bobbery | 0:b47c2a7920c2 | 71 | vector_full(string_type file_name_, numeric_type line_number_) |
bobbery | 0:b47c2a7920c2 | 72 | : vector_exception(ETL_ERROR_TEXT("vector:full", ETL_FILE"A"), file_name_, line_number_) |
bobbery | 0:b47c2a7920c2 | 73 | { |
bobbery | 0:b47c2a7920c2 | 74 | } |
bobbery | 0:b47c2a7920c2 | 75 | }; |
bobbery | 0:b47c2a7920c2 | 76 | |
bobbery | 0:b47c2a7920c2 | 77 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 78 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 79 | /// Vector empty exception. |
bobbery | 0:b47c2a7920c2 | 80 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 81 | class vector_empty : public vector_exception |
bobbery | 0:b47c2a7920c2 | 82 | { |
bobbery | 0:b47c2a7920c2 | 83 | public: |
bobbery | 0:b47c2a7920c2 | 84 | |
bobbery | 0:b47c2a7920c2 | 85 | vector_empty(string_type file_name_, numeric_type line_number_) |
bobbery | 0:b47c2a7920c2 | 86 | : vector_exception(ETL_ERROR_TEXT("vector:empty", ETL_FILE"B"), file_name_, line_number_) |
bobbery | 0:b47c2a7920c2 | 87 | { |
bobbery | 0:b47c2a7920c2 | 88 | } |
bobbery | 0:b47c2a7920c2 | 89 | }; |
bobbery | 0:b47c2a7920c2 | 90 | |
bobbery | 0:b47c2a7920c2 | 91 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 92 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 93 | /// Vector out of bounds exception. |
bobbery | 0:b47c2a7920c2 | 94 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 95 | class vector_out_of_bounds : public vector_exception |
bobbery | 0:b47c2a7920c2 | 96 | { |
bobbery | 0:b47c2a7920c2 | 97 | public: |
bobbery | 0:b47c2a7920c2 | 98 | |
bobbery | 0:b47c2a7920c2 | 99 | vector_out_of_bounds(string_type file_name_, numeric_type line_number_) |
bobbery | 0:b47c2a7920c2 | 100 | : vector_exception(ETL_ERROR_TEXT("vector:bounds", ETL_FILE"C"), file_name_, line_number_) |
bobbery | 0:b47c2a7920c2 | 101 | { |
bobbery | 0:b47c2a7920c2 | 102 | } |
bobbery | 0:b47c2a7920c2 | 103 | }; |
bobbery | 0:b47c2a7920c2 | 104 | |
bobbery | 0:b47c2a7920c2 | 105 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 106 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 107 | /// Vector incompatible type exception. |
bobbery | 0:b47c2a7920c2 | 108 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 109 | class vector_incompatible_type : public vector_exception |
bobbery | 0:b47c2a7920c2 | 110 | { |
bobbery | 0:b47c2a7920c2 | 111 | public: |
bobbery | 0:b47c2a7920c2 | 112 | |
bobbery | 0:b47c2a7920c2 | 113 | vector_incompatible_type(string_type file_name_, numeric_type line_number_) |
bobbery | 0:b47c2a7920c2 | 114 | : vector_exception(ETL_ERROR_TEXT("vector:type", ETL_FILE"D"), file_name_, line_number_) |
bobbery | 0:b47c2a7920c2 | 115 | { |
bobbery | 0:b47c2a7920c2 | 116 | } |
bobbery | 0:b47c2a7920c2 | 117 | }; |
bobbery | 0:b47c2a7920c2 | 118 | |
bobbery | 0:b47c2a7920c2 | 119 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 120 | ///\ingroup vector |
bobbery | 0:b47c2a7920c2 | 121 | /// The base class for all templated vector types. |
bobbery | 0:b47c2a7920c2 | 122 | //*************************************************************************** |
bobbery | 0:b47c2a7920c2 | 123 | class vector_base |
bobbery | 0:b47c2a7920c2 | 124 | { |
bobbery | 0:b47c2a7920c2 | 125 | public: |
bobbery | 0:b47c2a7920c2 | 126 | |
bobbery | 0:b47c2a7920c2 | 127 | typedef size_t size_type; |
bobbery | 0:b47c2a7920c2 | 128 | |
bobbery | 0:b47c2a7920c2 | 129 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 130 | /// Returns the capacity of the vector. |
bobbery | 0:b47c2a7920c2 | 131 | ///\return The capacity of the vector. |
bobbery | 0:b47c2a7920c2 | 132 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 133 | size_type capacity() const |
bobbery | 0:b47c2a7920c2 | 134 | { |
bobbery | 0:b47c2a7920c2 | 135 | return CAPACITY; |
bobbery | 0:b47c2a7920c2 | 136 | } |
bobbery | 0:b47c2a7920c2 | 137 | |
bobbery | 0:b47c2a7920c2 | 138 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 139 | /// Returns the maximum possible size of the vector. |
bobbery | 0:b47c2a7920c2 | 140 | ///\return The maximum size of the vector. |
bobbery | 0:b47c2a7920c2 | 141 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 142 | size_type max_size() const |
bobbery | 0:b47c2a7920c2 | 143 | { |
bobbery | 0:b47c2a7920c2 | 144 | return CAPACITY; |
bobbery | 0:b47c2a7920c2 | 145 | } |
bobbery | 0:b47c2a7920c2 | 146 | |
bobbery | 0:b47c2a7920c2 | 147 | protected: |
bobbery | 0:b47c2a7920c2 | 148 | |
bobbery | 0:b47c2a7920c2 | 149 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 150 | /// Constructor. |
bobbery | 0:b47c2a7920c2 | 151 | //************************************************************************* |
bobbery | 0:b47c2a7920c2 | 152 | vector_base(size_type max_size_) |
bobbery | 0:b47c2a7920c2 | 153 | : CAPACITY(max_size_) |
bobbery | 0:b47c2a7920c2 | 154 | { |
bobbery | 0:b47c2a7920c2 | 155 | } |
bobbery | 0:b47c2a7920c2 | 156 | |
bobbery | 0:b47c2a7920c2 | 157 | const size_type CAPACITY; ///<The maximum number of elements in the vector. |
bobbery | 0:b47c2a7920c2 | 158 | etl::debug_count construct_count; ///< Internal debugging. |
bobbery | 0:b47c2a7920c2 | 159 | }; |
bobbery | 0:b47c2a7920c2 | 160 | } |
bobbery | 0:b47c2a7920c2 | 161 | |
bobbery | 0:b47c2a7920c2 | 162 | #undef ETL_FILE |
bobbery | 0:b47c2a7920c2 | 163 | |
bobbery | 0:b47c2a7920c2 | 164 | #endif |
bobbery | 0:b47c2a7920c2 | 165 |