63 lines
1.2 KiB
C++
63 lines
1.2 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <stdio.h>
|
|
#include <memory>
|
|
#include <string.h>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
|
|
class SecSet
|
|
{
|
|
public:
|
|
typedef shared_ptr<SecSet> Ptr;
|
|
private:
|
|
vector<char> _buf;
|
|
// char * _buf=nullptr;
|
|
size_t _len=0;
|
|
public:
|
|
SecSet(/* args */){};
|
|
~SecSet(){
|
|
// if(_buf) delete _buf;
|
|
_len=0;
|
|
}
|
|
void setBuf(const char * buf, size_t len){
|
|
|
|
// _buf.clear();
|
|
_buf.assign(buf,buf+len);
|
|
// if(!_buf){
|
|
// _buf=new char[len] ;_len=len;
|
|
// }
|
|
// if (len>_len)
|
|
// {
|
|
// _buf=(char*)realloc(_buf,len) ;_len=len;
|
|
// }
|
|
// memcpy(_buf,buf,len);
|
|
}
|
|
void printBuf(){
|
|
printf("%s len %lu\n",_buf.data(),_buf.size());
|
|
}
|
|
|
|
Ptr clone(){
|
|
return make_shared<remove_reference<decltype(*this)>::type>(*this);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
int main(){
|
|
const char hl[]={"Hello World!"};
|
|
const char hl2[]={"Hello World_twic!"};
|
|
SecSet::Ptr A=make_shared<SecSet>() ;
|
|
A->setBuf(hl,sizeof(hl));
|
|
A->printBuf();
|
|
auto B=A->clone();
|
|
A->setBuf(hl2,sizeof(hl2));
|
|
A->printBuf();
|
|
B->printBuf();
|
|
A->setBuf(hl,sizeof(hl));A->printBuf();
|
|
B->printBuf();
|
|
return 0;
|
|
}
|
|
|