1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #ifndef CORE_STACK_HPP
- #define CORE_STACK_HPP
- #include "data/ArrayList.hpp"
- #include "data/List.hpp"
- namespace Core {
- namespace Internal {
- template<typename T, typename S>
- class BaseStack final {
- S data{};
- public:
- template<typename... Args>
- check_return Error push(Args&&... args) {
- return data.add(Core::forward<Args>(args)...);
- }
- void clear() {
- data.clear();
- }
- check_return Error pop() {
- return data.removeBySwap(data.getLength() - 1);
- }
- bool isEmpty() const {
- return data.getLength() == 0;
- }
- T& peek() {
- return data[data.getLength() - 1];
- }
- const T& peek() const {
- return data[data.getLength() - 1];
- }
- template<typename String>
- check_return Error toString(String& s) const {
- return s.append(data);
- }
- };
- }
- template<typename T>
- using ListStack = Internal::BaseStack<T, List<T>>;
- template<typename T, int N>
- using ArrayStack = Internal::BaseStack<T, ArrayList<T, N>>;
- }
- #endif
|