[libcamera-devel] [PATCH] libcamera: base: utils: Add missing constructor for Duration

Umang Jain umang.jain at ideasonboard.com
Wed Apr 6 20:05:01 CEST 2022


Hi Laurent,

On 4/6/22 20:48, Laurent Pinchart via libcamera-devel wrote:
> 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.


yay,

>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>


Reviewed-by: Umang Jain <umang.jain 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


More information about the libcamera-devel mailing list