GlobalInfo.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef GLOBALINFO_H
  2. #define GLOBALINFO_H
  3. #include <QString>
  4. #include <vector>
  5. #include "nlohmann/json.hpp"
  6. /**
  7. * @brief 全局信息
  8. *
  9. */
  10. using nJson = nlohmann::json;
  11. /* 算法相关信息 */
  12. struct AlgorithmInfo
  13. {
  14. int PKID; /* 主键ID */
  15. int ActionTaskID; /* 算法任务ID */
  16. std::string ActionID; /* 算法ID */
  17. std::string ActionName; /* 算法名称 */
  18. AlgorithmInfo() = default;
  19. AlgorithmInfo(const AlgorithmInfo& other)
  20. : PKID(other.PKID), ActionID(other.ActionID), ActionName(other.ActionName), ActionTaskID(other.ActionTaskID) {}
  21. AlgorithmInfo& operator=(const AlgorithmInfo& other) {
  22. if (this != &other) {
  23. ActionID = other.ActionID;
  24. ActionName = other.ActionName;
  25. ActionTaskID = other.ActionTaskID;
  26. PKID = other.PKID;
  27. }
  28. return *this;
  29. }
  30. /* 对比是否相等 */
  31. bool operator==(const AlgorithmInfo& other) const {
  32. if(ActionID != other.ActionID)
  33. {
  34. return false;
  35. }
  36. if(ActionName != other.ActionName || ActionTaskID != other.ActionTaskID)
  37. {
  38. return false;
  39. }
  40. return true;
  41. }
  42. };
  43. /* 设备列表 */
  44. struct DeviceInfo
  45. {
  46. int PKID; /* 主键ID */
  47. int DeviceID; /* 设备ID */
  48. int DevicePort; /* 设备端口 */
  49. std::string DeviceName; /* 设备名称 */
  50. std::string DeviceIP; /* 设备IP */
  51. std::string DeviceSerial; /* 设备序列号 */
  52. std::string DeviceType; /* 设备类型 */
  53. std::string UserAccount; /* 用户账号 */
  54. std::string UserPassword; /* 用户密码 */
  55. std::vector<AlgorithmInfo> vecAlgorithmInfo; /* 算法信息 */
  56. DeviceInfo() = default;
  57. DeviceInfo(const DeviceInfo& other)
  58. : PKID(other.PKID),
  59. DeviceID(other.DeviceID),
  60. DevicePort(other.DevicePort),
  61. DeviceName(other.DeviceName),
  62. DeviceSerial(other.DeviceSerial),
  63. DeviceType(other.DeviceType),
  64. DeviceIP(other.DeviceIP),
  65. UserAccount(other.UserAccount),
  66. UserPassword(other.UserPassword),
  67. vecAlgorithmInfo(other.vecAlgorithmInfo) {}
  68. DeviceInfo& operator=(const DeviceInfo& other) {
  69. if (this != &other) {
  70. DeviceID = other.DeviceID;
  71. DevicePort = other.DevicePort;
  72. DeviceName = other.DeviceName;
  73. DeviceSerial = other.DeviceSerial;
  74. DeviceType = other.DeviceType;
  75. DeviceIP = other.DeviceIP;
  76. UserAccount = other.UserAccount;
  77. UserPassword = other.UserPassword;
  78. vecAlgorithmInfo = other.vecAlgorithmInfo;
  79. }
  80. return *this;
  81. }
  82. /* 对比是否相等 */
  83. bool operator==(const DeviceInfo& other) const {
  84. if(DeviceID != other.DeviceID) {
  85. return false;
  86. }
  87. else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
  88. return false;
  89. }
  90. else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
  91. return false;
  92. }
  93. else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
  94. return false;
  95. }
  96. return true;
  97. }
  98. /* 对比设备关联的算法信息是否相等 */
  99. bool isEqualAlgorithmInfo(const DeviceInfo& other) const {
  100. /* 算法数目不相等,直接返回false */
  101. if(vecAlgorithmInfo.size() != other.vecAlgorithmInfo.size()) {
  102. return false;
  103. }else {
  104. /* 算法数目相等,进一步对比算法信息 */
  105. bool isEquality = true;
  106. /* 逐步对比算法信息 */
  107. for(const auto& it0 : vecAlgorithmInfo) {
  108. bool isEq2 = true;
  109. for(const auto& it1 : other.vecAlgorithmInfo) {
  110. if(it0 == it1) {
  111. continue;
  112. }else {
  113. isEq2 = false;
  114. break;
  115. }
  116. }
  117. if(!isEq2) {
  118. isEquality = false;
  119. break;
  120. }
  121. }
  122. if(!isEquality) {
  123. return false;
  124. }
  125. }
  126. return true;
  127. }
  128. };
  129. #endif /* GLOBALINFO_H */