HepuTargetRe.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. if(end == doc.FindMember("ackvalue") || !doc["ackvalue"].IsInt()) {
  35. return false;
  36. }else{
  37. ackvalue = doc["ackvalue"].GetInt();
  38. }
  39. if(end == doc.FindMember("channelid") || !doc["channelid"].IsInt()) {
  40. return false;
  41. }else{
  42. channelid = doc["channelid"].GetInt();
  43. }
  44. if(end == doc.FindMember("bTracking") || !doc["bTracking"].IsBool()) {
  45. return false;
  46. }else{
  47. bTracking = doc["bTracking"].GetBool();
  48. }
  49. }
  50. return true;
  51. }
  52. };