From 36e3bc290d58ad29692a4d594f37a6cb761912c7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 28 Nov 2009 11:41:15 +0200 Subject: Use a scanner interface instead of argc/argv This will allow supporting other sources of options, for example, an option file. --- cli/options.hxx | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) (limited to 'cli/options.hxx') 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 @@ -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); -- cgit v1.1