Embedded Template Library  1.0
 All Classes Files Functions Variables Typedefs Friends Modules Pages
deque.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_DEQUE__
30 #define __ETL_DEQUE__
31 
32 #include <stddef.h>
33 #include <iterator>
34 #include <algorithm>
35 
36 #include "ideque.h"
37 #include "container.h"
38 
39 //*****************************************************************************
43 //*****************************************************************************
44 
45 namespace etl
46 {
47  //***************************************************************************
53  //***************************************************************************
54  template <typename T, const size_t MAX_SIZE_>
55  class deque : public ideque<T>
56  {
57  public:
58 
59  static const size_t MAX_SIZE = MAX_SIZE_;
60 
61  private:
62 
63  static const size_t BUFFER_SIZE = MAX_SIZE + 1;
64 
65  public:
66 
67  typedef T value_type;
68  typedef T* pointer;
69  typedef const T* const_pointer;
70  typedef T& reference;
71  typedef const T& const_reference;
72  typedef size_t size_type;
73  typedef typename std::iterator_traits<pointer>::difference_type difference_type;
74 
75  //*************************************************************************
77  //*************************************************************************
79  : ideque<T>(&buffer[0], MAX_SIZE, BUFFER_SIZE)
80  {
81  }
82 
83  //*************************************************************************
85  //*************************************************************************
86  deque(const deque& other)
87  : ideque<T>(&buffer[0], MAX_SIZE, BUFFER_SIZE)
88  {
89  ideque<T>::assign(other.begin(), other.end());
90  }
91 
92  //*************************************************************************
94  //*************************************************************************
95  template <typename TIterator>
96  deque(TIterator begin, TIterator end)
97  : ideque<T>(&buffer[0], MAX_SIZE, BUFFER_SIZE)
98  {
99  ideque<T>::assign(begin, end);
100  }
101 
102  //*************************************************************************
104  //*************************************************************************
105  explicit deque(size_t n, typename ideque<T>::parameter_t value = value_type())
106  : ideque<T>(&buffer[0], MAX_SIZE, BUFFER_SIZE)
107  {
108  ideque<T>::assign(n, value);
109  }
110 
111  //*************************************************************************
113  //*************************************************************************
114  deque& operator =(const deque& other)
115  {
116  ideque<T>::assign(other.begin(), other.end());
117 
118  return *this;
119  }
120 
121  //*************************************************************************
123  //*************************************************************************
124  void swap(deque& other)
125  {
126  // Swap the internal iterators.
127  this->first.swap(other.first);
128  this->last.swap(other.last);
129 
130  // Swap the other data.
131  std::swap_ranges(etl::begin(buffer), etl::end(buffer), etl::begin(other.buffer));
132  std::swap(this->current_size, other.current_size);
133  }
134 
135  private:
136 
138  T buffer[BUFFER_SIZE];
139  };
140 
141  //*************************************************************************
143  //*************************************************************************
144  template <typename T, const size_t MAX_SIZE>
146  {
147  first.swap(second);
148  }
149 }
150 
151 #endif
iterator last
Iterator to the first item in the deque.
Definition: ideque.h:1291
Definition: ideque.h:52
void swap(etl::bitset< N > &lhs, etl::bitset< N > &rhs)
swap
Definition: bitset.h:1200
deque(TIterator begin, TIterator end)
Assigns data to the deque.
Definition: deque.h:96
Definition: algorithm.h:43
iterator end()
Gets an iterator to the end of the deque.
Definition: ideque.h:646
TContainer::iterator end(TContainer &container)
Definition: container.h:95
TContainer::iterator begin(TContainer &container)
Definition: container.h:45
void swap(deque &other)
Swap.
Definition: deque.h:124
iterator begin()
Gets an iterator to the beginning of the deque.
Definition: ideque.h:622
size_type current_size
The current number of elements in the deque.
Definition: deque_base.h:182
etl::enable_if< is_iterator< TIterator >::value, void >::type assign(TIterator range_begin, TIterator range_end)
Assigns a range to the deque.
Definition: ideque.h:477
deque()
Default constructor.
Definition: deque.h:78
deque(const deque &other)
Copy constructor.
Definition: deque.h:86
Definition: deque.h:55
deque(size_t n, typename ideque< T >::parameter_t value=value_type())
Assigns data to the deque.
Definition: deque.h:105
deque & operator=(const deque &other)
Assignment operator.
Definition: deque.h:114