multipart.h
Go to the documentation of this file.
1 #ifndef CPR_MULTIPART_H
2 #define CPR_MULTIPART_H
3 
4 #include <cstdint>
5 #include <initializer_list>
6 #include <string>
7 #include <type_traits>
8 #include <vector>
9 
10 #include "cpr/defines.h"
11 
12 namespace cpr {
13 
14 struct File {
15  template <typename StringType>
16  explicit File(StringType&& filepath)
19 };
20 
21 struct Buffer {
22  typedef const unsigned char* data_t;
23 
24  template <typename Iterator, typename StringType>
25  explicit Buffer(Iterator begin, Iterator end, StringType&& filename)
26  : data{reinterpret_cast<data_t>(&(*begin))},
27  datalen{static_cast<unsigned long>(std::distance(begin, end))},
29  is_random_access_iterator(begin, end);
30  static_assert(sizeof(*begin) == 1, "only byte buffers can be used");
31  }
32 
33  template <typename Iterator>
34  typename std::enable_if<std::is_same<typename std::iterator_traits<Iterator>::iterator_category,
35  std::random_access_iterator_tag>::value>::type
36  is_random_access_iterator(Iterator /* begin */, Iterator /* end */ ) {}
37 
38  data_t data;
39  unsigned long datalen;
41 };
42 
43 struct Part {
44  Part(const std::string& name, const std::string& value, const std::string& content_type = {})
45  : name{name}, value{value}, content_type{content_type}, is_file{false},
46  is_buffer{false} {}
47  Part(const std::string& name, const std::int32_t& value, const std::string& content_type = {})
48  : name{name}, value{std::to_string(value)}, content_type{content_type}, is_file{false},
49  is_buffer{false} {}
50  Part(const std::string& name, const File& file, const std::string& content_type = {})
51  : name{name}, value{file.filepath}, content_type{content_type}, is_file{true},
52  is_buffer{false} {}
53  Part(const std::string& name, const Buffer& buffer, const std::string& content_type = {})
54  : name{name}, value{buffer.filename}, content_type{content_type}, data{buffer.data},
55  datalen{buffer.datalen}, is_file{false}, is_buffer{true} {}
56 
61  unsigned long datalen;
62  bool is_file;
63  bool is_buffer;
64 };
65 
66 class Multipart {
67  public:
68  Multipart(const std::initializer_list<Part>& parts);
69 
70  std::vector<Part> parts;
71 };
72 
73 } // namespace cpr
74 
75 #endif
filename
unsigned long datalen
Definition: multipart.h:61
unsigned long datalen
Definition: multipart.h:39
const unsigned char * data_t
Definition: multipart.h:22
::std::string string
Definition: gtest-port.h:1129
File(StringType &&filepath)
Definition: multipart.h:16
Part(const std::string &name, const std::string &value, const std::string &content_type={})
Definition: multipart.h:44
char buffer[]
Definition: unit1308.c:48
#define CPR_FWD(...)
Definition: defines.h:6
data_t data
Definition: multipart.h:38
std::string content_type
Definition: multipart.h:59
Buffer::data_t data
Definition: multipart.h:60
std::enable_if< std::is_same< typename std::iterator_traits< Iterator >::iterator_category, std::random_access_iterator_tag >::value >::type is_random_access_iterator(Iterator, Iterator)
Definition: multipart.h:36
Part(const std::string &name, const Buffer &buffer, const std::string &content_type={})
Definition: multipart.h:53
Part(const std::string &name, const std::int32_t &value, const std::string &content_type={})
Definition: multipart.h:47
std::vector< Part > parts
Definition: multipart.h:70
Buffer(Iterator begin, Iterator end, StringType &&filename)
Definition: multipart.h:25
std::string filename
Definition: multipart.h:40
bool is_file
Definition: multipart.h:62
Definition: auth.cpp:3
Part(const std::string &name, const File &file, const std::string &content_type={})
Definition: multipart.h:50
std::string filepath
Definition: multipart.h:18
bool is_buffer
Definition: multipart.h:63
UNITTEST_START int * value
Definition: unit1602.c:51
std::string name
Definition: multipart.h:57
std::string value
Definition: multipart.h:58
const char * name
Definition: curl_sasl.c:54
Definition: debug.c:29


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16