Embedded Template Library  1.0
 All Classes Files Functions Variables Typedefs Friends Modules Pages
deque_base.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 
8 Copyright(c) 2014 jwellbelove
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files(the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions :
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 SOFTWARE.
27 ******************************************************************************/
28 
29 #ifndef __ETL_IN_IDEQUE_H__
30 #error This header is a private element of etl::deque & etl::ideque
31 #endif
32 
33 #ifndef __ETL_DEQUE_BASE__
34 #define __ETL_DEQUE_BASE__
35 
36 #include <stddef.h>
37 
38 #include "exception.h"
39 
40 namespace etl
41 {
42  //***************************************************************************
45  //***************************************************************************
46  class deque_exception : public exception
47  {
48  public:
49 
50  deque_exception(const char* what)
51  : exception(what)
52  {
53  }
54  };
55 
56  //***************************************************************************
59  //***************************************************************************
60  class deque_full : public deque_exception
61  {
62  public:
63 
64  deque_full()
65  : deque_exception("deque: full")
66  {
67  }
68  };
69 
70  //***************************************************************************
73  //***************************************************************************
75  {
76  public:
77 
78  deque_empty()
79  : deque_exception("deque: empty")
80  {
81  }
82  };
83 
84  //***************************************************************************
87  //***************************************************************************
89  {
90  public:
91 
93  : deque_exception("deque: out of bounds")
94  {
95  }
96  };
97 
98  //***************************************************************************
101  //***************************************************************************
103  {
104  public:
105 
106  typedef size_t size_type;
107 
108  //*************************************************************************
111  //*************************************************************************
112  size_type size() const
113  {
114  return current_size;
115  }
116 
117  //*************************************************************************
120  //*************************************************************************
121  bool empty() const
122  {
123  return (current_size == 0);
124  }
125 
126  //*************************************************************************
129  //*************************************************************************
130  bool full() const
131  {
132  return current_size == MAX_SIZE;
133  }
134 
135  //*************************************************************************
138  //*************************************************************************
139  size_type capacity() const
140  {
141  return MAX_SIZE;
142  }
143 
144  //*************************************************************************
147  //*************************************************************************
148  size_type max_size() const
149  {
150  return MAX_SIZE;
151  }
152 
153  //*************************************************************************
156  //*************************************************************************
157  size_t available() const
158  {
159  return max_size() - size();
160  }
161 
162  //*************************************************************************
164  //*************************************************************************
165  void clear()
166  {
167  current_size = 0;
168  }
169 
170  protected:
171 
172  //*************************************************************************
174  //*************************************************************************
175  deque_base(size_t max_size, size_t buffer_size)
176  : current_size(0),
177  MAX_SIZE(max_size),
178  BUFFER_SIZE(buffer_size)
179  {
180  }
181 
182  size_type current_size;
183  const size_type MAX_SIZE;
184  const size_type BUFFER_SIZE;
185  };
186 }
187 
188 #endif
size_type size() const
Definition: deque_base.h:112
Definition: deque_base.h:102
const size_type MAX_SIZE
The maximum number of elements in the deque.
Definition: deque_base.h:183
exception(value_type reason)
Constructor.
Definition: exception.h:51
Definition: algorithm.h:43
void clear()
Clears the deque.
Definition: deque_base.h:165
bool full() const
Definition: deque_base.h:130
size_type max_size() const
Definition: deque_base.h:148
deque_base(size_t max_size, size_t buffer_size)
Constructor.
Definition: deque_base.h:175
size_t available() const
Definition: deque_base.h:157
const size_type BUFFER_SIZE
The of elements in the buffer.
Definition: deque_base.h:184
Definition: exception.h:42
value_type what() const
Definition: exception.h:60
size_type current_size
The current number of elements in the deque.
Definition: deque_base.h:182
Definition: deque_base.h:74
size_type capacity() const
Definition: deque_base.h:139
bool empty() const
Definition: deque_base.h:121
Definition: deque_base.h:88
Definition: deque_base.h:46
Definition: deque_base.h:60