QueryServicePackAndPriceResult.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/ehpc/model/QueryServicePackAndPriceResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::EHPC;
  19. using namespace AlibabaCloud::EHPC::Model;
  20. QueryServicePackAndPriceResult::QueryServicePackAndPriceResult() :
  21. ServiceResult()
  22. {}
  23. QueryServicePackAndPriceResult::QueryServicePackAndPriceResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. QueryServicePackAndPriceResult::~QueryServicePackAndPriceResult()
  29. {}
  30. void QueryServicePackAndPriceResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto allServicePackNode = value["ServicePack"]["ServicePackInfo"];
  37. for (auto valueServicePackServicePackInfo : allServicePackNode)
  38. {
  39. ServicePackInfo servicePackObject;
  40. if(!valueServicePackServicePackInfo["EndTime"].isNull())
  41. servicePackObject.endTime = std::stoi(valueServicePackServicePackInfo["EndTime"].asString());
  42. if(!valueServicePackServicePackInfo["Capacity"].isNull())
  43. servicePackObject.capacity = std::stoi(valueServicePackServicePackInfo["Capacity"].asString());
  44. if(!valueServicePackServicePackInfo["StartTime"].isNull())
  45. servicePackObject.startTime = std::stoi(valueServicePackServicePackInfo["StartTime"].asString());
  46. if(!valueServicePackServicePackInfo["InstanceName"].isNull())
  47. servicePackObject.instanceName = valueServicePackServicePackInfo["InstanceName"].asString();
  48. servicePack_.push_back(servicePackObject);
  49. }
  50. if(!value["OriginalAmount"].isNull())
  51. originalAmount_ = std::stoi(value["OriginalAmount"].asString());
  52. if(!value["DiscountPrice"].isNull())
  53. discountPrice_ = std::stof(value["DiscountPrice"].asString());
  54. if(!value["TradePrice"].isNull())
  55. tradePrice_ = std::stof(value["TradePrice"].asString());
  56. if(!value["OriginalPrice"].isNull())
  57. originalPrice_ = std::stof(value["OriginalPrice"].asString());
  58. if(!value["ChargeAmount"].isNull())
  59. chargeAmount_ = std::stoi(value["ChargeAmount"].asString());
  60. if(!value["Currency"].isNull())
  61. currency_ = value["Currency"].asString();
  62. if(!value["RegionId"].isNull())
  63. regionId_ = value["RegionId"].asString();
  64. }
  65. float QueryServicePackAndPriceResult::getOriginalPrice()const
  66. {
  67. return originalPrice_;
  68. }
  69. float QueryServicePackAndPriceResult::getDiscountPrice()const
  70. {
  71. return discountPrice_;
  72. }
  73. std::string QueryServicePackAndPriceResult::getCurrency()const
  74. {
  75. return currency_;
  76. }
  77. std::vector<QueryServicePackAndPriceResult::ServicePackInfo> QueryServicePackAndPriceResult::getServicePack()const
  78. {
  79. return servicePack_;
  80. }
  81. std::string QueryServicePackAndPriceResult::getRegionId()const
  82. {
  83. return regionId_;
  84. }
  85. float QueryServicePackAndPriceResult::getTradePrice()const
  86. {
  87. return tradePrice_;
  88. }
  89. int QueryServicePackAndPriceResult::getOriginalAmount()const
  90. {
  91. return originalAmount_;
  92. }
  93. int QueryServicePackAndPriceResult::getChargeAmount()const
  94. {
  95. return chargeAmount_;
  96. }