]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/getopt.h
Allow std::vector to be used for GetOpt value lists
[libs/core.git] / source / core / getopt.h
index 8d78a728169a74e2b5715fce27ee63bccd100cc0..e60a22693483ef4626a039e2ab4e0a33399c045e 100644 (file)
@@ -228,6 +228,13 @@ public:
        Option &add_option(char s, const std::string &l, T &d, ArgType a = NO_ARG)
        { return add_option(s, l, SimpleStore<T>(d), a); }
 
+       /** Adds an option with both short and long forms.  The option may be
+       specified multiple times, and the argument from each occurrence is stored in
+       the list.  The argument type must be REQUIRED_ARG. */
+       template<typename T>
+       Option &add_option(char s, const std::string &l, std::vector<T> &d, ArgType a = REQUIRED_ARG)
+       { return add_option(s, l, ListStore<std::vector<T> >(d), a); }
+
        /** Adds an option with both short and long forms.  The option may be
        specified multiple times, and the argument from each occurrence is stored in
        the list.  The argument type must be REQUIRED_ARG. */
@@ -246,6 +253,13 @@ public:
        Argument &add_argument(const std::string &n, T &d, ArgType a = REQUIRED_ARG)
        { return add_argument(n, SimpleStore<T>(d), a); }
 
+       /** Adds a positional argument list.  If the list is declared as required,
+       at least one element must be given; an optional list may be empty.  Only one
+       list may be added, and optional fixed arguments can't be used with it. */
+       template<typename T>
+       Argument &add_argument(const std::string &n, std::vector<T> &d, ArgType a = REQUIRED_ARG)
+       { return add_argument(n, ListStore<std::vector<T> >(d), a); }
+
        /** Adds a positional argument list.  If the list is declared as required,
        at least one element must be given; an optional list may be empty.  Only one
        list may be added, and optional fixed arguments can't be used with it. */
@@ -292,6 +306,9 @@ template<> inline void GetOpt::SimpleStore<unsigned>::store()
 template<> inline void GetOpt::SimpleStore<std::string>::store(const std::string &a)
 { data = a; }
 
+template<> inline void GetOpt::ListStore<std::vector<std::string> >::store(const std::string &a)
+{ data.push_back(a); }
+
 template<> inline void GetOpt::ListStore<std::list<std::string> >::store(const std::string &a)
 { data.push_back(a); }