ORIGINAL
Loading...
Searching...
No Matches
serial.h
Go to the documentation of this file.
1#ifndef SERIAL_H
2#define SERIAL_H
3
4#include "container.h"
5
6namespace original {
18
33 template <typename TYPE, typename ALLOC>
34 class serial : public container<TYPE, ALLOC> {
35 protected:
42 using container<TYPE, ALLOC>::container;
43
51 [[nodiscard]] bool indexOutOfBound(integer index) const;
52
59 [[nodiscard]] integer parseNegIndex(integer index) const;
60
61 public:
68 virtual TYPE get(integer index) const = 0;
69
75 virtual TYPE getBegin() const;
76
82 virtual TYPE getEnd() const;
83
92 virtual TYPE operator[](integer index) const;
93
102 virtual TYPE& operator[](integer index) = 0;
103
110 virtual void set(integer index, const TYPE& e) = 0;
111
118 virtual u_integer indexOf(const TYPE& e) const = 0;
119
126 bool contains(const TYPE& e) const override;
127 };
128}
129
130// -------------------- Definitions of serial.h --------------------
131
132template<typename TYPE, typename ALLOC>
134{
135 integer parsed_index = this->parseNegIndex(index);
136 return parsed_index < 0 || parsed_index >= this->size();
137}
138
139template<typename TYPE, typename ALLOC>
141 return index >= 0 ? index : this->size() + index;
142}
143
144template<typename TYPE, typename ALLOC>
146 return this->get(0);
147}
148
149template<typename TYPE, typename ALLOC>
151 return this->get(-1);
152}
153
154template<typename TYPE, typename ALLOC>
156{
157 return this->get(index);
158}
159
160template<typename TYPE, typename ALLOC>
161auto original::serial<TYPE, ALLOC>::contains(const TYPE &e) const -> bool
162{
163 return this->indexOf(e) != this->size();
164}
165
166#endif //SERIAL_H
virtual u_integer size() const =0
Gets the number of elements in the container.
container(ALLOC alloc=ALLOC{})
Constructs a container with specified allocator.
Definition container.h:129
Abstract base class for sequential containers with index-based access.
Definition serial.h:34
bool contains(const TYPE &e) const override
Checks if the container contains the specified element.
Definition serial.h:161
virtual TYPE getEnd() const
Retrieves the last element in the container.
Definition serial.h:150
bool indexOutOfBound(integer index) const
Checks if the provided index is out of bounds.
Definition serial.h:133
virtual TYPE getBegin() const
Retrieves the first element in the container.
Definition serial.h:145
virtual TYPE & operator[](integer index)=0
Retrieves or sets the element at the specified index.
integer parseNegIndex(integer index) const
Converts negative indices into valid positive indices.
Definition serial.h:140
virtual TYPE get(integer index) const =0
Retrieves the element at the specified index.
virtual void set(integer index, const TYPE &e)=0
Sets the element at the specified index.
virtual TYPE operator[](integer index) const
Retrieves the element at the specified index (const version).
Definition serial.h:155
virtual u_integer indexOf(const TYPE &e) const =0
Finds the index of the specified element.
Abstract base class for container types.
Main namespace for the project Original.
Definition algorithms.h:21
std::uint32_t u_integer
32-bit unsigned integer type for sizes/indexes
Definition config.h:17
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:15