]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
Add infrastructure for handling string options which are repeated
authorJon TURNEY <jon.turney@dronecode.org.uk>
Thu, 23 Feb 2012 14:31:23 +0000 (14:31 +0000)
committerJon TURNEY <jon.turney@dronecode.org.uk>
Thu, 23 Feb 2012 14:31:23 +0000 (14:31 +0000)
2011-05-30 SZAVAI Gyula <szgyg@ludens.elte.hu>
        * libgetopt++/src/StringArrayOption.cc: New file.
        * libgetopt++/include/getopt++/StringArrayOption.h: New file.
        * libgetopt++/Makefile.am: Add new files.

libgetopt++/ChangeLog
libgetopt++/Makefile.am
libgetopt++/include/getopt++/StringArrayOption.h [new file with mode: 0644]
libgetopt++/src/StringArrayOption.cc [new file with mode: 0644]

index 14e4554c763ada1b8182dbe8eae75143a371647c..6c872c47bd68978c8cc8a5e7863dd81f473b2633 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-30 SZAVAI Gyula <szgyg@ludens.elte.hu>
+        * libgetopt++/src/StringArrayOption.cc: New file.
+        * libgetopt++/include/getopt++/StringArrayOption.h: New file.
+        * libgetopt++/Makefile.am: Add new files.
+
 2008-06-16  Dave Korn  <dave.korn.cygwin@gmail.com>
 
        * libgetopt++/src/OptionSet.cc (OptionSet::doOption):  Move value
index 1ce48eb15ca8fd96710990b419de2834caa9725b..3da877d841d8b0d4d7fef8ba879cb1dd8f57dd40 100644 (file)
@@ -26,7 +26,7 @@ TESTS = tests/OptionSet tests/optioniterator tests/BoolOptionTest
 
 libgetopt___la_SOURCES = src/GetOption.cc src/Option.cc src/BoolOption.cc \
        src/OptionSet.cc \
-       src/StringOption.cc
+       src/StringArrayOption.cc src/StringOption.cc
 
 libgetopt___la_LDFLAGS = -version-info 1:1:0
 
@@ -35,6 +35,7 @@ getoptinclude_HEADERS = include/getopt++/Option.h \
   include/getopt++/DefaultFormatter.h \
   include/getopt++/GetOption.h \
   include/getopt++/OptionSet.h \
+  include/getopt++/StringArrayOption.h \
   include/getopt++/StringOption.h
 
 tests_testoption_SOURCES = tests/testoption.cc
diff --git a/libgetopt++/include/getopt++/StringArrayOption.h b/libgetopt++/include/getopt++/StringArrayOption.h
new file mode 100644 (file)
index 0000000..d3f87c0
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Modified from StringOption.h by Szavai Gyula in 2011
+ *
+ * Copyright (c) 2002 Robert Collins.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ */
+
+#ifndef _STRINGARRAYOPTION_H_
+#define _STRINGARRAYOPTION_H_
+
+#include <getopt++/Option.h>
+#include <getopt++/GetOption.h>
+
+// Each registered option must implement this class.
+class StringArrayOption : public Option
+{
+public:
+  StringArrayOption(char shortopt, char const *longopt = 0,
+            std::string const &shorthelp = std::string(),
+            OptionSet &owner=GetOption::GetInstance());
+  virtual ~ StringArrayOption ();
+  virtual std::string const shortOption () const;
+  virtual std::string const longOption () const;
+  virtual std::string const shortHelp () const;
+  virtual Result Process (char const *);
+  virtual Argument argument () const;
+  operator std::vector<std::string> () const;
+
+private:
+  Argument _optional;
+  std::vector<std::string> _value;
+  char _shortopt;
+  char const *_longopt;
+  std::string _shorthelp;
+};
+
+#endif // _STRINGARRAYOPTION_H_
diff --git a/libgetopt++/src/StringArrayOption.cc b/libgetopt++/src/StringArrayOption.cc
new file mode 100644 (file)
index 0000000..79ba88c
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Modified from StringOption.cc by Szavai Gyula in 2011
+ *
+ * Copyright (c) 2002 Robert Collins.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ */
+
+#include <getopt++/StringArrayOption.h>
+
+using namespace std;
+
+StringArrayOption::StringArrayOption(char shortopt,
+                      char const *longopt, string const &shorthelp,
+                      OptionSet &owner) :
+                      _optional(Required), _shortopt(shortopt),
+                      _longopt (longopt), _shorthelp (shorthelp)
+{
+  owner.Register (this);
+};
+
+StringArrayOption::~ StringArrayOption () {};
+
+string const
+StringArrayOption::shortOption () const
+{
+  return string() + _shortopt + ":";
+}
+
+string const
+StringArrayOption::longOption () const
+{
+  return _longopt;
+}
+
+string const
+StringArrayOption::shortHelp () const
+{
+  return _shorthelp;
+}
+
+Option::Result
+StringArrayOption::Process (char const *optarg)
+{
+  if (optarg)
+    {
+      _value.push_back(optarg);
+      return Ok;
+    }
+  return Failed;
+}
+
+StringArrayOption::operator vector<string> () const
+{
+  return _value;
+}
+
+Option::Argument
+StringArrayOption::argument () const
+{
+    return _optional;
+}
This page took 0.050271 seconds and 5 git commands to generate.