diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-05 11:55:15 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-05 11:55:15 +0200 |
commit | 9fb791e9fad6c63fc1dac49f4d05ae63b8a3db9b (patch) | |
tree | d60322d4382ca5f97b676c5abe2e39524f35eab4 /build/options.cxx | |
parent | f159b1dac68c8714f7ba71ca168e3b695891aad9 (diff) |
Rename build directory/namespace to build2
Diffstat (limited to 'build/options.cxx')
-rw-r--r-- | build/options.cxx | 552 |
1 files changed, 0 insertions, 552 deletions
diff --git a/build/options.cxx b/build/options.cxx deleted file mode 100644 index b5c2754..0000000 --- a/build/options.cxx +++ /dev/null @@ -1,552 +0,0 @@ -// -*- C++ -*- -// -// This file was generated by CLI, a command line interface -// compiler for C++. -// - -// Begin prologue. -// -// -// End prologue. - -#include <build/options> - -#include <map> -#include <set> -#include <string> -#include <vector> -#include <ostream> -#include <sstream> - -namespace cl -{ - // unknown_option - // - unknown_option:: - ~unknown_option () throw () - { - } - - void unknown_option:: - print (::std::ostream& os) const - { - os << "unknown option '" << option ().c_str () << "'"; - } - - const char* unknown_option:: - what () const throw () - { - return "unknown option"; - } - - // unknown_argument - // - unknown_argument:: - ~unknown_argument () throw () - { - } - - void unknown_argument:: - print (::std::ostream& os) const - { - os << "unknown argument '" << argument ().c_str () << "'"; - } - - const char* unknown_argument:: - what () const throw () - { - return "unknown argument"; - } - - // missing_value - // - missing_value:: - ~missing_value () throw () - { - } - - void missing_value:: - print (::std::ostream& os) const - { - os << "missing value for option '" << option ().c_str () << "'"; - } - - const char* missing_value:: - what () const throw () - { - return "missing option value"; - } - - // invalid_value - // - invalid_value:: - ~invalid_value () throw () - { - } - - void invalid_value:: - print (::std::ostream& os) const - { - os << "invalid value '" << value ().c_str () << "' for option '" - << option ().c_str () << "'"; - } - - const char* invalid_value:: - what () const throw () - { - return "invalid option value"; - } - - // eos_reached - // - void eos_reached:: - print (::std::ostream& os) const - { - os << what (); - } - - const char* eos_reached:: - what () const throw () - { - return "end of argument stream reached"; - } - - // scanner - // - scanner:: - ~scanner () - { - } - - // argv_scanner - // - bool argv_scanner:: - more () - { - return i_ < argc_; - } - - const char* argv_scanner:: - peek () - { - if (i_ < argc_) - return argv_[i_]; - else - throw eos_reached (); - } - - const char* argv_scanner:: - next () - { - if (i_ < argc_) - { - const char* r (argv_[i_]); - - if (erase_) - { - for (int i (i_ + 1); i < argc_; ++i) - argv_[i - 1] = argv_[i]; - - --argc_; - argv_[argc_] = 0; - } - else - ++i_; - - return r; - } - else - throw eos_reached (); - } - - void argv_scanner:: - skip () - { - if (i_ < argc_) - ++i_; - else - throw eos_reached (); - } - - template <typename X> - struct parser - { - static void - parse (X& x, bool& xs, scanner& s) - { - std::string o (s.next ()); - - if (s.more ()) - { - std::string v (s.next ()); - std::istringstream is (v); - if (!(is >> x && is.eof ())) - throw invalid_value (o, v); - } - else - throw missing_value (o); - - xs = true; - } - }; - - template <> - struct parser<bool> - { - static void - parse (bool& x, scanner& s) - { - s.next (); - x = true; - } - }; - - template <> - struct parser<std::string> - { - static void - parse (std::string& x, bool& xs, scanner& s) - { - const char* o (s.next ()); - - if (s.more ()) - x = s.next (); - else - throw missing_value (o); - - xs = true; - } - }; - - template <typename X> - struct parser<std::vector<X> > - { - static void - parse (std::vector<X>& c, bool& xs, scanner& s) - { - X x; - bool dummy; - parser<X>::parse (x, dummy, s); - c.push_back (x); - xs = true; - } - }; - - template <typename X> - struct parser<std::set<X> > - { - static void - parse (std::set<X>& c, bool& xs, scanner& s) - { - X x; - bool dummy; - parser<X>::parse (x, dummy, s); - c.insert (x); - xs = true; - } - }; - - template <typename K, typename V> - struct parser<std::map<K, V> > - { - static void - parse (std::map<K, V>& m, bool& xs, scanner& s) - { - std::string o (s.next ()); - - if (s.more ()) - { - std::string ov (s.next ()); - std::string::size_type p = ov.find ('='); - - if (p == std::string::npos) - { - K k = K (); - - if (!ov.empty ()) - { - std::istringstream ks (ov); - - if (!(ks >> k && ks.eof ())) - throw invalid_value (o, ov); - } - - m[k] = V (); - } - else - { - K k = K (); - V v = V (); - std::string kstr (ov, 0, p); - std::string vstr (ov, p + 1); - - if (!kstr.empty ()) - { - std::istringstream ks (kstr); - - if (!(ks >> k && ks.eof ())) - throw invalid_value (o, ov); - } - - if (!vstr.empty ()) - { - std::istringstream vs (vstr); - - if (!(vs >> v && vs.eof ())) - throw invalid_value (o, ov); - } - - m[k] = v; - } - } - else - throw missing_value (o); - - xs = true; - } - }; - - template <typename X, typename T, T X::*M> - void - thunk (X& x, scanner& s) - { - parser<T>::parse (x.*M, s); - } - - template <typename X, typename T, T X::*M, bool X::*S> - void - thunk (X& x, scanner& s) - { - parser<T>::parse (x.*M, x.*S, s); - } -} - -#include <map> -#include <cstring> - -// options -// - -options:: -options () -: help_ (), - version_ (), - v_ (), - q_ (), - verbose_ (1), - verbose_specified_ (false) -{ -} - -options:: -options (int& argc, - char** argv, - bool erase, - ::cl::unknown_mode opt, - ::cl::unknown_mode arg) -: help_ (), - version_ (), - v_ (), - q_ (), - verbose_ (1), - verbose_specified_ (false) -{ - ::cl::argv_scanner s (argc, argv, erase); - _parse (s, opt, arg); -} - -options:: -options (int start, - int& argc, - char** argv, - bool erase, - ::cl::unknown_mode opt, - ::cl::unknown_mode arg) -: help_ (), - version_ (), - v_ (), - q_ (), - verbose_ (1), - verbose_specified_ (false) -{ - ::cl::argv_scanner s (start, argc, argv, erase); - _parse (s, opt, arg); -} - -options:: -options (int& argc, - char** argv, - int& end, - bool erase, - ::cl::unknown_mode opt, - ::cl::unknown_mode arg) -: help_ (), - version_ (), - v_ (), - q_ (), - verbose_ (1), - verbose_specified_ (false) -{ - ::cl::argv_scanner s (argc, argv, erase); - _parse (s, opt, arg); - end = s.end (); -} - -options:: -options (int start, - int& argc, - char** argv, - int& end, - bool erase, - ::cl::unknown_mode opt, - ::cl::unknown_mode arg) -: help_ (), - version_ (), - v_ (), - q_ (), - verbose_ (1), - verbose_specified_ (false) -{ - ::cl::argv_scanner s (start, argc, argv, erase); - _parse (s, opt, arg); - end = s.end (); -} - -options:: -options (::cl::scanner& s, - ::cl::unknown_mode opt, - ::cl::unknown_mode arg) -: help_ (), - version_ (), - v_ (), - q_ (), - verbose_ (1), - verbose_specified_ (false) -{ - _parse (s, opt, arg); -} - -void options:: -print_usage (::std::ostream& os) -{ - os << "--help Print usage information and exit." << ::std::endl; - - os << "--version Print version and exit." << ::std::endl; - - os << "-v Print actual commands being executed." << ::std::endl; - - os << "-q Run quietly, only printing error messages." << ::std::endl; - - os << "--verbose <level> Set the diagnostics verbosity to <level> between 0 (disabled)" << ::std::endl - << " and 6 (lots of information)." << ::std::endl; -} - -typedef -std::map<std::string, void (*) (options&, ::cl::scanner&)> -_cli_options_map; - -static _cli_options_map _cli_options_map_; - -struct _cli_options_map_init -{ - _cli_options_map_init () - { - _cli_options_map_["--help"] = - &::cl::thunk< options, bool, &options::help_ >; - _cli_options_map_["--version"] = - &::cl::thunk< options, bool, &options::version_ >; - _cli_options_map_["-v"] = - &::cl::thunk< options, bool, &options::v_ >; - _cli_options_map_["-q"] = - &::cl::thunk< options, bool, &options::q_ >; - _cli_options_map_["--verbose"] = - &::cl::thunk< options, std::uint16_t, &options::verbose_, - &options::verbose_specified_ >; - } -}; - -static _cli_options_map_init _cli_options_map_init_; - -bool options:: -_parse (const char* o, ::cl::scanner& s) -{ - _cli_options_map::const_iterator i (_cli_options_map_.find (o)); - - if (i != _cli_options_map_.end ()) - { - (*(i->second)) (*this, s); - return true; - } - - return false; -} - -void options:: -_parse (::cl::scanner& s, - ::cl::unknown_mode opt_mode, - ::cl::unknown_mode arg_mode) -{ - bool opt = true; - - while (s.more ()) - { - const char* o = s.peek (); - - if (std::strcmp (o, "--") == 0) - { - s.skip (); - opt = false; - continue; - } - - if (opt && _parse (o, s)); - else if (opt && std::strncmp (o, "-", 1) == 0 && o[1] != '\0') - { - switch (opt_mode) - { - case ::cl::unknown_mode::skip: - { - s.skip (); - continue; - } - case ::cl::unknown_mode::stop: - { - break; - } - case ::cl::unknown_mode::fail: - { - throw ::cl::unknown_option (o); - } - } - - break; - } - else - { - switch (arg_mode) - { - case ::cl::unknown_mode::skip: - { - s.skip (); - continue; - } - case ::cl::unknown_mode::stop: - { - break; - } - case ::cl::unknown_mode::fail: - { - throw ::cl::unknown_argument (o); - } - } - - break; - } - } -} - -// Begin epilogue. -// -// -// End epilogue. - |