1 | #ifndef CPR_RANGE_H |
---|---|
2 | #define CPR_RANGE_H |
3 | |
4 | #include <cstdint> |
5 | #include <optional> |
6 | |
7 | namespace cpr { |
8 | |
9 | class Range { |
10 | public: |
11 | Range(const std::optional<std::int64_t> p_resume_from = std::nullopt, const std::optional<std::int64_t> p_finish_at = std::nullopt) { |
12 | resume_from = p_resume_from.value_or(u: 0); |
13 | finish_at = p_finish_at.value_or(u: -1); |
14 | } |
15 | |
16 | std::int64_t resume_from; |
17 | std::int64_t finish_at; |
18 | |
19 | const std::string str() const { |
20 | std::string from_str = (resume_from < 0U) ? "": std::to_string(val: resume_from); |
21 | std::string to_str = (finish_at < 0U) ? "": std::to_string(val: finish_at); |
22 | return from_str + "-"+ to_str; |
23 | } |
24 | }; |
25 | |
26 | class MultiRange { |
27 | public: |
28 | MultiRange(std::initializer_list<Range> rs) : ranges{rs} {} |
29 | |
30 | const std::string str() const { |
31 | std::string multi_range_string{}; |
32 | for (Range range : ranges) { |
33 | multi_range_string += ((multi_range_string.empty()) ? "": ", ") + range.str(); |
34 | } |
35 | return multi_range_string; |
36 | } |
37 | |
38 | private: |
39 | std::vector<Range> ranges; |
40 | }; // namespace cpr |
41 | |
42 | } // namespace cpr |
43 | |
44 | #endif |
45 |