[libcamera-devel,1/6] utils: Satisfy LegacyInputIterator with StringSplitter::iterator
diff mbox series

Message ID 20220823174314.14881-2-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: Add support for color spaces to rkisp1 pipeline handler
Related show

Commit Message

Laurent Pinchart Aug. 23, 2022, 5:43 p.m. UTC
The StringSplitter::iterator is used with the utils::split() function to
iterate over components of a split string. Add the necessary member
types expected by std::iterator_trait in order to satisfy the
LegacyInputIterator requirement and make the iterator usable in
constructors for various containers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/base/utils.h | 6 ++++++
 test/utils.cpp                 | 8 ++++++++
 2 files changed, 14 insertions(+)

Comments

Umang Jain Aug. 24, 2022, 6:29 a.m. UTC | #1
Hi Laurent,
Thank you for the patch,

On 8/23/22 11:13 PM, Laurent Pinchart via libcamera-devel wrote:
> The StringSplitter::iterator is used with the utils::split() function to
> iterate over components of a split string. Add the necessary member
> types expected by std::iterator_trait in order to satisfy the
> LegacyInputIterator requirement and make the iterator usable in
> constructors for various containers.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>

> ---
>   include/libcamera/base/utils.h | 6 ++++++
>   test/utils.cpp                 | 8 ++++++++
>   2 files changed, 14 insertions(+)
>
> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
> index 889bb4a2270e..ed88b7163770 100644
> --- a/include/libcamera/base/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -170,6 +170,12 @@ public:
>   	class iterator
>   	{
>   	public:
> +		using difference_type = std::size_t;
> +		using value_type = std::string;
> +		using pointer = value_type *;
> +		using reference = value_type &;
> +		using iterator_category = std::input_iterator_tag;
> +
>   		iterator(const StringSplitter *ss, std::string::size_type pos);
>   
>   		iterator &operator++();
> diff --git a/test/utils.cpp b/test/utils.cpp
> index 129807a63ec6..58b5a59dd17d 100644
> --- a/test/utils.cpp
> +++ b/test/utils.cpp
> @@ -276,6 +276,14 @@ protected:
>   			return TestFail;
>   		}
>   
> +		const auto &split = utils::split(path, ":");
> +		dirs = std::vector<std::string>{ split.begin(), split.end() };
> +
> +		if (dirs != elements) {
> +			cerr << "utils::split() LegacyInputIterator test failed" << endl;
> +			return TestFail;
> +		}
> +
>   		/* utils::join() with conversion function test. */
>   		std::vector<Size> sizes = { { 0, 0 }, { 100, 100 } };
>   		s = utils::join(sizes, "/", [](const Size &size) {
Nicolas Dufresne via libcamera-devel Aug. 25, 2022, 5:38 p.m. UTC | #2
On Tue, Aug 23, 2022 at 08:43:09PM +0300, Laurent Pinchart via libcamera-devel wrote:
> The StringSplitter::iterator is used with the utils::split() function to
> iterate over components of a split string. Add the necessary member
> types expected by std::iterator_trait in order to satisfy the
> LegacyInputIterator requirement and make the iterator usable in
> constructors for various containers.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  include/libcamera/base/utils.h | 6 ++++++
>  test/utils.cpp                 | 8 ++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
> index 889bb4a2270e..ed88b7163770 100644
> --- a/include/libcamera/base/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -170,6 +170,12 @@ public:
>  	class iterator
>  	{
>  	public:
> +		using difference_type = std::size_t;
> +		using value_type = std::string;
> +		using pointer = value_type *;
> +		using reference = value_type &;
> +		using iterator_category = std::input_iterator_tag;
> +
>  		iterator(const StringSplitter *ss, std::string::size_type pos);
>  
>  		iterator &operator++();
> diff --git a/test/utils.cpp b/test/utils.cpp
> index 129807a63ec6..58b5a59dd17d 100644
> --- a/test/utils.cpp
> +++ b/test/utils.cpp
> @@ -276,6 +276,14 @@ protected:
>  			return TestFail;
>  		}
>  
> +		const auto &split = utils::split(path, ":");
> +		dirs = std::vector<std::string>{ split.begin(), split.end() };
> +
> +		if (dirs != elements) {
> +			cerr << "utils::split() LegacyInputIterator test failed" << endl;
> +			return TestFail;
> +		}
> +
>  		/* utils::join() with conversion function test. */
>  		std::vector<Size> sizes = { { 0, 0 }, { 100, 100 } };
>  		s = utils::join(sizes, "/", [](const Size &size) {

Patch
diff mbox series

diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
index 889bb4a2270e..ed88b7163770 100644
--- a/include/libcamera/base/utils.h
+++ b/include/libcamera/base/utils.h
@@ -170,6 +170,12 @@  public:
 	class iterator
 	{
 	public:
+		using difference_type = std::size_t;
+		using value_type = std::string;
+		using pointer = value_type *;
+		using reference = value_type &;
+		using iterator_category = std::input_iterator_tag;
+
 		iterator(const StringSplitter *ss, std::string::size_type pos);
 
 		iterator &operator++();
diff --git a/test/utils.cpp b/test/utils.cpp
index 129807a63ec6..58b5a59dd17d 100644
--- a/test/utils.cpp
+++ b/test/utils.cpp
@@ -276,6 +276,14 @@  protected:
 			return TestFail;
 		}
 
+		const auto &split = utils::split(path, ":");
+		dirs = std::vector<std::string>{ split.begin(), split.end() };
+
+		if (dirs != elements) {
+			cerr << "utils::split() LegacyInputIterator test failed" << endl;
+			return TestFail;
+		}
+
 		/* utils::join() with conversion function test. */
 		std::vector<Size> sizes = { { 0, 0 }, { 100, 100 } };
 		s = utils::join(sizes, "/", [](const Size &size) {