-
Notifications
You must be signed in to change notification settings - Fork 246
/
StrBlob.h
75 lines (58 loc) · 2.02 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
#ifndef STRBLOB_H
#define STRBLOB_H
class StrBlobPtr;
class ConstStrBlobPtr;
#include <vector>
#include <string>
#include <initializer_list>
#include <memory>
#include <iostream>
class StrBlob {
friend class StrBlobPtr;
friend class ConstStrBlobPtr;
friend bool operator==(const StrBlob &, const StrBlob &);
friend bool operator!=(const StrBlob &, const StrBlob &);
friend bool operator<(const StrBlob &, const StrBlob &);
friend bool operator>(const StrBlob &, const StrBlob &);
friend bool operator<=(const StrBlob &, const StrBlob &);
friend bool operator>=(const StrBlob &, const StrBlob &);
public:
typedef std::vector<std::string>::size_type size_type;
StrBlob();
StrBlob(std::initializer_list<std::string> il);
StrBlob(const StrBlob &);
StrBlob &operator=(const StrBlob &);
// do not check range
std::string &operator[](size_type n) { return (*data)[n]; }
const std::string &operator[](size_type n) const { return (*data)[n]; }
size_type size() const { return data->size(); }
bool empty() const { return data->empty(); }
void push_back(const std::string &s);
void push_back(std::string &&s);
void pop_back();
std::string &front();
const std::string &front() const;
std::string &back();
const std::string &back() const;
StrBlobPtr begin();
StrBlobPtr end();
ConstStrBlobPtr cbegin() const;
ConstStrBlobPtr cend() const;
private:
std::shared_ptr<std::vector<std::string>> data;
void check(size_type pos, const std::string &msg) const;
};
bool operator==(const StrBlob &, const StrBlob &);
bool operator!=(const StrBlob &, const StrBlob &);
bool operator<(const StrBlob &, const StrBlob &);
bool operator>(const StrBlob &, const StrBlob &);
bool operator<=(const StrBlob &, const StrBlob &);
bool operator>=(const StrBlob &, const StrBlob &);
inline void StrBlob::push_back(const std::string &s) {
data->push_back(s);
}
inline void StrBlob::push_back(std::string &&s) {
std::cout << "StrBlob::push_back(std::string &&s)" << std::endl;
data->push_back(std::move(s));
}
#endif