Embedded Template Library  1.0
 All Classes Files Functions Variables Typedefs Friends Modules Pages
istack.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_ISTACK__
30 #define __ETL_ISTACK__
31 #define __ETL_IN_ISTACK_H__
32 
33 #include <stddef.h>
34 
35 #include "stack_base.h"
36 #include "type_traits.h"
37 #include "parameter_type.h"
38 
39 #ifndef ETL_THROW_EXCEPTIONS
40 #include "error_handler.h"
41 #endif
42 
43 namespace etl
44 {
45  //***************************************************************************
55  //***************************************************************************
56  template <typename T>
57  class istack : public stack_base
58  {
59  public:
60 
61  typedef T value_type;
62  typedef T& reference;
63  typedef const T& const_reference;
64  typedef T* pointer;
65  typedef const T* const_pointer;
67 
68  private:
69 
70  typedef typename parameter_type<T>::type parameter_t;
71 
72  public:
73 
74  //*************************************************************************
77  //*************************************************************************
78  reference top()
79  {
80  return buffer[top_index];
81  }
82 
83  //*************************************************************************
88  //*************************************************************************
89  void push(parameter_t item)
90  {
91  if (!full())
92  {
94  buffer[top_index] = item;
95  }
96  else
97 #ifdef ETL_THROW_EXCEPTIONS
98  {
99  throw stack_full();
100  }
101 #else
102  {
104  }
105 #endif
106  }
107 
108  //*************************************************************************
115  //*************************************************************************
116  reference push()
117  {
118  if (!full())
119  {
121  }
122  else
123 #ifdef ETL_THROW_EXCEPTIONS
124  {
125  throw stack_full();
126  }
127 #else
128  {
130  }
131 #endif
132 
133  return buffer[top_index];
134  }
135 
136  //*************************************************************************
139  //*************************************************************************
140  const_reference top() const
141  {
142  return buffer[top_index];
143  }
144 
145  protected:
146 
147  //*************************************************************************
149  //*************************************************************************
150  istack(T* buffer, size_type max_size)
151  : stack_base(max_size),
152  buffer(buffer)
153  {
154  }
155 
156  private:
157 
158  T* buffer;
159  };
160 }
161 
162 #undef __etl_in_istack_h__
163 #endif
Definition: stack_base.h:60
T * pointer
A pointer to the type used in the stack.
Definition: istack.h:64
T value_type
The type stored in the stack.
Definition: istack.h:61
Determine how to pass parameters.
Definition: parameter_type.h:40
reference top()
Definition: istack.h:78
bool full() const
Definition: stack_base.h:94
This is the base for all stacks that contain a particular type.
Definition: istack.h:57
stack_base::size_type size_type
The type used for determining the size of the stack.
Definition: istack.h:66
Definition: algorithm.h:43
istack(T *buffer, size_type max_size)
The constructor that is called from derived classes.
Definition: istack.h:150
size_type top_index
The index of the top of the stack.
Definition: stack_base.h:165
size_type current_size
The number of items in the stack.
Definition: stack_base.h:166
const T & const_reference
A const reference to the type used in the stack.
Definition: istack.h:63
T & reference
A reference to the type used in the stack.
Definition: istack.h:62
size_type max_size() const
Returns the maximum number of items that can be stacked.
Definition: stack_base.h:118
size_t size_type
The type used for determining the size of stack.
Definition: stack_base.h:79
static void error(const exception &e)
Definition: error_handler.cpp:50
reference push()
Definition: istack.h:116
const_reference top() const
Definition: istack.h:140
void push(parameter_t item)
Definition: istack.h:89
Definition: stack_base.h:75
const T * const_pointer
A const pointer to the type used in the stack.
Definition: istack.h:65