[libcamera-devel,11/31] libcamera: controls: Add templates to convert a type T to a ControlType

Message ID 20200229164254.23604-12-laurent.pinchart@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: Add support for array controls
Related show

Commit Message

Laurent Pinchart Feb. 29, 2020, 4:42 p.m. UTC
This will be used to implement ControlValue::get() and set() as template
functions.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/Doxyfile.in    |  2 +-
 include/libcamera/controls.h | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

Comments

Kieran Bingham March 2, 2020, 11:18 p.m. UTC | #1
On 29/02/2020 16:42, Laurent Pinchart wrote:
> This will be used to implement ControlValue::get() and set() as template

/This/These/

> functions.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


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

> ---
>  Documentation/Doxyfile.in    |  2 +-
>  include/libcamera/controls.h | 28 ++++++++++++++++++++++++++++
>  2 files changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in
> index 457e23a086a2..430d80d5f21b 100644
> --- a/Documentation/Doxyfile.in
> +++ b/Documentation/Doxyfile.in
> @@ -882,7 +882,7 @@ EXCLUDE_SYMBOLS        = libcamera::BoundMethodArgs \
>                           libcamera::BoundMethodStatic \
>                           libcamera::SignalBase \
>                           libcamera::*::Private \
> -                         libcamera::*::details::* \
> +                         *::details::* \
>                           std::*
>  
>  # The EXAMPLE_PATH tag can be used to specify one or more files or directories
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 3b6b231c7c64..429f01b0fd24 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -22,6 +22,34 @@ enum ControlType {
>  	ControlTypeInteger64,
>  };
>  
> +namespace details {
> +
> +template<typename T>
> +struct control_type {
> +};
> +
> +template<>
> +struct control_type<void> {
> +	static constexpr ControlType value = ControlTypeNone;
> +};
> +
> +template<>
> +struct control_type<bool> {
> +	static constexpr ControlType value = ControlTypeBool;
> +};
> +
> +template<>
> +struct control_type<int32_t> {
> +	static constexpr ControlType value = ControlTypeInteger32;
> +};
> +
> +template<>
> +struct control_type<int64_t> {
> +	static constexpr ControlType value = ControlTypeInteger64;
> +};
> +
> +} /* namespace details */
> +

This looks interesting, does that mean we'll get compile time type
checking for the ControlType?

(or rather, not checking, it will just be guaranteed to be the right one?)

I think having these added when used would make them easier to review
and see their usage at the same time ... but I assume I'll find that
next, so no direct need to merge

>  class ControlValue
>  {
>  public:
>

Patch

diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in
index 457e23a086a2..430d80d5f21b 100644
--- a/Documentation/Doxyfile.in
+++ b/Documentation/Doxyfile.in
@@ -882,7 +882,7 @@  EXCLUDE_SYMBOLS        = libcamera::BoundMethodArgs \
                          libcamera::BoundMethodStatic \
                          libcamera::SignalBase \
                          libcamera::*::Private \
-                         libcamera::*::details::* \
+                         *::details::* \
                          std::*
 
 # The EXAMPLE_PATH tag can be used to specify one or more files or directories
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 3b6b231c7c64..429f01b0fd24 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -22,6 +22,34 @@  enum ControlType {
 	ControlTypeInteger64,
 };
 
+namespace details {
+
+template<typename T>
+struct control_type {
+};
+
+template<>
+struct control_type<void> {
+	static constexpr ControlType value = ControlTypeNone;
+};
+
+template<>
+struct control_type<bool> {
+	static constexpr ControlType value = ControlTypeBool;
+};
+
+template<>
+struct control_type<int32_t> {
+	static constexpr ControlType value = ControlTypeInteger32;
+};
+
+template<>
+struct control_type<int64_t> {
+	static constexpr ControlType value = ControlTypeInteger64;
+};
+
+} /* namespace details */
+
 class ControlValue
 {
 public: