[v2] libcamera: stream: Add operator<<(StreamConfiguration)
diff mbox series

Message ID 20241206162230.97619-1-jacopo.mondi@ideasonboard.com
State Accepted
Headers show
Series
  • [v2] libcamera: stream: Add operator<<(StreamConfiguration)
Related show

Commit Message

Jacopo Mondi Dec. 6, 2024, 4:22 p.m. UTC
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) and re-implement
StreamConfiguration::toString() on top of it.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 include/libcamera/stream.h |  2 ++
 src/libcamera/stream.cpp   | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

--
2.47.1

Comments

Kieran Bingham Dec. 6, 2024, 4:32 p.m. UTC | #1
Quoting Jacopo Mondi (2024-12-06 16:22:29)
> 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) and re-implement
> StreamConfiguration::toString() on top of it.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>  include/libcamera/stream.h |  2 ++
>  src/libcamera/stream.cpp   | 18 +++++++++++++++++-
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> 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..63aa5a027295 100644
> --- a/src/libcamera/stream.cpp
> +++ b/src/libcamera/stream.cpp
> @@ -392,7 +392,23 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
>   */
>  std::string StreamConfiguration::toString() const
>  {
> -       return size.toString() + "-" + pixelFormat.toString();
> +       std::stringstream ss;

Tiny nit: I'd probably have a blank line here. But it doesn't matter.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +       ss << *this;
> +
> +       return ss.str();
> +}
> +
> +/**
> + * \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 << size.toString() + "-" + pixelFormat.toString();
> +       return out;
>  }
> 
>  /**
> --
> 2.47.1
>
Stefan Klug Dec. 6, 2024, 4:33 p.m. UTC | #2
Hi Jacopo,

Thank you for the patch.

On Fri, Dec 06, 2024 at 05:22:29PM +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) and re-implement
> StreamConfiguration::toString() on top of it.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Regards,
Stefan
> ---
>  include/libcamera/stream.h |  2 ++
>  src/libcamera/stream.cpp   | 18 +++++++++++++++++-
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> 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..63aa5a027295 100644
> --- a/src/libcamera/stream.cpp
> +++ b/src/libcamera/stream.cpp
> @@ -392,7 +392,23 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
>   */
>  std::string StreamConfiguration::toString() const
>  {
> -	return size.toString() + "-" + pixelFormat.toString();
> +	std::stringstream ss;
> +	ss << *this;
> +
> +	return ss.str();
> +}
> +
> +/**
> + * \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 << size.toString() + "-" + pixelFormat.toString();
> +	return out;
>  }
> 
>  /**
> --
> 2.47.1
>
Jacopo Mondi Dec. 6, 2024, 4:53 p.m. UTC | #3
Hi Kieran

On Fri, Dec 06, 2024 at 04:32:58PM +0000, Kieran Bingham wrote:
> Quoting Jacopo Mondi (2024-12-06 16:22:29)
> > 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) and re-implement
> > StreamConfiguration::toString() on top of it.
> >
> > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> > ---
> >  include/libcamera/stream.h |  2 ++
> >  src/libcamera/stream.cpp   | 18 +++++++++++++++++-
> >  2 files changed, 19 insertions(+), 1 deletion(-)
> >
> > 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..63aa5a027295 100644
> > --- a/src/libcamera/stream.cpp
> > +++ b/src/libcamera/stream.cpp
> > @@ -392,7 +392,23 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
> >   */
> >  std::string StreamConfiguration::toString() const
> >  {
> > -       return size.toString() + "-" + pixelFormat.toString();
> > +       std::stringstream ss;
>
> Tiny nit: I'd probably have a blank line here. But it doesn't matter.
>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>

I copied the implementation from the Request class, and all the other
implementations of toString() based on operator<< are like this.

I'll keep it this way for consistency.

Thanks
  j

> > +       ss << *this;
> > +
> > +       return ss.str();
> > +}
> > +
> > +/**
> > + * \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 << size.toString() + "-" + pixelFormat.toString();
> > +       return out;
> >  }
> >
> >  /**
> > --
> > 2.47.1
> >
Jacopo Mondi Dec. 6, 2024, 4:56 p.m. UTC | #4
It's all good, except from the fact I sent a broken version of this patch

Sending v3, after it has gone through CI I'll merge it

On Fri, Dec 06, 2024 at 05:22:29PM +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) and re-implement
> StreamConfiguration::toString() on top of it.
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>  include/libcamera/stream.h |  2 ++
>  src/libcamera/stream.cpp   | 18 +++++++++++++++++-
>  2 files changed, 19 insertions(+), 1 deletion(-)
>
> 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..63aa5a027295 100644
> --- a/src/libcamera/stream.cpp
> +++ b/src/libcamera/stream.cpp
> @@ -392,7 +392,23 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
>   */
>  std::string StreamConfiguration::toString() const
>  {
> -	return size.toString() + "-" + pixelFormat.toString();
> +	std::stringstream ss;
> +	ss << *this;
> +
> +	return ss.str();
> +}
> +
> +/**
> + * \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 << size.toString() + "-" + pixelFormat.toString();
> +	return out;
>  }
>
>  /**
> --
> 2.47.1
>

Patch
diff mbox series

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..63aa5a027295 100644
--- a/src/libcamera/stream.cpp
+++ b/src/libcamera/stream.cpp
@@ -392,7 +392,23 @@  StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
  */
 std::string StreamConfiguration::toString() const
 {
-	return size.toString() + "-" + pixelFormat.toString();
+	std::stringstream ss;
+	ss << *this;
+
+	return ss.str();
+}
+
+/**
+ * \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 << size.toString() + "-" + pixelFormat.toString();
+	return out;
 }

 /**