Embedded Template Library  1.0
 All Classes Files Functions Variables Typedefs Friends Modules Pages
list_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_ILIST_H__
30 #error This header is a private element of etl::list & etl::ilist
31 #endif
32 
33 #ifndef __ETL_LIST_BASE__
34 #define __ETL_LIST_BASE__
35 
36 #include <stddef.h>
37 #include "exception.h"
38 
39 namespace etl
40 {
41  //***************************************************************************
44  //***************************************************************************
45  class list_exception : public exception
46  {
47  public:
48 
49  list_exception(const char* what)
50  : exception(what)
51  {
52  }
53  };
54 
55  //***************************************************************************
58  //***************************************************************************
59  class list_full : public list_exception
60  {
61  public:
62 
63  list_full()
64  : list_exception("list: full")
65  {
66  }
67  };
68 
69  //***************************************************************************
72  //***************************************************************************
74  {
75  public:
76 
78  : list_exception("list: iterator problem")
79  {
80  }
81  };
82 
83  //***************************************************************************
86  //***************************************************************************
87  class list_base
88  {
89  public:
90 
91  typedef size_t size_type;
92 
93  //*************************************************************************
95  //*************************************************************************
96  size_type size() const
97  {
98  return current_size;
99  }
100 
101  //*************************************************************************
103  //*************************************************************************
104  size_type max_size() const
105  {
106  return MAX_SIZE;
107  }
108 
109  //*************************************************************************
111  //*************************************************************************
112  bool empty() const
113  {
114  return current_size == 0;
115  }
116 
117  //*************************************************************************
119  //*************************************************************************
120  bool full() const
121  {
122  return current_size == MAX_SIZE;
123  }
124 
125  //*************************************************************************
128  //*************************************************************************
129  size_t available() const
130  {
131  return max_size() - size();
132  }
133 
134  protected:
135 
136  //*************************************************************************
138  //*************************************************************************
139  list_base(size_type max_size)
140  : next_free(0),
141  current_size(0),
142  MAX_SIZE(max_size)
143 
144  {
145  }
146 
147  size_type next_free;
148  size_type current_size;
149  const size_type MAX_SIZE;
150  };
151 }
152 
153 #endif
size_t available() const
Definition: list_base.h:129
const size_type MAX_SIZE
The maximum size of the list.
Definition: list_base.h:149
list_base(size_type max_size)
The constructor that is called from derived classes.
Definition: list_base.h:139
bool full() const
Checks to see if the list is full.
Definition: list_base.h:120
Definition: list_base.h:59
size_type current_size
The number of the used nodes.
Definition: list_base.h:148
exception(value_type reason)
Constructor.
Definition: exception.h:51
Definition: list_base.h:73
bool empty() const
Checks to see if the list is empty.
Definition: list_base.h:112
Definition: algorithm.h:43
Definition: list_base.h:45
Definition: exception.h:42
size_type max_size() const
Gets the maximum possible size of the list.
Definition: list_base.h:104
size_type next_free
The index of the next free node.
Definition: list_base.h:147
Definition: list_base.h:87
value_type what() const
Definition: exception.h:60
size_type size() const
Gets the size of the list.
Definition: list_base.h:96
size_t size_type
The type used for determining the size of list.
Definition: list_base.h:91