curl_container.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef CURL_CONTAINER_H
  2. #define CURL_CONTAINER_H
  3. #include <initializer_list>
  4. #include <memory>
  5. #include <string>
  6. #include <vector>
  7. #include "cpr/curlholder.h"
  8. namespace cpr {
  9. struct Parameter {
  10. Parameter(const std::string& p_key, const std::string& p_value) : key{p_key}, value{p_value} {}
  11. Parameter(std::string&& p_key, std::string&& p_value) : key{std::move(p_key)}, value{std::move(p_value)} {}
  12. std::string key;
  13. std::string value;
  14. };
  15. struct Pair {
  16. Pair(const std::string& p_key, const std::string& p_value) : key(p_key), value(p_value) {}
  17. Pair(std::string&& p_key, std::string&& p_value) : key(std::move(p_key)), value(std::move(p_value)) {}
  18. std::string key;
  19. std::string value;
  20. };
  21. template <class T>
  22. class CurlContainer {
  23. public:
  24. /**
  25. * Enables or disables URL encoding for keys and values when calling GetContent(...).
  26. **/
  27. bool encode = true;
  28. CurlContainer() = default;
  29. CurlContainer(const std::initializer_list<T>&);
  30. void Add(const std::initializer_list<T>&);
  31. void Add(const T&);
  32. const std::string GetContent(const CurlHolder&) const;
  33. protected:
  34. std::vector<T> containerList_;
  35. };
  36. } // namespace cpr
  37. #endif //