forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StrBlobPtr.h
62 lines (48 loc) · 1.87 KB
/
StrBlobPtr.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
#ifndef STRBLOBPTR_H
#define STRBLOBPTR_H
class StrBlob;
#include <vector>
#include <string>
#include <memory>
class StrBlobPtr {
friend bool operator==(const StrBlobPtr &, const StrBlobPtr &);
friend bool operator!=(const StrBlobPtr &, const StrBlobPtr &);
friend bool operator<(const StrBlobPtr &, const StrBlobPtr &);
friend bool operator>(const StrBlobPtr &, const StrBlobPtr &);
friend bool operator<=(const StrBlobPtr &, const StrBlobPtr &);
friend bool operator>=(const StrBlobPtr &, const StrBlobPtr &);
public:
typedef std::vector<std::string>::size_type size_type;
StrBlobPtr();
explicit StrBlobPtr(StrBlob &sb, size_type pos = 0);
// do not check range
std::string &operator[](size_type n) { return (*wptr.lock())[n]; }
const std::string &operator[](size_type n) const { return (*wptr.lock())[n]; }
//std::string &deref() const;
//StrBlobPtr &inc();
std::string &operator*() const;
std::string *operator->() const;
StrBlobPtr &operator++();
StrBlobPtr operator++(int);
StrBlobPtr &operator--();
StrBlobPtr operator--(int);
StrBlobPtr &operator+=(int);
StrBlobPtr &operator-=(int);
StrBlobPtr operator+(int) const;
StrBlobPtr operator-(int) const;
int operator-(const StrBlobPtr &) const;
private:
std::weak_ptr<std::vector<std::string>> wptr;
size_type curr;
std::shared_ptr<std::vector<std::string>>
check(size_type pos, const std::string &msg) const;
};
bool operator==(const StrBlobPtr &, const StrBlobPtr &);
bool operator!=(const StrBlobPtr &, const StrBlobPtr &);
bool operator<(const StrBlobPtr &, const StrBlobPtr &);
bool operator>(const StrBlobPtr &, const StrBlobPtr &);
bool operator<=(const StrBlobPtr &, const StrBlobPtr &);
bool operator>=(const StrBlobPtr &, const StrBlobPtr &);
StrBlobPtr operator+(const StrBlobPtr &, const StrBlobPtr &);
StrBlobPtr operator-(const StrBlobPtr &, const StrBlobPtr &);
#endif