HepuTargetRe.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <iostream>
  3. #include <rapidjson/document.h>
  4. #include <rapidjson/rapidjson.h>
  5. #include <rapidjson/stringbuffer.h>
  6. #include <rapidjson/writer.h>
  7. using namespace std;
  8. class HepuTargetRe
  9. {
  10. private:
  11. public:
  12. const string cmd = "ivpTrackingCtrl";
  13. int ackvalue;
  14. int channelid;
  15. bool bTracking;
  16. HepuTargetRe(){};
  17. ~HepuTargetRe(){};
  18. bool jsonToObject(string& json){
  19. rapidjson::Document doc;
  20. doc.Parse(json.c_str());
  21. if(!doc.IsObject()){
  22. return false;
  23. }
  24. const auto end = doc.MemberEnd();
  25. if(end == doc.FindMember("cmd") || !doc["cmd"].IsString()){
  26. return false;
  27. }else{
  28. if(cmd != doc["cmd"].GetString())
  29. return false;
  30. }
  31. if(end == doc.FindMember("param") || !doc["param"].IsObject()) {
  32. return false;
  33. }else{
  34. const rapidjson::Value& object = doc["param"];
  35. if(end == object.FindMember("ackvalue") || !object["ackvalue"].IsInt()) {
  36. return false;
  37. }else{
  38. ackvalue = object["ackvalue"].GetInt();
  39. }
  40. if(end == object.FindMember("channelid") || !object["channelid"].IsInt()) {
  41. return false;
  42. }else{
  43. channelid = object["channelid"].GetInt();
  44. }
  45. if(end == object.FindMember("bTracking") || !object["bTracking"].IsBool()) {
  46. return false;
  47. }else{
  48. bTracking = object["bTracking"].GetBool();
  49. }
  50. }
  51. return true;
  52. }
  53. };