1 | #include "cpr/timeout.h" |
---|---|
2 | |
3 | #include <limits> |
4 | #include <stdexcept> |
5 | #include <string> |
6 | #include <type_traits> |
7 | |
8 | namespace cpr { |
9 | |
10 | // No way around since curl uses a long here. |
11 | // NOLINTNEXTLINE(google-runtime-int) |
12 | long Timeout::Milliseconds() const { |
13 | static_assert(std::is_same<std::chrono::milliseconds, decltype(ms)>::value, "Following casting expects milliseconds."); |
14 | |
15 | // No way around since curl uses a long here. |
16 | // NOLINTNEXTLINE(google-runtime-int) |
17 | if (ms.count() > static_cast<std::chrono::milliseconds::rep>(std::numeric_limits<long>::max())) { |
18 | throw std::overflow_error("cpr::Timeout: timeout value overflow: "+ std::to_string(val: ms.count()) + " ms."); |
19 | } |
20 | // No way around since curl uses a long here. |
21 | // NOLINTNEXTLINE(google-runtime-int) |
22 | if (ms.count() < static_cast<std::chrono::milliseconds::rep>(std::numeric_limits<long>::min())) { |
23 | throw std::underflow_error("cpr::Timeout: timeout value underflow: "+ std::to_string(val: ms.count()) + " ms."); |
24 | } |
25 | |
26 | // No way around since curl uses a long here. |
27 | // NOLINTNEXTLINE(google-runtime-int) |
28 | return static_cast<long>(ms.count()); |
29 | } |
30 | |
31 | } // namespace cpr |
32 |