[libcamera-devel] [PATCH 2/6] cam: options: create a template class for options
Niklas Söderlund
niklas.soderlund at ragnatech.se
Mon Jan 28 01:41:05 CET 2019
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 at ragnatech.se>
---
src/cam/options.cpp | 24 ------------------------
src/cam/options.h | 28 ++++++++++++++++------------
2 files changed, 16 insertions(+), 36 deletions(-)
diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index 83601270207b67b3..b24964a8ce413a85 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -166,27 +166,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();
-}
diff --git a/src/cam/options.h b/src/cam/options.h
index 491f6a316fffbe5b..a08bfea1ba74c96b 100644
--- a/src/cam/options.h
+++ b/src/cam/options.h
@@ -17,21 +17,25 @@ enum OptionArgument {
ArgumentOptional,
};
+template <class T>
+class OptionsBase
+{
+public:
+ bool valid() const { return !values_.empty(); };
+ bool isSet(T opt) const { return values_.find(opt) != values_.end(); };
+ const std::string &operator[](T opt) const { return values_.find(opt)->second; };
+
+private:
+ friend class OptionsParser;
+ std::map<T, std::string> values_;
+ void clear() { values_.clear(); };
+};
+
class OptionsParser
{
public:
- class Options {
- public:
- Options();
-
- bool valid() const;
- bool isSet(int opt) const;
- const std::string &operator[](int opt) const;
-
- private:
- friend class OptionsParser;
- std::map<int, std::string> values_;
- void clear();
+ class Options : public OptionsBase<int>
+ {
};
void addOption(int opt, const char *help, const char *name = nullptr,
--
2.20.1
More information about the libcamera-devel
mailing list