summaryrefslogtreecommitdiff
path: root/cli/options.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-11-28 11:41:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-11-28 11:41:15 +0200
commit36e3bc290d58ad29692a4d594f37a6cb761912c7 (patch)
tree3ebbc1edf910e5168fb819404ecedbf23c95b9d0 /cli/options.hxx
parenta376ccf37122f0768fce8e3c5a16561e01ee2351 (diff)
Use a scanner interface instead of argc/argv
This will allow supporting other sources of options, for example, an option file.
Diffstat (limited to 'cli/options.hxx')
-rw-r--r--cli/options.hxx61
1 files changed, 57 insertions, 4 deletions
diff --git a/cli/options.hxx b/cli/options.hxx
index d5712d1..2be8e91 100644
--- a/cli/options.hxx
+++ b/cli/options.hxx
@@ -133,6 +133,61 @@ namespace cli
std::string option_;
std::string value_;
};
+
+ class eos_reached: public exception
+ {
+ public:
+ virtual void
+ print (std::ostream&) const;
+
+ virtual const char*
+ what () const throw ();
+ };
+
+ class scanner
+ {
+ public:
+ virtual
+ ~scanner ();
+
+ virtual bool
+ more () = 0;
+
+ virtual const char*
+ peek () = 0;
+
+ virtual const char*
+ next () = 0;
+
+ virtual void
+ skip () = 0;
+ };
+
+ class argv_scanner: public scanner
+ {
+ public:
+ argv_scanner (int argc, char** argv);
+ argv_scanner (int start, int argc, char** argv);
+
+ int
+ end () const;
+
+ virtual bool
+ more ();
+
+ virtual const char*
+ peek ();
+
+ virtual const char*
+ next ();
+
+ virtual void
+ skip ();
+
+ private:int i_;
+ int argc_;
+ char** argv_;
+ };
}
#include <map>
@@ -264,10 +319,8 @@ class options
print_usage (::std::ostream&);
private:
- int
- _parse (int start,
- int argc,
- char** argv,
+ void
+ _parse (::cli::scanner&,
::cli::unknown_mode option,
::cli::unknown_mode argument);