-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathStrBlob.h
154 lines (127 loc) · 5.53 KB
/
StrBlob.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef STRBLOB_H
#define STRBLOB_H
#include<vector>
#include<string>
#include<initializer_list>
#include<utility>
#include<memory>
class StrBlobPtr;
class ConstStrBlobPtr;
class StrBlob
{
friend class StrBlobPtr;
friend class ConstStrBlobPtr;
friend bool operator==(const StrBlob &lhs, const StrBlob &rhs);
friend bool operator!=(const StrBlob &lhs, const StrBlob &rhs);
friend bool operator<(const StrBlob &lhs, const StrBlob &rhs);
friend bool operator<=(const StrBlob &lhs, const StrBlob &rhs);
friend bool operator>(const StrBlob &lhs, const StrBlob &rhs);
friend bool operator>=(const StrBlob &lhs, const StrBlob &rhs);
public:
typedef std::vector<std::string>::size_type size_type;
StrBlob();
StrBlob(std::initializer_list<std::string> li);
StrBlob(const StrBlob &sb);
StrBlob & operator=(const StrBlob &sb);
std::string & operator[](std::size_t n);
const std::string & operator[](std::size_t n) const;
inline size_type size() const { return data->size(); }
bool empty() const { return data->empty(); }
void push_back(const std::string &t) { data->push_back(t); }
void push_back(std::string &&t);
void pop_back();
const std::string & front() const;
std::string & front();
const std::string & back() const;
std::string & back();
StrBlobPtr begin();
StrBlobPtr end();
ConstStrBlobPtr cbegin() const;
ConstStrBlobPtr cend() const;
private:
std::shared_ptr<std::vector<std::string>> data;
void check(size_type i, const std::string & msg) const;
};
class StrBlobPtr
{
friend bool compare(const StrBlobPtr &p1, const StrBlobPtr &p2);
friend bool operator==(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
friend bool operator!=(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
friend bool operator<(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
friend bool operator<=(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
friend bool operator>(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
friend bool operator>=(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
friend int operator-(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
public:
StrBlobPtr() : curr(0) { }
StrBlobPtr(StrBlob &a, std::size_t sz = 0) : wptr(a.data), curr(sz) { }
std::string & operator[](std::size_t n);
const std::string & operator[](std::size_t n) const;
StrBlobPtr & operator++();
StrBlobPtr & operator--();
StrBlobPtr operator++(int);
StrBlobPtr operator--(int);
StrBlobPtr & operator+=(int i);
StrBlobPtr & operator-=(int i);
std::string & operator*() const;
std::string * operator->() const;
std::string & deref() const;
private:
std::shared_ptr<std::vector<std::string>> check(std::size_t , const std::string &) const;
std::weak_ptr<std::vector<std::string>> wptr;
std::size_t curr;
};
class ConstStrBlobPtr
{
friend bool compare(const ConstStrBlobPtr &p1, const ConstStrBlobPtr &p2);
friend bool operator==(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
friend bool operator!=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
friend bool operator<(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
friend bool operator<=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
friend bool operator>(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
friend bool operator>=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
friend int operator-(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
public:
ConstStrBlobPtr() : curr(0) { }
ConstStrBlobPtr(const StrBlob &a, std::size_t sz = 0) : wptr(a.data), curr(sz) { }
const std::string & operator[](std::size_t n);
const std::string & operator[](std::size_t n) const;
std::string & deref() const;
ConstStrBlobPtr & operator++();
ConstStrBlobPtr & operator--();
ConstStrBlobPtr operator++(int);
ConstStrBlobPtr operator--(int);
ConstStrBlobPtr & operator+=(int i);
ConstStrBlobPtr & operator-=(int i);
const std::string & operator*() const;
const std::string * operator->() const;
private:
std::shared_ptr<std::vector<std::string>> check(std::size_t , const std::string &) const;
std::weak_ptr<std::vector<std::string>> wptr;
std::size_t curr;
};
bool operator==(const StrBlob &lhs, const StrBlob &rhs);
bool operator==(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
bool operator==(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
bool operator!=(const StrBlob &lhs, const StrBlob &rhs);
bool operator!=(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
bool operator!=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
bool operator<(const StrBlob &lhs, const StrBlob &rhs);
bool operator<=(const StrBlob &lhs, const StrBlob &rhs);
bool operator>(const StrBlob &lhs, const StrBlob &rhs);
bool operator>=(const StrBlob &lhs, const StrBlob &rhs);
bool operator<(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
bool operator<=(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
bool operator>(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
bool operator>=(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
bool operator<(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
bool operator<=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
bool operator>(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
bool operator>=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
StrBlobPtr operator+(const StrBlobPtr &sbp, int i);
StrBlobPtr operator-(const StrBlobPtr &sbp, int i);
ConstStrBlobPtr operator+(const ConstStrBlobPtr &sbp, int i);
ConstStrBlobPtr operator-(const ConstStrBlobPtr &sbp, int i);
int operator-(const StrBlobPtr &lhs, const StrBlobPtr &rhs);
int operator-(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs);
#endif