summaryrefslogtreecommitdiff
path: root/src/cam
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-01-28 00:35:12 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-02-01 11:41:55 +0200
commitc6468e45d1dedb295f6e67b3a49d2d4f4dfeee1c (patch)
tree8339946ea925852335c2d08e65df9cbaa0571cef /src/cam
parent377516a084467692cb275526a16d43b25f773e46 (diff)
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>
Diffstat (limited to 'src/cam')
-rw-r--r--src/cam/options.cpp50
-rw-r--r--src/cam/options.h28
2 files changed, 42 insertions, 36 deletions
diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index 83601270..f48bd1fc 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -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();
-}
diff --git a/src/cam/options.h b/src/cam/options.h
index 6d1b12d2..2bf1f160 100644
--- a/src/cam/options.h
+++ b/src/cam/options.h
@@ -28,21 +28,25 @@ struct Option {
bool hasLongOption() const { return name != nullptr; }
};
+template <typename T>
+class OptionsBase
+{
+public:
+ bool valid() const;
+ bool isSet(const T &opt) const;
+ const std::string &operator[](const T &opt) const;
+
+private:
+ friend class OptionsParser;
+ std::map<T, std::string> values_;
+ void 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,