[libcamera-devel,v2,03/16] libcamera: geometry: SizeRange: Add toString()

Message ID 20190612004359.15772-4-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: Add support for format information and validation
Related show

Commit Message

Niklas Söderlund June 12, 2019, 12:43 a.m. UTC
It's useful to be able to print a string representation of a SizeRange
to the log or console, add a toString() method. While at it turn the
structure into a class as it contains functions as well as data.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 include/libcamera/geometry.h |  6 +++++-
 src/libcamera/geometry.cpp   | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

Comments

Jacopo Mondi June 13, 2019, 2:43 p.m. UTC | #1
Hello,

On Wed, Jun 12, 2019 at 02:43:46AM +0200, Niklas Söderlund wrote:
> It's useful to be able to print a string representation of a SizeRange
> to the log or console, add a toString() method. While at it turn the
> structure into a class as it contains functions as well as data.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  include/libcamera/geometry.h |  6 +++++-
>  src/libcamera/geometry.cpp   | 14 ++++++++++++++
>  2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
> index b2a8e5b0e005e4db..03962d7d09fac2b0 100644
> --- a/include/libcamera/geometry.h
> +++ b/include/libcamera/geometry.h
> @@ -67,7 +67,9 @@ static inline bool operator>=(const Size &lhs, const Size &rhs)
>  	return !(lhs < rhs);
>  }
>
> -struct SizeRange {
> +class SizeRange
> +{
> +public:
>  	SizeRange()
>  	{
>  	}
> @@ -90,6 +92,8 @@ struct SizeRange {
>  	{
>  	}
>
> +	std::string toString() const;
> +
>  	Size min;
>  	Size max;
>  	unsigned int hStep;
> diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
> index c56c4e399ef307f5..6a1d1d78870b23ec 100644
> --- a/src/libcamera/geometry.cpp
> +++ b/src/libcamera/geometry.cpp
> @@ -261,6 +261,20 @@ bool operator<(const Size &lhs, const Size &rhs)
>   * \brief The vertical step
>   */
>
> +/**
> + * \brief Assemble and return a string describing the size range
> + * \return A string describing the SizeRange
> + */
> +std::string SizeRange::toString() const
> +{
> +	std::stringstream ss;
> +
> +	ss << "(" << min.toString() << ")-(" << max.toString() << ")/(+"
> +	   << hStep << ",+" << vStep << ")";

I should have replied to the v1 comments, and this is so minor you can
ignore it, but since it's a range of sizes I would use square brakets in
place of '(' when printing out the minimum and maximum sizes.

Patch's fine, feel free to ignore
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

> +
> +	return ss.str();
> +}
> +
>  /**
>   * \brief Compare size ranges for equality
>   * \return True if the two size ranges are equal, false otherwise
> --
> 2.21.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index b2a8e5b0e005e4db..03962d7d09fac2b0 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -67,7 +67,9 @@  static inline bool operator>=(const Size &lhs, const Size &rhs)
 	return !(lhs < rhs);
 }
 
-struct SizeRange {
+class SizeRange
+{
+public:
 	SizeRange()
 	{
 	}
@@ -90,6 +92,8 @@  struct SizeRange {
 	{
 	}
 
+	std::string toString() const;
+
 	Size min;
 	Size max;
 	unsigned int hStep;
diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index c56c4e399ef307f5..6a1d1d78870b23ec 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -261,6 +261,20 @@  bool operator<(const Size &lhs, const Size &rhs)
  * \brief The vertical step
  */
 
+/**
+ * \brief Assemble and return a string describing the size range
+ * \return A string describing the SizeRange
+ */
+std::string SizeRange::toString() const
+{
+	std::stringstream ss;
+
+	ss << "(" << min.toString() << ")-(" << max.toString() << ")/(+"
+	   << hStep << ",+" << vStep << ")";
+
+	return ss.str();
+}
+
 /**
  * \brief Compare size ranges for equality
  * \return True if the two size ranges are equal, false otherwise