123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2021-11-18 09:32:16
- * @LastEditors: lishengyin
- * @LastEditTime: 2021-11-29 09:14:48
- */
- #pragma once
- #include <iostream>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- #include <vector>
- using namespace std;
- class Crowdedness
- {
- public:
- int timeType;
- int cdLevel1Min;
- int cdLevel1Max;
- int cdLevel2Min;
- int cdLevel2Max;
- int cdLevel3Min;
- int cdLevel3Max;
- public:
- Crowdedness() {}
- ~Crowdedness() {}
- /**
- * @description: json转换为object
- * @param {Value&} object
- * @return {*}
- */
- bool jsonToObject(const rapidjson::Value& object){
- const auto end = object.MemberEnd();
- if(end == object.FindMember("timeType") || !object["timeType"].IsString()){
- return false;
- }else{
- timeType = atoi(object["timeType"].GetString());
- }
- if(end == object.FindMember("cdLevel1Min") || !object["cdLevel1Min"].IsString()){
- return false;
- }else{
- cdLevel1Min = atoi(object["cdLevel1Min"].GetString());
- }
- if(end == object.FindMember("cdLevel1Max") || !object["cdLevel1Max"].IsString()){
- return false;
- }else{
- cdLevel1Max = atoi(object["cdLevel1Max"].GetString());
- }
- if(end == object.FindMember("cdLevel2Min") || !object["cdLevel2Min"].IsString()){
- return false;
- }else{
- cdLevel2Min = atoi(object["cdLevel2Min"].GetString());
- }
- if(end == object.FindMember("cdLevel2Max") || !object["cdLevel2Max"].IsString()){
- return false;
- }else{
- cdLevel2Max = atoi(object["cdLevel2Max"].GetString());
- }
- if(end == object.FindMember("cdLevel3Min") || !object["cdLevel3Min"].IsString()){
- return false;
- }else{
- cdLevel3Min = atoi(object["cdLevel3Min"].GetString());
- }
- if(end == object.FindMember("cdLevel3Max") || !object["cdLevel3Max"].IsString()){
- return false;
- }else{
- cdLevel3Max = atoi(object["cdLevel3Max"].GetString());
- }
-
- return true;
- }
- };
- class CrowdednessConfig
- {
- public:
- vector<Crowdedness> CrowdednessVector;
- public:
- CrowdednessConfig() {}
- ~CrowdednessConfig() {}
- /**
- * @description: json转换为object
- * @param {string&} json
- * @return {*}
- */
- bool jsonToObject(const std::string& json)
- {
- rapidjson::Document doc;
- if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
- return false;
- }
- if(doc.IsArray())
- {
- const rapidjson::Value& objs = doc;
- for(int i = 0; i < (int)(objs.Size()); i++){
- Crowdedness crowdedness;
- if(!crowdedness.jsonToObject(objs[i])){
- return false;
- }
- CrowdednessVector.push_back(crowdedness);
- }
- }else{
- return false;
- }
- return true;
- }
- };
|