ORIGINAL
Loading...
Searching...
No Matches
container.h
Go to the documentation of this file.
1#ifndef CONTAINER_H
2#define CONTAINER_H
3#pragma once
4
5#include "config.h"
6
7
8namespace original {
9
17
27template <typename TYPE, typename ALLOC>
28class container {
29protected:
34 ALLOC allocator;
35
42 explicit container(ALLOC alloc = ALLOC{});
43
51
58 void deallocate(TYPE* ptr, u_integer size);
59
68 template<typename O_TYPE, typename... Args>
69 void construct(O_TYPE* o_ptr, Args&&... args);
70
77 template<typename O_TYPE>
78 void destroy(O_TYPE* o_ptr);
79public:
90 [[nodiscard]] virtual u_integer size() const = 0;
91
102 [[nodiscard]] bool empty() const;
103
115 virtual bool contains(const TYPE& e) const = 0;
116
121 virtual ~container() = default;
122};
123
124} // namespace original
125
126// ----------------- Definitions of container.h -----------------
127
128template<typename TYPE, typename ALLOC>
130 : allocator(std::move(alloc)) {}
131
132template<typename TYPE, typename ALLOC>
136
137template<typename TYPE, typename ALLOC>
139 this->allocator.deallocate(ptr, size);
140}
141
142template<typename TYPE, typename ALLOC>
143template<typename O_TYPE, typename... Args>
144void original::container<TYPE, ALLOC>::construct(O_TYPE *o_ptr, Args &&... args) {
145 this->allocator.construct(o_ptr, std::forward<Args>(args)...);
146}
147
148template<typename TYPE, typename ALLOC>
149template<typename O_TYPE>
151 this->allocator.destroy(o_ptr);
152}
153
154template <typename TYPE, typename ALLOC>
156 return this->size() == 0;
157}
158
159#endif //CONTAINER_H
ALLOC allocator
The allocator instance used for memory management.
Definition container.h:34
bool empty() const
Checks if the container is empty.
Definition container.h:155
virtual ~container()=default
Destructor for the container class.
void deallocate(TYPE *ptr, u_integer size)
Deallocates memory previously allocated by allocate()
Definition container.h:138
container(ALLOC alloc=ALLOC{})
Constructs a container with specified allocator.
Definition container.h:129
TYPE * allocate(u_integer size)
Allocates raw memory for elements.
Definition container.h:133
virtual bool contains(const TYPE &e) const =0
Checks if an element is contained in the container.
void destroy(O_TYPE *o_ptr)
Destroys an element.
Definition container.h:150
void construct(O_TYPE *o_ptr, Args &&... args)
Constructs an element in-place.
Definition container.h:144
Platform-independent integer and floating-point type definitions.
Main namespace for the project Original.
Definition algorithms.h:21
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:43