88#include " ../Literal.hpp"
99#include " ../Variant.hpp"
1010#include " ../always_false.hpp"
11+ #include " ../internal/durations_as_count_v.hpp"
1112#include " Parent.hpp"
1213#include " Parser_base.hpp"
1314#include " schema/Type.hpp"
@@ -55,13 +56,18 @@ struct ParserDuration {
5556 */
5657 static Result<DurationType> read (const R& _r,
5758 const InputVarType& _var) noexcept {
58- return Parser<R, W, RType, ProcessorsType>::read (_r, _var)
59- .and_then (to_duration)
60- .transform ([](auto && _duration) {
61- return _duration.visit ([](auto && _d) -> DurationType {
62- return std::chrono::duration_cast<DurationType>(std::move (_d));
59+ if constexpr (internal::durations_as_count_v<ProcessorsType>) {
60+ return Parser<R, W, Rep, ProcessorsType>::read (_r, _var).transform (
61+ [](const Rep _count) { return DurationType (_count); });
62+ } else {
63+ return Parser<R, W, RType, ProcessorsType>::read (_r, _var)
64+ .and_then (to_duration)
65+ .transform ([](auto && _duration) {
66+ return _duration.visit ([](auto && _d) -> DurationType {
67+ return std::chrono::duration_cast<DurationType>(std::move (_d));
68+ });
6369 });
64- });
70+ }
6571 }
6672
6773 /* *
@@ -74,9 +80,13 @@ struct ParserDuration {
7480 */
7581 template <class P >
7682 static void write (const W& _w, const DurationType& _d, const P& _parent) {
77- const auto r =
78- RType{.count = static_cast <int64_t >(_d.count ()), .unit = make_unit ()};
79- return Parser<R, W, RType, ProcessorsType>::write (_w, r, _parent);
83+ if constexpr (internal::durations_as_count_v<ProcessorsType>) {
84+ Parser<R, W, Rep, ProcessorsType>::write (_w, _d.count (), _parent);
85+ } else {
86+ const auto r = RType{.count = static_cast <int64_t >(_d.count ()),
87+ .unit = make_unit ()};
88+ Parser<R, W, RType, ProcessorsType>::write (_w, r, _parent);
89+ }
8090 }
8191
8292 /* *
@@ -87,7 +97,11 @@ struct ParserDuration {
8797 */
8898 static schema::Type to_schema (
8999 std::map<std::string, schema::Type>* _definitions) {
90- return Parser<R, W, RType, ProcessorsType>::to_schema (_definitions);
100+ if constexpr (internal::durations_as_count_v<ProcessorsType>) {
101+ return Parser<R, W, Rep, ProcessorsType>::to_schema (_definitions);
102+ } else {
103+ return Parser<R, W, RType, ProcessorsType>::to_schema (_definitions);
104+ }
91105 }
92106
93107 private:
0 commit comments