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