add deepcopy
This commit is contained in:
parent
0908b71e83
commit
cfda065d14
27
a8/mysql.cc
27
a8/mysql.cc
@ -80,7 +80,7 @@ namespace a8
|
|||||||
impl_->passwd.c_str(),
|
impl_->passwd.c_str(),
|
||||||
impl_->database.c_str(),
|
impl_->database.c_str(),
|
||||||
impl_->port,
|
impl_->port,
|
||||||
NULL,
|
nullptr,
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +102,31 @@ namespace a8
|
|||||||
return new Query(impl_);
|
return new Query(impl_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Connection::GetHost()
|
||||||
|
{
|
||||||
|
return impl_->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Connection::GetPort()
|
||||||
|
{
|
||||||
|
return impl_->port;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Connection::GetUser()
|
||||||
|
{
|
||||||
|
return impl_->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Connection::GetPasswd()
|
||||||
|
{
|
||||||
|
return impl_->passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Connection::GetDataBase()
|
||||||
|
{
|
||||||
|
return impl_->database;
|
||||||
|
}
|
||||||
|
|
||||||
Query::Query(a8::mysql::ConnectionImpl* conn_impl)
|
Query::Query(a8::mysql::ConnectionImpl* conn_impl)
|
||||||
{
|
{
|
||||||
impl_ = new QueryImpl();
|
impl_ = new QueryImpl();
|
||||||
|
@ -23,6 +23,12 @@ namespace a8
|
|||||||
std::string GetError();
|
std::string GetError();
|
||||||
a8::mysql::Query* CreateQuery();
|
a8::mysql::Query* CreateQuery();
|
||||||
|
|
||||||
|
std::string GetHost();
|
||||||
|
int GetPort();
|
||||||
|
std::string GetUser();
|
||||||
|
std::string GetPasswd();
|
||||||
|
std::string GetDataBase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
a8::mysql::ConnectionImpl* impl_ = nullptr;
|
a8::mysql::ConnectionImpl* impl_ = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -64,6 +64,68 @@ namespace a8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XObject::Reset()
|
||||||
|
{
|
||||||
|
switch (type_) {
|
||||||
|
case a8::XOT_SIMPLE:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case a8::XOT_ARRAY:
|
||||||
|
{
|
||||||
|
delete value_.array_value;
|
||||||
|
type_ = XOT_SIMPLE;
|
||||||
|
value_.x_value = new a8::XValue();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case a8::XOT_OBJECT:
|
||||||
|
{
|
||||||
|
delete value_.object_value;
|
||||||
|
type_ = XOT_SIMPLE;
|
||||||
|
value_.x_value = new a8::XValue();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XObject::DeepCopy(a8::XObject& to)
|
||||||
|
{
|
||||||
|
to.Reset();
|
||||||
|
switch (type_) {
|
||||||
|
case a8::XOT_SIMPLE:
|
||||||
|
{
|
||||||
|
value_.x_value->DeepCopy(*to.value_.x_value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case a8::XOT_ARRAY:
|
||||||
|
{
|
||||||
|
type_ = XOT_ARRAY;
|
||||||
|
value_.array_value = new std::vector<std::shared_ptr<a8::XObject>>();
|
||||||
|
for (auto& value : *value_.array_value) {
|
||||||
|
std::shared_ptr<a8::XObject> xobj_ptr = std::make_shared<a8::XObject>();
|
||||||
|
value->DeepCopy(*xobj_ptr.get());
|
||||||
|
value_.array_value->push_back(xobj_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case a8::XOT_OBJECT:
|
||||||
|
{
|
||||||
|
type_ = XOT_OBJECT;
|
||||||
|
value_.object_value = new std::map<std::string, std::shared_ptr<a8::XObject>>();
|
||||||
|
for (auto& pair : *value_.object_value) {
|
||||||
|
std::shared_ptr<a8::XObject> xobj_ptr = std::make_shared<a8::XObject>();
|
||||||
|
pair.second->DeepCopy(*xobj_ptr.get());
|
||||||
|
(*(value_.object_value))[pair.first] = xobj_ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
a8::XValue XObject::AsXValue()
|
a8::XValue XObject::AsXValue()
|
||||||
{
|
{
|
||||||
assert(type_ == XOT_SIMPLE);
|
assert(type_ == XOT_SIMPLE);
|
||||||
|
@ -27,6 +27,8 @@ namespace a8
|
|||||||
|
|
||||||
unsigned char GetType();
|
unsigned char GetType();
|
||||||
int Size();
|
int Size();
|
||||||
|
void Reset();
|
||||||
|
void DeepCopy(a8::XObject& to);
|
||||||
|
|
||||||
a8::XValue AsXValue();
|
a8::XValue AsXValue();
|
||||||
std::shared_ptr<a8::XObject> operator[] (int i);
|
std::shared_ptr<a8::XObject> operator[] (int i);
|
||||||
|
@ -36,6 +36,11 @@ namespace a8
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeepCopy(a8::XParams& to)
|
||||||
|
{
|
||||||
|
to = *this;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
a8::XValue sender;
|
a8::XValue sender;
|
||||||
a8::XValue param1;
|
a8::XValue param1;
|
||||||
|
@ -213,6 +213,11 @@ namespace a8
|
|||||||
value_.int_value = 0;
|
value_.int_value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XValue::DeepCopy(a8::XValue& to)
|
||||||
|
{
|
||||||
|
to = *this;
|
||||||
|
}
|
||||||
|
|
||||||
int XValue::Type() const
|
int XValue::Type() const
|
||||||
{
|
{
|
||||||
return type_;
|
return type_;
|
||||||
|
@ -45,6 +45,7 @@ namespace a8
|
|||||||
void SetUserData(void *userdata, int datasize);
|
void SetUserData(void *userdata, int datasize);
|
||||||
void Set(double v);
|
void Set(double v);
|
||||||
void SetNull();
|
void SetNull();
|
||||||
|
void DeepCopy(a8::XValue& to);
|
||||||
|
|
||||||
int Type() const;
|
int Type() const;
|
||||||
bool IsNull();
|
bool IsNull();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user