@@ -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();
-}
@@ -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,