ServiceRequest.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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/core/ServiceRequest.h>
  17. using namespace AlibabaCloud;
  18. ServiceRequest::ServiceRequest(const std::string &product, const std::string &version) :
  19. content_(nullptr),
  20. contentSize_(0),
  21. params_(),
  22. product_(product),
  23. resourcePath_("/"),
  24. version_(version)
  25. {
  26. }
  27. ServiceRequest::ServiceRequest(const ServiceRequest &other) :
  28. content_(nullptr),
  29. contentSize_(other.contentSize_),
  30. params_(other.params_),
  31. product_(other.product_),
  32. resourcePath_(other.resourcePath_),
  33. version_(other.version_)
  34. {
  35. setContent(other.content_, other.contentSize_);
  36. }
  37. ServiceRequest::ServiceRequest(ServiceRequest &&other)
  38. {
  39. *this = std::move(other);
  40. }
  41. ServiceRequest& ServiceRequest::operator=(const ServiceRequest &other)
  42. {
  43. if (this != &other) {
  44. content_ = nullptr;
  45. contentSize_ = 0;
  46. params_ = other.params_;
  47. setContent(other.content_, other.contentSize_);
  48. }
  49. return *this;
  50. }
  51. ServiceRequest& ServiceRequest::operator=(ServiceRequest &&other)
  52. {
  53. if (this != &other)
  54. *this = std::move(other);
  55. return *this;
  56. }
  57. ServiceRequest::~ServiceRequest()
  58. {
  59. if (content_)
  60. delete content_;
  61. }
  62. const char * ServiceRequest::content() const
  63. {
  64. return content_;
  65. }
  66. size_t ServiceRequest::contentSize() const
  67. {
  68. return contentSize_;
  69. }
  70. bool ServiceRequest::hasContent() const
  71. {
  72. return (contentSize_ != 0);
  73. }
  74. void ServiceRequest::setContent(const char * data, size_t size)
  75. {
  76. if (content_)
  77. delete content_;
  78. content_ = nullptr;
  79. contentSize_ = 0;
  80. if (size) {
  81. contentSize_ = size;
  82. content_ = new char[size];
  83. std::copy(data, data + size, content_);
  84. }
  85. }
  86. void ServiceRequest::addParameter(const ParameterNameType & name, const ParameterValueType & value)
  87. {
  88. setParameter(name, value);
  89. }
  90. ServiceRequest::ParameterValueType ServiceRequest::parameter(const ParameterNameType &name)const
  91. {
  92. return params_.at(name);
  93. }
  94. ServiceRequest::ParameterCollection ServiceRequest::parameters() const
  95. {
  96. return params_;
  97. }
  98. void ServiceRequest::removeParameter(const ParameterNameType & name)
  99. {
  100. params_.erase(name);
  101. }
  102. void ServiceRequest::setParameter(const ParameterNameType &name, const ParameterValueType &value)
  103. {
  104. params_[name] = value;
  105. }
  106. void ServiceRequest::setParameters(const ParameterCollection & params)
  107. {
  108. params_ = params;
  109. }
  110. std::string ServiceRequest::version()const
  111. {
  112. return version_;
  113. }
  114. void ServiceRequest::setVersion(const std::string &version)
  115. {
  116. version_ = version;
  117. }
  118. std::string ServiceRequest::product() const
  119. {
  120. return product_;
  121. }
  122. void ServiceRequest::setProduct(const std::string & product)
  123. {
  124. product_ = product;
  125. }
  126. std::string ServiceRequest::resourcePath() const
  127. {
  128. return resourcePath_;
  129. }
  130. void ServiceRequest::setResourcePath(const std::string & path)
  131. {
  132. resourcePath_ = path;
  133. }