[libcamera-devel] [PATCH] libcamera: base: utils: Add missing constructor for Duration
Kieran Bingham
kieran.bingham at ideasonboard.com
Wed Apr 6 21:00:03 CEST 2022
Quoting Laurent Pinchart via libcamera-devel (2022-04-06 16:18:33)
> The Duration class is missing the equivalent to the
> std::chrono::duration constructor that takes a number of ticks expressed
> as a scalar. Fix it, which allows initializing a Duration instance to 0
> or 0.0.
>
Sounds good. 0ms 0s and 0years are all the same when initialising so 0
and 0.0 seems good to me ;-)
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
> include/libcamera/base/utils.h | 6 ++++++
> src/libcamera/base/utils.cpp | 9 +++++++++
> 2 files changed, 15 insertions(+)
>
> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
> index 9ab18101cf27..cfff05836de7 100644
> --- a/include/libcamera/base/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -327,6 +327,12 @@ class Duration : public std::chrono::duration<double, std::nano>
> public:
> Duration() = default;
>
> + template<typename Rep>
> + constexpr explicit Duration(const Rep &r)
> + : BaseDuration(r)
> + {
> + }
> +
> template<typename Rep, typename Period>
> constexpr Duration(const std::chrono::duration<Rep, Period> &d)
> : BaseDuration(d)
> diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp
> index 8cf8a5b2c104..6a307940448e 100644
> --- a/src/libcamera/base/utils.cpp
> +++ b/src/libcamera/base/utils.cpp
> @@ -406,6 +406,15 @@ std::string toAscii(const std::string &str)
> * duration in nanoseconds with double precision
> */
>
> +/**
> + * \fn Duration::Duration(const Rep &r)
> + * \brief Construct a Duration with \a r ticks
> + * \param[in] r The number of ticks
> + *
> + * The constructed \a Duration object is internally represented in double
> + * precision with \a r nanoseconds ticks.
> + */
> +
> /**
> * \fn Duration::Duration(const std::chrono::duration<Rep, Period> &d)
> * \brief Construct a Duration by converting an arbitrary std::chrono::duration
> --
> Regards,
>
> Laurent Pinchart
>
More information about the libcamera-devel
mailing list