// -*- mode: c++; indent-tabs-mode: nil; -*- // // Copyright 2009 Illumina, Inc. // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). // // /// \file /// /// \author Chris Saunders /// #ifndef __BLT_ARG_PARSE_HH #define __BLT_ARG_PARSE_HH #include "blt_util/blt_types.hh" #include "blt_util/prog_info.hh" #include #include #include #include struct arg_data { arg_data(int init_argc,char* init_argv[],const prog_info& init_pinfo); void finalize_args(); int argc; char** argv; std::vector argmark; std::vector argstr; std::string cmdline; const prog_info& pinfo; }; template void set_val(const prog_info& pinfo, const char* arg_label, const char* arg, T& val){ try { val=boost::lexical_cast(arg); } catch(boost::bad_lexical_cast& e) { std::ostringstream oss; oss << "argument after flag " << arg_label << " (" << arg << ") cannot be parsed to expected type"; pinfo.usage(oss.str().c_str()); } } template void set_arg(int& argi, arg_data& ad, bool& is_val_set, T& val){ const char* arg_label(ad.argstr[argi].c_str()); ad.argmark[argi] = true; if(++argi>=static_cast(ad.argstr.size())) { ad.pinfo.usage((std::string("no value following ")+arg_label).c_str()); } if(is_val_set) { ad.pinfo.usage((std::string("multiple ")+arg_label+" arguments").c_str()); } set_val(ad.pinfo,arg_label,ad.argstr[argi].c_str(),val); is_val_set=true; } void set_xrange_arg(int& argi, arg_data& ad, bool& is_val_set, double& val, bool is_allow_zero=false, bool is_no_max_check=false); void set_filename_arg(int& argi, arg_data& ad, bool& is_val_set, std::string& file); void set_win_arg(int& argi, arg_data& ad, bool& is_val_set, int& val1, unsigned& val2); void set_nploid_arg(int& argi, arg_data& ad, bool& is_val_set, int& val1, double& val2); void set_xrange_win_arg(int& argi, arg_data& ad, bool& is_val_set, double& val1, unsigned& val2); #endif