cam: options: Create a template class for options
In preparation to adding more parsers create a template class to hold the parsed information. The rational for making it a template are that different parsers can index the options using different data types. The OptionsParser index its options using an int while the upcoming KeyValyeParser will index its options using strings for example. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
committed by
Laurent Pinchart
parent
377516a084
commit
c6468e45d1
+26
-24
@@ -12,6 +12,32 @@
|
||||
|
||||
#include "options.h"
|
||||
|
||||
template <typename T>
|
||||
bool OptionsBase<T>::valid() const
|
||||
{
|
||||
return !values_.empty();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool OptionsBase<T>::isSet(const T &opt) const
|
||||
{
|
||||
return values_.find(opt) != values_.end();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const std::string &OptionsBase<T>::operator[](const T &opt) const
|
||||
{
|
||||
return values_.find(opt)->second;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void OptionsBase<T>::clear()
|
||||
{
|
||||
values_.clear();
|
||||
}
|
||||
|
||||
template class OptionsBase<int>;
|
||||
|
||||
void OptionsParser::addOption(int opt, const char *help, const char *name,
|
||||
OptionArgument argument, const char *argumentName)
|
||||
{
|
||||
@@ -166,27 +192,3 @@ void OptionsParser::usage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OptionsParser::Options::Options()
|
||||
{
|
||||
}
|
||||
|
||||
bool OptionsParser::Options::valid() const
|
||||
{
|
||||
return !values_.empty();
|
||||
}
|
||||
|
||||
bool OptionsParser::Options::isSet(int opt) const
|
||||
{
|
||||
return values_.find(opt) != values_.end();
|
||||
}
|
||||
|
||||
const std::string &OptionsParser::Options::operator[](int opt) const
|
||||
{
|
||||
return values_.find(opt)->second;
|
||||
}
|
||||
|
||||
void OptionsParser::Options::clear()
|
||||
{
|
||||
values_.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user