1 | #ifndef CPR_BUFFER_H |
2 | #define CPR_BUFFER_H |
3 | |
4 | #include <string> |
5 | |
6 | #include <cpr/filesystem.h> |
7 | |
8 | namespace cpr { |
9 | |
10 | struct Buffer { |
11 | using data_t = const char*; |
12 | |
13 | template <typename Iterator> |
14 | Buffer(Iterator begin, Iterator end, fs::path&& p_filename) |
15 | // Ignored here since libcurl reqires a long. |
16 | // There is also no way around the reinterpret_cast. |
17 | // NOLINTNEXTLINE(google-runtime-int, cppcoreguidelines-pro-type-reinterpret-cast) |
18 | : data{reinterpret_cast<data_t>(&(*begin))}, datalen{static_cast<size_t>(std::distance(begin, end))}, filename(std::move(p_filename)) { |
19 | is_random_access_iterator(begin, end); |
20 | static_assert(sizeof(*begin) == 1, "Only byte buffers can be used" ); |
21 | } |
22 | |
23 | template <typename Iterator> |
24 | typename 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 /* begin */, Iterator /* end */) {} |
25 | |
26 | data_t data; |
27 | size_t datalen; |
28 | const fs::path filename; |
29 | }; |
30 | |
31 | } // namespace cpr |
32 | |
33 | #endif |
34 | |