Message ID | 20190201092919.8336-1-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Commit | 3fd5ade00c5da727184c6c5aa728d4ee27bb6ac2 |
Headers | show |
Series |
|
Related | show |
Hi Laurent, Thanks for your patch. On 2019-02-01 11:29:19 +0200, Laurent Pinchart wrote: > The OptionValue class defines operators to convert the variant to all > the supported option types. As a convenience, add explicit methods to > perform the same operations, avoiding the need to write long > static_cast<>() statements in the caller. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > src/cam/options.cpp | 19 +++++++++++++++++-- > src/cam/options.h | 4 ++++ > 2 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/src/cam/options.cpp b/src/cam/options.cpp > index 4c9f3a36d435..eb59376fa459 100644 > --- a/src/cam/options.cpp > +++ b/src/cam/options.cpp > @@ -273,6 +273,21 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) > } > > OptionValue::operator int() const > +{ > + return toInteger(); > +} > + > +OptionValue::operator std::string() const > +{ > + return toString(); > +} > + > +OptionValue::operator KeyValueParser::Options() const > +{ > + return toKeyValues(); > +} > + > +int OptionValue::toInteger() const > { > if (type_ != OptionInteger) > return 0; > @@ -280,7 +295,7 @@ OptionValue::operator int() const > return integer_; > } > > -OptionValue::operator std::string() const > +std::string OptionValue::toString() const > { > if (type_ != OptionString) > return std::string(); > @@ -288,7 +303,7 @@ OptionValue::operator std::string() const > return string_; > } > > -OptionValue::operator KeyValueParser::Options() const > +KeyValueParser::Options OptionValue::toKeyValues() const > { > if (type_ != OptionKeyValue) > return KeyValueParser::Options(); > diff --git a/src/cam/options.h b/src/cam/options.h > index e1fd62ecd369..2d3aa50b5051 100644 > --- a/src/cam/options.h > +++ b/src/cam/options.h > @@ -91,6 +91,10 @@ public: > operator std::string() const; > operator KeyValueParser::Options() const; > > + int toInteger() const; > + std::string toString() const; > + KeyValueParser::Options toKeyValues() const; > + > private: > OptionType type_; > int integer_; > -- > Regards, > > Laurent Pinchart >
diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 4c9f3a36d435..eb59376fa459 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -273,6 +273,21 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) } OptionValue::operator int() const +{ + return toInteger(); +} + +OptionValue::operator std::string() const +{ + return toString(); +} + +OptionValue::operator KeyValueParser::Options() const +{ + return toKeyValues(); +} + +int OptionValue::toInteger() const { if (type_ != OptionInteger) return 0; @@ -280,7 +295,7 @@ OptionValue::operator int() const return integer_; } -OptionValue::operator std::string() const +std::string OptionValue::toString() const { if (type_ != OptionString) return std::string(); @@ -288,7 +303,7 @@ OptionValue::operator std::string() const return string_; } -OptionValue::operator KeyValueParser::Options() const +KeyValueParser::Options OptionValue::toKeyValues() const { if (type_ != OptionKeyValue) return KeyValueParser::Options(); diff --git a/src/cam/options.h b/src/cam/options.h index e1fd62ecd369..2d3aa50b5051 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -91,6 +91,10 @@ public: operator std::string() const; operator KeyValueParser::Options() const; + int toInteger() const; + std::string toString() const; + KeyValueParser::Options toKeyValues() const; + private: OptionType type_; int integer_;
The OptionValue class defines operators to convert the variant to all the supported option types. As a convenience, add explicit methods to perform the same operations, avoiding the need to write long static_cast<>() statements in the caller. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- src/cam/options.cpp | 19 +++++++++++++++++-- src/cam/options.h | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-)