ORIGINAL
Loading...
Searching...
No Matches
serial.h
1#ifndef SERIAL_H
2#define SERIAL_H
3
4#include "container.h"
5
6namespace original{
7 template <typename TYPE>
8 class serial : public container<TYPE>{
9 protected:
10 [[nodiscard]] bool indexOutOfBound(int64_t index) const;
11 [[nodiscard]] int64_t parseNegIndex(int64_t index) const;
12 public:
13 virtual TYPE get(int64_t index) const = 0;
14 virtual TYPE getBegin() const;
15 virtual TYPE getEnd() const;
16 virtual TYPE operator[](int64_t index) const;
17 virtual TYPE& operator[](int64_t index) = 0;
18 virtual void set(int64_t index, const TYPE& e) = 0;
19 virtual uint32_t indexOf(const TYPE& e) const = 0;
20 bool contains(const TYPE& e) const override;
21 };
22}
23
24 template<typename TYPE>
25 auto original::serial<TYPE>::indexOutOfBound(const int64_t index) const -> bool
26 {
27 int64_t parsed_index = this->parseNegIndex(index);
28 return parsed_index < 0 || parsed_index >= this->size();
29 }
30
31 template<typename TYPE>
32 auto original::serial<TYPE>::parseNegIndex(int64_t index) const -> int64_t {
33 return index >= 0 ? index : this->size() + index;
34 }
35
36 template<typename TYPE>
37 auto original::serial<TYPE>::getBegin() const -> TYPE {
38 return this->get(0);
39 }
40
41 template<typename TYPE>
42 auto original::serial<TYPE>::getEnd() const -> TYPE {
43 return this->get(-1);
44 }
45
46 template <typename TYPE>
47 auto original::serial<TYPE>::operator[](const int64_t index) const -> TYPE
48 {
49 return this->get(index);
50 }
51
52 template <typename TYPE>
53 auto original::serial<TYPE>::contains(const TYPE &e) const -> bool
54 {
55 return this->indexOf(e) != this->size();
56 }
57
58#endif //SERIAL_H
Definition container.h:10
Definition serial.h:8