本文整理汇总了C++中rapidjson::Document::PushBack方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::PushBack方法的具体用法?C++ Document::PushBack怎么用?C++ Document::PushBack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidjson::Document
的用法示例。
在下文中一共展示了Document::PushBack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
static void
pyobj2doc(PyObject *object, rapidjson::Document& doc)
{
if (PyBool_Check(object)) {
if (Py_True == object) {
doc.SetBool(true);
}
else {
doc.SetBool(false);
}
}
else if (Py_None == object) {
doc.SetNull();
}
else if (PyFloat_Check(object)) {
doc.SetDouble(PyFloat_AsDouble(object));
}
else if (PyInt_Check(object)) {
doc.SetInt(PyLong_AsLong(object));
}
else if (PyString_Check(object)) {
doc.SetString(PyString_AsString(object), PyString_GET_SIZE(object));
}
else if (PyUnicode_Check(object)) {
#ifdef PY3
PyObject *utf8_item;
utf8_item = PyUnicode_AsUTF8String(object);
if (!utf8_item) {
// TODO: error handling
printf("error\n");
}
doc.SetString(PyBytes_AsString(utf8_item),
PyBytes_Size(utf8_item), doc.GetAllocator());
Py_XDECREF(utf8_item);
#else
doc.SetString(PyBytes_AsString(object), PyBytes_GET_SIZE(object));
#endif
}
else if (PyTuple_Check(object)) {
int len = PyTuple_Size(object), i;
doc.SetArray();
rapidjson::Value _v;
for (i = 0; i < len; ++i) {
PyObject *elm = PyList_GetItem(object, i);
pyobj2doc(elm, _v, doc);
doc.PushBack(_v, doc.GetAllocator());
}
}
else if (PyList_Check(object)) {
int len = PyList_Size(object), i;
doc.SetArray();
rapidjson::Value _v;
for (i = 0; i < len; ++i) {
PyObject *elm = PyList_GetItem(object, i);
pyobj2doc(elm, _v, doc);
doc.PushBack(_v, doc.GetAllocator());
}
}
else if (PyDict_Check(object)) {
doc.SetObject();
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(object, &pos, &key, &value)) {
pyobj2doc_pair(key, value, doc);
}
}
else {
// TODO: error handle
}
}
示例2: if
static bool
pyobj2doc(PyObject *object, rapidjson::Document& doc)
{
if (PyBool_Check(object)) {
if (Py_True == object) {
doc.SetBool(true);
}
else {
doc.SetBool(false);
}
}
else if (Py_None == object) {
doc.SetNull();
}
else if (PyFloat_Check(object)) {
doc.SetDouble(PyFloat_AsDouble(object));
}
else if (PyInt_Check(object)) {
doc.SetInt64(PyLong_AsLong(object));
}
else if (PyString_Check(object)) {
doc.SetString(PyString_AsString(object), PyString_GET_SIZE(object));
}
else if (PyUnicode_Check(object)) {
PyObject *utf8_item;
utf8_item = PyUnicode_AsUTF8String(object);
if (!utf8_item) {
PyErr_SetString(PyExc_RuntimeError, "codec error.");
return false;
}
#ifdef PY3
doc.SetString(PyBytes_AsString(utf8_item), PyBytes_GET_SIZE(utf8_item), doc.GetAllocator());
#else
doc.SetString(PyString_AsString(utf8_item), PyString_GET_SIZE(utf8_item), doc.GetAllocator());
#endif
Py_XDECREF(utf8_item);
}
else if (PyTuple_Check(object)) {
int len = PyTuple_Size(object), i;
doc.SetArray();
rapidjson::Value _v;
for (i = 0; i < len; ++i) {
PyObject *elm = PyTuple_GetItem(object, i);
if (false == pyobj2doc(elm, _v, doc)) {
return false;
}
doc.PushBack(_v, doc.GetAllocator());
}
}
else if (PyList_Check(object)) {
int len = PyList_Size(object), i;
doc.SetArray();
rapidjson::Value _v;
for (i = 0; i < len; ++i) {
PyObject *elm = PyList_GetItem(object, i);
if (false == pyobj2doc(elm, _v, doc)) {
return false;
}
doc.PushBack(_v, doc.GetAllocator());
}
}
else if (PyDict_Check(object)) {
doc.SetObject();
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(object, &pos, &key, &value)) {
if (false == pyobj2doc_pair(key, value, doc)) {
return false;
}
}
}
else {
PyErr_SetString(PyExc_RuntimeError, "invalid python object");
return false;
}
return true;
}
示例3: buildJson
void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int count = pCocoNode[13].GetChildNum();
int length = 0;
int num = 0;
int size = 0;
int extent = 0;
int border = 0;
std::string key0;
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray(pCocoLoader);
document.SetArray();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
for (int i0 = 0; i0 < count; ++i0)
{
rapidjson::Value vElemItem(rapidjson::kObjectType);
border = pTriggersArray[i0].GetChildNum();
stExpCocoNode *pTriggerArray = pTriggersArray[i0].GetChildArray(pCocoLoader);
for (int i1 = 0; i1 < border; ++i1)
{
std::string key1 = pTriggerArray[i1].GetName(pCocoLoader);
const char *str1 = pTriggerArray[i1].GetValue(pCocoLoader);
if (key1.compare("actions") == 0)
{
rapidjson::Value actionsItem(rapidjson::kArrayType);
length = pTriggerArray[i1].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerArray[i1].GetChildArray(pCocoLoader);
for (int i2 = 0; i2 < length; ++i2)
{
rapidjson::Value action(rapidjson::kObjectType);
num = pActionsArray[i2].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray(pCocoLoader);
for (int i3 = 0; i3 < num; ++i3)
{
std::string key2 = pActionArray[i3].GetName(pCocoLoader);
const char *str2 = pActionArray[i3].GetValue(pCocoLoader);
if (key2.compare("classname") == 0)
{
if (str2 != nullptr)
{
action.AddMember("classname", rapidjson::Value(str2,allocator), allocator);
}
}
else if (key2.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pActionArray[i3].GetChildNum();
stExpCocoNode *pDataItemsArray = pActionArray[i3].GetChildArray(pCocoLoader);
for (int i4 = 0; i4 < size; ++i4)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i4].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i4].GetChildArray(pCocoLoader);
for (int i5 = 0; i5 < extent; ++i5)
{
std::string key3 = pDataItemArray[i5].GetName(pCocoLoader);
const char *str3 = pDataItemArray[i5].GetValue(pCocoLoader);
if (key3.compare("key") == 0)
{
if (str3 != nullptr)
{
dataitem.AddMember("key", rapidjson::Value(str3,allocator), allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i5].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", rapidjson::Value(str3,allocator), allocator);
}
else
{
int nV = atoi(str3);
float fV = utils::atof(str3);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
action.AddMember("dataitems", dataitems, allocator);
}
}
actionsItem.PushBack(action, allocator);
}
vElemItem.AddMember("actions", actionsItem, allocator);
//.........这里部分代码省略.........