From 321a5a24cc132a775908b166baee03c8130730c9 Mon Sep 17 00:00:00 2001 From: Nora Abi Akar <nora.abiakar@gmail.com> Date: Tue, 24 Mar 2020 08:59:52 +0100 Subject: [PATCH] Remove TCLAP (#981) * Replace TCLAP with tinyopt, remove TCLAP from `ext/`. * Replace `sup/tinyopt.hpp` with copy of external tinyopt, update use of `tinyopt` in unit tests and examples to suit. * Use tinyopt's 'smallopt' interface in `modcc`, `brunel` example. * Update tinyopt interface in `single` example. Fix our attributions and add HBP acknowledgement Addresses #557 #695 #803 --- ATTRIBUTIONS.md | 24 +- CMakeLists.txt | 4 +- example/bench/CMakeLists.txt | 2 +- example/brunel/CMakeLists.txt | 2 +- example/brunel/brunel.cpp | 242 ++---- example/ring/CMakeLists.txt | 2 +- example/single/CMakeLists.txt | 2 +- example/single/single.cpp | 12 +- ext/CMakeLists.txt | 6 +- ext/tclap/AUTHORS | 6 - ext/tclap/COPYING | 25 - ext/tclap/README | 16 - ext/tclap/include/tclap/Arg.h | 692 ----------------- ext/tclap/include/tclap/ArgException.h | 200 ----- ext/tclap/include/tclap/ArgTraits.h | 87 --- ext/tclap/include/tclap/CmdLine.h | 651 ---------------- ext/tclap/include/tclap/CmdLineInterface.h | 150 ---- ext/tclap/include/tclap/CmdLineOutput.h | 74 -- ext/tclap/include/tclap/Constraint.h | 68 -- ext/tclap/include/tclap/DocBookOutput.h | 299 -------- ext/tclap/include/tclap/HelpVisitor.h | 76 -- ext/tclap/include/tclap/IgnoreRestVisitor.h | 52 -- ext/tclap/include/tclap/MultiArg.h | 433 ----------- ext/tclap/include/tclap/MultiSwitchArg.h | 216 ------ .../include/tclap/OptionalUnlabeledTracker.h | 62 -- ext/tclap/include/tclap/StandardTraits.h | 208 ------ ext/tclap/include/tclap/StdOutput.h | 299 -------- ext/tclap/include/tclap/SwitchArg.h | 266 ------- ext/tclap/include/tclap/UnlabeledMultiArg.h | 301 -------- ext/tclap/include/tclap/UnlabeledValueArg.h | 340 --------- ext/tclap/include/tclap/ValueArg.h | 425 ----------- ext/tclap/include/tclap/ValuesConstraint.h | 148 ---- ext/tclap/include/tclap/VersionVisitor.h | 81 -- ext/tclap/include/tclap/Visitor.h | 53 -- ext/tclap/include/tclap/XorHandler.h | 166 ---- ext/tclap/include/tclap/ZshCompletionOutput.h | 323 -------- ext/tinyopt/LICENSE | 29 + ext/tinyopt/include/tinyopt/common.h | 192 +++++ ext/tinyopt/include/tinyopt/maybe.h | 170 +++++ ext/tinyopt/include/tinyopt/smolopt.h | 706 ++++++++++++++++++ ext/tinyopt/include/tinyopt/tinyopt.h | 77 ++ modcc/CMakeLists.txt | 2 +- modcc/modcc.cpp | 142 ++-- modcc/printer/cprinter.cpp | 1 + modcc/printer/simd.hpp | 5 +- sup/include/sup/tinyopt.hpp | 131 ---- test/unit-distributed/CMakeLists.txt | 4 +- test/unit-distributed/test.cpp | 12 +- 48 files changed, 1337 insertions(+), 6147 deletions(-) delete mode 100644 ext/tclap/AUTHORS delete mode 100644 ext/tclap/COPYING delete mode 100644 ext/tclap/README delete mode 100644 ext/tclap/include/tclap/Arg.h delete mode 100644 ext/tclap/include/tclap/ArgException.h delete mode 100644 ext/tclap/include/tclap/ArgTraits.h delete mode 100644 ext/tclap/include/tclap/CmdLine.h delete mode 100644 ext/tclap/include/tclap/CmdLineInterface.h delete mode 100644 ext/tclap/include/tclap/CmdLineOutput.h delete mode 100644 ext/tclap/include/tclap/Constraint.h delete mode 100644 ext/tclap/include/tclap/DocBookOutput.h delete mode 100644 ext/tclap/include/tclap/HelpVisitor.h delete mode 100644 ext/tclap/include/tclap/IgnoreRestVisitor.h delete mode 100644 ext/tclap/include/tclap/MultiArg.h delete mode 100644 ext/tclap/include/tclap/MultiSwitchArg.h delete mode 100644 ext/tclap/include/tclap/OptionalUnlabeledTracker.h delete mode 100644 ext/tclap/include/tclap/StandardTraits.h delete mode 100644 ext/tclap/include/tclap/StdOutput.h delete mode 100644 ext/tclap/include/tclap/SwitchArg.h delete mode 100644 ext/tclap/include/tclap/UnlabeledMultiArg.h delete mode 100644 ext/tclap/include/tclap/UnlabeledValueArg.h delete mode 100644 ext/tclap/include/tclap/ValueArg.h delete mode 100644 ext/tclap/include/tclap/ValuesConstraint.h delete mode 100644 ext/tclap/include/tclap/VersionVisitor.h delete mode 100644 ext/tclap/include/tclap/Visitor.h delete mode 100644 ext/tclap/include/tclap/XorHandler.h delete mode 100644 ext/tclap/include/tclap/ZshCompletionOutput.h create mode 100644 ext/tinyopt/LICENSE create mode 100644 ext/tinyopt/include/tinyopt/common.h create mode 100644 ext/tinyopt/include/tinyopt/maybe.h create mode 100644 ext/tinyopt/include/tinyopt/smolopt.h create mode 100644 ext/tinyopt/include/tinyopt/tinyopt.h delete mode 100644 sup/include/sup/tinyopt.hpp diff --git a/ATTRIBUTIONS.md b/ATTRIBUTIONS.md index af7d00af..60ad7d06 100644 --- a/ATTRIBUTIONS.md +++ b/ATTRIBUTIONS.md @@ -7,20 +7,18 @@ MIT license. https://github.com/nlohmann/json -## Templatized C++ Command Line Parser Library (TCLAP) +## tinyopt -A header only C++ library for command line argument parsing, written by Michael E. Smoot. -MIT license. - -https://sourceforge.net/projects/tclap +A header only C++ library for command line argument parsing, written by Stuart Yates. +BSD license. -## TBB module for CMake +https://github.com/halfflat/tinyopt -The CMake scripts provided in the Intel Threading Building Blocks respository are -to configure TBB. These are located in the cmake/tbb path. -Apache 2.0 license. +## Random123 +A header only counter-based random number generator, written by DE Shaw research +BSD license. -https://github.com/01org/tbb/blob/tbb_2017/LICENSE +https://www.deshawresearch.com/downloads/download_random123.cgi/ ## Sphinx module for CMake @@ -47,3 +45,9 @@ Custom license (as it appears in the original `readme` from the project's page): >commercial product. In either event, it is copyrighted by the author. >What you see here may be used freely but it comes with no support or >guarantee. + +## Acknowledgements +This open source software code was developed in part or in whole in the Human +Brain Project, funded from the European Union’s Horizon 2020 Framework +Programme for Research and Innovation under the Specific Grant Agreement +No. 720270 (Human Brain Project SGA1) and No. 785907 (Human Brain Project SGA2). \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ce372dd..4576c062 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,8 +153,8 @@ install(TARGETS arborenv-private-deps EXPORT arbor-targets) add_library(arbor-public-deps INTERFACE) install(TARGETS arbor-public-deps EXPORT arbor-targets) -# External libraries in `ext` sub-directory: json and tclap. -# Creates interface libraries `ext-json` and `ext-tclap`. +# External libraries in `ext` sub-directory: json, tinyopt and randon123. +# Creates interface libraries `ext-json`, `ext-tinyopt` and `ext-random123` add_subdirectory(ext) diff --git a/example/bench/CMakeLists.txt b/example/bench/CMakeLists.txt index 3db3345f..49fb7016 100644 --- a/example/bench/CMakeLists.txt +++ b/example/bench/CMakeLists.txt @@ -1,4 +1,4 @@ add_executable(bench EXCLUDE_FROM_ALL bench.cpp) add_dependencies(examples bench) -target_link_libraries(bench PRIVATE arbor arborenv arbor-sup ext-tclap ext-json) +target_link_libraries(bench PRIVATE arbor arborenv arbor-sup ext-json) diff --git a/example/brunel/CMakeLists.txt b/example/brunel/CMakeLists.txt index 79b68394..7a20c7a1 100644 --- a/example/brunel/CMakeLists.txt +++ b/example/brunel/CMakeLists.txt @@ -1,4 +1,4 @@ add_executable(brunel EXCLUDE_FROM_ALL brunel.cpp) add_dependencies(examples brunel) -target_link_libraries(brunel PRIVATE arbor arborenv arbor-sup ext-tclap) +target_link_libraries(brunel PRIVATE arbor arborenv arbor-sup ext-tinyopt) diff --git a/example/brunel/brunel.cpp b/example/brunel/brunel.cpp index 22a49674..1c37b7b8 100644 --- a/example/brunel/brunel.cpp +++ b/example/brunel/brunel.cpp @@ -7,7 +7,7 @@ #include <set> #include <vector> -#include <tclap/CmdLine.h> +#include <tinyopt/smolopt.h> #include <arbor/context.hpp> #include <arbor/common_types.hpp> @@ -68,7 +68,7 @@ struct cl_options { std::ostream& operator<<(std::ostream& o, const cl_options& opt); -cl_options read_options(int argc, char** argv); +util::optional<cl_options> read_options(int argc, char** argv); void banner(const context& ctx); @@ -237,7 +237,9 @@ int main(int argc, char** argv) { meters.start(context); // read parameters - cl_options options = read_options(argc, argv); + auto o = read_options(argc, argv); + if (!o) {return 0; } + cl_options options = o.value(); std::fstream spike_out; if (options.spike_file_output && root) { @@ -351,193 +353,83 @@ std::vector<cell_gid_type> sample_subset(cell_gid_type gid, cell_gid_type start, return {s.begin(), s.end()}; } -// Let TCLAP understand value arguments that are of an optional type. -namespace TCLAP { - template <typename V> - struct ArgTraits<arb::util::optional<V>> { - using ValueCategory = ValueLike; +// Read options from (optional) json file and command line arguments. +util::optional<cl_options> read_options(int argc, char** argv) { + using namespace to; + auto usage_str = "\n" + "-n|--n-excitatory [Number of cells in the excitatory population]\n" + "-m|--n-inhibitory [Number of cells in the inhibitory population]\n" + "-e|--n-external [Number of incoming Poisson (external) connections per cell]\n" + "-p|--in-degree-prop [Proportion of the connections received per cell]\n" + "-w|--weight [Weight of excitatory connections]\n" + "-d|--delay [Delay of all connections]\n" + "-g|--rel-inh-w [Relative strength of inhibitory synapses with respect to the excitatory ones]\n" + "-l|--lambda [Expected number of spikes from a single poisson cell per ms]\n" + "-t|--tfinal [Length of the simulation period (ms)]\n" + "-s|--dt [Simulation time step (ms)]\n" + "-G|--group-size [Number of cells per cell group]\n" + "-S|--seed [Seed for poisson spike generators]\n" + "-f|--write-spikes [Save spikes to file]\n" + "-z|--profile-rank-zero [Only output profile information for rank 0]\n" + "-v|--verbose [Print more verbose information to stdout]\n"; + + cl_options opt; + auto help = [argv0 = argv[0], &usage_str] { + to::usage(argv0, usage_str); }; -} // namespace TCLAP - -namespace arb { - namespace util { - // Using static here because we do not want external linkage for this operator. - template <typename V> - static std::istream& operator>>(std::istream& I, optional<V>& v) { - V u; - if (I >> u) { - v = u; - } - return I; - } - } -} - -// Override annoying parameters listed back-to-front behaviour. -// -// TCLAP argument creation _prepends_ its arguments to the internal -// list (_argList), where standard options --help etc. are already -// pre-inserted. -// -// reorder_arguments() reverses the arguments to restore ordering, -// and moves the standard options to the end. -class CustomCmdLine: public TCLAP::CmdLine { -public: - CustomCmdLine(const std::string &message, const std::string &version = "none"): - TCLAP::CmdLine(message, ' ', version, true) - {} - - void reorder_arguments() { - _argList.reverse(); - for (auto opt: {"help", "version", "ignore_rest"}) { - auto i = std::find_if( - _argList.begin(), _argList.end(), - [&opt](TCLAP::Arg* a) { return a->getName()==opt; }); - - if (i!=_argList.end()) { - auto a = *i; - _argList.erase(i); - _argList.push_back(a); - } - } - } -}; -// Update an option value from command line argument if set. -template < - typename T, - typename Arg, - typename = std::enable_if_t<std::is_base_of<TCLAP::Arg, Arg>::value> -> -static void update_option(T& opt, Arg& arg) { - if (arg.isSet()) { - opt = arg.getValue(); - } -} - -// Read options from (optional) json file and command line arguments. -cl_options read_options(int argc, char** argv) { - cl_options options; + to::option options[] = { + { opt.nexc, "-n", "--n-excitatory" }, + { opt.ninh, "-m", "--n-inhibitory" }, + { opt.next, "-e", "--n-external" }, + { opt.syn_per_cell_prop, "-p", "--in-degree-prop" }, + { opt.weight, "-w", "--weight" }, + { opt.delay, "-d", "--delay" }, + { opt.rel_inh_strength, "-g", "--rel-inh-w" }, + { opt.poiss_lambda, "-l", "--lambda" }, + { opt.tfinal, "-t", "--tfinal" }, + { opt.dt, "-s", "--dt" }, + { opt.group_size, "-G", "--group-size" }, + { opt.seed, "-s", "--seed" }, + { to::set(opt.spike_file_output), to::flag, "-f", "--write-spikes" }, + { to::set(opt.profile_only_zero), to::flag, "-z", "--profile-rank-zero" }, + { to::set(opt.verbose), to::flag, "-v", "--verbose" }, + { to::action(help), to::flag, to::exit, "-h", "--help" } + }; - // Parse command line arguments. - try { - cl_options defopts; - - CustomCmdLine cmd("nest brunel miniapp harness", "0.1"); - - TCLAP::ValueArg<uint32_t> nexc_arg - ("n", "n-excitatory", "total number of cells in the excitatory population", - false, defopts.nexc, "integer", cmd); - - TCLAP::ValueArg<uint32_t> ninh_arg - ("m", "n-inhibitory", "total number of cells in the inhibitory population", - false, defopts.ninh, "integer", cmd); - - TCLAP::ValueArg<uint32_t> next_arg - ("e", "n-external", "total number of incoming Poisson (external) connections per cell.", - false, defopts.ninh, "integer", cmd); - - TCLAP::ValueArg<double> syn_prop_arg - ("p", "in-degree-prop", "the proportion of connections both the excitatory and inhibitory populations that each neuron receives", - false, defopts.syn_per_cell_prop, "double", cmd); - - TCLAP::ValueArg<float> weight_arg - ("w", "weight", "the weight of all excitatory connections", - false, defopts.weight, "float", cmd); - - TCLAP::ValueArg<float> delay_arg - ("d", "delay", "the delay of all connections", - false, defopts.delay, "float", cmd); - - TCLAP::ValueArg<float> rel_inh_strength_arg - ("g", "rel-inh-w", "relative strength of inhibitory synapses with respect to the excitatory ones", - false, defopts.rel_inh_strength, "float", cmd); - - TCLAP::ValueArg<double> poiss_lambda_arg - ("l", "lambda", "Expected number of spikes from a single poisson cell per ms", - false, defopts.poiss_lambda, "double", cmd); - - TCLAP::ValueArg<double> tfinal_arg - ("t", "tfinal", "length of the simulation period [ms]", - false, defopts.tfinal, "time", cmd); - - TCLAP::ValueArg<double> dt_arg - ("s", "delta-t", "simulation time step [ms] (this parameter is ignored)", - false, defopts.dt, "time", cmd); - - TCLAP::ValueArg<uint32_t> group_size_arg - ("G", "group-size", "number of cells per cell group", - false, defopts.group_size, "integer", cmd); - - TCLAP::ValueArg<uint32_t> seed_arg - ("S", "seed", "seed for poisson spike generators", - false, defopts.seed, "integer", cmd); - - TCLAP::SwitchArg spike_output_arg - ("f","spike-file-output","save spikes to file", cmd, false); - - TCLAP::SwitchArg profile_only_zero_arg - ("z", "profile-only-zero", "Only output profile information for rank 0", - cmd, false); - - TCLAP::SwitchArg verbose_arg - ("v", "verbose", "Present more verbose information to stdout", cmd, false); - - cmd.reorder_arguments(); - cmd.parse(argc, argv); - - // Handle verbosity separately from other options: it is not considered part - // of the saved option state. - options.verbose = verbose_arg.getValue(); - update_option(options.nexc, nexc_arg); - update_option(options.ninh, ninh_arg); - update_option(options.next, next_arg); - update_option(options.syn_per_cell_prop, syn_prop_arg); - update_option(options.weight, weight_arg); - update_option(options.delay, delay_arg); - update_option(options.rel_inh_strength, rel_inh_strength_arg); - update_option(options.poiss_lambda, poiss_lambda_arg); - update_option(options.tfinal, tfinal_arg); - update_option(options.dt, dt_arg); - update_option(options.group_size, group_size_arg); - update_option(options.seed, seed_arg); - update_option(options.spike_file_output, spike_output_arg); - update_option(options.profile_only_zero, profile_only_zero_arg); - - if (options.group_size < 1) { - throw std::runtime_error("minimum of one cell per group"); - } + if (!to::run(options, argc, argv+1)) return {}; + if (argv[1]) throw to::option_error("unrecogonized argument", argv[1]); - if (options.rel_inh_strength <= 0 || options.rel_inh_strength > 1) { - throw std::runtime_error("relative strength of inhibitory connections must be in the interval (0, 1]."); - } + if (opt.group_size < 1) { + throw std::runtime_error("minimum of one cell per group"); } - catch (TCLAP::ArgException& e) { - throw std::runtime_error("error parsing command line argument "+e.argId()+": "+e.error()); + + if (opt.rel_inh_strength <= 0 || opt.rel_inh_strength > 1) { + throw std::runtime_error("relative strength of inhibitory connections must be in the interval (0, 1]."); } // If verbose output requested, emit option summary. - if (options.verbose) { - std::cout << options << "\n"; + if (opt.verbose) { + std::cout << opt << "\n"; } - return options; + return opt; } std::ostream& operator<<(std::ostream& o, const cl_options& options) { - o << "simulation options:\n"; - o << " excitatory cells : " << options.nexc << "\n"; - o << " inhibitory cells : " << options.ninh << "\n"; + o << "Simulation options:\n"; + o << " Excitatory cells : " << options.nexc << "\n"; + o << " Inhibitory cells : " << options.ninh << "\n"; o << " Poisson connections per cell : " << options.next << "\n"; - o << " proportion of synapses/cell from each population : " << options.syn_per_cell_prop << "\n"; - o << " weight of excitatory synapses : " << options.weight << "\n"; - o << " relative strength of inhibitory synapses : " << options.rel_inh_strength << "\n"; - o << " delay of all synapses : " << options.delay << "\n"; - o << " expected number of spikes from a single poisson cell per ms: " << options.poiss_lambda << "\n"; + o << " Proportion of synapses/cell from each population : " << options.syn_per_cell_prop << "\n"; + o << " Weight of excitatory synapses : " << options.weight << "\n"; + o << " Relative strength of inhibitory synapses : " << options.rel_inh_strength << "\n"; + o << " Delay of all synapses : " << options.delay << "\n"; + o << " Expected number of spikes from a single poisson cell per ms: " << options.poiss_lambda << "\n"; o << "\n"; - o << " simulation time : " << options.tfinal << "\n"; + o << " Simulation time : " << options.tfinal << "\n"; o << " dt : " << options.dt << "\n"; - o << " group size : " << options.group_size << "\n"; - o << " seed : " << options.seed << "\n"; + o << " Group size : " << options.group_size << "\n"; + o << " Seed : " << options.seed << "\n"; return o; } diff --git a/example/ring/CMakeLists.txt b/example/ring/CMakeLists.txt index f35cba80..76bb5afb 100644 --- a/example/ring/CMakeLists.txt +++ b/example/ring/CMakeLists.txt @@ -1,4 +1,4 @@ add_executable(ring EXCLUDE_FROM_ALL ring.cpp) add_dependencies(examples ring) -target_link_libraries(ring PRIVATE arbor arborenv arbor-sup ext-tclap ext-json) +target_link_libraries(ring PRIVATE arbor arborenv arbor-sup ext-json) diff --git a/example/single/CMakeLists.txt b/example/single/CMakeLists.txt index 6b2afe48..ad5257c6 100644 --- a/example/single/CMakeLists.txt +++ b/example/single/CMakeLists.txt @@ -1,3 +1,3 @@ add_executable(single-cell EXCLUDE_FROM_ALL single.cpp) add_dependencies(examples single-cell) -target_link_libraries(single-cell PRIVATE arbor arborenv arbor-sup) +target_link_libraries(single-cell PRIVATE arbor arborenv arbor-sup ext-tinyopt) diff --git a/example/single/single.cpp b/example/single/single.cpp index d42f03b8..3946d9c7 100644 --- a/example/single/single.cpp +++ b/example/single/single.cpp @@ -13,7 +13,7 @@ #include <arbor/simulation.hpp> #include <arbor/simple_sampler.hpp> -#include <sup/tinyopt.hpp> +#include <tinyopt/tinyopt.h> struct options { std::string swc_file; @@ -117,19 +117,19 @@ options parse_options(int argc, char** argv) { char** arg = argv+1; while (*arg) { - if (auto dt = parse_opt<double>(arg, 'd', "dt")) { + if (auto dt = parse<double>(arg, 'd', "dt")) { opt.dt = dt.value(); } - else if (auto t_end = parse_opt<double>(arg, 't', "t-end")) { + else if (auto t_end = parse<double>(arg, 't', "t-end")) { opt.t_end = t_end.value(); } - else if (auto weight = parse_opt<float>(arg, 'w', "weight")) { + else if (auto weight = parse<float>(arg, 'w', "weight")) { opt.syn_weight = weight.value(); } - else if (auto swc = parse_opt<std::string>(arg, 'm', "morphology")) { + else if (auto swc = parse<std::string>(arg, 'm', "morphology")) { opt.swc_file = swc.value(); } - else if (auto nseg = parse_opt<unsigned>(arg, 'n', "cv-per-branch")) { + else if (auto nseg = parse<unsigned>(arg, 'n', "cv-per-branch")) { opt.policy = arb::cv_policy_fixed_per_branch(nseg.value(), arb::cv_policy_flag::single_root_cv); } else { diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 634a2889..b06c0cd2 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -3,10 +3,10 @@ add_library(ext-json INTERFACE) target_include_directories(ext-json INTERFACE json/single_include) -# TCLAP command line parsing libary (header-only). +# tinyopt command line parsing libary (header-only). -add_library(ext-tclap INTERFACE) -target_include_directories(ext-tclap INTERFACE tclap/include) +add_library(ext-tinyopt INTERFACE) +target_include_directories(ext-tinyopt INTERFACE tinyopt/include) # Random123 (DE Shaw Research) counter-based random number generators (header-only) diff --git a/ext/tclap/AUTHORS b/ext/tclap/AUTHORS deleted file mode 100644 index 875a852a..00000000 --- a/ext/tclap/AUTHORS +++ /dev/null @@ -1,6 +0,0 @@ - -original author: Michael E. Smoot -invaluable contributions: Daniel Aarno -more contributions: Erik Zeek -more contributions: Fabien Carmagnac (Tinbergen-AM) -outstanding editing: Carol Smoot diff --git a/ext/tclap/COPYING b/ext/tclap/COPYING deleted file mode 100644 index 987be0ce..00000000 --- a/ext/tclap/COPYING +++ /dev/null @@ -1,25 +0,0 @@ - - -Copyright (c) 2003 Michael E. Smoot - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of the Software, -and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - diff --git a/ext/tclap/README b/ext/tclap/README deleted file mode 100644 index 225e33f4..00000000 --- a/ext/tclap/README +++ /dev/null @@ -1,16 +0,0 @@ - -TCLAP - Templatized Command Line Argument Parser - -This is a simple C++ library that facilitates parsing command line -arguments in a type independent manner. It doesn't conform exactly -to either the GNU or POSIX standards, although it is close. See -docs/manual.html for descriptions of how things work or look at the -simple examples in the examples dir. - -To find out what the latest changes are read the NEWS file in this directory. - - -Any and all feedback is welcome to: Mike Smoot <mes@aescon.com> - - - diff --git a/ext/tclap/include/tclap/Arg.h b/ext/tclap/include/tclap/Arg.h deleted file mode 100644 index b28eef11..00000000 --- a/ext/tclap/include/tclap/Arg.h +++ /dev/null @@ -1,692 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: Arg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_ARGUMENT_H -#define TCLAP_ARGUMENT_H - -#ifdef HAVE_CONFIG_H -#include <config.h> -#else -#define HAVE_SSTREAM -#endif - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <iomanip> -#include <cstdio> - -#if defined(HAVE_SSTREAM) -#include <sstream> -typedef std::istringstream istringstream; -#elif defined(HAVE_STRSTREAM) -#include <strstream> -typedef std::istrstream istringstream; -#else -#error "Need a stringstream (sstream or strstream) to compile!" -#endif - -#include <tclap/ArgException.h> -#include <tclap/Visitor.h> -#include <tclap/CmdLineInterface.h> -#include <tclap/ArgTraits.h> -#include <tclap/StandardTraits.h> - -namespace TCLAP { - -/** - * A virtual base class that defines the essential data for all arguments. - * This class, or one of its existing children, must be subclassed to do - * anything. - */ -class Arg -{ - private: - /** - * Prevent accidental copying. - */ - Arg(const Arg& rhs); - - /** - * Prevent accidental copying. - */ - Arg& operator=(const Arg& rhs); - - /** - * Indicates whether the rest of the arguments should be ignored. - */ - static bool& ignoreRestRef() { static bool ign = false; return ign; } - - /** - * The delimiter that separates an argument flag/name from the - * value. - */ - static char& delimiterRef() { static char delim = ' '; return delim; } - - protected: - - /** - * The single char flag used to identify the argument. - * This value (preceded by a dash {-}), can be used to identify - * an argument on the command line. The _flag can be blank, - * in fact this is how unlabeled args work. Unlabeled args must - * override appropriate functions to get correct handling. Note - * that the _flag does NOT include the dash as part of the flag. - */ - std::string _flag; - - /** - * A single work namd indentifying the argument. - * This value (preceded by two dashed {--}) can also be used - * to identify an argument on the command line. Note that the - * _name does NOT include the two dashes as part of the _name. The - * _name cannot be blank. - */ - std::string _name; - - /** - * Description of the argument. - */ - std::string _description; - - /** - * Indicating whether the argument is required. - */ - bool _required; - - /** - * Label to be used in usage description. Normally set to - * "required", but can be changed when necessary. - */ - std::string _requireLabel; - - /** - * Indicates whether a value is required for the argument. - * Note that the value may be required but the argument/value - * combination may not be, as specified by _required. - */ - bool _valueRequired; - - /** - * Indicates whether the argument has been set. - * Indicates that a value on the command line has matched the - * name/flag of this argument and the values have been set accordingly. - */ - bool _alreadySet; - - /** - * A pointer to a vistitor object. - * The visitor allows special handling to occur as soon as the - * argument is matched. This defaults to NULL and should not - * be used unless absolutely necessary. - */ - Visitor* _visitor; - - /** - * Whether this argument can be ignored, if desired. - */ - bool _ignoreable; - - /** - * Indicates that the arg was set as part of an XOR and not on the - * command line. - */ - bool _xorSet; - - bool _acceptsMultipleValues; - - /** - * Performs the special handling described by the Vistitor. - */ - void _checkWithVisitor() const; - - /** - * Primary constructor. YOU (yes you) should NEVER construct an Arg - * directly, this is a base class that is extended by various children - * that are meant to be used. Use SwitchArg, ValueArg, MultiArg, - * UnlabeledValueArg, or UnlabeledMultiArg instead. - * - * \param flag - The flag identifying the argument. - * \param name - The name identifying the argument. - * \param desc - The description of the argument, used in the usage. - * \param req - Whether the argument is required. - * \param valreq - Whether the a value is required for the argument. - * \param v - The visitor checked by the argument. Defaults to NULL. - */ - Arg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - bool valreq, - Visitor* v = NULL ); - - public: - /** - * Destructor. - */ - virtual ~Arg(); - - /** - * Adds this to the specified list of Args. - * \param argList - The list to add this to. - */ - virtual void addToList( std::list<Arg*>& argList ) const; - - /** - * Begin ignoring arguments since the "--" argument was specified. - */ - static void beginIgnoring() { ignoreRestRef() = true; } - - /** - * Whether to ignore the rest. - */ - static bool ignoreRest() { return ignoreRestRef(); } - - /** - * The delimiter that separates an argument flag/name from the - * value. - */ - static char delimiter() { return delimiterRef(); } - - /** - * The char used as a place holder when SwitchArgs are combined. - * Currently set to the bell char (ASCII 7). - */ - static char blankChar() { return (char)7; } - - /** - * The char that indicates the beginning of a flag. Defaults to '-', but - * clients can define TCLAP_FLAGSTARTCHAR to override. - */ -#ifndef TCLAP_FLAGSTARTCHAR -#define TCLAP_FLAGSTARTCHAR '-' -#endif - static char flagStartChar() { return TCLAP_FLAGSTARTCHAR; } - - /** - * The sting that indicates the beginning of a flag. Defaults to "-", but - * clients can define TCLAP_FLAGSTARTSTRING to override. Should be the same - * as TCLAP_FLAGSTARTCHAR. - */ -#ifndef TCLAP_FLAGSTARTSTRING -#define TCLAP_FLAGSTARTSTRING "-" -#endif - static const std::string flagStartString() { return TCLAP_FLAGSTARTSTRING; } - - /** - * The sting that indicates the beginning of a name. Defaults to "--", but - * clients can define TCLAP_NAMESTARTSTRING to override. - */ -#ifndef TCLAP_NAMESTARTSTRING -#define TCLAP_NAMESTARTSTRING "--" -#endif - static const std::string nameStartString() { return TCLAP_NAMESTARTSTRING; } - - /** - * The name used to identify the ignore rest argument. - */ - static const std::string ignoreNameString() { return "ignore_rest"; } - - /** - * Sets the delimiter for all arguments. - * \param c - The character that delimits flags/names from values. - */ - static void setDelimiter( char c ) { delimiterRef() = c; } - - /** - * Pure virtual method meant to handle the parsing and value assignment - * of the string on the command line. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. What is - * passed in from main. - */ - virtual bool processArg(int *i, std::vector<std::string>& args) = 0; - - /** - * Operator ==. - * Equality operator. Must be virtual to handle unlabeled args. - * \param a - The Arg to be compared to this. - */ - virtual bool operator==(const Arg& a) const; - - /** - * Returns the argument flag. - */ - const std::string& getFlag() const; - - /** - * Returns the argument name. - */ - const std::string& getName() const; - - /** - * Returns the argument description. - */ - std::string getDescription() const; - - /** - * Indicates whether the argument is required. - */ - virtual bool isRequired() const; - - /** - * Sets _required to true. This is used by the XorHandler. - * You really have no reason to ever use it. - */ - void forceRequired(); - - /** - * Sets the _alreadySet value to true. This is used by the XorHandler. - * You really have no reason to ever use it. - */ - void xorSet(); - - /** - * Indicates whether a value must be specified for argument. - */ - bool isValueRequired() const; - - /** - * Indicates whether the argument has already been set. Only true - * if the arg has been matched on the command line. - */ - bool isSet() const; - - /** - * Indicates whether the argument can be ignored, if desired. - */ - bool isIgnoreable() const; - - /** - * A method that tests whether a string matches this argument. - * This is generally called by the processArg() method. This - * method could be re-implemented by a child to change how - * arguments are specified on the command line. - * \param s - The string to be compared to the flag/name to determine - * whether the arg matches. - */ - virtual bool argMatches( const std::string& s ) const; - - /** - * Returns a simple string representation of the argument. - * Primarily for debugging. - */ - virtual std::string toString() const; - - /** - * Returns a short ID for the usage. - * \param valueId - The value used in the id. - */ - virtual std::string shortID( const std::string& valueId = "val" ) const; - - /** - * Returns a long ID for the usage. - * \param valueId - The value used in the id. - */ - virtual std::string longID( const std::string& valueId = "val" ) const; - - /** - * Trims a value off of the flag. - * \param flag - The string from which the flag and value will be - * trimmed. Contains the flag once the value has been trimmed. - * \param value - Where the value trimmed from the string will - * be stored. - */ - virtual void trimFlag( std::string& flag, std::string& value ) const; - - /** - * Checks whether a given string has blank chars, indicating that - * it is a combined SwitchArg. If so, return true, otherwise return - * false. - * \param s - string to be checked. - */ - bool _hasBlanks( const std::string& s ) const; - - /** - * Sets the requireLabel. Used by XorHandler. You shouldn't ever - * use this. - * \param s - Set the requireLabel to this value. - */ - void setRequireLabel( const std::string& s ); - - /** - * Used for MultiArgs and XorHandler to determine whether args - * can still be set. - */ - virtual bool allowMore(); - - /** - * Use by output classes to determine whether an Arg accepts - * multiple values. - */ - virtual bool acceptsMultipleValues(); - - /** - * Clears the Arg object and allows it to be reused by new - * command lines. - */ - virtual void reset(); -}; - -/** - * Typedef of an Arg list iterator. - */ -typedef std::list<Arg*>::iterator ArgListIterator; - -/** - * Typedef of an Arg vector iterator. - */ -typedef std::vector<Arg*>::iterator ArgVectorIterator; - -/** - * Typedef of a Visitor list iterator. - */ -typedef std::list<Visitor*>::iterator VisitorListIterator; - -/* - * Extract a value of type T from it's string representation contained - * in strVal. The ValueLike parameter used to select the correct - * specialization of ExtractValue depending on the value traits of T. - * ValueLike traits use operator>> to assign the value from strVal. - */ -template<typename T> void -ExtractValue(T &destVal, const std::string& strVal, ValueLike vl) -{ - static_cast<void>(vl); // Avoid warning about unused vl - std::istringstream is(strVal); - - int valuesRead = 0; - while ( is.good() ) { - if ( is.peek() != EOF ) -#ifdef TCLAP_SETBASE_ZERO - is >> std::setbase(0) >> destVal; -#else - is >> destVal; -#endif - else - break; - - valuesRead++; - } - - if ( is.fail() ) - throw( ArgParseException("Couldn't read argument value " - "from string '" + strVal + "'")); - - - if ( valuesRead > 1 ) - throw( ArgParseException("More than one valid value parsed from " - "string '" + strVal + "'")); - -} - -/* - * Extract a value of type T from it's string representation contained - * in strVal. The ValueLike parameter used to select the correct - * specialization of ExtractValue depending on the value traits of T. - * StringLike uses assignment (operator=) to assign from strVal. - */ -template<typename T> void -ExtractValue(T &destVal, const std::string& strVal, StringLike sl) -{ - static_cast<void>(sl); // Avoid warning about unused sl - SetString(destVal, strVal); -} - -////////////////////////////////////////////////////////////////////// -//BEGIN Arg.cpp -////////////////////////////////////////////////////////////////////// - -inline Arg::Arg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - bool valreq, - Visitor* v) : - _flag(flag), - _name(name), - _description(desc), - _required(req), - _requireLabel("required"), - _valueRequired(valreq), - _alreadySet(false), - _visitor( v ), - _ignoreable(true), - _xorSet(false), - _acceptsMultipleValues(false) -{ - if ( _flag.length() > 1 ) - throw(SpecificationException( - "Argument flag can only be one character long", toString() ) ); - - if ( _name != ignoreNameString() && - ( _flag == Arg::flagStartString() || - _flag == Arg::nameStartString() || - _flag == " " ) ) - throw(SpecificationException("Argument flag cannot be either '" + - Arg::flagStartString() + "' or '" + - Arg::nameStartString() + "' or a space.", - toString() ) ); - - if ( ( _name.substr( 0, Arg::flagStartString().length() ) == Arg::flagStartString() ) || - ( _name.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) || - ( _name.find( " ", 0 ) != std::string::npos ) ) - throw(SpecificationException("Argument name begin with either '" + - Arg::flagStartString() + "' or '" + - Arg::nameStartString() + "' or space.", - toString() ) ); - -} - -inline Arg::~Arg() { } - -inline std::string Arg::shortID( const std::string& valueId ) const -{ - std::string id = ""; - - if ( _flag != "" ) - id = Arg::flagStartString() + _flag; - else - id = Arg::nameStartString() + _name; - - if ( _valueRequired ) - id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; - - if ( !_required ) - id = "[" + id + "]"; - - return id; -} - -inline std::string Arg::longID( const std::string& valueId ) const -{ - std::string id = ""; - - if ( _flag != "" ) - { - id += Arg::flagStartString() + _flag; - - if ( _valueRequired ) - id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; - - id += ", "; - } - - id += Arg::nameStartString() + _name; - - if ( _valueRequired ) - id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; - - return id; - -} - -inline bool Arg::operator==(const Arg& a) const -{ - if ( ( _flag != "" && _flag == a._flag ) || _name == a._name) - return true; - else - return false; -} - -inline std::string Arg::getDescription() const -{ - std::string desc = ""; - if ( _required ) - desc = "(" + _requireLabel + ") "; - -// if ( _valueRequired ) -// desc += "(value required) "; - - desc += _description; - return desc; -} - -inline const std::string& Arg::getFlag() const { return _flag; } - -inline const std::string& Arg::getName() const { return _name; } - -inline bool Arg::isRequired() const { return _required; } - -inline bool Arg::isValueRequired() const { return _valueRequired; } - -inline bool Arg::isSet() const -{ - if ( _alreadySet && !_xorSet ) - return true; - else - return false; -} - -inline bool Arg::isIgnoreable() const { return _ignoreable; } - -inline void Arg::setRequireLabel( const std::string& s) -{ - _requireLabel = s; -} - -inline bool Arg::argMatches( const std::string& argFlag ) const -{ - if ( ( argFlag == Arg::flagStartString() + _flag && _flag != "" ) || - argFlag == Arg::nameStartString() + _name ) - return true; - else - return false; -} - -inline std::string Arg::toString() const -{ - std::string s = ""; - - if ( _flag != "" ) - s += Arg::flagStartString() + _flag + " "; - - s += "(" + Arg::nameStartString() + _name + ")"; - - return s; -} - -inline void Arg::_checkWithVisitor() const -{ - if ( _visitor != NULL ) - _visitor->visit(); -} - -/** - * Implementation of trimFlag. - */ -inline void Arg::trimFlag(std::string& flag, std::string& value) const -{ - int stop = 0; - for ( int i = 0; static_cast<unsigned int>(i) < flag.length(); i++ ) - if ( flag[i] == Arg::delimiter() ) - { - stop = i; - break; - } - - if ( stop > 1 ) - { - value = flag.substr(stop+1); - flag = flag.substr(0,stop); - } - -} - -/** - * Implementation of _hasBlanks. - */ -inline bool Arg::_hasBlanks( const std::string& s ) const -{ - for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ ) - if ( s[i] == Arg::blankChar() ) - return true; - - return false; -} - -inline void Arg::forceRequired() -{ - _required = true; -} - -inline void Arg::xorSet() -{ - _alreadySet = true; - _xorSet = true; -} - -/** - * Overridden by Args that need to added to the end of the list. - */ -inline void Arg::addToList( std::list<Arg*>& argList ) const -{ - argList.push_front( const_cast<Arg*>(this) ); -} - -inline bool Arg::allowMore() -{ - return false; -} - -inline bool Arg::acceptsMultipleValues() -{ - return _acceptsMultipleValues; -} - -inline void Arg::reset() -{ - _xorSet = false; - _alreadySet = false; -} - -////////////////////////////////////////////////////////////////////// -//END Arg.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif - diff --git a/ext/tclap/include/tclap/ArgException.h b/ext/tclap/include/tclap/ArgException.h deleted file mode 100644 index 3411aa95..00000000 --- a/ext/tclap/include/tclap/ArgException.h +++ /dev/null @@ -1,200 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: ArgException.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_ARG_EXCEPTION_H -#define TCLAP_ARG_EXCEPTION_H - -#include <string> -#include <exception> - -namespace TCLAP { - -/** - * A simple class that defines and argument exception. Should be caught - * whenever a CmdLine is created and parsed. - */ -class ArgException : public std::exception -{ - public: - - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source. - * \param td - Text describing the type of ArgException it is. - * of the exception. - */ - ArgException( const std::string& text = "undefined exception", - const std::string& id = "undefined", - const std::string& td = "Generic ArgException") - : std::exception(), - _errorText(text), - _argId( id ), - _typeDescription(td) - { } - - /** - * Destructor. - */ - virtual ~ArgException() throw() { } - - /** - * Returns the error text. - */ - std::string error() const { return ( _errorText ); } - - /** - * Returns the argument id. - */ - std::string argId() const - { - if ( _argId == "undefined" ) - return " "; - else - return ( "Argument: " + _argId ); - } - - /** - * Returns the arg id and error text. - */ - const char* what() const throw() - { - static std::string ex; - ex = _argId + " -- " + _errorText; - return ex.c_str(); - } - - /** - * Returns the type of the exception. Used to explain and distinguish - * between different child exceptions. - */ - std::string typeDescription() const - { - return _typeDescription; - } - - - private: - - /** - * The text of the exception message. - */ - std::string _errorText; - - /** - * The argument related to this exception. - */ - std::string _argId; - - /** - * Describes the type of the exception. Used to distinguish - * between different child exceptions. - */ - std::string _typeDescription; - -}; - -/** - * Thrown from within the child Arg classes when it fails to properly - * parse the argument it has been passed. - */ -class ArgParseException : public ArgException -{ - public: - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source - * of the exception. - */ - ArgParseException( const std::string& text = "undefined exception", - const std::string& id = "undefined" ) - : ArgException( text, - id, - std::string( "Exception found while parsing " ) + - std::string( "the value the Arg has been passed." )) - { } -}; - -/** - * Thrown from CmdLine when the arguments on the command line are not - * properly specified, e.g. too many arguments, required argument missing, etc. - */ -class CmdLineParseException : public ArgException -{ - public: - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source - * of the exception. - */ - CmdLineParseException( const std::string& text = "undefined exception", - const std::string& id = "undefined" ) - : ArgException( text, - id, - std::string( "Exception found when the values ") + - std::string( "on the command line do not meet ") + - std::string( "the requirements of the defined ") + - std::string( "Args." )) - { } -}; - -/** - * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. - * same flag as another Arg, same name, etc. - */ -class SpecificationException : public ArgException -{ - public: - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source - * of the exception. - */ - SpecificationException( const std::string& text = "undefined exception", - const std::string& id = "undefined" ) - : ArgException( text, - id, - std::string("Exception found when an Arg object ")+ - std::string("is improperly defined by the ") + - std::string("developer." )) - { } - -}; - -class ExitException { -public: - ExitException(int estat) : _estat(estat) {} - - int getExitStatus() const { return _estat; } - -private: - int _estat; -}; - -} // namespace TCLAP - -#endif - diff --git a/ext/tclap/include/tclap/ArgTraits.h b/ext/tclap/include/tclap/ArgTraits.h deleted file mode 100644 index 0b2c18f7..00000000 --- a/ext/tclap/include/tclap/ArgTraits.h +++ /dev/null @@ -1,87 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: ArgTraits.h - * - * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -// This is an internal tclap file, you should probably not have to -// include this directly - -#ifndef TCLAP_ARGTRAITS_H -#define TCLAP_ARGTRAITS_H - -namespace TCLAP { - -// We use two empty structs to get compile type specialization -// function to work - -/** - * A value like argument value type is a value that can be set using - * operator>>. This is the default value type. - */ -struct ValueLike { - typedef ValueLike ValueCategory; - virtual ~ValueLike() {} -}; - -/** - * A string like argument value type is a value that can be set using - * operator=(string). Usefull if the value type contains spaces which - * will be broken up into individual tokens by operator>>. - */ -struct StringLike { - virtual ~StringLike() {} -}; - -/** - * A class can inherit from this object to make it have string like - * traits. This is a compile time thing and does not add any overhead - * to the inherenting class. - */ -struct StringLikeTrait { - typedef StringLike ValueCategory; - virtual ~StringLikeTrait() {} -}; - -/** - * A class can inherit from this object to make it have value like - * traits. This is a compile time thing and does not add any overhead - * to the inherenting class. - */ -struct ValueLikeTrait { - typedef ValueLike ValueCategory; - virtual ~ValueLikeTrait() {} -}; - -/** - * Arg traits are used to get compile type specialization when parsing - * argument values. Using an ArgTraits you can specify the way that - * values gets assigned to any particular type during parsing. The two - * supported types are StringLike and ValueLike. - */ -template<typename T> -struct ArgTraits { - typedef typename T::ValueCategory ValueCategory; - virtual ~ArgTraits() {} - //typedef ValueLike ValueCategory; -}; - -#endif - -} // namespace diff --git a/ext/tclap/include/tclap/CmdLine.h b/ext/tclap/include/tclap/CmdLine.h deleted file mode 100644 index aabe3a28..00000000 --- a/ext/tclap/include/tclap/CmdLine.h +++ /dev/null @@ -1,651 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: CmdLine.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_CMDLINE_H -#define TCLAP_CMDLINE_H - -#include <tclap/SwitchArg.h> -#include <tclap/MultiSwitchArg.h> -#include <tclap/UnlabeledValueArg.h> -#include <tclap/UnlabeledMultiArg.h> - -#include <tclap/XorHandler.h> -#include <tclap/HelpVisitor.h> -#include <tclap/VersionVisitor.h> -#include <tclap/IgnoreRestVisitor.h> - -#include <tclap/CmdLineOutput.h> -#include <tclap/StdOutput.h> - -#include <tclap/Constraint.h> -#include <tclap/ValuesConstraint.h> - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <iomanip> -#include <algorithm> -#include <stdlib.h> // Needed for exit(), which isn't defined in some envs. - -namespace TCLAP { - -template<typename T> void DelPtr(T ptr) -{ - delete ptr; -} - -template<typename C> void ClearContainer(C &c) -{ - typedef typename C::value_type value_type; - std::for_each(c.begin(), c.end(), DelPtr<value_type>); - c.clear(); -} - - -/** - * The base class that manages the command line definition and passes - * along the parsing to the appropriate Arg classes. - */ -class CmdLine : public CmdLineInterface -{ - protected: - - /** - * The list of arguments that will be tested against the - * command line. - */ - std::list<Arg*> _argList; - - /** - * The name of the program. Set to argv[0]. - */ - std::string _progName; - - /** - * A message used to describe the program. Used in the usage output. - */ - std::string _message; - - /** - * The version to be displayed with the --version switch. - */ - std::string _version; - - /** - * The number of arguments that are required to be present on - * the command line. This is set dynamically, based on the - * Args added to the CmdLine object. - */ - int _numRequired; - - /** - * The character that is used to separate the argument flag/name - * from the value. Defaults to ' ' (space). - */ - char _delimiter; - - /** - * The handler that manages xoring lists of args. - */ - XorHandler _xorHandler; - - /** - * A list of Args to be explicitly deleted when the destructor - * is called. At the moment, this only includes the three default - * Args. - */ - std::list<Arg*> _argDeleteOnExitList; - - /** - * A list of Visitors to be explicitly deleted when the destructor - * is called. At the moment, these are the Vistors created for the - * default Args. - */ - std::list<Visitor*> _visitorDeleteOnExitList; - - /** - * Object that handles all output for the CmdLine. - */ - CmdLineOutput* _output; - - /** - * Should CmdLine handle parsing exceptions internally? - */ - bool _handleExceptions; - - /** - * Throws an exception listing the missing args. - */ - void missingArgsException(); - - /** - * Checks whether a name/flag string matches entirely matches - * the Arg::blankChar. Used when multiple switches are combined - * into a single argument. - * \param s - The message to be used in the usage. - */ - bool _emptyCombined(const std::string& s); - - /** - * Perform a delete ptr; operation on ptr when this object is deleted. - */ - void deleteOnExit(Arg* ptr); - - /** - * Perform a delete ptr; operation on ptr when this object is deleted. - */ - void deleteOnExit(Visitor* ptr); - -private: - - /** - * Prevent accidental copying. - */ - CmdLine(const CmdLine& rhs); - CmdLine& operator=(const CmdLine& rhs); - - /** - * Encapsulates the code common to the constructors - * (which is all of it). - */ - void _constructor(); - - - /** - * Is set to true when a user sets the output object. We use this so - * that we don't delete objects that are created outside of this lib. - */ - bool _userSetOutput; - - /** - * Whether or not to automatically create help and version switches. - */ - bool _helpAndVersion; - - /** - * Whether or not to ignore unmatched args. - */ - bool _ignoreUnmatched; - - public: - - /** - * Command line constructor. Defines how the arguments will be - * parsed. - * \param message - The message to be used in the usage - * output. - * \param delimiter - The character that is used to separate - * the argument flag/name from the value. Defaults to ' ' (space). - * \param version - The version number to be used in the - * --version switch. - * \param helpAndVersion - Whether or not to create the Help and - * Version switches. Defaults to true. - */ - CmdLine(const std::string& message, - const char delimiter = ' ', - const std::string& version = "none", - bool helpAndVersion = true); - - /** - * Deletes any resources allocated by a CmdLine object. - */ - virtual ~CmdLine(); - - /** - * Adds an argument to the list of arguments to be parsed. - * \param a - Argument to be added. - */ - void add( Arg& a ); - - /** - * An alternative add. Functionally identical. - * \param a - Argument to be added. - */ - void add( Arg* a ); - - /** - * Add two Args that will be xor'd. If this method is used, add does - * not need to be called. - * \param a - Argument to be added and xor'd. - * \param b - Argument to be added and xor'd. - */ - void xorAdd( Arg& a, Arg& b ); - - /** - * Add a list of Args that will be xor'd. If this method is used, - * add does not need to be called. - * \param xors - List of Args to be added and xor'd. - */ - void xorAdd( std::vector<Arg*>& xors ); - - /** - * Parses the command line. - * \param argc - Number of arguments. - * \param argv - Array of arguments. - */ - void parse(int argc, const char * const * argv); - - /** - * Parses the command line. - * \param args - A vector of strings representing the args. - * args[0] is still the program name. - */ - void parse(std::vector<std::string>& args); - - /** - * - */ - CmdLineOutput* getOutput(); - - /** - * - */ - void setOutput(CmdLineOutput* co); - - /** - * - */ - std::string& getVersion(); - - /** - * - */ - std::string& getProgramName(); - - /** - * - */ - std::list<Arg*>& getArgList(); - - /** - * - */ - XorHandler& getXorHandler(); - - /** - * - */ - char getDelimiter(); - - /** - * - */ - std::string& getMessage(); - - /** - * - */ - bool hasHelpAndVersion(); - - /** - * Disables or enables CmdLine's internal parsing exception handling. - * - * @param state Should CmdLine handle parsing exceptions internally? - */ - void setExceptionHandling(const bool state); - - /** - * Returns the current state of the internal exception handling. - * - * @retval true Parsing exceptions are handled internally. - * @retval false Parsing exceptions are propagated to the caller. - */ - bool getExceptionHandling() const; - - /** - * Allows the CmdLine object to be reused. - */ - void reset(); - - /** - * Allows unmatched args to be ignored. By default false. - * - * @param ignore If true the cmdline will ignore any unmatched args - * and if false it will behave as normal. - */ - void ignoreUnmatched(const bool ignore); -}; - - -/////////////////////////////////////////////////////////////////////////////// -//Begin CmdLine.cpp -/////////////////////////////////////////////////////////////////////////////// - -inline CmdLine::CmdLine(const std::string& m, - char delim, - const std::string& v, - bool help ) - : - _argList(std::list<Arg*>()), - _progName("not_set_yet"), - _message(m), - _version(v), - _numRequired(0), - _delimiter(delim), - _xorHandler(XorHandler()), - _argDeleteOnExitList(std::list<Arg*>()), - _visitorDeleteOnExitList(std::list<Visitor*>()), - _output(0), - _handleExceptions(true), - _userSetOutput(false), - _helpAndVersion(help), - _ignoreUnmatched(false) -{ - _constructor(); -} - -inline CmdLine::~CmdLine() -{ - ClearContainer(_argDeleteOnExitList); - ClearContainer(_visitorDeleteOnExitList); - - if ( !_userSetOutput ) { - delete _output; - _output = 0; - } -} - -inline void CmdLine::_constructor() -{ - _output = new StdOutput; - - Arg::setDelimiter( _delimiter ); - - Visitor* v; - - if ( _helpAndVersion ) - { - v = new HelpVisitor( this, &_output ); - SwitchArg* help = new SwitchArg("h","help", - "Displays usage information and exits.", - false, v); - add( help ); - deleteOnExit(help); - deleteOnExit(v); - - v = new VersionVisitor( this, &_output ); - SwitchArg* vers = new SwitchArg("","version", - "Displays version information and exits.", - false, v); - add( vers ); - deleteOnExit(vers); - deleteOnExit(v); - } - - v = new IgnoreRestVisitor(); - SwitchArg* ignore = new SwitchArg(Arg::flagStartString(), - Arg::ignoreNameString(), - "Ignores the rest of the labeled arguments following this flag.", - false, v); - add( ignore ); - deleteOnExit(ignore); - deleteOnExit(v); -} - -inline void CmdLine::xorAdd( std::vector<Arg*>& ors ) -{ - _xorHandler.add( ors ); - - for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++) - { - (*it)->forceRequired(); - (*it)->setRequireLabel( "OR required" ); - add( *it ); - } -} - -inline void CmdLine::xorAdd( Arg& a, Arg& b ) -{ - std::vector<Arg*> ors; - ors.push_back( &a ); - ors.push_back( &b ); - xorAdd( ors ); -} - -inline void CmdLine::add( Arg& a ) -{ - add( &a ); -} - -inline void CmdLine::add( Arg* a ) -{ - for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) - if ( *a == *(*it) ) - throw( SpecificationException( - "Argument with same flag/name already exists!", - a->longID() ) ); - - a->addToList( _argList ); - - if ( a->isRequired() ) - _numRequired++; -} - - -inline void CmdLine::parse(int argc, const char * const * argv) -{ - // this step is necessary so that we have easy access to - // mutable strings. - std::vector<std::string> args; - for (int i = 0; i < argc; i++) - args.push_back(argv[i]); - - parse(args); -} - -inline void CmdLine::parse(std::vector<std::string>& args) -{ - bool shouldExit = false; - int estat = 0; - - try { - _progName = args.front(); - args.erase(args.begin()); - - int requiredCount = 0; - - for (int i = 0; static_cast<unsigned int>(i) < args.size(); i++) - { - bool matched = false; - for (ArgListIterator it = _argList.begin(); - it != _argList.end(); it++) { - if ( (*it)->processArg( &i, args ) ) - { - requiredCount += _xorHandler.check( *it ); - matched = true; - break; - } - } - - // checks to see if the argument is an empty combined - // switch and if so, then we've actually matched it - if ( !matched && _emptyCombined( args[i] ) ) - matched = true; - - if ( !matched && !Arg::ignoreRest() && !_ignoreUnmatched) - throw(CmdLineParseException("Couldn't find match " - "for argument", - args[i])); - } - - if ( requiredCount < _numRequired ) - missingArgsException(); - - if ( requiredCount > _numRequired ) - throw(CmdLineParseException("Too many arguments!")); - - } catch ( ArgException& e ) { - // If we're not handling the exceptions, rethrow. - if ( !_handleExceptions) { - throw; - } - - try { - _output->failure(*this,e); - } catch ( ExitException &ee ) { - estat = ee.getExitStatus(); - shouldExit = true; - } - } catch (ExitException &ee) { - // If we're not handling the exceptions, rethrow. - if ( !_handleExceptions) { - throw; - } - - estat = ee.getExitStatus(); - shouldExit = true; - } - - if (shouldExit) - exit(estat); -} - -inline bool CmdLine::_emptyCombined(const std::string& s) -{ - if ( s.length() > 0 && s[0] != Arg::flagStartChar() ) - return false; - - for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ ) - if ( s[i] != Arg::blankChar() ) - return false; - - return true; -} - -inline void CmdLine::missingArgsException() -{ - int count = 0; - - std::string missingArgList; - for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++) - { - if ( (*it)->isRequired() && !(*it)->isSet() ) - { - missingArgList += (*it)->getName(); - missingArgList += ", "; - count++; - } - } - missingArgList = missingArgList.substr(0,missingArgList.length()-2); - - std::string msg; - if ( count > 1 ) - msg = "Required arguments missing: "; - else - msg = "Required argument missing: "; - - msg += missingArgList; - - throw(CmdLineParseException(msg)); -} - -inline void CmdLine::deleteOnExit(Arg* ptr) -{ - _argDeleteOnExitList.push_back(ptr); -} - -inline void CmdLine::deleteOnExit(Visitor* ptr) -{ - _visitorDeleteOnExitList.push_back(ptr); -} - -inline CmdLineOutput* CmdLine::getOutput() -{ - return _output; -} - -inline void CmdLine::setOutput(CmdLineOutput* co) -{ - if ( !_userSetOutput ) - delete _output; - _userSetOutput = true; - _output = co; -} - -inline std::string& CmdLine::getVersion() -{ - return _version; -} - -inline std::string& CmdLine::getProgramName() -{ - return _progName; -} - -inline std::list<Arg*>& CmdLine::getArgList() -{ - return _argList; -} - -inline XorHandler& CmdLine::getXorHandler() -{ - return _xorHandler; -} - -inline char CmdLine::getDelimiter() -{ - return _delimiter; -} - -inline std::string& CmdLine::getMessage() -{ - return _message; -} - -inline bool CmdLine::hasHelpAndVersion() -{ - return _helpAndVersion; -} - -inline void CmdLine::setExceptionHandling(const bool state) -{ - _handleExceptions = state; -} - -inline bool CmdLine::getExceptionHandling() const -{ - return _handleExceptions; -} - -inline void CmdLine::reset() -{ - for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) - (*it)->reset(); - - _progName.clear(); -} - -inline void CmdLine::ignoreUnmatched(const bool ignore) -{ - _ignoreUnmatched = ignore; -} - -/////////////////////////////////////////////////////////////////////////////// -//End CmdLine.cpp -/////////////////////////////////////////////////////////////////////////////// - - - -} //namespace TCLAP -#endif diff --git a/ext/tclap/include/tclap/CmdLineInterface.h b/ext/tclap/include/tclap/CmdLineInterface.h deleted file mode 100644 index 1b25e9b8..00000000 --- a/ext/tclap/include/tclap/CmdLineInterface.h +++ /dev/null @@ -1,150 +0,0 @@ - -/****************************************************************************** - * - * file: CmdLineInterface.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_COMMANDLINE_INTERFACE_H -#define TCLAP_COMMANDLINE_INTERFACE_H - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <algorithm> - - -namespace TCLAP { - -class Arg; -class CmdLineOutput; -class XorHandler; - -/** - * The base class that manages the command line definition and passes - * along the parsing to the appropriate Arg classes. - */ -class CmdLineInterface -{ - public: - - /** - * Destructor - */ - virtual ~CmdLineInterface() {} - - /** - * Adds an argument to the list of arguments to be parsed. - * \param a - Argument to be added. - */ - virtual void add( Arg& a )=0; - - /** - * An alternative add. Functionally identical. - * \param a - Argument to be added. - */ - virtual void add( Arg* a )=0; - - /** - * Add two Args that will be xor'd. - * If this method is used, add does - * not need to be called. - * \param a - Argument to be added and xor'd. - * \param b - Argument to be added and xor'd. - */ - virtual void xorAdd( Arg& a, Arg& b )=0; - - /** - * Add a list of Args that will be xor'd. If this method is used, - * add does not need to be called. - * \param xors - List of Args to be added and xor'd. - */ - virtual void xorAdd( std::vector<Arg*>& xors )=0; - - /** - * Parses the command line. - * \param argc - Number of arguments. - * \param argv - Array of arguments. - */ - virtual void parse(int argc, const char * const * argv)=0; - - /** - * Parses the command line. - * \param args - A vector of strings representing the args. - * args[0] is still the program name. - */ - void parse(std::vector<std::string>& args); - - /** - * Returns the CmdLineOutput object. - */ - virtual CmdLineOutput* getOutput()=0; - - /** - * \param co - CmdLineOutput object that we want to use instead. - */ - virtual void setOutput(CmdLineOutput* co)=0; - - /** - * Returns the version string. - */ - virtual std::string& getVersion()=0; - - /** - * Returns the program name string. - */ - virtual std::string& getProgramName()=0; - - /** - * Returns the argList. - */ - virtual std::list<Arg*>& getArgList()=0; - - /** - * Returns the XorHandler. - */ - virtual XorHandler& getXorHandler()=0; - - /** - * Returns the delimiter string. - */ - virtual char getDelimiter()=0; - - /** - * Returns the message string. - */ - virtual std::string& getMessage()=0; - - /** - * Indicates whether or not the help and version switches were created - * automatically. - */ - virtual bool hasHelpAndVersion()=0; - - /** - * Resets the instance as if it had just been constructed so that the - * instance can be reused. - */ - virtual void reset()=0; -}; - -} //namespace - - -#endif diff --git a/ext/tclap/include/tclap/CmdLineOutput.h b/ext/tclap/include/tclap/CmdLineOutput.h deleted file mode 100644 index 71ee5a3b..00000000 --- a/ext/tclap/include/tclap/CmdLineOutput.h +++ /dev/null @@ -1,74 +0,0 @@ - - -/****************************************************************************** - * - * file: CmdLineOutput.h - * - * Copyright (c) 2004, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_CMDLINEOUTPUT_H -#define TCLAP_CMDLINEOUTPUT_H - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <iomanip> -#include <algorithm> - -namespace TCLAP { - -class CmdLineInterface; -class ArgException; - -/** - * The interface that any output object must implement. - */ -class CmdLineOutput -{ - - public: - - /** - * Virtual destructor. - */ - virtual ~CmdLineOutput() {} - - /** - * Generates some sort of output for the USAGE. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c)=0; - - /** - * Generates some sort of output for the version. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c)=0; - - /** - * Generates some sort of output for a failure. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure( CmdLineInterface& c, - ArgException& e )=0; - -}; - -} //namespace TCLAP -#endif diff --git a/ext/tclap/include/tclap/Constraint.h b/ext/tclap/include/tclap/Constraint.h deleted file mode 100644 index a92acf9a..00000000 --- a/ext/tclap/include/tclap/Constraint.h +++ /dev/null @@ -1,68 +0,0 @@ - -/****************************************************************************** - * - * file: Constraint.h - * - * Copyright (c) 2005, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_CONSTRAINT_H -#define TCLAP_CONSTRAINT_H - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <iomanip> -#include <algorithm> - -namespace TCLAP { - -/** - * The interface that defines the interaction between the Arg and Constraint. - */ -template<class T> -class Constraint -{ - - public: - /** - * Returns a description of the Constraint. - */ - virtual std::string description() const =0; - - /** - * Returns the short ID for the Constraint. - */ - virtual std::string shortID() const =0; - - /** - * The method used to verify that the value parsed from the command - * line meets the constraint. - * \param value - The value that will be checked. - */ - virtual bool check(const T& value) const =0; - - /** - * Destructor. - * Silences warnings about Constraint being a base class with virtual - * functions but without a virtual destructor. - */ - virtual ~Constraint() { ; } -}; - -} //namespace TCLAP -#endif diff --git a/ext/tclap/include/tclap/DocBookOutput.h b/ext/tclap/include/tclap/DocBookOutput.h deleted file mode 100644 index a42ca274..00000000 --- a/ext/tclap/include/tclap/DocBookOutput.h +++ /dev/null @@ -1,299 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: DocBookOutput.h - * - * Copyright (c) 2004, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_DOCBOOKOUTPUT_H -#define TCLAP_DOCBOOKOUTPUT_H - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <algorithm> - -#include <tclap/CmdLineInterface.h> -#include <tclap/CmdLineOutput.h> -#include <tclap/XorHandler.h> -#include <tclap/Arg.h> - -namespace TCLAP { - -/** - * A class that generates DocBook output for usage() method for the - * given CmdLine and its Args. - */ -class DocBookOutput : public CmdLineOutput -{ - - public: - - /** - * Prints the usage to stdout. Can be overridden to - * produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c); - - /** - * Prints the version to stdout. Can be overridden - * to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c); - - /** - * Prints (to stderr) an error message, short usage - * Can be overridden to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure(CmdLineInterface& c, - ArgException& e ); - - protected: - - /** - * Substitutes the char r for string x in string s. - * \param s - The string to operate on. - * \param r - The char to replace. - * \param x - What to replace r with. - */ - void substituteSpecialChars( std::string& s, char r, std::string& x ); - void removeChar( std::string& s, char r); - void basename( std::string& s ); - - void printShortArg(Arg* it); - void printLongArg(Arg* it); - - char theDelimiter; -}; - - -inline void DocBookOutput::version(CmdLineInterface& _cmd) -{ - std::cout << _cmd.getVersion() << std::endl; -} - -inline void DocBookOutput::usage(CmdLineInterface& _cmd ) -{ - std::list<Arg*> argList = _cmd.getArgList(); - std::string progName = _cmd.getProgramName(); - std::string xversion = _cmd.getVersion(); - theDelimiter = _cmd.getDelimiter(); - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); - basename(progName); - - std::cout << "<?xml version='1.0'?>" << std::endl; - std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl; - std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl; - - std::cout << "<refentry>" << std::endl; - - std::cout << "<refmeta>" << std::endl; - std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl; - std::cout << "<manvolnum>1</manvolnum>" << std::endl; - std::cout << "</refmeta>" << std::endl; - - std::cout << "<refnamediv>" << std::endl; - std::cout << "<refname>" << progName << "</refname>" << std::endl; - std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl; - std::cout << "</refnamediv>" << std::endl; - - std::cout << "<refsynopsisdiv>" << std::endl; - std::cout << "<cmdsynopsis>" << std::endl; - - std::cout << "<command>" << progName << "</command>" << std::endl; - - // xor - for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) - { - std::cout << "<group choice='req'>" << std::endl; - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); it++ ) - printShortArg((*it)); - - std::cout << "</group>" << std::endl; - } - - // rest of args - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - if ( !xorHandler.contains( (*it) ) ) - printShortArg((*it)); - - std::cout << "</cmdsynopsis>" << std::endl; - std::cout << "</refsynopsisdiv>" << std::endl; - - std::cout << "<refsect1>" << std::endl; - std::cout << "<title>Description</title>" << std::endl; - std::cout << "<para>" << std::endl; - std::cout << _cmd.getMessage() << std::endl; - std::cout << "</para>" << std::endl; - std::cout << "</refsect1>" << std::endl; - - std::cout << "<refsect1>" << std::endl; - std::cout << "<title>Options</title>" << std::endl; - - std::cout << "<variablelist>" << std::endl; - - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - printLongArg((*it)); - - std::cout << "</variablelist>" << std::endl; - std::cout << "</refsect1>" << std::endl; - - std::cout << "<refsect1>" << std::endl; - std::cout << "<title>Version</title>" << std::endl; - std::cout << "<para>" << std::endl; - std::cout << xversion << std::endl; - std::cout << "</para>" << std::endl; - std::cout << "</refsect1>" << std::endl; - - std::cout << "</refentry>" << std::endl; - -} - -inline void DocBookOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) -{ - static_cast<void>(_cmd); // unused - std::cout << e.what() << std::endl; - throw ExitException(1); -} - -inline void DocBookOutput::substituteSpecialChars( std::string& s, - char r, - std::string& x ) -{ - size_t p; - while ( (p = s.find_first_of(r)) != std::string::npos ) - { - s.erase(p,1); - s.insert(p,x); - } -} - -inline void DocBookOutput::removeChar( std::string& s, char r) -{ - size_t p; - while ( (p = s.find_first_of(r)) != std::string::npos ) - { - s.erase(p,1); - } -} - -inline void DocBookOutput::basename( std::string& s ) -{ - size_t p = s.find_last_of('/'); - if ( p != std::string::npos ) - { - s.erase(0, p + 1); - } -} - -inline void DocBookOutput::printShortArg(Arg* a) -{ - std::string lt = "<"; - std::string gt = ">"; - - std::string id = a->shortID(); - substituteSpecialChars(id,'<',lt); - substituteSpecialChars(id,'>',gt); - removeChar(id,'['); - removeChar(id,']'); - - std::string choice = "opt"; - if ( a->isRequired() ) - choice = "plain"; - - std::cout << "<arg choice='" << choice << '\''; - if ( a->acceptsMultipleValues() ) - std::cout << " rep='repeat'"; - - - std::cout << '>'; - if ( !a->getFlag().empty() ) - std::cout << a->flagStartChar() << a->getFlag(); - else - std::cout << a->nameStartString() << a->getName(); - if ( a->isValueRequired() ) - { - std::string arg = a->shortID(); - removeChar(arg,'['); - removeChar(arg,']'); - removeChar(arg,'<'); - removeChar(arg,'>'); - arg.erase(0, arg.find_last_of(theDelimiter) + 1); - std::cout << theDelimiter; - std::cout << "<replaceable>" << arg << "</replaceable>"; - } - std::cout << "</arg>" << std::endl; - -} - -inline void DocBookOutput::printLongArg(Arg* a) -{ - std::string lt = "<"; - std::string gt = ">"; - - std::string desc = a->getDescription(); - substituteSpecialChars(desc,'<',lt); - substituteSpecialChars(desc,'>',gt); - - std::cout << "<varlistentry>" << std::endl; - - if ( !a->getFlag().empty() ) - { - std::cout << "<term>" << std::endl; - std::cout << "<option>"; - std::cout << a->flagStartChar() << a->getFlag(); - std::cout << "</option>" << std::endl; - std::cout << "</term>" << std::endl; - } - - std::cout << "<term>" << std::endl; - std::cout << "<option>"; - std::cout << a->nameStartString() << a->getName(); - if ( a->isValueRequired() ) - { - std::string arg = a->shortID(); - removeChar(arg,'['); - removeChar(arg,']'); - removeChar(arg,'<'); - removeChar(arg,'>'); - arg.erase(0, arg.find_last_of(theDelimiter) + 1); - std::cout << theDelimiter; - std::cout << "<replaceable>" << arg << "</replaceable>"; - } - std::cout << "</option>" << std::endl; - std::cout << "</term>" << std::endl; - - std::cout << "<listitem>" << std::endl; - std::cout << "<para>" << std::endl; - std::cout << desc << std::endl; - std::cout << "</para>" << std::endl; - std::cout << "</listitem>" << std::endl; - - std::cout << "</varlistentry>" << std::endl; -} - -} //namespace TCLAP -#endif diff --git a/ext/tclap/include/tclap/HelpVisitor.h b/ext/tclap/include/tclap/HelpVisitor.h deleted file mode 100644 index cc3bd070..00000000 --- a/ext/tclap/include/tclap/HelpVisitor.h +++ /dev/null @@ -1,76 +0,0 @@ - -/****************************************************************************** - * - * file: HelpVisitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_HELP_VISITOR_H -#define TCLAP_HELP_VISITOR_H - -#include <tclap/CmdLineInterface.h> -#include <tclap/CmdLineOutput.h> -#include <tclap/Visitor.h> - -namespace TCLAP { - -/** - * A Visitor object that calls the usage method of the given CmdLineOutput - * object for the specified CmdLine object. - */ -class HelpVisitor: public Visitor -{ - private: - /** - * Prevent accidental copying. - */ - HelpVisitor(const HelpVisitor& rhs); - HelpVisitor& operator=(const HelpVisitor& rhs); - - protected: - - /** - * The CmdLine the output will be generated for. - */ - CmdLineInterface* _cmd; - - /** - * The output object. - */ - CmdLineOutput** _out; - - public: - - /** - * Constructor. - * \param cmd - The CmdLine the output will be generated for. - * \param out - The type of output. - */ - HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) - : Visitor(), _cmd( cmd ), _out( out ) { } - - /** - * Calls the usage method of the CmdLineOutput for the - * specified CmdLine. - */ - void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } - -}; - -} - -#endif diff --git a/ext/tclap/include/tclap/IgnoreRestVisitor.h b/ext/tclap/include/tclap/IgnoreRestVisitor.h deleted file mode 100644 index e328649e..00000000 --- a/ext/tclap/include/tclap/IgnoreRestVisitor.h +++ /dev/null @@ -1,52 +0,0 @@ - -/****************************************************************************** - * - * file: IgnoreRestVisitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_IGNORE_REST_VISITOR_H -#define TCLAP_IGNORE_REST_VISITOR_H - -#include <tclap/Visitor.h> -#include <tclap/Arg.h> - -namespace TCLAP { - -/** - * A Vistor that tells the CmdLine to begin ignoring arguments after - * this one is parsed. - */ -class IgnoreRestVisitor: public Visitor -{ - public: - - /** - * Constructor. - */ - IgnoreRestVisitor() : Visitor() {} - - /** - * Sets Arg::_ignoreRest. - */ - void visit() { Arg::beginIgnoring(); } -}; - -} - -#endif diff --git a/ext/tclap/include/tclap/MultiArg.h b/ext/tclap/include/tclap/MultiArg.h deleted file mode 100644 index 34bb2d78..00000000 --- a/ext/tclap/include/tclap/MultiArg.h +++ /dev/null @@ -1,433 +0,0 @@ -/****************************************************************************** - * - * file: MultiArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_MULTIPLE_ARGUMENT_H -#define TCLAP_MULTIPLE_ARGUMENT_H - -#include <string> -#include <vector> - -#include <tclap/Arg.h> -#include <tclap/Constraint.h> - -namespace TCLAP { -/** - * An argument that allows multiple values of type T to be specified. Very - * similar to a ValueArg, except a vector of values will be returned - * instead of just one. - */ -template<class T> -class MultiArg : public Arg -{ -public: - typedef std::vector<T> container_type; - typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - -protected: - - /** - * The list of values parsed from the CmdLine. - */ - std::vector<T> _values; - - /** - * The description of type T to be used in the usage. - */ - std::string _typeDesc; - - /** - * A list of constraint on this Arg. - */ - Constraint<T>* _constraint; - - /** - * Extracts the value from the string. - * Attempts to parse string as type T, if this fails an exception - * is thrown. - * \param val - The string to be read. - */ - void _extractValue( const std::string& val ); - - /** - * Used by XorHandler to decide whether to keep parsing for this arg. - */ - bool _allowMore; - -public: - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - Visitor* v = NULL); - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - Visitor* v = NULL ); - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. It knows the difference - * between labeled and unlabeled. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed from main(). - */ - virtual bool processArg(int* i, std::vector<std::string>& args); - - /** - * Returns a vector of type T containing the values parsed from - * the command line. - */ - const std::vector<T>& getValue(); - - /** - * Returns an iterator over the values parsed from the command - * line. - */ - const_iterator begin() const { return _values.begin(); } - - /** - * Returns the end of the values parsed from the command - * line. - */ - const_iterator end() const { return _values.end(); } - - /** - * Returns the a short id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string shortID(const std::string& val="val") const; - - /** - * Returns the a long id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string longID(const std::string& val="val") const; - - /** - * Once we've matched the first value, then the arg is no longer - * required. - */ - virtual bool isRequired() const; - - virtual bool allowMore(); - - virtual void reset(); - -private: - /** - * Prevent accidental copying - */ - MultiArg<T>(const MultiArg<T>& rhs); - MultiArg<T>& operator=(const MultiArg<T>& rhs); - -}; - -template<class T> -MultiArg<T>::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - Visitor* v) : - Arg( flag, name, desc, req, true, v ), - _values(std::vector<T>()), - _typeDesc( typeDesc ), - _constraint( NULL ), - _allowMore(false) -{ - _acceptsMultipleValues = true; -} - -template<class T> -MultiArg<T>::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v) -: Arg( flag, name, desc, req, true, v ), - _values(std::vector<T>()), - _typeDesc( typeDesc ), - _constraint( NULL ), - _allowMore(false) -{ - parser.add( this ); - _acceptsMultipleValues = true; -} - -/** - * - */ -template<class T> -MultiArg<T>::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - Visitor* v) -: Arg( flag, name, desc, req, true, v ), - _values(std::vector<T>()), - _typeDesc( constraint->shortID() ), - _constraint( constraint ), - _allowMore(false) -{ - _acceptsMultipleValues = true; -} - -template<class T> -MultiArg<T>::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - CmdLineInterface& parser, - Visitor* v) -: Arg( flag, name, desc, req, true, v ), - _values(std::vector<T>()), - _typeDesc( constraint->shortID() ), - _constraint( constraint ), - _allowMore(false) -{ - parser.add( this ); - _acceptsMultipleValues = true; -} - -template<class T> -const std::vector<T>& MultiArg<T>::getValue() { return _values; } - -template<class T> -bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - if ( _hasBlanks( args[*i] ) ) - return false; - - std::string flag = args[*i]; - std::string value = ""; - - trimFlag( flag, value ); - - if ( argMatches( flag ) ) - { - if ( Arg::delimiter() != ' ' && value == "" ) - throw( ArgParseException( - "Couldn't find delimiter for this argument!", - toString() ) ); - - // always take the first one, regardless of start string - if ( value == "" ) - { - (*i)++; - if ( static_cast<unsigned int>(*i) < args.size() ) - _extractValue( args[*i] ); - else - throw( ArgParseException("Missing a value for this argument!", - toString() ) ); - } - else - _extractValue( value ); - - /* - // continuing taking the args until we hit one with a start string - while ( (unsigned int)(*i)+1 < args.size() && - args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && - args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) - _extractValue( args[++(*i)] ); - */ - - _alreadySet = true; - _checkWithVisitor(); - - return true; - } - else - return false; -} - -/** - * - */ -template<class T> -std::string MultiArg<T>::shortID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - return Arg::shortID(_typeDesc) + " ... "; -} - -/** - * - */ -template<class T> -std::string MultiArg<T>::longID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - return Arg::longID(_typeDesc) + " (accepted multiple times)"; -} - -/** - * Once we've matched the first value, then the arg is no longer - * required. - */ -template<class T> -bool MultiArg<T>::isRequired() const -{ - if ( _required ) - { - if ( _values.size() > 1 ) - return false; - else - return true; - } - else - return false; - -} - -template<class T> -void MultiArg<T>::_extractValue( const std::string& val ) -{ - try { - T tmp; - ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory()); - _values.push_back(tmp); - } catch( ArgParseException &e) { - throw ArgParseException(e.error(), toString()); - } - - if ( _constraint != NULL ) - if ( ! _constraint->check( _values.back() ) ) - throw( CmdLineParseException( "Value '" + val + - "' does not meet constraint: " + - _constraint->description(), - toString() ) ); -} - -template<class T> -bool MultiArg<T>::allowMore() -{ - bool am = _allowMore; - _allowMore = true; - return am; -} - -template<class T> -void MultiArg<T>::reset() -{ - Arg::reset(); - _values.clear(); -} - -} // namespace TCLAP - -#endif diff --git a/ext/tclap/include/tclap/MultiSwitchArg.h b/ext/tclap/include/tclap/MultiSwitchArg.h deleted file mode 100644 index 8820b641..00000000 --- a/ext/tclap/include/tclap/MultiSwitchArg.h +++ /dev/null @@ -1,216 +0,0 @@ - -/****************************************************************************** -* -* file: MultiSwitchArg.h -* -* Copyright (c) 2003, Michael E. Smoot . -* Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. -* Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. -* All rights reverved. -* -* See the file COPYING in the top directory of this distribution for -* more information. -* -* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -* -*****************************************************************************/ - - -#ifndef TCLAP_MULTI_SWITCH_ARG_H -#define TCLAP_MULTI_SWITCH_ARG_H - -#include <string> -#include <vector> - -#include <tclap/SwitchArg.h> - -namespace TCLAP { - -/** -* A multiple switch argument. If the switch is set on the command line, then -* the getValue method will return the number of times the switch appears. -*/ -class MultiSwitchArg : public SwitchArg -{ - protected: - - /** - * The value of the switch. - */ - int _value; - - /** - * Used to support the reset() method so that ValueArg can be - * reset to their constructed value. - */ - int _default; - - public: - - /** - * MultiSwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param init - Optional. The initial/default value of this Arg. - * Defaults to 0. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - int init = 0, - Visitor* v = NULL); - - - /** - * MultiSwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param parser - A CmdLine parser object to add this Arg to - * \param init - Optional. The initial/default value of this Arg. - * Defaults to 0. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - int init = 0, - Visitor* v = NULL); - - - /** - * Handles the processing of the argument. - * This re-implements the SwitchArg version of this method to set the - * _value of the argument appropriately. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed - * in from main(). - */ - virtual bool processArg(int* i, std::vector<std::string>& args); - - /** - * Returns int, the number of times the switch has been set. - */ - int getValue(); - - /** - * Returns the shortID for this Arg. - */ - std::string shortID(const std::string& val) const; - - /** - * Returns the longID for this Arg. - */ - std::string longID(const std::string& val) const; - - void reset(); - -}; - -////////////////////////////////////////////////////////////////////// -//BEGIN MultiSwitchArg.cpp -////////////////////////////////////////////////////////////////////// -inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - int init, - Visitor* v ) -: SwitchArg(flag, name, desc, false, v), -_value( init ), -_default( init ) -{ } - -inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - int init, - Visitor* v ) -: SwitchArg(flag, name, desc, false, v), -_value( init ), -_default( init ) -{ - parser.add( this ); -} - -inline int MultiSwitchArg::getValue() { return _value; } - -inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - if ( argMatches( args[*i] )) - { - // so the isSet() method will work - _alreadySet = true; - - // Matched argument: increment value. - ++_value; - - _checkWithVisitor(); - - return true; - } - else if ( combinedSwitchesMatch( args[*i] ) ) - { - // so the isSet() method will work - _alreadySet = true; - - // Matched argument: increment value. - ++_value; - - // Check for more in argument and increment value. - while ( combinedSwitchesMatch( args[*i] ) ) - ++_value; - - _checkWithVisitor(); - - return false; - } - else - return false; -} - -inline std::string -MultiSwitchArg::shortID(const std::string& val) const -{ - return Arg::shortID(val) + " ... "; -} - -inline std::string -MultiSwitchArg::longID(const std::string& val) const -{ - return Arg::longID(val) + " (accepted multiple times)"; -} - -inline void -MultiSwitchArg::reset() -{ - MultiSwitchArg::_value = MultiSwitchArg::_default; -} - -////////////////////////////////////////////////////////////////////// -//END MultiSwitchArg.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif diff --git a/ext/tclap/include/tclap/OptionalUnlabeledTracker.h b/ext/tclap/include/tclap/OptionalUnlabeledTracker.h deleted file mode 100644 index 8174c5f6..00000000 --- a/ext/tclap/include/tclap/OptionalUnlabeledTracker.h +++ /dev/null @@ -1,62 +0,0 @@ - - -/****************************************************************************** - * - * file: OptionalUnlabeledTracker.h - * - * Copyright (c) 2005, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H -#define TCLAP_OPTIONAL_UNLABELED_TRACKER_H - -#include <string> - -namespace TCLAP { - -class OptionalUnlabeledTracker -{ - - public: - - static void check( bool req, const std::string& argName ); - - static void gotOptional() { alreadyOptionalRef() = true; } - - static bool& alreadyOptional() { return alreadyOptionalRef(); } - - private: - - static bool& alreadyOptionalRef() { static bool ct = false; return ct; } -}; - - -inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) -{ - if ( OptionalUnlabeledTracker::alreadyOptional() ) - throw( SpecificationException( - "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", - argName ) ); - - if ( !req ) - OptionalUnlabeledTracker::gotOptional(); -} - - -} // namespace TCLAP - -#endif diff --git a/ext/tclap/include/tclap/StandardTraits.h b/ext/tclap/include/tclap/StandardTraits.h deleted file mode 100644 index 46d7f6fa..00000000 --- a/ext/tclap/include/tclap/StandardTraits.h +++ /dev/null @@ -1,208 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: StandardTraits.h - * - * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -// This is an internal tclap file, you should probably not have to -// include this directly - -#ifndef TCLAP_STANDARD_TRAITS_H -#define TCLAP_STANDARD_TRAITS_H - -#ifdef HAVE_CONFIG_H -#include <config.h> // To check for long long -#endif - -// If Microsoft has already typedef'd wchar_t as an unsigned -// short, then compiles will break because it's as if we're -// creating ArgTraits twice for unsigned short. Thus... -#ifdef _MSC_VER -#ifndef _NATIVE_WCHAR_T_DEFINED -#define TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS -#endif -#endif - -namespace TCLAP { - -// ====================================================================== -// Integer types -// ====================================================================== - -/** - * longs have value-like semantics. - */ -template<> -struct ArgTraits<long> { - typedef ValueLike ValueCategory; -}; - -/** - * ints have value-like semantics. - */ -template<> -struct ArgTraits<int> { - typedef ValueLike ValueCategory; -}; - -/** - * shorts have value-like semantics. - */ -template<> -struct ArgTraits<short> { - typedef ValueLike ValueCategory; -}; - -/** - * chars have value-like semantics. - */ -template<> -struct ArgTraits<char> { - typedef ValueLike ValueCategory; -}; - -#ifdef HAVE_LONG_LONG -/** - * long longs have value-like semantics. - */ -template<> -struct ArgTraits<long long> { - typedef ValueLike ValueCategory; -}; -#endif - -// ====================================================================== -// Unsigned integer types -// ====================================================================== - -/** - * unsigned longs have value-like semantics. - */ -template<> -struct ArgTraits<unsigned long> { - typedef ValueLike ValueCategory; -}; - -/** - * unsigned ints have value-like semantics. - */ -template<> -struct ArgTraits<unsigned int> { - typedef ValueLike ValueCategory; -}; - -/** - * unsigned shorts have value-like semantics. - */ -template<> -struct ArgTraits<unsigned short> { - typedef ValueLike ValueCategory; -}; - -/** - * unsigned chars have value-like semantics. - */ -template<> -struct ArgTraits<unsigned char> { - typedef ValueLike ValueCategory; -}; - -// Microsoft implements size_t awkwardly. -#if defined(_MSC_VER) && defined(_M_X64) -/** - * size_ts have value-like semantics. - */ -template<> -struct ArgTraits<size_t> { - typedef ValueLike ValueCategory; -}; -#endif - - -#ifdef HAVE_LONG_LONG -/** - * unsigned long longs have value-like semantics. - */ -template<> -struct ArgTraits<unsigned long long> { - typedef ValueLike ValueCategory; -}; -#endif - -// ====================================================================== -// Float types -// ====================================================================== - -/** - * floats have value-like semantics. - */ -template<> -struct ArgTraits<float> { - typedef ValueLike ValueCategory; -}; - -/** - * doubles have value-like semantics. - */ -template<> -struct ArgTraits<double> { - typedef ValueLike ValueCategory; -}; - -// ====================================================================== -// Other types -// ====================================================================== - -/** - * bools have value-like semantics. - */ -template<> -struct ArgTraits<bool> { - typedef ValueLike ValueCategory; -}; - - -/** - * wchar_ts have value-like semantics. - */ -#ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS -template<> -struct ArgTraits<wchar_t> { - typedef ValueLike ValueCategory; -}; -#endif - -/** - * Strings have string like argument traits. - */ -template<> -struct ArgTraits<std::string> { - typedef StringLike ValueCategory; -}; - -template<typename T> -void SetString(T &dst, const std::string &src) -{ - dst = src; -} - -} // namespace - -#endif - diff --git a/ext/tclap/include/tclap/StdOutput.h b/ext/tclap/include/tclap/StdOutput.h deleted file mode 100644 index 944cff4d..00000000 --- a/ext/tclap/include/tclap/StdOutput.h +++ /dev/null @@ -1,299 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: StdOutput.h - * - * Copyright (c) 2004, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_STDCMDLINEOUTPUT_H -#define TCLAP_STDCMDLINEOUTPUT_H - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <algorithm> - -#include <tclap/CmdLineInterface.h> -#include <tclap/CmdLineOutput.h> -#include <tclap/XorHandler.h> -#include <tclap/Arg.h> - -namespace TCLAP { - -/** - * A class that isolates any output from the CmdLine object so that it - * may be easily modified. - */ -class StdOutput : public CmdLineOutput -{ - - public: - - /** - * Prints the usage to stdout. Can be overridden to - * produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c); - - /** - * Prints the version to stdout. Can be overridden - * to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c); - - /** - * Prints (to stderr) an error message, short usage - * Can be overridden to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure(CmdLineInterface& c, - ArgException& e ); - - protected: - - /** - * Writes a brief usage message with short args. - * \param c - The CmdLine object the output is generated for. - * \param os - The stream to write the message to. - */ - void _shortUsage( CmdLineInterface& c, std::ostream& os ) const; - - /** - * Writes a longer usage message with long and short args, - * provides descriptions and prints message. - * \param c - The CmdLine object the output is generated for. - * \param os - The stream to write the message to. - */ - void _longUsage( CmdLineInterface& c, std::ostream& os ) const; - - /** - * This function inserts line breaks and indents long strings - * according the params input. It will only break lines at spaces, - * commas and pipes. - * \param os - The stream to be printed to. - * \param s - The string to be printed. - * \param maxWidth - The maxWidth allowed for the output line. - * \param indentSpaces - The number of spaces to indent the first line. - * \param secondLineOffset - The number of spaces to indent the second - * and all subsequent lines in addition to indentSpaces. - */ - void spacePrint( std::ostream& os, - const std::string& s, - int maxWidth, - int indentSpaces, - int secondLineOffset ) const; - -}; - - -inline void StdOutput::version(CmdLineInterface& _cmd) -{ - std::string progName = _cmd.getProgramName(); - std::string xversion = _cmd.getVersion(); - - std::cout << std::endl << progName << " version: " - << xversion << std::endl << std::endl; -} - -inline void StdOutput::usage(CmdLineInterface& _cmd ) -{ - std::cout << std::endl << "USAGE: " << std::endl << std::endl; - - _shortUsage( _cmd, std::cout ); - - std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; - - _longUsage( _cmd, std::cout ); - - std::cout << std::endl; - -} - -inline void StdOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) -{ - std::string progName = _cmd.getProgramName(); - - std::cerr << "PARSE ERROR: " << e.argId() << std::endl - << " " << e.error() << std::endl << std::endl; - - if ( _cmd.hasHelpAndVersion() ) - { - std::cerr << "Brief USAGE: " << std::endl; - - _shortUsage( _cmd, std::cerr ); - - std::cerr << std::endl << "For complete USAGE and HELP type: " - << std::endl << " " << progName << " " - << Arg::nameStartString() << "help" - << std::endl << std::endl; - } - else - usage(_cmd); - - throw ExitException(1); -} - -inline void -StdOutput::_shortUsage( CmdLineInterface& _cmd, - std::ostream& os ) const -{ - std::list<Arg*> argList = _cmd.getArgList(); - std::string progName = _cmd.getProgramName(); - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); - - std::string s = progName + " "; - - // first the xor - for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) - { - s += " {"; - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); it++ ) - s += (*it)->shortID() + "|"; - - s[s.length()-1] = '}'; - } - - // then the rest - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - if ( !xorHandler.contains( (*it) ) ) - s += " " + (*it)->shortID(); - - // if the program name is too long, then adjust the second line offset - int secondLineOffset = static_cast<int>(progName.length()) + 2; - if ( secondLineOffset > 75/2 ) - secondLineOffset = static_cast<int>(75/2); - - spacePrint( os, s, 75, 3, secondLineOffset ); -} - -inline void -StdOutput::_longUsage( CmdLineInterface& _cmd, - std::ostream& os ) const -{ - std::list<Arg*> argList = _cmd.getArgList(); - std::string message = _cmd.getMessage(); - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); - - // first the xor - for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) - { - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); - it++ ) - { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - - if ( it+1 != xorList[i].end() ) - spacePrint(os, "-- OR --", 75, 9, 0); - } - os << std::endl << std::endl; - } - - // then the rest - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - if ( !xorHandler.contains( (*it) ) ) - { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - os << std::endl; - } - - os << std::endl; - - spacePrint( os, message, 75, 3, 0 ); -} - -inline void StdOutput::spacePrint( std::ostream& os, - const std::string& s, - int maxWidth, - int indentSpaces, - int secondLineOffset ) const -{ - int len = static_cast<int>(s.length()); - - if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) - { - int allowedLen = maxWidth - indentSpaces; - int start = 0; - while ( start < len ) - { - // find the substring length - // int stringLen = std::min<int>( len - start, allowedLen ); - // doing it this way to support a VisualC++ 2005 bug - using namespace std; - int stringLen = min<int>( len - start, allowedLen ); - - // trim the length so it doesn't end in middle of a word - if ( stringLen == allowedLen ) - while ( stringLen >= 0 && - s[stringLen+start] != ' ' && - s[stringLen+start] != ',' && - s[stringLen+start] != '|' ) - stringLen--; - - // ok, the word is longer than the line, so just split - // wherever the line ends - if ( stringLen <= 0 ) - stringLen = allowedLen; - - // check for newlines - for ( int i = 0; i < stringLen; i++ ) - if ( s[start+i] == '\n' ) - stringLen = i+1; - - // print the indent - for ( int i = 0; i < indentSpaces; i++ ) - os << " "; - - if ( start == 0 ) - { - // handle second line offsets - indentSpaces += secondLineOffset; - - // adjust allowed len - allowedLen -= secondLineOffset; - } - - os << s.substr(start,stringLen) << std::endl; - - // so we don't start a line with a space - while ( s[stringLen+start] == ' ' && start < len ) - start++; - - start += stringLen; - } - } - else - { - for ( int i = 0; i < indentSpaces; i++ ) - os << " "; - os << s << std::endl; - } -} - -} //namespace TCLAP -#endif diff --git a/ext/tclap/include/tclap/SwitchArg.h b/ext/tclap/include/tclap/SwitchArg.h deleted file mode 100644 index 39161090..00000000 --- a/ext/tclap/include/tclap/SwitchArg.h +++ /dev/null @@ -1,266 +0,0 @@ - -/****************************************************************************** - * - * file: SwitchArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_SWITCH_ARG_H -#define TCLAP_SWITCH_ARG_H - -#include <string> -#include <vector> - -#include <tclap/Arg.h> - -namespace TCLAP { - -/** - * A simple switch argument. If the switch is set on the command line, then - * the getValue method will return the opposite of the default value for the - * switch. - */ -class SwitchArg : public Arg -{ - protected: - - /** - * The value of the switch. - */ - bool _value; - - /** - * Used to support the reset() method so that ValueArg can be - * reset to their constructed value. - */ - bool _default; - - public: - - /** - * SwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param def - The default value for this Switch. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool def = false, - Visitor* v = NULL); - - - /** - * SwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param parser - A CmdLine parser object to add this Arg to - * \param def - The default value for this Switch. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - bool def = false, - Visitor* v = NULL); - - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed - * in from main(). - */ - virtual bool processArg(int* i, std::vector<std::string>& args); - - /** - * Checks a string to see if any of the chars in the string - * match the flag for this Switch. - */ - bool combinedSwitchesMatch(std::string& combined); - - /** - * Returns bool, whether or not the switch has been set. - */ - bool getValue(); - - virtual void reset(); - - private: - /** - * Checks to see if we've found the last match in - * a combined string. - */ - bool lastCombined(std::string& combined); - - /** - * Does the common processing of processArg. - */ - void commonProcessing(); -}; - -////////////////////////////////////////////////////////////////////// -//BEGIN SwitchArg.cpp -////////////////////////////////////////////////////////////////////// -inline SwitchArg::SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool default_val, - Visitor* v ) -: Arg(flag, name, desc, false, false, v), - _value( default_val ), - _default( default_val ) -{ } - -inline SwitchArg::SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - bool default_val, - Visitor* v ) -: Arg(flag, name, desc, false, false, v), - _value( default_val ), - _default(default_val) -{ - parser.add( this ); -} - -inline bool SwitchArg::getValue() { return _value; } - -inline bool SwitchArg::lastCombined(std::string& combinedSwitches ) -{ - for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) - if ( combinedSwitches[i] != Arg::blankChar() ) - return false; - - return true; -} - -inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) -{ - // make sure this is actually a combined switch - if ( combinedSwitches.length() > 0 && - combinedSwitches[0] != Arg::flagStartString()[0] ) - return false; - - // make sure it isn't a long name - if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == - Arg::nameStartString() ) - return false; - - // make sure the delimiter isn't in the string - if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos ) - return false; - - // ok, we're not specifying a ValueArg, so we know that we have - // a combined switch list. - for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) - if ( _flag.length() > 0 && - combinedSwitches[i] == _flag[0] && - _flag[0] != Arg::flagStartString()[0] ) - { - // update the combined switches so this one is no longer present - // this is necessary so that no unlabeled args are matched - // later in the processing. - //combinedSwitches.erase(i,1); - combinedSwitches[i] = Arg::blankChar(); - return true; - } - - // none of the switches passed in the list match. - return false; -} - -inline void SwitchArg::commonProcessing() -{ - if ( _xorSet ) - throw(CmdLineParseException( - "Mutually exclusive argument already set!", toString())); - - if ( _alreadySet ) - throw(CmdLineParseException("Argument already set!", toString())); - - _alreadySet = true; - - if ( _value == true ) - _value = false; - else - _value = true; - - _checkWithVisitor(); -} - -inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - // if the whole string matches the flag or name string - if ( argMatches( args[*i] ) ) - { - commonProcessing(); - - return true; - } - // if a substring matches the flag as part of a combination - else if ( combinedSwitchesMatch( args[*i] ) ) - { - // check again to ensure we don't misinterpret - // this as a MultiSwitchArg - if ( combinedSwitchesMatch( args[*i] ) ) - throw(CmdLineParseException("Argument already set!", - toString())); - - commonProcessing(); - - // We only want to return true if we've found the last combined - // match in the string, otherwise we return true so that other - // switches in the combination will have a chance to match. - return lastCombined( args[*i] ); - } - else - return false; -} - -inline void SwitchArg::reset() -{ - Arg::reset(); - _value = _default; -} -////////////////////////////////////////////////////////////////////// -//End SwitchArg.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif diff --git a/ext/tclap/include/tclap/UnlabeledMultiArg.h b/ext/tclap/include/tclap/UnlabeledMultiArg.h deleted file mode 100644 index d5e17810..00000000 --- a/ext/tclap/include/tclap/UnlabeledMultiArg.h +++ /dev/null @@ -1,301 +0,0 @@ - -/****************************************************************************** - * - * file: UnlabeledMultiArg.h - * - * Copyright (c) 2003, Michael E. Smoot. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H -#define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H - -#include <string> -#include <vector> - -#include <tclap/MultiArg.h> -#include <tclap/OptionalUnlabeledTracker.h> - -namespace TCLAP { - -/** - * Just like a MultiArg, except that the arguments are unlabeled. Basically, - * this Arg will slurp up everything that hasn't been matched to another - * Arg. - */ -template<class T> -class UnlabeledMultiArg : public MultiArg<T> -{ - - // If compiler has two stage name lookup (as gcc >= 3.4 does) - // this is requried to prevent undef. symbols - using MultiArg<T>::_ignoreable; - using MultiArg<T>::_hasBlanks; - using MultiArg<T>::_extractValue; - using MultiArg<T>::_typeDesc; - using MultiArg<T>::_name; - using MultiArg<T>::_description; - using MultiArg<T>::_alreadySet; - using MultiArg<T>::toString; - - public: - - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - bool ignoreable = false, - Visitor* v = NULL ); - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. It knows the difference - * between labeled and unlabeled. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed from main(). - */ - virtual bool processArg(int* i, std::vector<std::string>& args); - - /** - * Returns the a short id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string shortID(const std::string& val="val") const; - - /** - * Returns the a long id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string longID(const std::string& val="val") const; - - /** - * Opertor ==. - * \param a - The Arg to be compared to this. - */ - virtual bool operator==(const Arg& a) const; - - /** - * Pushes this to back of list rather than front. - * \param argList - The list this should be added to. - */ - virtual void addToList( std::list<Arg*>& argList ) const; -}; - -template<class T> -UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - bool ignoreable, - Visitor* v) -: MultiArg<T>("", name, desc, req, typeDesc, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); -} - -template<class T> -UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: MultiArg<T>("", name, desc, req, typeDesc, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); - parser.add( this ); -} - - -template<class T> -UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - bool ignoreable, - Visitor* v) -: MultiArg<T>("", name, desc, req, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); -} - -template<class T> -UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - Constraint<T>* constraint, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: MultiArg<T>("", name, desc, req, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); - parser.add( this ); -} - - -template<class T> -bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args) -{ - - if ( _hasBlanks( args[*i] ) ) - return false; - - // never ignore an unlabeled multi arg - - - // always take the first value, regardless of the start string - _extractValue( args[(*i)] ); - - /* - // continue taking args until we hit the end or a start string - while ( (unsigned int)(*i)+1 < args.size() && - args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && - args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) - _extractValue( args[++(*i)] ); - */ - - _alreadySet = true; - - return true; -} - -template<class T> -std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - return std::string("<") + _typeDesc + "> ..."; -} - -template<class T> -std::string UnlabeledMultiArg<T>::longID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - return std::string("<") + _typeDesc + "> (accepted multiple times)"; -} - -template<class T> -bool UnlabeledMultiArg<T>::operator==(const Arg& a) const -{ - if ( _name == a.getName() || _description == a.getDescription() ) - return true; - else - return false; -} - -template<class T> -void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const -{ - argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) ); -} - -} - -#endif diff --git a/ext/tclap/include/tclap/UnlabeledValueArg.h b/ext/tclap/include/tclap/UnlabeledValueArg.h deleted file mode 100644 index 5721d612..00000000 --- a/ext/tclap/include/tclap/UnlabeledValueArg.h +++ /dev/null @@ -1,340 +0,0 @@ - -/****************************************************************************** - * - * file: UnlabeledValueArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H -#define TCLAP_UNLABELED_VALUE_ARGUMENT_H - -#include <string> -#include <vector> - -#include <tclap/ValueArg.h> -#include <tclap/OptionalUnlabeledTracker.h> - - -namespace TCLAP { - -/** - * The basic unlabeled argument that parses a value. - * This is a template class, which means the type T defines the type - * that a given object will attempt to parse when an UnlabeledValueArg - * is reached in the list of args that the CmdLine iterates over. - */ -template<class T> -class UnlabeledValueArg : public ValueArg<T> -{ - - // If compiler has two stage name lookup (as gcc >= 3.4 does) - // this is requried to prevent undef. symbols - using ValueArg<T>::_ignoreable; - using ValueArg<T>::_hasBlanks; - using ValueArg<T>::_extractValue; - using ValueArg<T>::_typeDesc; - using ValueArg<T>::_name; - using ValueArg<T>::_description; - using ValueArg<T>::_alreadySet; - using ValueArg<T>::toString; - - public: - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - bool ignoreable = false, - Visitor* v = NULL); - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint<T>* constraint, - bool ignoreable = false, - Visitor* v = NULL ); - - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint<T>* constraint, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. Handling specific to - * unlabled arguments. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. - */ - virtual bool processArg(int* i, std::vector<std::string>& args); - - /** - * Overrides shortID for specific behavior. - */ - virtual std::string shortID(const std::string& val="val") const; - - /** - * Overrides longID for specific behavior. - */ - virtual std::string longID(const std::string& val="val") const; - - /** - * Overrides operator== for specific behavior. - */ - virtual bool operator==(const Arg& a ) const; - - /** - * Instead of pushing to the front of list, push to the back. - * \param argList - The list to add this to. - */ - virtual void addToList( std::list<Arg*>& argList ) const; - -}; - -/** - * Constructor implemenation. - */ -template<class T> -UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - bool ignoreable, - Visitor* v) -: ValueArg<T>("", name, desc, req, val, typeDesc, v) -{ - _ignoreable = ignoreable; - - OptionalUnlabeledTracker::check(req, toString()); - -} - -template<class T> -UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: ValueArg<T>("", name, desc, req, val, typeDesc, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(req, toString()); - parser.add( this ); -} - -/** - * Constructor implemenation. - */ -template<class T> -UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint<T>* constraint, - bool ignoreable, - Visitor* v) -: ValueArg<T>("", name, desc, req, val, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(req, toString()); -} - -template<class T> -UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint<T>* constraint, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: ValueArg<T>("", name, desc, req, val, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(req, toString()); - parser.add( this ); -} - -/** - * Implementation of processArg(). - */ -template<class T> -bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args) -{ - - if ( _alreadySet ) - return false; - - if ( _hasBlanks( args[*i] ) ) - return false; - - // never ignore an unlabeled arg - - _extractValue( args[*i] ); - _alreadySet = true; - return true; -} - -/** - * Overriding shortID for specific output. - */ -template<class T> -std::string UnlabeledValueArg<T>::shortID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - return std::string("<") + _typeDesc + ">"; -} - -/** - * Overriding longID for specific output. - */ -template<class T> -std::string UnlabeledValueArg<T>::longID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - - // Ideally we would like to be able to use RTTI to return the name - // of the type required for this argument. However, g++ at least, - // doesn't appear to return terribly useful "names" of the types. - return std::string("<") + _typeDesc + ">"; -} - -/** - * Overriding operator== for specific behavior. - */ -template<class T> -bool UnlabeledValueArg<T>::operator==(const Arg& a ) const -{ - if ( _name == a.getName() || _description == a.getDescription() ) - return true; - else - return false; -} - -template<class T> -void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const -{ - argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) ); -} - -} -#endif diff --git a/ext/tclap/include/tclap/ValueArg.h b/ext/tclap/include/tclap/ValueArg.h deleted file mode 100644 index 7ac29526..00000000 --- a/ext/tclap/include/tclap/ValueArg.h +++ /dev/null @@ -1,425 +0,0 @@ -/****************************************************************************** - * - * file: ValueArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_VALUE_ARGUMENT_H -#define TCLAP_VALUE_ARGUMENT_H - -#include <string> -#include <vector> - -#include <tclap/Arg.h> -#include <tclap/Constraint.h> - -namespace TCLAP { - -/** - * The basic labeled argument that parses a value. - * This is a template class, which means the type T defines the type - * that a given object will attempt to parse when the flag/name is matched - * on the command line. While there is nothing stopping you from creating - * an unflagged ValueArg, it is unwise and would cause significant problems. - * Instead use an UnlabeledValueArg. - */ -template<class T> -class ValueArg : public Arg -{ - protected: - - /** - * The value parsed from the command line. - * Can be of any type, as long as the >> operator for the type - * is defined. - */ - T _value; - - /** - * Used to support the reset() method so that ValueArg can be - * reset to their constructed value. - */ - T _default; - - /** - * A human readable description of the type to be parsed. - * This is a hack, plain and simple. Ideally we would use RTTI to - * return the name of type T, but until there is some sort of - * consistent support for human readable names, we are left to our - * own devices. - */ - std::string _typeDesc; - - /** - * A Constraint this Arg must conform to. - */ - Constraint<T>* _constraint; - - /** - * Extracts the value from the string. - * Attempts to parse string as type T, if this fails an exception - * is thrown. - * \param val - value to be parsed. - */ - void _extractValue( const std::string& val ); - - public: - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - Visitor* v = NULL); - - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint<T>* constraint, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint<T>* constraint, - Visitor* v = NULL ); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. It knows the difference - * between labeled and unlabeled. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed - * in from main(). - */ - virtual bool processArg(int* i, std::vector<std::string>& args); - - /** - * Returns the value of the argument. - */ - T& getValue() ; - - /** - * Specialization of shortID. - * \param val - value to be used. - */ - virtual std::string shortID(const std::string& val = "val") const; - - /** - * Specialization of longID. - * \param val - value to be used. - */ - virtual std::string longID(const std::string& val = "val") const; - - virtual void reset() ; - -private: - /** - * Prevent accidental copying - */ - ValueArg<T>(const ValueArg<T>& rhs); - ValueArg<T>& operator=(const ValueArg<T>& rhs); -}; - - -/** - * Constructor implementation. - */ -template<class T> -ValueArg<T>::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( typeDesc ), - _constraint( NULL ) -{ } - -template<class T> -ValueArg<T>::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( typeDesc ), - _constraint( NULL ) -{ - parser.add( this ); -} - -template<class T> -ValueArg<T>::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint<T>* constraint, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( constraint->shortID() ), - _constraint( constraint ) -{ } - -template<class T> -ValueArg<T>::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint<T>* constraint, - CmdLineInterface& parser, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( constraint->shortID() ), - _constraint( constraint ) -{ - parser.add( this ); -} - - -/** - * Implementation of getValue(). - */ -template<class T> -T& ValueArg<T>::getValue() { return _value; } - -/** - * Implementation of processArg(). - */ -template<class T> -bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - if ( _hasBlanks( args[*i] ) ) - return false; - - std::string flag = args[*i]; - - std::string value = ""; - trimFlag( flag, value ); - - if ( argMatches( flag ) ) - { - if ( _alreadySet ) - { - if ( _xorSet ) - throw( CmdLineParseException( - "Mutually exclusive argument already set!", - toString()) ); - else - throw( CmdLineParseException("Argument already set!", - toString()) ); - } - - if ( Arg::delimiter() != ' ' && value == "" ) - throw( ArgParseException( - "Couldn't find delimiter for this argument!", - toString() ) ); - - if ( value == "" ) - { - (*i)++; - if ( static_cast<unsigned int>(*i) < args.size() ) - _extractValue( args[*i] ); - else - throw( ArgParseException("Missing a value for this argument!", - toString() ) ); - } - else - _extractValue( value ); - - _alreadySet = true; - _checkWithVisitor(); - return true; - } - else - return false; -} - -/** - * Implementation of shortID. - */ -template<class T> -std::string ValueArg<T>::shortID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - return Arg::shortID( _typeDesc ); -} - -/** - * Implementation of longID. - */ -template<class T> -std::string ValueArg<T>::longID(const std::string& val) const -{ - static_cast<void>(val); // Ignore input, don't warn - return Arg::longID( _typeDesc ); -} - -template<class T> -void ValueArg<T>::_extractValue( const std::string& val ) -{ - try { - ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory()); - } catch( ArgParseException &e) { - throw ArgParseException(e.error(), toString()); - } - - if ( _constraint != NULL ) - if ( ! _constraint->check( _value ) ) - throw( CmdLineParseException( "Value '" + val + - + "' does not meet constraint: " - + _constraint->description(), - toString() ) ); -} - -template<class T> -void ValueArg<T>::reset() -{ - Arg::reset(); - _value = _default; -} - -} // namespace TCLAP - -#endif diff --git a/ext/tclap/include/tclap/ValuesConstraint.h b/ext/tclap/include/tclap/ValuesConstraint.h deleted file mode 100644 index cb41f645..00000000 --- a/ext/tclap/include/tclap/ValuesConstraint.h +++ /dev/null @@ -1,148 +0,0 @@ - - -/****************************************************************************** - * - * file: ValuesConstraint.h - * - * Copyright (c) 2005, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_VALUESCONSTRAINT_H -#define TCLAP_VALUESCONSTRAINT_H - -#include <string> -#include <vector> -#include <tclap/Constraint.h> - -#ifdef HAVE_CONFIG_H -#include <config.h> -#else -#define HAVE_SSTREAM -#endif - -#if defined(HAVE_SSTREAM) -#include <sstream> -#elif defined(HAVE_STRSTREAM) -#include <strstream> -#else -#error "Need a stringstream (sstream or strstream) to compile!" -#endif - -namespace TCLAP { - -/** - * A Constraint that constrains the Arg to only those values specified - * in the constraint. - */ -template<class T> -class ValuesConstraint : public Constraint<T> -{ - - public: - - /** - * Constructor. - * \param allowed - vector of allowed values. - */ - ValuesConstraint(std::vector<T>& allowed); - - /** - * Virtual destructor. - */ - virtual ~ValuesConstraint() {} - - /** - * Returns a description of the Constraint. - */ - virtual std::string description() const; - - /** - * Returns the short ID for the Constraint. - */ - virtual std::string shortID() const; - - /** - * The method used to verify that the value parsed from the command - * line meets the constraint. - * \param value - The value that will be checked. - */ - virtual bool check(const T& value) const; - - protected: - - /** - * The list of valid values. - */ - std::vector<T> _allowed; - - /** - * The string used to describe the allowed values of this constraint. - */ - std::string _typeDesc; - -}; - -template<class T> -ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed) -: _allowed(allowed), - _typeDesc("") -{ - for ( unsigned int i = 0; i < _allowed.size(); i++ ) - { - -#if defined(HAVE_SSTREAM) - std::ostringstream os; -#elif defined(HAVE_STRSTREAM) - std::ostrstream os; -#else -#error "Need a stringstream (sstream or strstream) to compile!" -#endif - - os << _allowed[i]; - - std::string temp( os.str() ); - - if ( i > 0 ) - _typeDesc += "|"; - _typeDesc += temp; - } -} - -template<class T> -bool ValuesConstraint<T>::check( const T& val ) const -{ - if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() ) - return false; - else - return true; -} - -template<class T> -std::string ValuesConstraint<T>::shortID() const -{ - return _typeDesc; -} - -template<class T> -std::string ValuesConstraint<T>::description() const -{ - return _typeDesc; -} - - -} //namespace TCLAP -#endif - diff --git a/ext/tclap/include/tclap/VersionVisitor.h b/ext/tclap/include/tclap/VersionVisitor.h deleted file mode 100644 index c110d4fa..00000000 --- a/ext/tclap/include/tclap/VersionVisitor.h +++ /dev/null @@ -1,81 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: VersionVisitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_VERSION_VISITOR_H -#define TCLAP_VERSION_VISITOR_H - -#include <tclap/CmdLineInterface.h> -#include <tclap/CmdLineOutput.h> -#include <tclap/Visitor.h> - -namespace TCLAP { - -/** - * A Vistor that will call the version method of the given CmdLineOutput - * for the specified CmdLine object and then exit. - */ -class VersionVisitor: public Visitor -{ - private: - /** - * Prevent accidental copying - */ - VersionVisitor(const VersionVisitor& rhs); - VersionVisitor& operator=(const VersionVisitor& rhs); - - protected: - - /** - * The CmdLine of interest. - */ - CmdLineInterface* _cmd; - - /** - * The output object. - */ - CmdLineOutput** _out; - - public: - - /** - * Constructor. - * \param cmd - The CmdLine the output is generated for. - * \param out - The type of output. - */ - VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) - : Visitor(), _cmd( cmd ), _out( out ) { } - - /** - * Calls the version method of the output object using the - * specified CmdLine. - */ - void visit() { - (*_out)->version(*_cmd); - throw ExitException(0); - } - -}; - -} - -#endif diff --git a/ext/tclap/include/tclap/Visitor.h b/ext/tclap/include/tclap/Visitor.h deleted file mode 100644 index 38ddcbdb..00000000 --- a/ext/tclap/include/tclap/Visitor.h +++ /dev/null @@ -1,53 +0,0 @@ - -/****************************************************************************** - * - * file: Visitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_VISITOR_H -#define TCLAP_VISITOR_H - -namespace TCLAP { - -/** - * A base class that defines the interface for visitors. - */ -class Visitor -{ - public: - - /** - * Constructor. Does nothing. - */ - Visitor() { } - - /** - * Destructor. Does nothing. - */ - virtual ~Visitor() { } - - /** - * Does nothing. Should be overridden by child. - */ - virtual void visit() { } -}; - -} - -#endif diff --git a/ext/tclap/include/tclap/XorHandler.h b/ext/tclap/include/tclap/XorHandler.h deleted file mode 100644 index d9dfad31..00000000 --- a/ext/tclap/include/tclap/XorHandler.h +++ /dev/null @@ -1,166 +0,0 @@ - -/****************************************************************************** - * - * file: XorHandler.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_XORHANDLER_H -#define TCLAP_XORHANDLER_H - -#include <tclap/Arg.h> -#include <string> -#include <vector> -#include <algorithm> -#include <iostream> - -namespace TCLAP { - -/** - * This class handles lists of Arg's that are to be XOR'd on the command - * line. This is used by CmdLine and you shouldn't ever use it. - */ -class XorHandler -{ - protected: - - /** - * The list of of lists of Arg's to be or'd together. - */ - std::vector< std::vector<Arg*> > _orList; - - public: - - /** - * Constructor. Does nothing. - */ - XorHandler( ) : _orList(std::vector< std::vector<Arg*> >()) {} - - /** - * Add a list of Arg*'s that will be orred together. - * \param ors - list of Arg* that will be xor'd. - */ - void add( std::vector<Arg*>& ors ); - - /** - * Checks whether the specified Arg is in one of the xor lists and - * if it does match one, returns the size of the xor list that the - * Arg matched. If the Arg matches, then it also sets the rest of - * the Arg's in the list. You shouldn't use this. - * \param a - The Arg to be checked. - */ - int check( const Arg* a ); - - /** - * Returns the XOR specific short usage. - */ - std::string shortUsage(); - - /** - * Prints the XOR specific long usage. - * \param os - Stream to print to. - */ - void printLongUsage(std::ostream& os); - - /** - * Simply checks whether the Arg is contained in one of the arg - * lists. - * \param a - The Arg to be checked. - */ - bool contains( const Arg* a ); - - std::vector< std::vector<Arg*> >& getXorList(); - -}; - - -////////////////////////////////////////////////////////////////////// -//BEGIN XOR.cpp -////////////////////////////////////////////////////////////////////// -inline void XorHandler::add( std::vector<Arg*>& ors ) -{ - _orList.push_back( ors ); -} - -inline int XorHandler::check( const Arg* a ) -{ - // iterate over each XOR list - for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ ) - { - // if the XOR list contains the arg.. - ArgVectorIterator ait = std::find( _orList[i].begin(), - _orList[i].end(), a ); - if ( ait != _orList[i].end() ) - { - // first check to see if a mutually exclusive switch - // has not already been set - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); - it++ ) - if ( a != (*it) && (*it)->isSet() ) - throw(CmdLineParseException( - "Mutually exclusive argument already set!", - (*it)->toString())); - - // go through and set each arg that is not a - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); - it++ ) - if ( a != (*it) ) - (*it)->xorSet(); - - // return the number of required args that have now been set - if ( (*ait)->allowMore() ) - return 0; - else - return static_cast<int>(_orList[i].size()); - } - } - - if ( a->isRequired() ) - return 1; - else - return 0; -} - -inline bool XorHandler::contains( const Arg* a ) -{ - for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ ) - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); - it++ ) - if ( a == (*it) ) - return true; - - return false; -} - -inline std::vector< std::vector<Arg*> >& XorHandler::getXorList() -{ - return _orList; -} - - - -////////////////////////////////////////////////////////////////////// -//END XOR.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif diff --git a/ext/tclap/include/tclap/ZshCompletionOutput.h b/ext/tclap/include/tclap/ZshCompletionOutput.h deleted file mode 100644 index 0b37fc72..00000000 --- a/ext/tclap/include/tclap/ZshCompletionOutput.h +++ /dev/null @@ -1,323 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: ZshCompletionOutput.h - * - * Copyright (c) 2006, Oliver Kiddle - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H -#define TCLAP_ZSHCOMPLETIONOUTPUT_H - -#include <string> -#include <vector> -#include <list> -#include <iostream> -#include <map> - -#include <tclap/CmdLineInterface.h> -#include <tclap/CmdLineOutput.h> -#include <tclap/XorHandler.h> -#include <tclap/Arg.h> - -namespace TCLAP { - -/** - * A class that generates a Zsh completion function as output from the usage() - * method for the given CmdLine and its Args. - */ -class ZshCompletionOutput : public CmdLineOutput -{ - - public: - - ZshCompletionOutput(); - - /** - * Prints the usage to stdout. Can be overridden to - * produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c); - - /** - * Prints the version to stdout. Can be overridden - * to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c); - - /** - * Prints (to stderr) an error message, short usage - * Can be overridden to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure(CmdLineInterface& c, - ArgException& e ); - - protected: - - void basename( std::string& s ); - void quoteSpecialChars( std::string& s ); - - std::string getMutexList( CmdLineInterface& _cmd, Arg* a ); - void printOption( Arg* it, std::string mutex ); - void printArg( Arg* it ); - - std::map<std::string, std::string> common; - char theDelimiter; -}; - -ZshCompletionOutput::ZshCompletionOutput() -: common(std::map<std::string, std::string>()), - theDelimiter('=') -{ - common["host"] = "_hosts"; - common["hostname"] = "_hosts"; - common["file"] = "_files"; - common["filename"] = "_files"; - common["user"] = "_users"; - common["username"] = "_users"; - common["directory"] = "_directories"; - common["path"] = "_directories"; - common["url"] = "_urls"; -} - -inline void ZshCompletionOutput::version(CmdLineInterface& _cmd) -{ - std::cout << _cmd.getVersion() << std::endl; -} - -inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd ) -{ - std::list<Arg*> argList = _cmd.getArgList(); - std::string progName = _cmd.getProgramName(); - std::string xversion = _cmd.getVersion(); - theDelimiter = _cmd.getDelimiter(); - basename(progName); - - std::cout << "#compdef " << progName << std::endl << std::endl << - "# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl << - "_arguments -s -S"; - - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - { - if ( (*it)->shortID().at(0) == '<' ) - printArg((*it)); - else if ( (*it)->getFlag() != "-" ) - printOption((*it), getMutexList(_cmd, *it)); - } - - std::cout << std::endl; -} - -inline void ZshCompletionOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) -{ - static_cast<void>(_cmd); // unused - std::cout << e.what() << std::endl; -} - -inline void ZshCompletionOutput::quoteSpecialChars( std::string& s ) -{ - size_t idx = s.find_last_of(':'); - while ( idx != std::string::npos ) - { - s.insert(idx, 1, '\\'); - idx = s.find_last_of(':', idx); - } - idx = s.find_last_of('\''); - while ( idx != std::string::npos ) - { - s.insert(idx, "'\\'"); - if (idx == 0) - idx = std::string::npos; - else - idx = s.find_last_of('\'', --idx); - } -} - -inline void ZshCompletionOutput::basename( std::string& s ) -{ - size_t p = s.find_last_of('/'); - if ( p != std::string::npos ) - { - s.erase(0, p + 1); - } -} - -inline void ZshCompletionOutput::printArg(Arg* a) -{ - static int count = 1; - - std::cout << " \\" << std::endl << " '"; - if ( a->acceptsMultipleValues() ) - std::cout << '*'; - else - std::cout << count++; - std::cout << ':'; - if ( !a->isRequired() ) - std::cout << ':'; - - std::cout << a->getName() << ':'; - std::map<std::string, std::string>::iterator compArg = common.find(a->getName()); - if ( compArg != common.end() ) - { - std::cout << compArg->second; - } - else - { - std::cout << "_guard \"^-*\" " << a->getName(); - } - std::cout << '\''; -} - -inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex) -{ - std::string flag = a->flagStartChar() + a->getFlag(); - std::string name = a->nameStartString() + a->getName(); - std::string desc = a->getDescription(); - - // remove full stop and capitalisation from description as - // this is the convention for zsh function - if (!desc.compare(0, 12, "(required) ")) - { - desc.erase(0, 12); - } - if (!desc.compare(0, 15, "(OR required) ")) - { - desc.erase(0, 15); - } - size_t len = desc.length(); - if (len && desc.at(--len) == '.') - { - desc.erase(len); - } - if (len) - { - desc.replace(0, 1, 1, tolower(desc.at(0))); - } - - std::cout << " \\" << std::endl << " '" << mutex; - - if ( a->getFlag().empty() ) - { - std::cout << name; - } - else - { - std::cout << "'{" << flag << ',' << name << "}'"; - } - if ( theDelimiter == '=' && a->isValueRequired() ) - std::cout << "=-"; - quoteSpecialChars(desc); - std::cout << '[' << desc << ']'; - - if ( a->isValueRequired() ) - { - std::string arg = a->shortID(); - arg.erase(0, arg.find_last_of(theDelimiter) + 1); - if ( arg.at(arg.length()-1) == ']' ) - arg.erase(arg.length()-1); - if ( arg.at(arg.length()-1) == ']' ) - { - arg.erase(arg.length()-1); - } - if ( arg.at(0) == '<' ) - { - arg.erase(arg.length()-1); - arg.erase(0, 1); - } - size_t p = arg.find('|'); - if ( p != std::string::npos ) - { - do - { - arg.replace(p, 1, 1, ' '); - } - while ( (p = arg.find_first_of('|', p)) != std::string::npos ); - quoteSpecialChars(arg); - std::cout << ": :(" << arg << ')'; - } - else - { - std::cout << ':' << arg; - std::map<std::string, std::string>::iterator compArg = common.find(arg); - if ( compArg != common.end() ) - { - std::cout << ':' << compArg->second; - } - } - } - - std::cout << '\''; -} - -inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Arg* a) -{ - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); - - if (a->getName() == "help" || a->getName() == "version") - { - return "(-)"; - } - - std::ostringstream list; - if ( a->acceptsMultipleValues() ) - { - list << '*'; - } - - for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) - { - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); - it++) - if ( a == (*it) ) - { - list << '('; - for ( ArgVectorIterator iu = xorList[i].begin(); - iu != xorList[i].end(); - iu++ ) - { - bool notCur = (*iu) != a; - bool hasFlag = !(*iu)->getFlag().empty(); - if ( iu != xorList[i].begin() && (notCur || hasFlag) ) - list << ' '; - if (hasFlag) - list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' '; - if ( notCur || hasFlag ) - list << (*iu)->nameStartString() << (*iu)->getName(); - } - list << ')'; - return list.str(); - } - } - - // wasn't found in xor list - if (!a->getFlag().empty()) { - list << "(" << a->flagStartChar() << a->getFlag() << ' ' << - a->nameStartString() << a->getName() << ')'; - } - - return list.str(); -} - -} //namespace TCLAP -#endif diff --git a/ext/tinyopt/LICENSE b/ext/tinyopt/LICENSE new file mode 100644 index 00000000..a6e2baeb --- /dev/null +++ b/ext/tinyopt/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2019, Stuart Yates +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ext/tinyopt/include/tinyopt/common.h b/ext/tinyopt/include/tinyopt/common.h new file mode 100644 index 00000000..fb4a654b --- /dev/null +++ b/ext/tinyopt/include/tinyopt/common.h @@ -0,0 +1,192 @@ +#pragma once + +#include <algorithm> +#include <cstddef> +#include <cstring> +#include <iomanip> +#include <iostream> +#include <iterator> +#include <sstream> +#include <string> +#include <utility> +#include <vector> + +#include <tinyopt/maybe.h> + +namespace to { + +// `option_error` is the base class for exceptions thrown +// by the option handling functions. + +struct option_error: public std::runtime_error { + option_error(const std::string& message): std::runtime_error(message) {} + option_error(const std::string& message, std::string arg): + std::runtime_error(message+": "+arg), arg(std::move(arg)) {} + + std::string arg; +}; + +struct option_parse_error: option_error { + option_parse_error(const std::string &arg): + option_error("option parse error", arg) {} +}; + +struct missing_mandatory_option: option_error { + missing_mandatory_option(const std::string &arg): + option_error("missing mandatory option", arg) {} +}; + +struct missing_argument: option_error { + missing_argument(const std::string &arg): + option_error("option misssing argument", arg) {} +}; + +struct user_option_error: option_error { + user_option_error(const std::string &arg): + option_error(arg) {} +}; + +// `usage` prints usage information to stdout (no error message) +// or to stderr (with error message). It extracts the program basename +// from the provided argv[0] string. + +inline void usage(const char* argv0, const std::string& usage_str) { + const char* basename = std::strrchr(argv0, '/'); + basename = basename? basename+1: argv0; + + std::cout << "Usage: " << basename << " " << usage_str << "\n"; +} + +inline void usage(const char* argv0, const std::string& usage_str, const std::string& parse_err) { + const char* basename = std::strrchr(argv0, '/'); + basename = basename? basename+1: argv0; + + std::cerr << basename << ": " << parse_err << "\n"; + std::cerr << "Usage: " << basename << " " << usage_str << "\n"; +} + +// Parser objects act as functionals, taking +// a const char* argument and returning maybe<T> +// for some T. + +template <typename V> +struct default_parser { + maybe<V> operator()(const char* text) const { + if (!text) return nothing; + V v; + std::istringstream stream(text); + stream >> v >> std::ws; + return stream && stream.get()==EOF? maybe<V>(v): nothing; + } +}; + +template <> +struct default_parser<const char*> { + maybe<const char*> operator()(const char* text) const { + return just(text); + } +}; + +template <> +struct default_parser<std::string> { + maybe<std::string> operator()(const char* text) const { + return just(std::string(text)); + } +}; + +template <> +struct default_parser<void> { + maybe<void> operator()(const char* text) const { + return something; + } +}; + +template <typename V> +class keyword_parser { + std::vector<std::pair<std::string, V>> map_; + +public: + template <typename KeywordPairs> + keyword_parser(const KeywordPairs& pairs) { + using std::begin; + using std::end; + map_.assign(begin(pairs), end(pairs)); + } + + maybe<V> operator()(const char* text) const { + if (!text) return nothing; + for (const auto& p: map_) { + if (text==p.first) return p.second; + } + return nothing; + } +}; + +// Returns a parser that matches a set of keywords, +// returning the corresponding values in the supplied +// pairs. + +template <typename KeywordPairs> +auto keywords(const KeywordPairs& pairs) { + using std::begin; + using value_type = std::decay_t<decltype(std::get<1>(*begin(pairs)))>; + return keyword_parser<value_type>(pairs); +} + + +// A parser for delimited sequences of values; returns +// a vector of the values obtained from the supplied +// per-item parser. + +template <typename P> +class delimited_parser { + char delim_; + P parse_; + using inner_value_type = std::decay_t<decltype(*std::declval<P>()(""))>; + +public: + template <typename Q> + delimited_parser(char delim, Q&& parse): delim_(delim), parse_(std::forward<Q>(parse)) {} + + maybe<std::vector<inner_value_type>> operator()(const char* text) const { + if (!text) return nothing; + + std::vector<inner_value_type> values; + if (!*text) return values; + + std::size_t n = std::strlen(text); + std::vector<char> input(1+n); + std::copy(text, text+n, input.data()); + + char* p = input.data(); + char* end = input.data()+1+n; + do { + char* q = p; + while (*q && *q!=delim_) ++q; + *q++ = 0; + + if (auto mv = parse_(p)) values.push_back(*mv); + else return nothing; + + p = q; + } while (p<end); + + return values; + } +}; + +// Convenience constructors for delimited parser. + +template <typename Q> +auto delimited(char delim, Q&& parse) { + using P = std::decay_t<Q>; + return delimited_parser<P>(delim, std::forward<Q>(parse)); +} + +template <typename V> +auto delimited(char delim = ',') { + return delimited(delim, default_parser<V>{}); +} + + +} // namespace to diff --git a/ext/tinyopt/include/tinyopt/maybe.h b/ext/tinyopt/include/tinyopt/maybe.h new file mode 100644 index 00000000..a8ab24cc --- /dev/null +++ b/ext/tinyopt/include/tinyopt/maybe.h @@ -0,0 +1,170 @@ +#pragma once + +#include <stdexcept> +#include <utility> +#include <type_traits> + +#include <iostream> + +namespace to { + +// nothing is a special value that converts +// to an empty maybe<T> for any T. + +constexpr struct nothing_t {} nothing; + +// maybe<T> represents an optional value of type T, +// with an interface similar to C++17 std::optional. + +template <typename T> +struct maybe { + bool ok = false; + alignas(T) char data[sizeof(T)]; + + maybe() noexcept: ok(false) {} + maybe(nothing_t) noexcept: ok(false) {} + maybe(const T& v): ok(true) { construct(v); } + maybe(T&& v): ok(true) { construct(std::move(v)); } + maybe(const maybe& m): ok(m.ok) { if (ok) construct(*m); } + maybe(maybe&& m): ok(m.ok) { if (ok) construct(std::move(*m)); } + + ~maybe() { destroy(); } + + template <typename U> + maybe(const maybe<U>& m): ok(m.ok) { if (ok) construct(*m); } + + template <typename U> + maybe(maybe<U>&& m): ok(m.ok) { if (ok) construct(std::move(*m)); } + + maybe& operator=(nothing_t) { return destroy(), *this; } + maybe& operator=(const T& v) { return assign(v), *this; } + maybe& operator=(T&& v) { return assign(std::move(v)), *this; } + maybe& operator=(const maybe& m) { return m.ok? assign(*m): destroy(), *this; } + maybe& operator=(maybe&& m) { return m.ok? assign(std::move(*m)): destroy(), *this; } + + const T& value() const & { return assert_ok(), *vptr(); } + T&& value() && { return assert_ok(), std::move(*vptr()); } + + const T& operator*() const & noexcept { return *vptr(); } + const T* operator->() const & noexcept { return vptr(); } + T&& operator*() && { return std::move(*vptr()); } + + bool has_value() const noexcept { return ok; } + explicit operator bool() const noexcept { return ok; } + +private: + T* vptr() noexcept { return reinterpret_cast<T*>(data); } + const T* vptr() const noexcept { return reinterpret_cast<const T*>(data); } + + void construct(const T& v) { new (data) T(v); ok = true; } + void construct(T&& v) { new (data) T(std::move(v)); ok = true; } + + void assign(const T& v) { if (ok) *vptr()=v; else construct(v); } + void assign(T&& v) { if (ok) *vptr()=std::move(v); else construct(std::move(v)); } + + void destroy() { if (ok) (**this).~T(); ok = false; } + void assert_ok() const { if (!ok) throw std::invalid_argument("is nothing"); } +}; + +namespace impl { + template <typename T> + struct is_maybe_: std::false_type {}; + + template <typename T> + struct is_maybe_<maybe<T>>: std::true_type {}; +} + +template <typename T> +using is_maybe = impl::is_maybe_<std::remove_cv_t<std::remove_reference_t<T>>>; + +// maybe<void> acts as a maybe<T> with an empty or inaccessible wrapped value. + +template <> +struct maybe<void> { + bool ok = false; + + constexpr maybe() noexcept: ok(false) {} + constexpr maybe(nothing_t&) noexcept: ok(false) {} + constexpr maybe(const nothing_t&) noexcept: ok(false) {} + constexpr maybe(nothing_t&&) noexcept: ok(false) {} + + template <typename X, typename = std::enable_if_t<!is_maybe<X>::value>> + constexpr maybe(X&&) noexcept: ok(true) {} + + template <typename U> + constexpr maybe(const maybe<U>& m) noexcept: ok(m.ok) {} + + maybe& operator=(nothing_t) noexcept { return ok = false, *this; } + maybe& operator=(const maybe& m) noexcept { return ok = m.ok, *this; } + template <typename U> + maybe& operator=(U&& v) noexcept { return ok = true, *this; } + + bool has_value() const noexcept { return ok; } + constexpr explicit operator bool() const noexcept { return ok; } +}; + +// something is a non-empty maybe<void> value. + +constexpr maybe<void> something(true); + +// just<X> converts a value of type X to a maybe<X> containing the value. + +template <typename X> +auto just(X&& x) { return maybe<std::decay_t<X>>(std::forward<X>(x)); } + +// operator<< offers monadic-style chaining of maybe<X> values: +// (f << m) evaluates to an empty maybe if m is empty, or else to +// a maybe<V> value wrapping the result of applying f to the value +// in m. + +template < + typename F, + typename T, + typename R = std::decay_t<decltype(std::declval<F>()(std::declval<const T&>()))>, + typename = std::enable_if_t<std::is_same<R, void>::value> +> +maybe<void> operator<<(F&& f, const maybe<T>& m) { + if (m) return f(*m), something; else return nothing; +} + +template < + typename F, + typename T, + typename R = std::decay_t<decltype(std::declval<F>()(std::declval<const T&>()))>, + typename = std::enable_if_t<!std::is_same<R, void>::value> +> +maybe<R> operator<<(F&& f, const maybe<T>& m) { + if (m) return f(*m); else return nothing; +} + +template < + typename F, + typename R = std::decay_t<decltype(std::declval<F>()())>, + typename = std::enable_if_t<std::is_same<R, void>::value> +> +maybe<void> operator<<(F&& f, const maybe<void>& m) { + return m? (f(), something): nothing; +} + +template < + typename F, + typename R = std::decay_t<decltype(std::declval<F>()())>, + typename = std::enable_if_t<!std::is_same<R, void>::value> +> +maybe<R> operator<<(F&& f, const maybe<void>& m) { + return m? just(f()): nothing; +} + +// If the lhs is not functional, return a maybe value with the result +// of assigning the value in the rhs, or nothing if the rhs is nothing. + +template <typename T, typename U> +auto operator<<(T& x, const maybe<U>& m) -> maybe<std::decay_t<decltype(x=*m)>> { + if (m) return x=*m; else return nothing; +} + +template <typename T> +auto operator<<(T& x, const maybe<void>& m) -> maybe<std::decay_t<decltype(x=true)>> { + if (m) return x=true; else return nothing; +} +} // namespace to diff --git a/ext/tinyopt/include/tinyopt/smolopt.h b/ext/tinyopt/include/tinyopt/smolopt.h new file mode 100644 index 00000000..b9dde78c --- /dev/null +++ b/ext/tinyopt/include/tinyopt/smolopt.h @@ -0,0 +1,706 @@ +#pragma once + +// Small option parsing/handling, but no so teeny as tinyopt. + +#include <cstddef> +#include <cstring> +#include <functional> +#include <type_traits> +#include <utility> + +#include <tinyopt/maybe.h> +#include <tinyopt/common.h> + +namespace to { + +// Option keys +// ----------- +// +// A key is how the option is specified in an argument list, and is typically +// represented as a 'short' (e.g. '-a') option or a 'long' option (e.g. +// '--apple'). +// +// The value for an option can always be taken from the next argument in the +// list, but in addition can be specified together with the key itself, +// depending on the properties of the option key: +// +// --key=value 'Long' style argument for key "--key" +// -kvalue 'Compact' style argument for key "-k" +// +// Compact option keys can be combined in the one item in the argument list, if +// the options do not take any values (that is, they are flags). For example, +// if -a, -b are flags and -c takes an integer argument, with all three keys +// marked as compact, then an item '-abc3' in the argument list will be parsed +// in the same way as the sequence of items '-a', '-b', '-c', '3'. +// +// An option without a key will match any item in the argument list; options +// with keys are always checked first. + +struct key { + std::string label; + enum style { shortfmt, longfmt, compact } style = shortfmt; + + key(std::string l): label(std::move(l)) { + if (label[0]=='-' && label[1]=='-') style = longfmt; + } + + key(const char* label): key(std::string(label)) {} + + key(std::string label, enum style style): + label(std::move(label)), style(style) {} +}; + +inline namespace literals { + +inline key operator""_short(const char* label, std::size_t) { + return key(label, key::shortfmt); +} + +inline key operator""_long(const char* label, std::size_t) { + return key(label, key::longfmt); +} + +inline key operator""_compact(const char* label, std::size_t) { + return key(label, key::compact); +} + +} // namespace literals + +// Argument state +// -------------- +// +// to::state represents the collection of command line arguments. Mutating +// operations (shift(), successful option matching, etc.) will modify the +// underlying set of arguments used to construct the state object. + +struct state { + int& argc; + char** argv; + unsigned optoff = 0; + + state(int& argc, char** argv): argc(argc), argv(argv) {} + + // False => no more arguments. + explicit operator bool() const { return *argv; } + + // Shift arguments left in-place. + void shift(unsigned n = 1) { + char** skip = argv; + while (*skip && n) ++skip, --n; + + argc -= (skip-argv); + auto p = argv; + do { *p++ = *skip; } while (*skip++); + + optoff = 0; + } + + // Skip current argument without modifying list. + void skip() { + if (*argv) ++argv; + } + + // Match an option given by the key which takes an argument. + // If successful, consume option and argument and return pointer to + // argument string, else return nothing. + maybe<const char*> match_option(const key& k) { + const char* p = nullptr; + + if (k.style==key::compact) { + if ((p = match_compact_key(k.label.c_str()))) { + if (!*p) { + p = argv[1]; + shift(2); + } + else shift(); + return p; + } + } + else if (!optoff && k.label==*argv) { + p = argv[1]; + shift(2); + return p; + } + else if (!optoff && k.style==key::longfmt) { + auto keylen = k.label.length(); + if (!std::strncmp(*argv, k.label.c_str(), keylen) && (*argv)[keylen]=='=') { + p = &(*argv)[keylen+1]; + shift(); + return p; + } + } + + return nothing; + } + + // Match a flag given by the key. + // If successful, consume flag and return true, else return false. + bool match_flag(const key& k) { + if (k.style==key::compact) { + if (auto p = match_compact_key(k.label.c_str())) { + if (!*p) shift(); + return true; + } + } + else if (!optoff && k.label==*argv) { + shift(); + return true; + } + + return false; + } + + // Compact-style keys can be combined in one argument; combined keys + // with a common prefix only need to supply the prefix once at the + // beginning of the argument. + const char* match_compact_key(const char* k) { + unsigned keylen = std::strlen(k); + + unsigned prefix_max = std::min(keylen-1, optoff); + for (std::size_t l = 0; l<=prefix_max; ++l) { + if (l && strncmp(*argv, k, l)) break; + if (strncmp(*argv+optoff, k+l, keylen-l)) continue; + optoff += keylen-l; + return *argv+optoff; + } + + return nullptr; + } +}; + +// Sinks and actions +// ----------------- +// +// Sinks wrap a function that takes a pointer to an option parameter and stores +// or acts upon the parsed result. +// +// They can be constructed from an lvalue reference or a functional object (via +// the `action` function) with or without an explicit parser function. If no +// parser is given, a default one is used if the correct value type can be +// determined. + +namespace impl { + template <typename T> struct fn_arg_type { using type = void; }; + template <typename R, typename X> struct fn_arg_type<R (X)> { using type = X; }; + template <typename R, typename X> struct fn_arg_type<R (*)(X)> { using type = X; }; + template <typename R, typename C, typename X> struct fn_arg_type<R (C::*)(X)> { using type = X; }; + template <typename R, typename C, typename X> struct fn_arg_type<R (C::*)(X) const> { using type = X; }; + template <typename R, typename C, typename X> struct fn_arg_type<R (C::*)(X) volatile> { using type = X; }; + template <typename R, typename C, typename X> struct fn_arg_type<R (C::*)(X) const volatile> { using type = X; }; + + template <typename...> struct void_type { using type = void; }; +} + +template <typename T, typename = void> +struct unary_argument_type { using type = typename impl::fn_arg_type<T>::type; }; + +template <typename T> +struct unary_argument_type<T, typename impl::void_type<decltype(&T::operator())>::type> { + using type = typename impl::fn_arg_type<decltype(&T::operator())>::type; +}; + +template <typename T> +using unary_argument_type_t = typename unary_argument_type<T>::type; + +struct sink { + // Tag class for constructor. + static struct action_t {} action; + + sink(): + sink(action, [](const char* param) { return true; }) + {} + + template <typename V> + sink(V& var): sink(var, default_parser<V>{}) {} + + template <typename V, typename P> + sink(V& var, P parser): + sink(action, [ref=std::ref(var), parser](const char* param) { + if (auto p = parser(param)) return ref.get() = std::move(*p), true; + else return false; + }) + {} + + template <typename Action> + sink(action_t, Action a): op(std::move(a)) {} + + bool operator()(const char* param) const { return op(param); } + std::function<bool (const char*)> op; + +}; + +// Convenience functions for construction of sink actions +// with explicit or implicit parser. + +template <typename F, typename A = std::decay_t<unary_argument_type_t<F>>> +sink action(F f) { + return sink(sink::action, + [f = std::move(f)](const char* arg) -> bool { + return static_cast<bool>(f << default_parser<A>{}(arg)); + }); +} + +template <typename F, typename P> +sink action(F f, P parser) { + return sink(sink::action, + [f = std::move(f), parser = std::move(parser)](const char* arg) -> bool { + return static_cast<bool>(f << parser(arg)); + }); +} + +// Special actions: +// +// error(message) Throw a user_option_error with the supplied message. + +inline sink error(std::string message) { + return sink(sink::action, + [m = std::move(message)](const char*) -> bool { + throw user_option_error(m); + }); +} + +// Sink adaptors: +// +// These adaptors constitute short cuts for making actions that count the +// occurance of a flag, set a fixed value when a flag is provided, or for +// appending an option parameter onto a vector of values. + +// Push parsed option parameter on to container. +template <typename Container, typename P = default_parser<typename Container::value_type>> +sink push_back(Container& c, P parser = P{}) { + return action( + [ref = std::ref(c)](typename Container::value_type v) { ref.get().push_back(std::move(v)); }, + std::move(parser)); +} + +// Set v to value when option parsed; ignore any option parameter. +template <typename V, typename X> +sink set(V& v, X value) { + return action([ref = std::ref(v), value = std::move(value)] { ref.get() = value; }); +} + +// Set v to true when option parsed; ignore any option parameter. +template <typename V> +sink set(V& v) { + return set(v, true); +} + +// Incrememnt v when option parsed; ignore any option parameter. +template <typename V> +sink increment(V& v) { + return action([ref = std::ref(v)] { ++ref.get(); }); +} + +template <typename V, typename X> +sink increment(V& v, X delta) { + return action([ref = std::ref(v), delta = std::move(delta)] { ref.get() += delta; }); +} + +// Modal configuration +// ------------------- +// +// Options can be filtered by some predicate, and can trigger a state +// change when successfully processed. +// +// Filter construction: +// to::when(Fn f) f is a functional with signature bool (int) +// to::when(int s) equivalent to to::when([](int k) { return k==s; }) +// to::when(a, b, ...) filter than is satisfied by to::when(a) or +// to::when(b) or ... +// +// The argument to the filter predicate is the 'mode', a mutable state maintained +// during a single run of to::run(). +// +// Mode changes: +// to::then(Fn f) f is a functional with signature int (int) +// to::then(int s) equivalent to to::then([](int) { return s; }) +// +// The argument to the functional is the current mode; the return value +// sets the new value of mode. +// +// Filters are called before keys are matched; modal changes are called +// after an option is processed. All + +using filter = std::function<bool (int)>; +using modal = std::function<int (int)>; + +template <typename F, typename = decltype(std::declval<F>()(0))> +filter when(F f) { + return [f = std::move(f)](int mode) { return static_cast<bool>(f(mode)); }; +} + +inline filter when(int m) { + return [m](int mode) { return m==mode; }; +} + +template <typename A, typename B, typename... Rest> +filter when(A a, B&& b, Rest&&... rest) { + return + [fhead = when(std::forward<A>(a)), + ftail = when(std::forward<B>(b), std::forward<Rest>(rest)...)](int m) { + return fhead(m) || ftail(m); + }; +} + +template <typename F, typename = decltype(std::declval<F>()(0))> +modal then(F f) { + return [f = std::move(f)](int mode) { return static_cast<int>(f(mode)); }; +} + +inline modal then(int m) { + return [m](int) { return m; }; +} + + +// Option specification +// -------------------- +// +// An option specification comprises zero or more keys (e.g. "-a", "--foo"), +// a sink (where the parsed argument will be sent), a parser - which may be +// the default parser - and zero or more flags that modify its behaviour. +// +// Option flags: + +enum option_flag { + flag = 1, // Option takes no parameter. + ephemeral = 2, // Option is not saved in returned results. + single = 4, // Option is parsed at most once. + mandatory = 8, // Option must be present in argument list. + exit = 16, // Option stops further argument processing. +}; + +struct option { + sink s; + std::vector<key> keys; + std::vector<filter> filters; + std::vector<modal> modals; + std::string prefkey; + + bool is_flag = false; + bool is_ephemeral = false; + bool is_single = false; + bool is_mandatory = false; + bool is_exit = false; + + template <typename... Rest> + option(sink s, Rest&&... rest): s(std::move(s)) { + init_(std::forward<Rest>(rest)...); + } + + void init_() {} + + template <typename... Rest> + void init_(enum option_flag f, Rest&&... rest) { + is_flag |= f & flag; + is_ephemeral |= f & ephemeral; + is_single |= f & single; + is_mandatory |= f & mandatory; + is_exit |= f & exit; + init_(std::forward<Rest>(rest)...); + } + + template <typename... Rest> + void init_(filter f, Rest&&... rest) { + filters.push_back(std::move(f)); + init_(std::forward<Rest>(rest)...); + } + + template <typename... Rest> + void init_(modal f, Rest&&... rest) { + modals.push_back(std::move(f)); + init_(std::forward<Rest>(rest)...); + } + + template <typename... Rest> + void init_(key k, Rest&&... rest) { + if (k.label.length()>prefkey.length()) prefkey = k.label; + keys.push_back(std::move(k)); + init_(std::forward<Rest>(rest)...); + } + + bool has_key(const std::string& arg) const { + if (keys.empty() && arg.empty()) return true; + for (const auto& k: keys) { + if (arg==k.label) return true; + } + return false; + } + + bool check_mode(int mode) const { + for (auto& f: filters) { + if (!f(mode)) return false; + } + return true; + } + + void set_mode(int& mode) const { + for (auto& f: modals) mode = f(mode); + } + + void run(const std::string& label, const char* arg) const { + if (!is_flag && !arg) throw missing_argument(label); + if (!s(arg)) throw option_parse_error(label); + } +}; + +// Saved options +// ------------- +// +// Successfully matched options, excluding those with the to::ephemeral flag +// set, are collated in a saved_options structure for potential documentation +// or replay. + +struct saved_options: private std::vector<std::string> { + using std::vector<std::string>::begin; + using std::vector<std::string>::end; + using std::vector<std::string>::size; + using std::vector<std::string>::empty; + + void add(std::string s) { push_back(std::move(s)); } + + saved_options& operator+=(const saved_options& so) { + insert(end(), so.begin(), so.end()); + return *this; + } + + struct arglist { + int argc; + char** argv; + std::vector<char*> arg_data; + }; + + // Construct argv representing argument list. + arglist as_arglist() const { + arglist A; + + for (auto& a: *this) A.arg_data.push_back(const_cast<char*>(a.c_str())); + A.arg_data.push_back(nullptr); + A.argv = A.arg_data.data(); + A.argc = A.arg_data.size()-1; + return A; + } + + // Serialized representation: + // + // Saved arguments are separated by white space. If an argument + // contains whitespace or a special character, it is escaped with + // single quotes in a POSIX shell compatible fashion, so that + // the representation can be used directly on a shell command line. + + friend std::ostream& operator<<(std::ostream& out, const saved_options& s) { + auto escape = [](const std::string& v) { + if (!v.empty() && v.find_first_of("\\*?[#~=%|^;<>()$'`\" \t\n")==std::string::npos) return v; + + // Wrap string in single quotes, replacing any internal single quote + // character with: '\'' + + std::string q ="'"; + for (auto c: v) { + c=='\''? q += "'\\''": q += c; + } + return q += '\''; + }; + + bool first = true; + for (auto& p: s) { + if (first) first = false; else out << ' '; + out << escape(p); + } + return out; + } + + friend std::istream& operator>>(std::istream& in, saved_options& s) { + std::string w; + bool have_word = false; + bool quote = false; // true => within single quotes. + bool escape = false; // true => previous character was backslash. + while (in) { + char c = in.get(); + if (c==EOF) break; + + if (quote) { + if (c!='\'') w += c; + else quote = false; + } + else { + if (escape) { + w += c; + escape = false; + } + else if (c=='\\') { + escape = true; + have_word = true; + } + else if (c=='\'') { + quote = true; + have_word = true; + } + else if (c!=' ' && c!='\t' && c!='\n') { + w += c; + have_word = true; + } + else { + if (have_word) s.add(w); + have_word = false; + w = ""; + } + } + } + + if (have_word) s.add(w); + return in; + } +}; + +// Option with mutable state (for checking single and mandatory flags), +// used by to::run(). + +namespace impl { + struct counted_option: option { + int count = 0; + + counted_option(const option& o): option(o) {} + + // On successful match, return pointers to matched key and value. + // For flags, use nullptr for value; for empty key sets, use + // nullptr for key. + maybe<std::pair<const char*, const char*>> match(state& st) { + if (is_flag) { + for (auto& k: keys) { + if (st.match_flag(k)) return set(k.label, nullptr); + } + return nothing; + } + else if (!keys.empty()) { + for (auto& k: keys) { + if (auto param = st.match_option(k)) return set(k.label, *param); + } + return nothing; + } + else { + const char* param = *st.argv; + st.shift(); + return set("", param); + } + } + + std::pair<const char*, const char*> set(const char* arg) { + run("", arg); + ++count; + return {nullptr, arg}; + } + + std::pair<const char*, const char*> set(const std::string& label, const char* arg) { + run(label, arg); + ++count; + return {label.c_str(), arg}; + } + }; +} // namespace impl + +// Running a set of options +// ------------------------ +// +// to::run() can be used to parse options from the command-line and/or from +// saved_options data. +// +// The first argument is a collection or sequence of option specifications, +// followed optionally by command line argc and argv or just argv. A +// saved_options object can be optionally passed as the last parameter. +// +// If an option with the to::exit flag is matched, option parsing will +// immediately stop and an empty value will be returned. Otherwise to::run() +// will return a saved_options structure recording the successfully parsed +// options. + +namespace impl { + inline maybe<saved_options> run(std::vector<impl::counted_option>& opts, int& argc, char** argv) { + saved_options collate; + bool exit = false; + state st{argc, argv}; + int mode = 0; + while (st && !exit) { + // Try options with a key first. + for (auto& o: opts) { + if (o.keys.empty()) continue; + if (o.is_single && o.count) continue; + if (!o.check_mode(mode)) continue; + + if (auto ma = o.match(st)) { + if (!o.is_ephemeral) { + if (ma->first) collate.add(ma->first); + if (ma->second) collate.add(ma->second); + } + o.set_mode(mode); + exit = o.is_exit; + goto next; + } + } + + // Literal "--" terminates option parsing. + if (!std::strcmp(*argv, "--")) { + st.shift(); + return collate; + } + + // Try free options. + for (auto& o: opts) { + if (!o.keys.empty()) continue; + if (o.is_single && o.count) continue; + if (!o.check_mode(mode)) continue; + + if (auto ma = o.match(st)) { + if (!o.is_ephemeral) collate.add(ma->second); + o.set_mode(mode); + exit = o.is_exit; + goto next; + } + } + + // Nothing matched, so increment argv. + st.skip(); + next: ; + } + + return exit? nothing: just(collate); + } +} // namespace impl + + +template <typename Options> +maybe<saved_options> run(const Options& options, int& argc, char** argv, const saved_options& restore = saved_options{}) { + using std::begin; + using std::end; + std::vector<impl::counted_option> opts(begin(options), end(options)); + auto r_args = restore.as_arglist(); + + saved_options coll1, coll2; + if (coll1 << impl::run(opts, r_args.argc, r_args.argv) && coll2 << impl::run(opts, argc, argv)) { + for (auto& o: opts) { + if (o.is_mandatory && !o.count) throw missing_mandatory_option(o.prefkey); + } + return coll1 += coll2; + } + + return nothing; +} + +template <typename Options> +maybe<saved_options> run(const Options& options, const saved_options& restore) { + int ignore_argc = 0; + char* end_of_args = nullptr; + return run(options, ignore_argc, &end_of_args, restore); +} + +template <typename Options> +maybe<saved_options> run(const Options& options, char** argv) { + int ignore_argc = 0; + return run(options, ignore_argc, argv); +} + +template <typename Options> +maybe<saved_options> run(const Options& options, char** argv, const saved_options& restore) { + int ignore_argc = 0; + return run(options, ignore_argc, argv, restore); +} +} // namespace to diff --git a/ext/tinyopt/include/tinyopt/tinyopt.h b/ext/tinyopt/include/tinyopt/tinyopt.h new file mode 100644 index 00000000..73d64bce --- /dev/null +++ b/ext/tinyopt/include/tinyopt/tinyopt.h @@ -0,0 +1,77 @@ +#pragma once + +#include <cstring> +#include <iostream> +#include <iterator> +#include <sstream> +#include <stdexcept> +#include <string> +#include <utility> +#include <type_traits> +#include <vector> + +#include <tinyopt/common.h> +#include <tinyopt/maybe.h> + +namespace to { + +template <typename V = std::string, typename P = default_parser<V>, typename = std::enable_if_t<!std::is_same<V, void>::value>> +maybe<V> parse(char**& argp, char shortopt, const char* longopt = nullptr, const P& parser = P{}) { + const char* arg = argp[0]; + + if (!arg || arg[0]!='-') { + return nothing; + } + + const char* text; + + if (arg[1]=='-' && longopt) { + const char* rest = arg+2; + const char* eq = std::strchr(rest, '='); + + if (!std::strcmp(rest, longopt)) { + if (!argp[1]) throw missing_argument(arg); + text = argp[1]; + argp += 2; + } + else if (eq && !std::strncmp(rest, longopt, eq-rest)) { + text = eq+1; + argp += 1; + } + else { + return nothing; + } + } + else if (shortopt && arg[1]==shortopt && arg[2]==0) { + if (!argp[1]) throw missing_argument(arg); + text = argp[1]; + argp += 2; + } + else { + return nothing; + } + + auto v = parser(text); + + if (!v) throw option_parse_error(arg); + return v; +} + +inline maybe<void> parse(char**& argp, char shortopt, const char* longopt = nullptr) { + if (!*argp || *argp[0]!='-') { + return nothing; + } + else if (argp[0][1]=='-' && longopt && !std::strcmp(argp[0]+2, longopt)) { + ++argp; + return true; + } + else if (shortopt && argp[0][1]==shortopt && argp[0][2]==0) { + ++argp; + return true; + } + else { + return nothing; + } +} + +} // namespace to diff --git a/modcc/CMakeLists.txt b/modcc/CMakeLists.txt index c0a6537e..3ff48b0d 100644 --- a/modcc/CMakeLists.txt +++ b/modcc/CMakeLists.txt @@ -33,7 +33,7 @@ target_include_directories(libmodcc PUBLIC .) set_target_properties(libmodcc PROPERTIES OUTPUT_NAME modcc) add_executable(modcc ${modcc_sources}) -target_link_libraries(modcc libmodcc ext-tclap) +target_link_libraries(modcc libmodcc ext-tinyopt) set_target_properties(modcc libmodcc PROPERTIES EXCLUDE_FROM_ALL ${ARB_WITH_EXTERNAL_MODCC}) diff --git a/modcc/modcc.cpp b/modcc/modcc.cpp index 06556f1a..e2753189 100644 --- a/modcc/modcc.cpp +++ b/modcc/modcc.cpp @@ -4,7 +4,7 @@ #include <unordered_map> #include <unordered_set> -#include <tclap/CmdLine.h> +#include <tinyopt/smolopt.h> #include "printer/cprinter.hpp" #include "printer/cudaprinter.hpp" @@ -47,6 +47,7 @@ std::unordered_map<std::string, targetKind> targetKindMap = { std::unordered_map<std::string, enum simd_spec::simd_abi> simdAbiMap = { {"none", simd_spec::none}, + {"neon", simd_spec::neon}, {"avx", simd_spec::avx}, {"avx2", simd_spec::avx2}, {"avx512", simd_spec::avx512}, @@ -66,7 +67,7 @@ struct Options { std::string outprefix; std::string modfile; std::string modulename; - bool verbose = true; + bool verbose = false; bool analysis = false; std::unordered_set<targetKind> targets; }; @@ -113,112 +114,75 @@ std::ostream& operator<<(std::ostream& out, const printer_options& popt) { table_prefix{"simd"} << popt.simd << line_end; } -// Constraints for TCLAP arguments that are names for enumertion values. -struct MapConstraint: private std::vector<std::string>, public TCLAP::ValuesConstraint<std::string> { - template <typename Map> - MapConstraint(const Map& map): - std::vector<std::string>(keys(map)), - TCLAP::ValuesConstraint<std::string>(static_cast<std::vector<std::string>&>(*this)) {} - - template <typename Map> - static std::vector<std::string> keys(const Map& map) { - std::vector<std::string> ks; - for (auto& kv: map) ks.push_back(kv.first); - return ks; - } -}; - -simd_spec parse_simd_spec(std::string spec) { +std::istream& operator>> (std::istream& i, simd_spec& spec) { auto npos = std::string::npos; + std::string s; + i >> s; unsigned width = 0; - auto suffix = spec.find_last_of('/'); + auto suffix = s.find_last_of('/'); if (suffix!=npos) { - width = stoul(spec.substr(suffix+1)); - spec = spec.substr(0, suffix); + width = stoul(s.substr(suffix+1)); + s = s.substr(0, suffix); } - return simd_spec(simdAbiMap.at(spec.c_str()), width); + spec = simd_spec(simdAbiMap.at(s.c_str()), width); + return i; } -struct SimdAbiConstraint: public TCLAP::Constraint<std::string> { - std::string description() const override { - return "simd_abi[/n]"; - } - std::string shortID() const override { - return description(); - } - bool check(const std::string& spec) const override { - try { - (void)parse_simd_spec(spec); - return true; - } - catch (...) { - return false; - } - } -}; +const char* usage_str = + "\n" + "-o|--output [Prefix for output file names]\n" + "-N|--namespace [Namespace for generated code]\n" + "-t|--target [Build module for target; Avaliable targets: 'cpu', 'gpu']\n" + "-s|--simd [Generate code with explicit SIMD vectorization]\n" + "-S|--simd-abi [Override SIMD ABI in generated code. Use /n suffix to force SIMD width to be size n. Examples: 'avx2', 'native/4', ...]\n" + "-P|--profile [Build with profiled kernels]\n" + "-V|--verbose [Toggle verbose mode]\n" + "-A|--analyse [Toggle analysis mode]\n" + "<filename> [File to be compiled]\n"; int main(int argc, char **argv) { + using namespace to; + Options opt; printer_options popt; - try { - TCLAP::CmdLine cmd("modcc code generator for arbor", ' ', "0.1"); - - TCLAP::UnlabeledValueArg<std::string> - fin_arg("input_file", "the name of the .mod file to compile", true, "", "filename", cmd); - - TCLAP::ValueArg<std::string> - fout_arg("o", "output", "prefix for output file names", false, "", "filename", cmd); - - TCLAP::ValueArg<std::string> - namespace_arg("N", "namespace", "namespace for generated code", false, "arb", "name", cmd); - - MapConstraint targets_arg_constraint(targetKindMap); - TCLAP::MultiArg<std::string> - target_arg("t", "target", "build module for cpu or gpu back-end", false, &targets_arg_constraint, cmd); + std::vector<std::string> targets; - TCLAP::SwitchArg - simd_arg("s", "simd", "generate code with explicit SIMD vectorization", cmd, false); - - SimdAbiConstraint simd_abi_constraint; - TCLAP::ValueArg<std::string> - simd_abi_arg("S", "simd-abi", "override SIMD ABI in generated code. Use /n suffix to force SIMD width to be size n. Examples: 'avx2', 'native/4', ...", false, "", &simd_abi_constraint, cmd); - - TCLAP::SwitchArg profile_arg("P","profile","build with profiled kernels", cmd, false); - - TCLAP::SwitchArg verbose_arg("V","verbose","toggle verbose mode", cmd, false); - - TCLAP::SwitchArg analysis_arg("A","analyse","toggle analysis mode", cmd, false); - - TCLAP::ValueArg<std::string> - module_arg("m", "module", "module name to use (default taken from input .mod file)", false, "", "module", cmd); - - cmd.parse(argc, argv); + auto help = [argv0 = argv[0]] { + to::usage(argv0, usage_str); + }; - opt.outprefix = fout_arg.getValue(); - opt.modfile = fin_arg.getValue(); - opt.modulename = module_arg.getValue(); - opt.verbose = verbose_arg.getValue(); - opt.analysis = analysis_arg.getValue(); + auto enable_simd = [&popt] { + if (popt.simd.abi==simd_spec::none) { + popt.simd = simd_spec(simd_spec::native); + } + }; - popt.cpp_namespace = namespace_arg.getValue(); - popt.profile = profile_arg.getValue(); + auto add_target = [&opt](targetKind t) { + opt.targets.insert(t); + }; - if (simd_arg.getValue()) { - popt.simd = simd_spec(simd_spec::native); - if (!simd_abi_arg.getValue().empty()) { - popt.simd = parse_simd_spec(simd_abi_arg.getValue()); - } - } + to::option options[] = { + { opt.modfile, to::mandatory}, + { opt.outprefix, "-o", "--output" }, + { to::set(opt.verbose), to::flag, "-V", "--verbose" }, + { to::set(opt.analysis), to::flag, "-A", "--analyse" }, + { opt.modulename, "-m", "--module" }, + { to::set(popt.profile), to::flag, "-P", "--profile" }, + { popt.cpp_namespace, "-N", "--namespace" }, + { to::action(enable_simd), to::flag, "-s", "--simd" }, + { popt.simd, "-S", "--simd-abi" }, + { {to::action(add_target, to::keywords(targetKindMap))}, "-t", "--target" }, + { to::action(help), to::flag, to::exit, "-h", "--help" } + }; - for (auto& target: target_arg.getValue()) { - opt.targets.insert(targetKindMap.at(target)); - } + if (!to::run(options, argc, argv+1)) return 0; } - catch(TCLAP::ArgException &e) { - return report_error(pprintf("% for argument %", e.error(), e.argId())); + catch (to::option_error& e) { + to::usage(argv[0], usage_str, e.what()); + return 1; } try { diff --git a/modcc/printer/cprinter.cpp b/modcc/printer/cprinter.cpp index 9c12821b..2ebd8db3 100644 --- a/modcc/printer/cprinter.cpp +++ b/modcc/printer/cprinter.cpp @@ -187,6 +187,7 @@ std::string emit_cpp_source(const Module& module_, const printer_options& opt) { case simd_spec::avx: abi += "avx"; break; case simd_spec::avx2: abi += "avx2"; break; case simd_spec::avx512: abi += "avx512"; break; + case simd_spec::neon: abi += "neon"; break; case simd_spec::native: abi += "native"; break; default: abi += "default_abi"; break; diff --git a/modcc/printer/simd.hpp b/modcc/printer/simd.hpp index 800ddacc..a218842f 100644 --- a/modcc/printer/simd.hpp +++ b/modcc/printer/simd.hpp @@ -1,7 +1,7 @@ #pragma once struct simd_spec { - enum simd_abi { none, avx, avx2, avx512, native, default_abi } abi = none; + enum simd_abi { none, neon, avx, avx2, avx512, native, default_abi } abi = none; unsigned width = 0; // zero => use `simd::native_width` to determine. simd_spec() = default; @@ -18,6 +18,9 @@ struct simd_spec { case avx512: width = 8; break; + case neon: + width = 2; + break; default: ; } } diff --git a/sup/include/sup/tinyopt.hpp b/sup/include/sup/tinyopt.hpp deleted file mode 100644 index 8bb6fc24..00000000 --- a/sup/include/sup/tinyopt.hpp +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -#include <cstring> -#include <iostream> -#include <iterator> -#include <sstream> -#include <stdexcept> -#include <string> -#include <utility> -#include <vector> - -#include <arbor/util/optional.hpp> - -namespace to { - -using arb::util::optional; -using arb::util::nullopt; -using arb::util::just; - -struct parse_opt_error: public std::runtime_error { - parse_opt_error(const std::string& s): std::runtime_error(s) {} - parse_opt_error(const char *arg, const std::string& s): - std::runtime_error(s+": "+arg) {} -}; - -void usage(const char* argv0, const std::string& usage_str) { - const char* basename = std::strrchr(argv0, '/'); - basename = basename? basename+1: argv0; - - std::cout << "Usage: " << basename << " " << usage_str << "\n"; -} - -void usage(const char* argv0, const std::string& usage_str, const std::string& parse_err) { - const char* basename = std::strrchr(argv0, '/'); - basename = basename? basename+1: argv0; - - std::cerr << basename << ": " << parse_err << "\n"; - std::cerr << "Usage: " << basename << " " << usage_str << "\n"; -} - -template <typename V> -struct default_parser { - optional<V> operator()(const std::string& text) const { - V v; - std::istringstream stream(text); - stream >> v; - return stream? just(v): nullopt; - } -}; - -template <typename V> -class keyword_parser { - std::vector<std::pair<std::string, V>> map_; - -public: - template <typename KeywordPairs> - keyword_parser(const KeywordPairs& pairs): map_(std::begin(pairs), std::end(pairs)) {} - - optional<V> operator()(const std::string& text) const { - for (const auto& p: map_) { - if (text==p.first) return p.second; - } - return nullopt; - } -}; - -template <typename KeywordPairs> -auto keywords(const KeywordPairs& pairs) -> keyword_parser<decltype(std::begin(pairs)->second)> { - return keyword_parser<decltype(std::begin(pairs)->second)>(pairs); -} - -template <typename V = std::string, typename P = default_parser<V>, typename = std::enable_if_t<!std::is_same<V, void>::value>> -optional<V> parse_opt(char **& argp, char shortopt, const char* longopt=nullptr, const P& parse = P{}) { - const char* arg = argp[0]; - - if (!arg || arg[0]!='-') { - return nullopt; - } - - std::string text; - - if (arg[1]=='-' && longopt) { - const char* rest = arg+2; - const char* eq = std::strchr(rest, '='); - - if (!std::strcmp(rest, longopt)) { - if (!argp[1]) throw parse_opt_error(arg, "missing argument"); - text = argp[1]; - argp += 2; - } - else if (eq && !std::strncmp(rest, longopt, eq-rest)) { - text = eq+1; - argp += 1; - } - else { - return nullopt; - } - } - else if (shortopt && arg[1]==shortopt && arg[2]==0) { - if (!argp[1]) throw parse_opt_error(arg, "missing argument"); - text = argp[1]; - argp += 2; - } - else { - return nullopt; - } - - auto v = parse(text); - - if (!v) throw parse_opt_error(arg, "failed to parse option argument"); - return v; -} - -optional<void> parse_opt(char **& argp, char shortopt, const char* longopt) { - if (!*argp || *argp[0]!='-') { - return nullopt; - } - else if (argp[0][1]=='-' && longopt && !std::strcmp(argp[0]+2, longopt)) { - ++argp; - return true; - } - else if (shortopt && argp[0][1]==shortopt && argp[0][2]==0) { - ++argp; - return true; - } - else { - return nullopt; - } -} - -} // namespace to diff --git a/test/unit-distributed/CMakeLists.txt b/test/unit-distributed/CMakeLists.txt index d93748c9..8defe961 100644 --- a/test/unit-distributed/CMakeLists.txt +++ b/test/unit-distributed/CMakeLists.txt @@ -13,7 +13,7 @@ add_dependencies(tests unit-local) target_compile_options(unit-local PRIVATE ${ARB_CXXOPT_ARCH}) target_compile_definitions(unit-local PRIVATE TEST_LOCAL) -target_link_libraries(unit-local PRIVATE gtest arbor arborenv arbor-sup arbor-private-headers) +target_link_libraries(unit-local PRIVATE gtest arbor arborenv arbor-sup arbor-private-headers ext-tinyopt) if(ARB_WITH_MPI) add_executable(unit-mpi EXCLUDE_FROM_ALL ${unit-distributed_sources}) @@ -21,6 +21,6 @@ if(ARB_WITH_MPI) target_compile_options(unit-mpi PRIVATE ${ARB_CXXOPT_ARCH}) target_compile_definitions(unit-mpi PRIVATE TEST_MPI) - target_link_libraries(unit-mpi PRIVATE gtest arbor arborenv arbor-sup arbor-private-headers) + target_link_libraries(unit-mpi PRIVATE gtest arbor arborenv arbor-sup arbor-private-headers ext-tinyopt) endif() diff --git a/test/unit-distributed/test.cpp b/test/unit-distributed/test.cpp index cc5a52d4..cf2abddd 100644 --- a/test/unit-distributed/test.cpp +++ b/test/unit-distributed/test.cpp @@ -8,7 +8,7 @@ #include <arbor/context.hpp> #include <sup/ioutil.hpp> -#include <sup/tinyopt.hpp> +#include <tinyopt/tinyopt.h> #ifdef TEST_MPI #include <arborenv/with_mpi.hpp> @@ -57,9 +57,9 @@ int main(int argc, char **argv) { try { auto arg = argv+1; while (*arg) { - if (auto comm_size = to::parse_opt<unsigned>(arg, 'd', "dryrun")) { + if (auto comm_size = to::parse<unsigned>(arg, 'd', "dryrun")) { if (*comm_size==0) { - throw to::parse_opt_error(*arg, "must be positive integer"); + throw to::option_error("must be positive integer", *arg); } // Note that this must be set again for each test that uses a different // number of cells per domain, e.g. @@ -67,12 +67,12 @@ int main(int argc, char **argv) { // TODO: fix when dry run mode reimplemented //policy::set_sizes(*comm_size, 0); } - else if (auto o = to::parse_opt(arg, 'h', "help")) { + else if (auto o = to::parse(arg, 'h', "help")) { to::usage(argv[0], usage_str); return 0; } else { - throw to::parse_opt_error(*arg, "unrecognized option"); + throw to::option_error("unrecognized option", *arg); } } @@ -81,7 +81,7 @@ int main(int argc, char **argv) { // 1 : failure return_value = RUN_ALL_TESTS(); } - catch (to::parse_opt_error& e) { + catch (to::option_error& e) { to::usage(argv[0], usage_str, e.what()); return_value = 1; } -- GitLab