[libcamera-devel,14/31] libcamera: controls: Move Control constructor to controls.h

Message ID 20200229164254.23604-15-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
To avoid defining all specializations of the Control constructor
manually, move the definition of those functions to controls.h.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/controls.h |  5 ++++-
 src/libcamera/controls.cpp   | 26 --------------------------
 2 files changed, 4 insertions(+), 27 deletions(-)

Comments

Kieran Bingham March 2, 2020, 11:33 p.m. UTC | #1
On 29/02/2020 16:42, Laurent Pinchart wrote:
> To avoid defining all specializations of the Control constructor
> manually, move the definition of those functions to controls.h.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Excellent, more simplifications. (wait, I'm not sure I can use the word
'simple' in the context of templates hehe)

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

> ---
>  include/libcamera/controls.h |  5 ++++-
>  src/libcamera/controls.cpp   | 26 --------------------------
>  2 files changed, 4 insertions(+), 27 deletions(-)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index dfe69916cd64..6f0ebf4f3ca5 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -146,7 +146,10 @@ class Control : public ControlId
>  public:
>  	using type = T;
>  
> -	Control(unsigned int id, const char *name);
> +	Control(unsigned int id, const char *name)
> +		: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
> +	{
> +	}
>  
>  private:
>  	Control(const Control &) = delete;
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 5cc8ce2199d0..76230a052de1 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -249,32 +249,6 @@ bool ControlValue::operator==(const ControlValue &other) const
>   * \brief The Control template type T
>   */
>  
> -#ifndef __DOXYGEN__
> -template<>
> -Control<void>::Control(unsigned int id, const char *name)
> -	: ControlId(id, name, ControlTypeNone)
> -{
> -}
> -
> -template<>
> -Control<bool>::Control(unsigned int id, const char *name)
> -	: ControlId(id, name, ControlTypeBool)
> -{
> -}
> -
> -template<>
> -Control<int32_t>::Control(unsigned int id, const char *name)
> -	: ControlId(id, name, ControlTypeInteger32)
> -{
> -}
> -
> -template<>
> -Control<int64_t>::Control(unsigned int id, const char *name)
> -	: ControlId(id, name, ControlTypeInteger64)
> -{
> -}
> -#endif /* __DOXYGEN__ */
> -
>  /**
>   * \class ControlRange
>   * \brief Describe the limits of valid values for a Control
>
Kieran Bingham March 2, 2020, 11:35 p.m. UTC | #2
One more thing,

On 02/03/2020 23:33, Kieran Bingham wrote:
> On 29/02/2020 16:42, Laurent Pinchart wrote:
>> To avoid defining all specializations of the Control constructor
>> manually, move the definition of those functions to controls.h.

I think this comment applies to the previous couple of patches too, but
the commit message is sort of missing an important piece of information
here.

You've moved them *and* simplified them to a single constructor...

>>
>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> Excellent, more simplifications. (wait, I'm not sure I can use the word
> 'simple' in the context of templates hehe)
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
>> ---
>>  include/libcamera/controls.h |  5 ++++-
>>  src/libcamera/controls.cpp   | 26 --------------------------
>>  2 files changed, 4 insertions(+), 27 deletions(-)
>>
>> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
>> index dfe69916cd64..6f0ebf4f3ca5 100644
>> --- a/include/libcamera/controls.h
>> +++ b/include/libcamera/controls.h
>> @@ -146,7 +146,10 @@ class Control : public ControlId
>>  public:
>>  	using type = T;
>>  
>> -	Control(unsigned int id, const char *name);
>> +	Control(unsigned int id, const char *name)
>> +		: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
>> +	{
>> +	}
>>  
>>  private:
>>  	Control(const Control &) = delete;
>> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
>> index 5cc8ce2199d0..76230a052de1 100644
>> --- a/src/libcamera/controls.cpp
>> +++ b/src/libcamera/controls.cpp
>> @@ -249,32 +249,6 @@ bool ControlValue::operator==(const ControlValue &other) const
>>   * \brief The Control template type T
>>   */
>>  
>> -#ifndef __DOXYGEN__
>> -template<>
>> -Control<void>::Control(unsigned int id, const char *name)
>> -	: ControlId(id, name, ControlTypeNone)
>> -{
>> -}
>> -
>> -template<>
>> -Control<bool>::Control(unsigned int id, const char *name)
>> -	: ControlId(id, name, ControlTypeBool)
>> -{
>> -}
>> -
>> -template<>
>> -Control<int32_t>::Control(unsigned int id, const char *name)
>> -	: ControlId(id, name, ControlTypeInteger32)
>> -{
>> -}
>> -
>> -template<>
>> -Control<int64_t>::Control(unsigned int id, const char *name)
>> -	: ControlId(id, name, ControlTypeInteger64)
>> -{
>> -}
>> -#endif /* __DOXYGEN__ */
>> -
>>  /**
>>   * \class ControlRange
>>   * \brief Describe the limits of valid values for a Control
>>
>

Patch

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index dfe69916cd64..6f0ebf4f3ca5 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -146,7 +146,10 @@  class Control : public ControlId
 public:
 	using type = T;
 
-	Control(unsigned int id, const char *name);
+	Control(unsigned int id, const char *name)
+		: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
+	{
+	}
 
 private:
 	Control(const Control &) = delete;
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 5cc8ce2199d0..76230a052de1 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -249,32 +249,6 @@  bool ControlValue::operator==(const ControlValue &other) const
  * \brief The Control template type T
  */
 
-#ifndef __DOXYGEN__
-template<>
-Control<void>::Control(unsigned int id, const char *name)
-	: ControlId(id, name, ControlTypeNone)
-{
-}
-
-template<>
-Control<bool>::Control(unsigned int id, const char *name)
-	: ControlId(id, name, ControlTypeBool)
-{
-}
-
-template<>
-Control<int32_t>::Control(unsigned int id, const char *name)
-	: ControlId(id, name, ControlTypeInteger32)
-{
-}
-
-template<>
-Control<int64_t>::Control(unsigned int id, const char *name)
-	: ControlId(id, name, ControlTypeInteger64)
-{
-}
-#endif /* __DOXYGEN__ */
-
 /**
  * \class ControlRange
  * \brief Describe the limits of valid values for a Control