Embedded Template Library  1.0
vector_base.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) 2014 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 #if !defined(ETL_IN_VECTOR_H) && !defined(ETL_IN_PVOIDVECTOR)
32 #error This header is a private element of etl::vector & etl::pvoidvector
33 #endif
34 
35 #ifndef ETL_VECTOR_BASE_INCLUDED
36 #define ETL_VECTOR_BASE_INCLUDED
37 
38 #include <stddef.h>
39 
40 #include "../platform.h"
41 #include "../exception.h"
42 #include "../error_handler.h"
43 #include "../debug_count.h"
44 
45 #undef ETL_FILE
46 #define ETL_FILE "17"
47 
48 namespace etl
49 {
50  //***************************************************************************
53  //***************************************************************************
54  class vector_exception : public exception
55  {
56  public:
57 
58  vector_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
59  : exception(reason_, file_name_, line_number_)
60  {
61  }
62  };
63 
64  //***************************************************************************
67  //***************************************************************************
69  {
70  public:
71 
72  vector_full(string_type file_name_, numeric_type line_number_)
73  : vector_exception(ETL_ERROR_TEXT("vector:full", ETL_FILE"A"), file_name_, line_number_)
74  {
75  }
76  };
77 
78  //***************************************************************************
81  //***************************************************************************
83  {
84  public:
85 
86  vector_empty(string_type file_name_, numeric_type line_number_)
87  : vector_exception(ETL_ERROR_TEXT("vector:empty", ETL_FILE"B"), file_name_, line_number_)
88  {
89  }
90  };
91 
92  //***************************************************************************
95  //***************************************************************************
97  {
98  public:
99 
100  vector_out_of_bounds(string_type file_name_, numeric_type line_number_)
101  : vector_exception(ETL_ERROR_TEXT("vector:bounds", ETL_FILE"C"), file_name_, line_number_)
102  {
103  }
104  };
105 
106  //***************************************************************************
109  //***************************************************************************
111  {
112  public:
113 
114  vector_incompatible_type(string_type file_name_, numeric_type line_number_)
115  : vector_exception(ETL_ERROR_TEXT("vector:type", ETL_FILE"D"), file_name_, line_number_)
116  {
117  }
118  };
119 
120  //***************************************************************************
123  //***************************************************************************
125  {
126  public:
127 
128  typedef size_t size_type;
129 
130  //*************************************************************************
133  //*************************************************************************
134  size_type capacity() const
135  {
136  return CAPACITY;
137  }
138 
139  //*************************************************************************
142  //*************************************************************************
143  size_type max_size() const
144  {
145  return CAPACITY;
146  }
147 
148  protected:
149 
150  //*************************************************************************
152  //*************************************************************************
153  vector_base(size_t max_size_)
154  : CAPACITY(max_size_)
155  {
156  }
157 
158  //*************************************************************************
160  //*************************************************************************
162  {
163  }
164 
165  const size_type CAPACITY;
166  ETL_DECLARE_DEBUG_COUNT
167  };
168 }
169 
170 #undef ETL_FILE
171 
172 #endif
exception(string_type reason_, string_type file_, numeric_type line_)
Constructor.
Definition: exception.h:67
Definition: exception.h:47
size_type max_size() const
Definition: vector_base.h:143
size_type capacity() const
Definition: vector_base.h:134
vector_base(size_t max_size_)
Constructor.
Definition: vector_base.h:153
const size_type CAPACITY
The maximum number of elements in the vector.
Definition: vector_base.h:165
~vector_base()
Destructor.
Definition: vector_base.h:161
Definition: vector_base.h:125
Definition: vector_base.h:83
Definition: vector_base.h:55
Definition: vector_base.h:69
Definition: vector_base.h:111
Definition: vector_base.h:97
Definition: absolute.h:37