[libcamera-devel] pipeline: ipa: raspberrypi: Switch to use C++17 features where possible

Message ID 20201006090731.185060-1-naush@raspberrypi.com
State Accepted
Commit bb6167873ee309da12ed71c7943d54823e4b6709
Headers show
Series
  • [libcamera-devel] pipeline: ipa: raspberrypi: Switch to use C++17 features where possible
Related show

Commit Message

Naushir Patuck Oct. 6, 2020, 9:07 a.m. UTC
With the recent change to use C++17, the following code changes can be
made:
- Use C++17 [[fallthough]] attribute instead of /* Fall through */.
- Swap boost::any to std::any.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/ipa/raspberrypi/controller/metadata.hpp        | 9 ++++-----
 src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 2 +-
 2 files changed, 5 insertions(+), 6 deletions(-)

Comments

Kieran Bingham Oct. 6, 2020, 9:33 a.m. UTC | #1
Hi Naush,

On 06/10/2020 10:07, Naushir Patuck wrote:
> With the recent change to use C++17, the following code changes can be
> made:
> - Use C++17 [[fallthough]] attribute instead of /* Fall through */.
> - Swap boost::any to std::any.

Ohhhhh ;-)

> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>

Sounds and looks good to me, and one less boost header ;-)

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

> ---
>  src/ipa/raspberrypi/controller/metadata.hpp        | 9 ++++-----
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 2 +-
>  2 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp
> index f3a8dfab..4f44ffc6 100644
> --- a/src/ipa/raspberrypi/controller/metadata.hpp
> +++ b/src/ipa/raspberrypi/controller/metadata.hpp
> @@ -8,13 +8,12 @@
>  
>  // A simple class for carrying arbitrary metadata, for example about an image.
>  
> +#include <any>
>  #include <string>
>  #include <mutex>
>  #include <map>
>  #include <memory>
>  
> -#include <boost/any.hpp>
> -
>  namespace RPiController {
>  
>  class Metadata
> @@ -31,7 +30,7 @@ public:
>  		auto it = data_.find(tag);
>  		if (it == data_.end())
>  			return -1;
> -		value = boost::any_cast<T>(it->second);
> +		value = std::any_cast<T>(it->second);
>  		return 0;
>  	}
>  	void Clear()
> @@ -53,7 +52,7 @@ public:
>  		auto it = data_.find(tag);
>  		if (it == data_.end())
>  			return nullptr;
> -		return boost::any_cast<T>(&it->second);
> +		return std::any_cast<T>(&it->second);
>  	}
>  	template<typename T>
>  	void SetLocked(std::string const &tag, T const &value)
> @@ -69,7 +68,7 @@ public:
>  
>  private:
>  	mutable std::mutex mutex_;
> -	std::map<std::string, boost::any> data_;
> +	std::map<std::string, std::any> data_;
>  };
>  
>  typedef std::shared_ptr<Metadata> MetadataPtr;
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 1052bdce..26dbd257 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -1494,7 +1494,7 @@ void RPiCameraData::handleState()
>  		 * No break here, we want to try running the pipeline again.
>  		 * The fallthrough clause below suppresses compiler warnings.
>  		 */
> -		/* Fall through */
> +		[[fallthrough]];
>  
>  	case State::Idle:
>  		tryRunPipeline();
>
Laurent Pinchart Oct. 7, 2020, 2:03 a.m. UTC | #2
Hi Naush,

Thank you for the patch.

On Tue, Oct 06, 2020 at 10:07:31AM +0100, Naushir Patuck wrote:
> With the recent change to use C++17, the following code changes can be
> made:
> - Use C++17 [[fallthough]] attribute instead of /* Fall through */.
> - Swap boost::any to std::any.
> 
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I will push shortly.

> ---
>  src/ipa/raspberrypi/controller/metadata.hpp        | 9 ++++-----
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 2 +-
>  2 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp
> index f3a8dfab..4f44ffc6 100644
> --- a/src/ipa/raspberrypi/controller/metadata.hpp
> +++ b/src/ipa/raspberrypi/controller/metadata.hpp
> @@ -8,13 +8,12 @@
>  
>  // A simple class for carrying arbitrary metadata, for example about an image.
>  
> +#include <any>
>  #include <string>
>  #include <mutex>
>  #include <map>
>  #include <memory>
>  
> -#include <boost/any.hpp>
> -
>  namespace RPiController {
>  
>  class Metadata
> @@ -31,7 +30,7 @@ public:
>  		auto it = data_.find(tag);
>  		if (it == data_.end())
>  			return -1;
> -		value = boost::any_cast<T>(it->second);
> +		value = std::any_cast<T>(it->second);
>  		return 0;
>  	}
>  	void Clear()
> @@ -53,7 +52,7 @@ public:
>  		auto it = data_.find(tag);
>  		if (it == data_.end())
>  			return nullptr;
> -		return boost::any_cast<T>(&it->second);
> +		return std::any_cast<T>(&it->second);
>  	}
>  	template<typename T>
>  	void SetLocked(std::string const &tag, T const &value)
> @@ -69,7 +68,7 @@ public:
>  
>  private:
>  	mutable std::mutex mutex_;
> -	std::map<std::string, boost::any> data_;
> +	std::map<std::string, std::any> data_;
>  };
>  
>  typedef std::shared_ptr<Metadata> MetadataPtr;
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 1052bdce..26dbd257 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -1494,7 +1494,7 @@ void RPiCameraData::handleState()
>  		 * No break here, we want to try running the pipeline again.
>  		 * The fallthrough clause below suppresses compiler warnings.
>  		 */
> -		/* Fall through */
> +		[[fallthrough]];
>  
>  	case State::Idle:
>  		tryRunPipeline();

Patch

diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp
index f3a8dfab..4f44ffc6 100644
--- a/src/ipa/raspberrypi/controller/metadata.hpp
+++ b/src/ipa/raspberrypi/controller/metadata.hpp
@@ -8,13 +8,12 @@ 
 
 // A simple class for carrying arbitrary metadata, for example about an image.
 
+#include <any>
 #include <string>
 #include <mutex>
 #include <map>
 #include <memory>
 
-#include <boost/any.hpp>
-
 namespace RPiController {
 
 class Metadata
@@ -31,7 +30,7 @@  public:
 		auto it = data_.find(tag);
 		if (it == data_.end())
 			return -1;
-		value = boost::any_cast<T>(it->second);
+		value = std::any_cast<T>(it->second);
 		return 0;
 	}
 	void Clear()
@@ -53,7 +52,7 @@  public:
 		auto it = data_.find(tag);
 		if (it == data_.end())
 			return nullptr;
-		return boost::any_cast<T>(&it->second);
+		return std::any_cast<T>(&it->second);
 	}
 	template<typename T>
 	void SetLocked(std::string const &tag, T const &value)
@@ -69,7 +68,7 @@  public:
 
 private:
 	mutable std::mutex mutex_;
-	std::map<std::string, boost::any> data_;
+	std::map<std::string, std::any> data_;
 };
 
 typedef std::shared_ptr<Metadata> MetadataPtr;
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index 1052bdce..26dbd257 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -1494,7 +1494,7 @@  void RPiCameraData::handleState()
 		 * No break here, we want to try running the pipeline again.
 		 * The fallthrough clause below suppresses compiler warnings.
 		 */
-		/* Fall through */
+		[[fallthrough]];
 
 	case State::Idle:
 		tryRunPipeline();