cam: options: Add explicit conversion methods to OptionValue
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>
This commit is contained in:
parent
86a7b45bdb
commit
3fd5ade00c
2 changed files with 21 additions and 2 deletions
|
@ -273,6 +273,21 @@ OptionValue::OptionValue(const KeyValueParser::Options &value)
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionValue::operator int() const
|
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)
|
if (type_ != OptionInteger)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -280,7 +295,7 @@ OptionValue::operator int() const
|
||||||
return integer_;
|
return integer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionValue::operator std::string() const
|
std::string OptionValue::toString() const
|
||||||
{
|
{
|
||||||
if (type_ != OptionString)
|
if (type_ != OptionString)
|
||||||
return std::string();
|
return std::string();
|
||||||
|
@ -288,7 +303,7 @@ OptionValue::operator std::string() const
|
||||||
return string_;
|
return string_;
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionValue::operator KeyValueParser::Options() const
|
KeyValueParser::Options OptionValue::toKeyValues() const
|
||||||
{
|
{
|
||||||
if (type_ != OptionKeyValue)
|
if (type_ != OptionKeyValue)
|
||||||
return KeyValueParser::Options();
|
return KeyValueParser::Options();
|
||||||
|
|
|
@ -91,6 +91,10 @@ public:
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
operator KeyValueParser::Options() const;
|
operator KeyValueParser::Options() const;
|
||||||
|
|
||||||
|
int toInteger() const;
|
||||||
|
std::string toString() const;
|
||||||
|
KeyValueParser::Options toKeyValues() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OptionType type_;
|
OptionType type_;
|
||||||
int integer_;
|
int integer_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue