64,649
社区成员
发帖
与我相关
我的任务
分享
#ifndef STRBLOB_H_INCLUDED
#define STRBLOB_H_INCLUDED
#include"dxgzg.h"
using namespace std;
class StrBlobPtr;
class StrBlob {
friend class StrBlobPtr;
private:
typedef string::size_type size_type;
shared_ptr<vector<string>>data;
bool check(size_type i){
if (i > 0)return true;
else return false;
return true;
}
public:
StrBlob():data(make_shared<vector<string>>()){}
StrBlob(initializer_list<string>s):data(make_shared<vector<string>>(s)){}
size_type size() {
return data->size();
}
size_type csize()const {
return data->size();
}
size_type psize(){
return data.use_count();
}
void push_back(const string &s){
data->emplace_back(s);
}
string front() {
if (check(data->size())) {
return *(data->begin());
}
}
string back() {
if (check(data->size())) {
return data->back();
}
}
bool empty() {
return data->empty();
}
void show() {
auto it = data->begin();
while (it != data->end()) {
cout << *it++ << ' ';
}
}
~StrBlob() {}
};
#endif;
#ifndef STRBLOBPTR_H_INCLUDED
#define STRBLOBPTR_H_INCLUDED
#include"dxgzg.h"
#include"StrBlob.h"
using namespace std;
class StrBlob;
class StrBlobPtr {
size_t curr;
weak_ptr<vector<string>>wptr;
shared_ptr<vector<string>> check(size_t i) {
auto sptr = wptr.lock();//返回一个shared_ptr指针。
if (!sptr) {
throw runtime_error("当前容器已经失效");
}
if (i >= sptr->size()) {
throw runtime_error("溢出");
}
return sptr;
}
public:
StrBlobPtr() = default;
StrBlobPtr(StrBlob &s,size_t i):wptr(s.data){}
};
#endif