[PATCH] libcamera: stream: Add operator<<(StreamConfiguration)

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu Dec 5 13:23:45 CET 2024


Hi Jacopo,

Thank you for the patch.

On Thu, Dec 05, 2024 at 12:23:13PM +0100, Jacopo Mondi wrote:
> The StreamConfiguration class only implements toString() but doesn't
> offer an overload of operator<<() which is more convenient to use.
> 
> Add an overload for operator<<(StreamConfiguration) which is based on
> the usage of StreamConfiguration::toString().
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>
> ---
>  include/libcamera/stream.h |  2 ++
>  src/libcamera/stream.cpp   | 13 +++++++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h
> index 071b71698acb..ea228aea7d56 100644
> --- a/include/libcamera/stream.h
> +++ b/include/libcamera/stream.h
> @@ -61,6 +61,8 @@ private:
>  	StreamFormats formats_;
>  };
> 
> +std::ostream &operator<<(std::ostream &out, StreamConfiguration cfg);
> +
>  enum class StreamRole {
>  	Raw,
>  	StillCapture,
> diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
> index 1f75dbbc5b64..a093abf48c7c 100644
> --- a/src/libcamera/stream.cpp
> +++ b/src/libcamera/stream.cpp
> @@ -395,6 +395,19 @@ std::string StreamConfiguration::toString() const
>  	return size.toString() + "-" + pixelFormat.toString();
>  }
> 
> +/**
> + * \brief Insert a text representation of a StreamConfiguration into an output
> + * stream
> + * \param[in] out The output stream
> + * \param[in] cfg The StreamConfiguration
> + * \return The output stream \a out
> + */
> +std::ostream &operator<<(std::ostream &out, StreamConfiguration cfg)
> +{
> +	out << cfg.toString();
> +	return out;
> +}

Would it be more efficient to instead implement toString() on top of
operator<<(), like we do for the Request class for instance ?

> +
>  /**
>   * \enum StreamRole
>   * \brief Identify the role a stream is intended to play

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list