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
15namespace original {
25template <typename TYPE, typename ALLOC>
26class container {
27protected:
33
40 explicit container(ALLOC alloc = ALLOC{});
41
49
57
66 template<typename O_TYPE, typename... Args>
68
75 template<typename O_TYPE>
77public:
88 [[nodiscard]] virtual u_integer size() const = 0;
89
100 [[nodiscard]] bool empty() const;
101
113 virtual bool contains(const TYPE& e) const = 0;
114
119 virtual ~container() = default;
120};
121
122} // namespace original
123
124// ----------------- Definitions of container.h -----------------
125
126template<typename TYPE, typename ALLOC>
129
130template<typename TYPE, typename ALLOC>
134
135template<typename TYPE, typename ALLOC>
139
140template<typename TYPE, typename ALLOC>
141template<typename O_TYPE, typename... Args>
143 this->allocator.construct(o_ptr, std::forward<Args>(args)...);
144}
145
146template<typename TYPE, typename ALLOC>
147template<typename O_TYPE>
151
152template <typename TYPE, typename ALLOC>
154 return this->size() == 0;
155}
156
157#endif //CONTAINER_H
void construct(O_TYPE *o_ptr, Args &&... args)
Constructs an object in allocated memory.
Definition allocator.h:391
static void destroy(O_TYPE *o_ptr)
Destroys an object without deallocating.
Definition allocator.h:397
Default memory allocator using allocators utilities.
Definition allocator.h:153
void deallocate(TYPE *ptr, u_integer size) override
Deallocates memory using global operator delete.
Definition allocator.h:407
TYPE * allocate(u_integer size) override
Allocates memory using global operator new.
Definition allocator.h:402
Abstract base class for containers.
Definition container.h:26
ALLOC allocator
The allocator instance used for memory management.
Definition container.h:32
virtual u_integer size() const =0
Gets the number of elements in the container.
bool empty() const
Checks if the container is empty.
Definition container.h:153
virtual ~container()=default
Destructor for the container class.
void deallocate(TYPE *ptr, u_integer size)
Deallocates memory previously allocated by allocate()
Definition container.h:136
container(ALLOC alloc=ALLOC{})
Constructs a container with specified allocator.
Definition container.h:127
TYPE * allocate(u_integer size)
Allocates raw memory for elements.
Definition container.h:131
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:148
void construct(O_TYPE *o_ptr, Args &&... args)
Constructs an element in-place.
Definition container.h:142
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Platform-independent type definitions and compiler/platform detection.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
Main namespace for the project Original.
Definition algorithms.h:21
Standard namespace extensions for original::alternative.
Definition allocator.h:351