ORIGINAL
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1#ifndef STACK_H
2#define STACK_H
3
10
11#include "chain.h"
12#include "containerAdapter.h"
13#include <string>
14
15namespace original {
16
35 template<typename TYPE,
36 template <typename, typename> typename SERIAL = chain,
37 template <typename> typename ALLOC = allocator>
38 class stack final : public containerAdapter<TYPE, SERIAL, ALLOC> {
39 public:
47 explicit stack(const SERIAL<TYPE, ALLOC<TYPE>>& serial = SERIAL<TYPE, ALLOC<TYPE>>{});
48
55 stack(const std::initializer_list<TYPE>& lst);
56
62 stack(const stack& other);
63
70 stack& operator=(const stack& other);
71
78 stack(stack&& other) noexcept;
79
87 stack& operator=(stack&& other) noexcept;
88
96 void push(const TYPE& e);
97
107 TYPE pop();
108
117 TYPE top() const;
118
123 [[nodiscard]] std::string className() const override;
124 };
125}
126
127 template<typename TYPE,
128 template <typename, typename> typename SERIAL,
129 template <typename> typename ALLOC>
130 original::stack<TYPE, SERIAL, ALLOC>::stack(const SERIAL<TYPE, ALLOC<TYPE>>& serial)
131 : containerAdapter<TYPE, SERIAL, ALLOC>(serial) {}
132
133 template<typename TYPE,
134 template <typename, typename> typename SERIAL,
135 template <typename> typename ALLOC>
136 original::stack<TYPE, SERIAL, ALLOC>::stack(const std::initializer_list<TYPE> &lst)
137 : stack(SERIAL<TYPE, ALLOC<TYPE>>(lst)) {}
138
139 template<typename TYPE,
140 template <typename, typename> typename SERIAL,
141 template <typename> typename ALLOC>
143 : containerAdapter<TYPE, SERIAL, ALLOC>(other.serial_) {}
144
145 template<typename TYPE,
146 template <typename, typename> typename SERIAL,
147 template <typename> typename ALLOC>
149 if (this == &other) return *this;
150 this->serial_ = other.serial_;
151 return *this;
152 }
153
154 template<typename TYPE,
155 template <typename, typename> typename SERIAL,
156 template <typename> typename ALLOC>
158 {
159 this->operator=(std::move(other));
160 }
161
162template<typename TYPE,
163 template <typename, typename> typename SERIAL,
164 template <typename> typename ALLOC>
166 {
167 if (this == &other)
168 return *this;
169
170 this->serial_ = std::move(other.serial_);
171 other.serial_ = SERIAL<TYPE, ALLOC<TYPE>>{};
172 return *this;
173 }
174
175 template<typename TYPE,
176 template <typename, typename> typename SERIAL,
177 template <typename> typename ALLOC>
178 auto original::stack<TYPE, SERIAL, ALLOC>::push(const TYPE& e) -> void {
179 this->serial_.pushEnd(e);
180 }
181
182 template<typename TYPE,
183 template <typename, typename> typename SERIAL,
184 template <typename> typename ALLOC>
186 return this->serial_.popEnd();
187 }
188
189 template<typename TYPE,
190 template <typename, typename> typename SERIAL,
191 template <typename> typename ALLOC>
193 return this->serial_.getEnd();
194 }
195
196 template<typename TYPE,
197 template <typename, typename> typename SERIAL,
198 template <typename> typename ALLOC>
200 return "stack";
201 }
202
203#endif // STACK_H
Non-cyclic doubly linked list implementation.
Default memory allocator using allocators utilities.
Definition allocator.h:154
Non-cyclic doubly linked list container.
Definition chain.h:36
chain< TYPE, allocator< TYPE > > serial_
Definition containerAdapter.h:60
containerAdapter(const chain< TYPE, allocator< TYPE > > &serial)
Definition containerAdapter.h:139
Abstract base class for sequential containers with index-based access.
Definition serial.h:34
TYPE top() const
Accesses the top element of the stack.
Definition stack.h:192
stack & operator=(const stack &other)
Copy assignment operator.
Definition stack.h:148
void push(const TYPE &e)
Pushes element to the top of the stack.
Definition stack.h:178
TYPE pop()
Removes and returns top element from the stack.
Definition stack.h:185
stack(const SERIAL< TYPE, ALLOC< TYPE > > &serial=SERIAL< TYPE, ALLOC< TYPE > >{})
Constructs a stack with specified underlying container and allocator.
Definition stack.h:130
std::string className() const override
Gets the class name identifier.
Definition stack.h:199
Base class for container adapters with common interfaces.
Main namespace for the project Original.
Definition algorithms.h:21