a8/a8/mutable_xobject.cc
aozhiwei 0908b71e83 1
2018-11-23 10:54:12 +08:00

79 lines
2.1 KiB
C++

#include <a8/a8.h>
#include <a8/mutable_xobject.h>
namespace a8
{
MutableXObject::MutableXObject():XObject()
{
}
a8::MutableXObject* MutableXObject::NewObject()
{
a8::MutableXObject* obj = new a8::MutableXObject();
obj->type_ = XOT_OBJECT;
obj->value_.object_value = new std::map<std::string, std::shared_ptr<a8::XObject>>();
return obj;
}
a8::MutableXObject* MutableXObject::NewArray()
{
a8::MutableXObject* obj = new a8::MutableXObject();
obj->type_ = XOT_ARRAY;
obj->value_.array_value = new std::vector<std::shared_ptr<a8::XObject>>();
return obj;
}
a8::MutableXObject& MutableXObject::Push(a8::XValue val)
{
if (type_ != XOT_ARRAY) {
abort();
}
value_.array_value->push_back(std::make_shared<a8::XObject>(val));
return *this;
}
a8::MutableXObject& MutableXObject::Push(a8::MutableXObject& val)
{
if (type_ != XOT_ARRAY) {
abort();
}
std::shared_ptr<a8::XObject> p = std::make_shared<a8::XObject>();
val.Move(*p.get());
value_.array_value->push_back(p);
return *this;
}
a8::MutableXObject& MutableXObject::SetVal(const std::string& key, a8::XValue val)
{
if (type_ != XOT_OBJECT) {
abort();
}
(*value_.object_value)[key] = std::make_shared<a8::XObject>(val);
return *this;
}
a8::MutableXObject& MutableXObject::SetVal(const std::string& key, a8::XObject& val)
{
if (type_ != XOT_OBJECT) {
abort();
}
std::shared_ptr<a8::XObject> p = std::make_shared<a8::XObject>();
val.Move(*p.get());
(*value_.object_value)[key] = p;
return *this;
}
a8::MutableXObject& MutableXObject::SetVal(const std::string& key, a8::MutableXObject& val)
{
if (type_ != XOT_OBJECT) {
abort();
}
std::shared_ptr<a8::XObject> p = std::make_shared<a8::XObject>();
val.Move(*p.get());
(*value_.object_value)[key] = p;
return *this;
}
}