[{"id":2720,"web_url":"https://patchwork.libcamera.org/comment/2720/","msgid":"<20190929085804.zzobfuif5ultlavg@uno.localdomain>","date":"2019-09-29T08:58:04","subject":"Re: [libcamera-devel] [PATCH 02/12] libcamera: controls: Make\n\tControlValue get/set accessors template methods","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Sat, Sep 28, 2019 at 06:22:28PM +0300, Laurent Pinchart wrote:\n> The ControlValue get accessors are implemented with functions of\n> different names, whlie the set accessors use polymorphism to support\n> different control types. This isn't very consistent and intuitive. Make\n> the API clearer by using template methods. This will also have the added\n> advantage that support for the new types will only require adding\n> template specialisations, without adding new methods.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  include/libcamera/controls.h        |  11 ++-\n>  src/libcamera/controls.cpp          | 101 +++++++++++++---------------\n>  src/libcamera/pipeline/uvcvideo.cpp |  10 +--\n>  src/libcamera/pipeline/vimc.cpp     |   6 +-\n>  test/controls/control_info.cpp      |   4 +-\n>  test/controls/control_list.cpp      |  16 ++---\n>  test/controls/control_value.cpp     |  12 ++--\n>  7 files changed, 74 insertions(+), 86 deletions(-)\n>\n> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\n> index ffba880a66ff..0886370f0901 100644\n> --- a/include/libcamera/controls.h\n> +++ b/include/libcamera/controls.h\n> @@ -36,13 +36,10 @@ public:\n>  \tControlType type() const { return type_; };\n>  \tbool isNone() const { return type_ == ControlTypeNone; };\n>\n> -\tvoid set(bool value);\n> -\tvoid set(int value);\n> -\tvoid set(int64_t value);\n> -\n> -\tbool getBool() const;\n> -\tint getInt() const;\n> -\tint64_t getInt64() const;\n> +\ttemplate<typename T>\n> +\tconst T &get() const;\n> +\ttemplate<typename T>\n> +\tvoid set(const T &value);\n>\n>  \tstd::string toString() const;\n>\n> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> index 9960a30dfa03..88aab88db327 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -90,76 +90,67 @@ ControlValue::ControlValue(int64_t value)\n>   */\n>\n>  /**\n> - * \\brief Set the value with a boolean\n> - * \\param[in] value Boolean value to store\n> + * \\fn template<typename T> const T &ControlValue::get() const\n> + * \\brief Get the control value\n> + *\n> + * The control value type shall match the type T, otherwise the behaviour is\n> + * undefined.\n> + *\n> + * \\return The control value\n>   */\n> -void ControlValue::set(bool value)\n> +\n> +/**\n> + * \\fn template<typename T> void ControlValue::set(const T &value)\n> + * \\brief Set the control value to \\a value\n> + * \\param[in] value The control value\n> + */\n> +\n> +#ifndef __DOXYGEN__\n> +template<>\n> +const bool &ControlValue::get<bool>() const\n> +{\n> +\tASSERT(type_ == ControlTypeBool);\n> +\n> +\treturn bool_;\n> +}\n> +\n> +template<>\n> +const int &ControlValue::get<int>() const\n> +{\n> +\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> +\n> +\treturn integer_;\n> +}\n> +\n> +template<>\n> +const int64_t &ControlValue::get<int64_t>() const\n> +{\n> +\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> +\n> +\treturn integer64_;\n> +}\n> +\n> +template<>\n> +void ControlValue::set<bool>(const bool &value)\n>  {\n>  \ttype_ = ControlTypeBool;\n>  \tbool_ = value;\n>  }\n>\n> -/**\n> - * \\brief Set the value with an integer\n> - * \\param[in] value Integer value to store\n> - */\n> -void ControlValue::set(int value)\n> +template<>\n> +void ControlValue::set<int>(const int &value)\n>  {\n>  \ttype_ = ControlTypeInteger;\n>  \tinteger_ = value;\n>  }\n>\n> -/**\n> - * \\brief Set the value with a 64 bit integer\n> - * \\param[in] value 64 bit integer value to store\n> - */\n> -void ControlValue::set(int64_t value)\n> +template<>\n> +void ControlValue::set<int64_t>(const int64_t &value)\n>  {\n>  \ttype_ = ControlTypeInteger64;\n>  \tinteger64_ = value;\n\nThis was probably here already, but with the option of getting\ninteger64_ from controls set as int, what would we get ?\nThe union occupies 8 bytes, we set 4 with integer32_ = value, then get\nback 8 with get<int64_t>(). Is this ok?\n\nOther than that, the burden of having get<type>() is repaid in full by\nhow nice set() looks like.\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nAh, wait, can we mix the two ? getInt() and set(Control<int>, value) ?\nIs this desirable ?\n\nThanks\n   j\n\n\n>  }\n> -\n> -/**\n> - * \\brief Get the boolean value\n> - *\n> - * The value type must be Boolean.\n> - *\n> - * \\return The boolean value\n> - */\n> -bool ControlValue::getBool() const\n> -{\n> -\tASSERT(type_ == ControlTypeBool);\n> -\n> -\treturn bool_;\n> -}\n> -\n> -/**\n> - * \\brief Get the integer value\n> - *\n> - * The value type must be Integer or Integer64.\n> - *\n> - * \\return The integer value\n> - */\n> -int ControlValue::getInt() const\n> -{\n> -\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> -\n> -\treturn integer_;\n> -}\n> -\n> -/**\n> - * \\brief Get the 64-bit integer value\n> - *\n> - * The value type must be Integer or Integer64.\n> - *\n> - * \\return The 64-bit integer value\n> - */\n> -int64_t ControlValue::getInt64() const\n> -{\n> -\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> -\n> -\treturn integer64_;\n> -}\n> +#endif /* __DOXYGEN__ */\n>\n>  /**\n>   * \\brief Assemble and return a string describing the value\n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index 8965210550d2..81c548af2c64 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -235,24 +235,24 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n>\n>  \t\tswitch (ci->id()) {\n>  \t\tcase Brightness:\n> -\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tcase Contrast:\n> -\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tcase Saturation:\n> -\t\t\tcontrols.add(V4L2_CID_SATURATION, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_SATURATION, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tcase ManualExposure:\n>  \t\t\tcontrols.add(V4L2_CID_EXPOSURE_AUTO, 1);\n> -\t\t\tcontrols.add(V4L2_CID_EXPOSURE_ABSOLUTE, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_EXPOSURE_ABSOLUTE, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tcase ManualGain:\n> -\t\t\tcontrols.add(V4L2_CID_GAIN, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_GAIN, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tdefault:\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index f26a91f86ec1..3e34e7a0edbf 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -288,15 +288,15 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n>\n>  \t\tswitch (ci->id()) {\n>  \t\tcase Brightness:\n> -\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tcase Contrast:\n> -\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tcase Saturation:\n> -\t\t\tcontrols.add(V4L2_CID_SATURATION, value.getInt());\n> +\t\t\tcontrols.add(V4L2_CID_SATURATION, value.get<int>());\n>  \t\t\tbreak;\n>\n>  \t\tdefault:\n> diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp\n> index 8cda860b9fe9..faefaaa444d9 100644\n> --- a/test/controls/control_info.cpp\n> +++ b/test/controls/control_info.cpp\n> @@ -32,7 +32,7 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (info.min().getInt() != 0 || info.max().getInt() != 0) {\n> +\t\tif (info.min().get<int>() != 0 || info.max().get<int>() != 0) {\n>  \t\t\tcout << \"Invalid control range for Brightness\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -50,7 +50,7 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (info.min().getInt() != 10 || info.max().getInt() != 200) {\n> +\t\tif (info.min().get<int>() != 10 || info.max().get<int>() != 200) {\n>  \t\t\tcout << \"Invalid control range for Contrast\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp\n> index f1d79ff8fcfd..0402e7c23dba 100644\n> --- a/test/controls/control_list.cpp\n> +++ b/test/controls/control_list.cpp\n> @@ -96,7 +96,7 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (list[Brightness].getInt() != 255) {\n> +\t\tif (list[Brightness].get<int>() != 255) {\n>  \t\t\tcout << \"Incorrest Brightness control value\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -125,8 +125,8 @@ protected:\n>  \t\t/*\n>  \t\t * Test control value retrieval and update through ControlInfo.\n>  \t\t */\n> -\t\tif (list[brightness].getInt() != 64 ||\n> -\t\t    list[contrast].getInt() != 128) {\n> +\t\tif (list[brightness].get<int>() != 64 ||\n> +\t\t    list[contrast].get<int>() != 128) {\n>  \t\t\tcout << \"Failed to retrieve control value\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -134,8 +134,8 @@ protected:\n>  \t\tlist[brightness] = 10;\n>  \t\tlist[contrast] = 20;\n>\n> -\t\tif (list[brightness].getInt() != 10 ||\n> -\t\t    list[contrast].getInt() != 20) {\n> +\t\tif (list[brightness].get<int>() != 10 ||\n> +\t\t    list[contrast].get<int>() != 20) {\n>  \t\t\tcout << \"Failed to update control value\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -185,9 +185,9 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (newList[Brightness].getInt() != 10 ||\n> -\t\t    newList[Contrast].getInt() != 20 ||\n> -\t\t    newList[Saturation].getInt() != 255) {\n> +\t\tif (newList[Brightness].get<int>() != 10 ||\n> +\t\t    newList[Contrast].get<int>() != 20 ||\n> +\t\t    newList[Saturation].get<int>() != 255) {\n>  \t\t\tcout << \"New list contains incorrect values\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp\n> index 778efe5c115f..397c43f799ad 100644\n> --- a/test/controls/control_value.cpp\n> +++ b/test/controls/control_value.cpp\n> @@ -27,12 +27,12 @@ protected:\n>  \t\t     << \" Bool: \" << boolean.toString()\n>  \t\t     << endl;\n>\n> -\t\tif (integer.getInt() != 1234) {\n> +\t\tif (integer.get<int>() != 1234) {\n>  \t\t\tcerr << \"Failed to get Integer\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (boolean.getBool() != true) {\n> +\t\tif (boolean.get<bool>() != true) {\n>  \t\t\tcerr << \"Failed to get Boolean\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -45,19 +45,19 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tvalue.set(true);\n> +\t\tvalue.set<bool>(true);\n>  \t\tif (value.isNone()) {\n>  \t\t\tcerr << \"Failed to set an empty object\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (value.getBool() != true) {\n> +\t\tif (value.get<bool>() != true) {\n>  \t\t\tcerr << \"Failed to get Booleans\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tvalue.set(10);\n> -\t\tif (value.getInt() != 10) {\n> +\t\tvalue.set<int>(10);\n> +\t\tif (value.get<int>() != 10) {\n>  \t\t\tcerr << \"Failed to get Integer\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 90DBC60BE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 29 Sep 2019 10:56:23 +0200 (CEST)","from uno.localdomain\n\t(host7-199-dynamic.171-212-r.retail.telecomitalia.it [212.171.199.7])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 8CBAF1C0005;\n\tSun, 29 Sep 2019 08:56:21 +0000 (UTC)"],"X-Originating-IP":"212.171.199.7","Date":"Sun, 29 Sep 2019 10:58:04 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190929085804.zzobfuif5ultlavg@uno.localdomain>","References":"<20190928152238.23752-1-laurent.pinchart@ideasonboard.com>\n\t<20190928152238.23752-3-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"amf3vgpr4gmggrby\"","Content-Disposition":"inline","In-Reply-To":"<20190928152238.23752-3-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 02/12] libcamera: controls: Make\n\tControlValue get/set accessors template methods","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sun, 29 Sep 2019 08:56:23 -0000"}},{"id":2730,"web_url":"https://patchwork.libcamera.org/comment/2730/","msgid":"<20190929113230.GB4827@pendragon.ideasonboard.com>","date":"2019-09-29T11:32:30","subject":"Re: [libcamera-devel] [PATCH 02/12] libcamera: controls: Make\n\tControlValue get/set accessors template methods","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Sun, Sep 29, 2019 at 10:58:04AM +0200, Jacopo Mondi wrote:\n> On Sat, Sep 28, 2019 at 06:22:28PM +0300, Laurent Pinchart wrote:\n> > The ControlValue get accessors are implemented with functions of\n> > different names, whlie the set accessors use polymorphism to support\n> > different control types. This isn't very consistent and intuitive. Make\n> > the API clearer by using template methods. This will also have the added\n> > advantage that support for the new types will only require adding\n> > template specialisations, without adding new methods.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  include/libcamera/controls.h        |  11 ++-\n> >  src/libcamera/controls.cpp          | 101 +++++++++++++---------------\n> >  src/libcamera/pipeline/uvcvideo.cpp |  10 +--\n> >  src/libcamera/pipeline/vimc.cpp     |   6 +-\n> >  test/controls/control_info.cpp      |   4 +-\n> >  test/controls/control_list.cpp      |  16 ++---\n> >  test/controls/control_value.cpp     |  12 ++--\n> >  7 files changed, 74 insertions(+), 86 deletions(-)\n> >\n> > diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\n> > index ffba880a66ff..0886370f0901 100644\n> > --- a/include/libcamera/controls.h\n> > +++ b/include/libcamera/controls.h\n> > @@ -36,13 +36,10 @@ public:\n> >  \tControlType type() const { return type_; };\n> >  \tbool isNone() const { return type_ == ControlTypeNone; };\n> >\n> > -\tvoid set(bool value);\n> > -\tvoid set(int value);\n> > -\tvoid set(int64_t value);\n> > -\n> > -\tbool getBool() const;\n> > -\tint getInt() const;\n> > -\tint64_t getInt64() const;\n> > +\ttemplate<typename T>\n> > +\tconst T &get() const;\n> > +\ttemplate<typename T>\n> > +\tvoid set(const T &value);\n> >\n> >  \tstd::string toString() const;\n> >\n> > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> > index 9960a30dfa03..88aab88db327 100644\n> > --- a/src/libcamera/controls.cpp\n> > +++ b/src/libcamera/controls.cpp\n> > @@ -90,76 +90,67 @@ ControlValue::ControlValue(int64_t value)\n> >   */\n> >\n> >  /**\n> > - * \\brief Set the value with a boolean\n> > - * \\param[in] value Boolean value to store\n> > + * \\fn template<typename T> const T &ControlValue::get() const\n> > + * \\brief Get the control value\n> > + *\n> > + * The control value type shall match the type T, otherwise the behaviour is\n> > + * undefined.\n> > + *\n> > + * \\return The control value\n> >   */\n> > -void ControlValue::set(bool value)\n> > +\n> > +/**\n> > + * \\fn template<typename T> void ControlValue::set(const T &value)\n> > + * \\brief Set the control value to \\a value\n> > + * \\param[in] value The control value\n> > + */\n> > +\n> > +#ifndef __DOXYGEN__\n> > +template<>\n> > +const bool &ControlValue::get<bool>() const\n> > +{\n> > +\tASSERT(type_ == ControlTypeBool);\n> > +\n> > +\treturn bool_;\n> > +}\n> > +\n> > +template<>\n> > +const int &ControlValue::get<int>() const\n> > +{\n> > +\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> > +\n> > +\treturn integer_;\n> > +}\n> > +\n> > +template<>\n> > +const int64_t &ControlValue::get<int64_t>() const\n> > +{\n> > +\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> > +\n> > +\treturn integer64_;\n> > +}\n> > +\n> > +template<>\n> > +void ControlValue::set<bool>(const bool &value)\n> >  {\n> >  \ttype_ = ControlTypeBool;\n> >  \tbool_ = value;\n> >  }\n> >\n> > -/**\n> > - * \\brief Set the value with an integer\n> > - * \\param[in] value Integer value to store\n> > - */\n> > -void ControlValue::set(int value)\n> > +template<>\n> > +void ControlValue::set<int>(const int &value)\n> >  {\n> >  \ttype_ = ControlTypeInteger;\n> >  \tinteger_ = value;\n> >  }\n> >\n> > -/**\n> > - * \\brief Set the value with a 64 bit integer\n> > - * \\param[in] value 64 bit integer value to store\n> > - */\n> > -void ControlValue::set(int64_t value)\n> > +template<>\n> > +void ControlValue::set<int64_t>(const int64_t &value)\n> >  {\n> >  \ttype_ = ControlTypeInteger64;\n> >  \tinteger64_ = value;\n> \n> This was probably here already, but with the option of getting\n> integer64_ from controls set as int, what would we get ?\n> The union occupies 8 bytes, we set 4 with integer32_ = value, then get\n> back 8 with get<int64_t>(). Is this ok?\n\nProbably not. I think this needs to be addressed, and we need to decide\nhow to do so. One option would be to disallow reading a 32-bit control\nas a 64-bit value. I'm not opposed to that, but the consequences need to\nbe considered. It used to cause issues, one of them being, if I remember\nconnectly, that V4L2 controls min and max values were always stored as\n64-bit, leading to a .set(min) on a ControlValue storing a 64-bit\ninteger, even for 32-bit controls. This one should be fixed now that we\nhave a more explicit API, and it may be time to disallow unsafe integer\nconversions.\n\nWhat's the general opinion, should we give this a try ?\n\n> Other than that, the burden of having get<type>() is repaid in full by\n> how nice set() looks like.\n> \n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> Ah, wait, can we mix the two ? getInt() and set(Control<int>, value) ?\n> Is this desirable ?\n\nControlValue::get is typically called from ControlList::get(const\nControl<T> &), so the template version of ControlValue::get is required\nto make this possible. We could also have a getInt in addition to\nget<int>, but I think that would be overkill, beside the fact that\nhaving two functions that fulfil the same purpose isn't very nice.\n\n> >  }\n> > -\n> > -/**\n> > - * \\brief Get the boolean value\n> > - *\n> > - * The value type must be Boolean.\n> > - *\n> > - * \\return The boolean value\n> > - */\n> > -bool ControlValue::getBool() const\n> > -{\n> > -\tASSERT(type_ == ControlTypeBool);\n> > -\n> > -\treturn bool_;\n> > -}\n> > -\n> > -/**\n> > - * \\brief Get the integer value\n> > - *\n> > - * The value type must be Integer or Integer64.\n> > - *\n> > - * \\return The integer value\n> > - */\n> > -int ControlValue::getInt() const\n> > -{\n> > -\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> > -\n> > -\treturn integer_;\n> > -}\n> > -\n> > -/**\n> > - * \\brief Get the 64-bit integer value\n> > - *\n> > - * The value type must be Integer or Integer64.\n> > - *\n> > - * \\return The 64-bit integer value\n> > - */\n> > -int64_t ControlValue::getInt64() const\n> > -{\n> > -\tASSERT(type_ == ControlTypeInteger || type_ == ControlTypeInteger64);\n> > -\n> > -\treturn integer64_;\n> > -}\n> > +#endif /* __DOXYGEN__ */\n> >\n> >  /**\n> >   * \\brief Assemble and return a string describing the value\n> > diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> > index 8965210550d2..81c548af2c64 100644\n> > --- a/src/libcamera/pipeline/uvcvideo.cpp\n> > +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> > @@ -235,24 +235,24 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n> >\n> >  \t\tswitch (ci->id()) {\n> >  \t\tcase Brightness:\n> > -\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tcase Contrast:\n> > -\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tcase Saturation:\n> > -\t\t\tcontrols.add(V4L2_CID_SATURATION, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_SATURATION, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tcase ManualExposure:\n> >  \t\t\tcontrols.add(V4L2_CID_EXPOSURE_AUTO, 1);\n> > -\t\t\tcontrols.add(V4L2_CID_EXPOSURE_ABSOLUTE, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_EXPOSURE_ABSOLUTE, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tcase ManualGain:\n> > -\t\t\tcontrols.add(V4L2_CID_GAIN, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_GAIN, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tdefault:\n> > diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> > index f26a91f86ec1..3e34e7a0edbf 100644\n> > --- a/src/libcamera/pipeline/vimc.cpp\n> > +++ b/src/libcamera/pipeline/vimc.cpp\n> > @@ -288,15 +288,15 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n> >\n> >  \t\tswitch (ci->id()) {\n> >  \t\tcase Brightness:\n> > -\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tcase Contrast:\n> > -\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tcase Saturation:\n> > -\t\t\tcontrols.add(V4L2_CID_SATURATION, value.getInt());\n> > +\t\t\tcontrols.add(V4L2_CID_SATURATION, value.get<int>());\n> >  \t\t\tbreak;\n> >\n> >  \t\tdefault:\n> > diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp\n> > index 8cda860b9fe9..faefaaa444d9 100644\n> > --- a/test/controls/control_info.cpp\n> > +++ b/test/controls/control_info.cpp\n> > @@ -32,7 +32,7 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (info.min().getInt() != 0 || info.max().getInt() != 0) {\n> > +\t\tif (info.min().get<int>() != 0 || info.max().get<int>() != 0) {\n> >  \t\t\tcout << \"Invalid control range for Brightness\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > @@ -50,7 +50,7 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (info.min().getInt() != 10 || info.max().getInt() != 200) {\n> > +\t\tif (info.min().get<int>() != 10 || info.max().get<int>() != 200) {\n> >  \t\t\tcout << \"Invalid control range for Contrast\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp\n> > index f1d79ff8fcfd..0402e7c23dba 100644\n> > --- a/test/controls/control_list.cpp\n> > +++ b/test/controls/control_list.cpp\n> > @@ -96,7 +96,7 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (list[Brightness].getInt() != 255) {\n> > +\t\tif (list[Brightness].get<int>() != 255) {\n> >  \t\t\tcout << \"Incorrest Brightness control value\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > @@ -125,8 +125,8 @@ protected:\n> >  \t\t/*\n> >  \t\t * Test control value retrieval and update through ControlInfo.\n> >  \t\t */\n> > -\t\tif (list[brightness].getInt() != 64 ||\n> > -\t\t    list[contrast].getInt() != 128) {\n> > +\t\tif (list[brightness].get<int>() != 64 ||\n> > +\t\t    list[contrast].get<int>() != 128) {\n> >  \t\t\tcout << \"Failed to retrieve control value\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > @@ -134,8 +134,8 @@ protected:\n> >  \t\tlist[brightness] = 10;\n> >  \t\tlist[contrast] = 20;\n> >\n> > -\t\tif (list[brightness].getInt() != 10 ||\n> > -\t\t    list[contrast].getInt() != 20) {\n> > +\t\tif (list[brightness].get<int>() != 10 ||\n> > +\t\t    list[contrast].get<int>() != 20) {\n> >  \t\t\tcout << \"Failed to update control value\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > @@ -185,9 +185,9 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (newList[Brightness].getInt() != 10 ||\n> > -\t\t    newList[Contrast].getInt() != 20 ||\n> > -\t\t    newList[Saturation].getInt() != 255) {\n> > +\t\tif (newList[Brightness].get<int>() != 10 ||\n> > +\t\t    newList[Contrast].get<int>() != 20 ||\n> > +\t\t    newList[Saturation].get<int>() != 255) {\n> >  \t\t\tcout << \"New list contains incorrect values\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp\n> > index 778efe5c115f..397c43f799ad 100644\n> > --- a/test/controls/control_value.cpp\n> > +++ b/test/controls/control_value.cpp\n> > @@ -27,12 +27,12 @@ protected:\n> >  \t\t     << \" Bool: \" << boolean.toString()\n> >  \t\t     << endl;\n> >\n> > -\t\tif (integer.getInt() != 1234) {\n> > +\t\tif (integer.get<int>() != 1234) {\n> >  \t\t\tcerr << \"Failed to get Integer\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (boolean.getBool() != true) {\n> > +\t\tif (boolean.get<bool>() != true) {\n> >  \t\t\tcerr << \"Failed to get Boolean\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > @@ -45,19 +45,19 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tvalue.set(true);\n> > +\t\tvalue.set<bool>(true);\n> >  \t\tif (value.isNone()) {\n> >  \t\t\tcerr << \"Failed to set an empty object\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (value.getBool() != true) {\n> > +\t\tif (value.get<bool>() != true) {\n> >  \t\t\tcerr << \"Failed to get Booleans\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tvalue.set(10);\n> > -\t\tif (value.getInt() != 10) {\n> > +\t\tvalue.set<int>(10);\n> > +\t\tif (value.get<int>() != 10) {\n> >  \t\t\tcerr << \"Failed to get Integer\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E37861654\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 29 Sep 2019 13:32:42 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7034A320;\n\tSun, 29 Sep 2019 13:32:41 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1569756761;\n\tbh=ThpN7gP1kvJ92RdQoyKqTzGiv07nnD/lyW0cYS/zLT0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=v6RU7iUcDeT5GGi+8dRM8Wf/l34p/bvlX+EfPi/gpWUoOGUJY78R8MdUvwsxJMdMq\n\tWTaOPIhDJ+XB2WJK+JDlN7mKDAxeVCzprSdIaq7wmsCERFL0HZBClGCh9DOfl5uodu\n\tggMw8+6YfakeHCi/yAn95WSEKXgkHkuPfCYCwHbY=","Date":"Sun, 29 Sep 2019 14:32:30 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190929113230.GB4827@pendragon.ideasonboard.com>","References":"<20190928152238.23752-1-laurent.pinchart@ideasonboard.com>\n\t<20190928152238.23752-3-laurent.pinchart@ideasonboard.com>\n\t<20190929085804.zzobfuif5ultlavg@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190929085804.zzobfuif5ultlavg@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 02/12] libcamera: controls: Make\n\tControlValue get/set accessors template methods","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sun, 29 Sep 2019 11:32:42 -0000"}}]