From 770804ecad19db910f8b881b00dfce7da80d3f79 Mon Sep 17 00:00:00 2001
From: Christopher Subich <Christopher.Subich@ec.gc.ca>
Date: Fri, 9 Sep 2016 14:45:08 -0400
Subject: [PATCH] Add vector-valued options to the config file

This change modifeis Options.hpp to add the possibility of
vector-valued options to the config file and command line.
From the 'case' code, this option is used by (for example)

std::vector<int> intvec;
add_option("Name",&intvec,"Description);

When run, options of the form --Name 1 2 3 4 (at the command
line) or Name = 1 2 3 4 (in the config file) will be added
to the vector 'intvec' as separate entries.

Because add_option is a template function, this works
identically for double (floating point)-valued options.  It
has not been tested with string options.

Since an empty vector is a perfectly cromulent and
unambiguous possibility, vector-valued options do *not*
permit the specification of defaults.
---
 src/Options.hpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/Options.hpp b/src/Options.hpp
index 6d6b013..5be95d9 100644
--- a/src/Options.hpp
+++ b/src/Options.hpp
@@ -44,6 +44,13 @@ void add_option(
       const char * name, string * location,
       const char * def_value, const char * description);
 
+// Overload for vector list (no default value)
+template <class t> void add_option(
+      const char * name, std::vector<t> * location, const char * description) {
+   categories.back()->add_options()
+      (name,popt::value< std::vector<t> >(location)->multitoken(),description);
+}
+
 // Wrapper for adding a "switch" option that is either present (true) or
 // not present (false).
 void add_switch(const char * name, bool * location, const char * description);
-- 
GitLab