当前位置:网站首页>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 "}]
}
}
边栏推荐
- 1147 Heaps (30 分)
- Pointer functions and function pointers
- L2-3 is this a binary search tree- The explanation is wonderful
- Recyclerview sticky (suspended) head
- JVM instructions for four call methods
- L2-026 small generation (25 points)
- Nacos环境隔离
- 完全二叉树的权值 递归做法 ——最后的编程挑战
- Time varying and non time varying
- L2-031 go deep into the tiger's den (25 points)
猜你喜欢
随机推荐
SeaweedFS安全配置(Security Configuration)
Weight recursion of complete binary tree -- the last programming challenge
std::make_shared<T>/std::make_unique<T>与std::shared_ptr<T>/std::unique_ptr<T>的区别与联系
Time varying and non time varying
Slide the custom control to close the activity control
HDU 4578 Transformation(线段树+有技巧的懒标记下放)
Codeforces Round #657 Div. 2
云主机端口扫描
CodeForces - 1151B 思维
To 3 -- the last programming challenge
Image of the basic component of the shutter
GridView of basic component of shutter
Judgment of points inside and outside polygon
Recyclerview sticky (suspended) head
2019.10.16训练总结
1098 Insertion or Heap Sort (25 分)
Codeforces Round #659 (Div. 2)
2019.11.3 learning summary
Analyze in detail the PBOT mining virus family behavior and the principle of exploited vulnerabilities, and provide detailed protection suggestions for the blue army
Codeforces Round #659 (Div. 2)








