-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringList.h
104 lines (81 loc) · 2.11 KB
/
StringList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<string>
#include <utility>
class StringList
{
class Node
{
public:
Node(Node *prev, Node *next)
{
this->prev = prev;
this->next = next;
}
virtual ~Node() = default;
virtual std::string &GetData()
{
throw std::runtime_error("Невозможно извлечь данные! :(");
}
Node *prev, *next;
};
class NodeWithData : public Node
{
public:
NodeWithData(const std::string &string, Node *prev, Node *next)
: Node(prev, next)
{
this->m_string = string;
}
std::string &GetData() override
{
return m_string;
}
std::string m_string;
};
public:
StringList();
StringList(const StringList& list);
StringList(StringList&& list) noexcept;
~StringList() noexcept;
StringList& operator=(const StringList& list);
StringList& operator=(StringList&& list) noexcept;
void PushBack(const std::string &string);
void PushFront(const std::string &string);
[[nodiscard]] size_t GetSize() const;
[[nodiscard]] bool IsEmpty() const;
void Clear();
class Iterator
{
public:
Iterator() = delete;
std::string & operator*() const;
Iterator & operator++();
Iterator operator++(int);
Iterator & operator--();
Iterator operator--(int);
bool operator==(const Iterator& other) const;
bool operator!=(const Iterator& other) const;
private:
friend StringList;
explicit Iterator(Node *node, bool isReverse = false);
Node *m_node;
bool m_isReverse;
};
std::string& GetBackElement();
[[nodiscard]] std::string const& GetBackElement() const;
std::string& GetFrontElement();
[[nodiscard]] std::string const& GetFrontElement() const;
[[nodiscard]] Iterator begin() const;
[[nodiscard]] Iterator end() const;
[[nodiscard]] const Iterator cbegin() const;
[[nodiscard]] const Iterator cend() const;
[[nodiscard]] Iterator rbegin() const;
[[nodiscard]] Iterator rend() const;
[[nodiscard]] const Iterator crbegin() const;
[[nodiscard]] const Iterator crend() const;
void Insert(const Iterator &iterator, const std::string &string);
void Delete(const Iterator &iterator);
private:
size_t m_size{};
Node *m_first{}, *m_last{};
void ThrowEmptyList() const;
};