当前位置:网站首页>September 29, 2020 non commodity templating code level rapidjson Library
September 29, 2020 non commodity templating code level rapidjson Library
2022-06-29 10:20:00 【qqq2018】
Business
'''
MatBuilderBase:
Build() // call FillMat() Fill in JSON.
FillMat()=0
XXXBuilder:MatBuilderBase // Six non commodity Builder Class pair pure virtual function FillMat() To achieve .
FillMat(){
xxx}
NowareMatHelper:
GetBuilder(AD_TYPE_ACTIVITY){
return xxxBuilder} // according to AD_TYPE_ACTIVITY Select to use the corresponding builder, Corresponding builder Can write the corresponding JSON
Init()
GetMatByType() // Depending on the type of AD, give the template or not
UseMat() // Determine whether to use a template for an advertising type
mat_ctrl_ // The configuration string of the template used to read which advertising spaces
noware and general Of WriteBidResponse() Calling the RecommendRequestHandler::WriteBidResponse()
What you do is initialize NowareMatHelper Of mat_ctrl_, Which ad slots read from the thesaurus use the configuration string of the template
'''
rapidjson library
Tencent headeronly The library of , Small and fast ( It's actually commendatory hh) Without relying on other libraries .
The simple usage is JSON->DOM-> Yes DOM Make changes -> Write back to JSON
( It seems to mean that it cannot be modified directly JSON)
Reference documents http://rapidjson.org/zh-cn/index.html
Example :
// rapidjson/example/simpledom/simpledom.cpp`
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
using namespace rapidjson;
int main() {
// 1. hold JSON Resolve to DOM.
const char* json = "{\"project\":\"rapidjson\",\"stars\":10}";
Document d;
d.Parse(json);
// 2. utilize DOM Make changes .
Value& s = d["stars"];
s.SetInt(s.GetInt() + 1);
// 3. hold DOM transformation (stringify) become JSON.
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
d.Accept(writer);
// Output {"project":"rapidjson","stars":11}
std::cout << buffer.GetString() << std::endl;
return 0;
}

std::string() Constructors
And string(const char *s, size_type n, const Allocator &a = Allocator());
The generated is s Before n A string of characters ,s If it is not long enough, it will take the random value after the string position in the memory to expand .
appendix 1 rapidjson Write json
rapidjson::StringBuffer buf;
//rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf); // it can word wrap
writer.StartObject();
writer.Key("name"); writer.String("spring");
writer.Key("address"); writer.String(" Beijing ");
writer.Key("age"); writer.Int(30);
writer.Key("value1");
writer.StartArray();
writer.StartArray();
writer.StartObject();
writer.Key("name"); writer.String("spring");
writer.Key("address"); writer.String(" Beijing ");
writer.Key("age"); writer.Int(30);
writer.Key("value1");
writer.StartArray();
writer.StartArray();
writer.Double(23); writer.Double(43); writer.Double(-2.3); writer.Double(6.7);
writer.Double(90);
writer.EndArray();
writer.StartArray();
writer.Int(-9); writer.Int(-19); writer.Int(10); writer.Int(2);
writer.EndArray();
writer.StartArray();
writer.Int(-5); writer.Int(-55);
writer.EndArray();
writer.EndArray();
writer.Key("value2");
writer.StartArray();
writer.Double(13.3); writer.Double(1.9); writer.Double(2.10);
writer.EndArray();
writer.Key("bei_jing");
writer.StartObject();
writer.Key("address"); writer.String(" haidian ");
writer.Key("car"); writer.Bool(false);
writer.Key("cat"); writer.Bool(true);
writer.EndObject();
writer.Key("shan_dong");
writer.StartObject();
writer.Key("address"); writer.String(" jinan ");
writer.Key("value1");
writer.StartArray();
writer.Key("ji_nan"); writer.String(" Baotu Spring ");
writer.Key("tai_an"); writer.String(" Mount Tai ");
writer.EndArray();
writer.EndObject();
result
{
"name": "spring",
"address": " Beijing ",
"age": 30,
"value1": [[23, 43, -2.3, 6.7, 90],
[-9, -19, 10, 2],
[-5, -55]],
"value2": [13.3, 1.9, 2.10],
"bei_jing": {
"address": " haidian ",
"car": false,
"cat": true
},
"shan_dong": {
"address": " jinan ",
"value1": [{"ji_nan": " Baotu Spring "}, {"tai_an": " Mount Tai "}]
}
}
边栏推荐
猜你喜欢
随机推荐
1098 insertion or heap sort (25 points)
SymPy Tutorial(译)
Serpentine filling number
Wandering -- the last programming challenge
Codeforces Round #657 Div. 2
Symphony tutorial
Power Strings【KMP循环节】
使用Rancher搭建Kubernetes集群
Listview of the basic component of the shutter
L2-025 分而治之 (25 分)
EDA and VHDL question bank
Text of the basic component of the shutter
Codeforces Round #645 (Div. 2)
2019.11.13 training summary
std::make_shared<T>/std::make_unique<T>与std::shared_ptr<T>/std::unique_ptr<T>的区别与联系
MySQL中innodb_page_cleaners详解
函数指针、函数指针数组、计算器+转移表等归纳总结
To 3 -- the last programming challenge
This open source project is super wow, and handwritten photos are generated Online
2019.11.13训练总结









