本文整理汇总了C++中rapidjson::Value::Reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::Reserve方法的具体用法?C++ Value::Reserve怎么用?C++ Value::Reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidjson::Value
的用法示例。
在下文中一共展示了Value::Reserve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clone_value
bool clone_value(rapidjson::Value & output, const rapidjson::Value & input, rapidjson::Value::AllocatorType & allocator)
{
if(&output == &input)
{
return false;
}
if(input.IsNull())
{
output.SetNull();
}
else if(input.IsInt64())
{
output.SetInt(input.GetInt64());
}
else if(input.IsInt())
{
output.SetInt(input.GetInt());
}
else if(input.IsDouble())
{
output.SetDouble(input.GetDouble());
}
else if(input.IsBool())
{
output.SetBool(input.GetBool());
}
else if(input.IsString())
{
output.SetString(input.GetString(), input.GetStringLength(), allocator);
}
else if(input.IsArray())
{
rapidjson::Value temp;
output.SetArray();
output.Reserve(input.Size(), allocator);
for(rapidjson::SizeType i = 0; i < input.Size(); ++i)
{
clone_value(temp, input[i], allocator);
output.PushBack(temp, allocator);
}
}
else if(input.IsObject())
{
output.SetObject();
rapidjson::Value key, val;
for(rapidjson::Value::ConstMemberIterator it = input.MemberBegin();
it != input.MemberEnd(); ++it)
{
clone_value(key, it->name, allocator);
clone_value(val, it->value, allocator);
output.AddMember(key, val, allocator);
}
}
else
{
assert(false && "shuldn't execute to here.");
return false;
}
return true;
}
示例2: ToRapidjsonValue
static void ToRapidjsonValue(rapidjson::Value& rapidjsonValue, const JSONValue& jsonValue, rapidjson::MemoryPoolAllocator<>& allocator)
{
switch (jsonValue.GetValueType())
{
case JSON_NULL:
rapidjsonValue.SetNull();
break;
case JSON_BOOL:
rapidjsonValue.SetBool(jsonValue.GetBool());
break;
case JSON_NUMBER:
{
switch (jsonValue.GetNumberType())
{
case JSONNT_INT:
rapidjsonValue.SetInt(jsonValue.GetInt());
break;
case JSONNT_UINT:
rapidjsonValue.SetUint(jsonValue.GetUInt());
break;
default:
rapidjsonValue.SetDouble(jsonValue.GetDouble());
break;
}
}
break;
case JSON_STRING:
rapidjsonValue.SetString(jsonValue.GetCString(), allocator);
break;
case JSON_ARRAY:
{
const JSONArray& jsonArray = jsonValue.GetArray();
rapidjsonValue.SetArray();
rapidjsonValue.Reserve(jsonArray.Size(), allocator);
for (unsigned i = 0; i < jsonArray.Size(); ++i)
{
rapidjson::Value value;
rapidjsonValue.PushBack(value, allocator);
ToRapidjsonValue(rapidjsonValue[i], jsonArray[i], allocator);
}
}
break;
case JSON_OBJECT:
{
const JSONObject& jsonObject = jsonValue.GetObject();
rapidjsonValue.SetObject();
for (JSONObject::ConstIterator i = jsonObject.Begin(); i != jsonObject.End(); ++i)
{
const char* name = i->first_.CString();
rapidjson::Value value;
rapidjsonValue.AddMember(name, value, allocator);
ToRapidjsonValue(rapidjsonValue[name], i->second_, allocator);
}
}
break;
default:
break;
}
}
示例3: switch
void tvalue2json(rapidjson::Value & output, const QVariant & input, rapidjson::Value::AllocatorType & allocator)
{
switch(input.type())
{
case QVariant::Invalid:
{
output.SetNull();
break;
}
case QVariant::Bool:
{
output.SetBool(input.toBool());
break;
}
case QVariant::Int:
{
output.SetInt64(input.toInt());
break;
}
case QVariant::LongLong:
{
output.SetInt64(input.toLongLong());
break;
}
case QVariant::Double:
{
output.SetDouble(input.toDouble());
break;
}
case QVariant::String:
{
QByteArray str = input.toString().toUtf8();
output.SetString(str.data(), str.size(), allocator);
break;
}
case QVariant::StringList:
{
QStringList list = input.toStringList();
output.SetArray();
output.Reserve(list.size(), allocator);
rapidjson::Value temp;
for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
{
QByteArray str = it->toUtf8();
temp.SetString(str.data(), str.size(), allocator);
output.PushBack(temp, allocator);
}
break;
}
case QVariant::List:
{
QList<QVariant> list = input.toList();
output.SetArray();
output.Reserve(list.size(), allocator);
rapidjson::Value temp;
for(QList<QVariant>::const_iterator it = list.begin(); it != list.end(); ++it)
{
tvalue2json(temp, *it, allocator);
output.PushBack(temp, allocator);
}
break;
}
case QVariant::Map:
{
output.SetObject();
rapidjson::Value tempK, tempV;
QMap<QString, QVariant> qmap = input.toMap();
for(QMap<QString, QVariant>::const_iterator it = qmap.begin(); it != qmap.end(); ++it)
{
tvalue2json(tempK, it.key(), allocator);
tvalue2json(tempV, it.value(), allocator);
output.AddMember(tempK, tempV, allocator);
}
break;
}
case QVariant::Point:
{
QPoint pt = input.toPoint();
output.SetArray();
output.Reserve(2, allocator);
output.PushBack(pt.x(), allocator);
output.PushBack(pt.y(), allocator);
break;
}
case QVariant::PointF:
{
QPointF pt = input.toPointF();
output.SetArray();
output.Reserve(2, allocator);
output.PushBack(pt.x(), allocator);
output.PushBack(pt.y(), allocator);
//.........这里部分代码省略.........