Changeset 2410:fe46b61da4e3 in lemon-0.x
- Timestamp:
- 03/14/07 19:01:04 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3241
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/arg_parser.cc
r2406 r2410 27 27 } 28 28 29 ArgParser::ArgParser(int argc, c har **argv) :_argc(argc), _argv(argv),30 29 ArgParser::ArgParser(int argc, const char **argv) :_argc(argc), _argv(argv), 30 _command_name(argv[0]) { 31 31 funcOption("-help","Print a short help message",_showHelp,this); 32 32 synonym("help","-help"); … … 135 135 136 136 ArgParser &ArgParser::refOption(const std::string &name, 137 138 137 const std::string &help, 138 double &ref, bool obl) 139 139 { 140 140 ParData p; … … 149 149 150 150 ArgParser &ArgParser::refOption(const std::string &name, 151 152 151 const std::string &help, 152 bool &ref, bool obl) 153 153 { 154 154 ParData p; … … 198 198 { 199 199 Opts::iterator i = _opts.find(opt); 200 if(i==_opts.end()) throw LogicError(); 201 else if(i->second.ingroup) throw LogicError(); 202 else { 203 GroupData &g=_groups[group]; 204 g.opts.push_back(opt); 205 i->second.ingroup=true; 206 } 200 LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'"); 201 LEMON_ASSERT(!(i->second.ingroup), 202 "Option already in option group: '"+opt+"'"); 203 GroupData &g=_groups[group]; 204 g.opts.push_back(opt); 205 i->second.ingroup=true; 207 206 return *this; 208 207 } … … 220 219 Opts::iterator o = _opts.find(opt); 221 220 Opts::iterator s = _opts.find(syn); 222 if(o==_opts.end()||s!=_opts.end()) 223 throw LogicError(); 224 else { 225 ParData p; 226 p.help=opt; 227 p.mandatory=false; 228 p.syn=true; 229 _opts[syn]=p; 230 o->second.has_syn=true; 231 } 221 LEMON_ASSERT(o!=_opts.end(), "Unknown option: '"+opt+"'"); 222 LEMON_ASSERT(s==_opts.end(), "Option already used: '"+syn+"'"); 223 ParData p; 224 p.help=opt; 225 p.mandatory=false; 226 p.syn=true; 227 _opts[syn]=p; 228 o->second.has_syn=true; 232 229 return *this; 233 230 } -
lemon/arg_parser.h
r2407 r2410 48 48 49 49 int _argc; 50 c har **_argv;50 const char **_argv; 51 51 52 52 enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 }; … … 108 108 109 109 ///\e 110 ArgParser(int argc, c har **argv);110 ArgParser(int argc, const char **argv); 111 111 112 112 ~ArgParser(); -
lemon/error.h
r2391 r2410 476 476 477 477 template <typename Exception> 478 inline void assert_fail(const char *file, int line, const char *func, 479 Exception exception, const char *assertion = 0, 480 bool do_abort=true) 478 inline void assert_fail(const char *file, int line, 479 const char *func, 480 Exception exception, 481 const char *assertion = 0, 482 bool do_abort=true) 481 483 { 482 484 using namespace std; … … 511 513 } 512 514 515 template <> 516 inline void assert_fail<std::string>(const char *file, int line, 517 const char *func, 518 std::string message, 519 const char *assertion, 520 bool do_abort) 521 { 522 assert_fail(file, line, func, message.c_str(), assertion, do_abort); 523 } 524 513 525 template <typename Exception> 514 526 inline void assert_fail_failure(const char *file, int line, const char *func, … … 522 534 template <> 523 535 inline void assert_fail_failure<const char *>(const char *file, int line, 524 525 526 527 536 const char *func, 537 const char *message, 538 const char *assertion, 539 bool) 528 540 { 529 541 throw AssertionFailedError(file, line, func, message, assertion); 542 } 543 544 template <> 545 inline void assert_fail_failure<std::string>(const char *file, int line, 546 const char *func, 547 std::string message, 548 const char *assertion, 549 bool) 550 { 551 assert_fail_failure(file, line, func, message.c_str(), assertion, true); 530 552 } 531 553 … … 546 568 { 547 569 throw AssertionFailedError(file, line, func, message, assertion); 570 } 571 572 template <> 573 inline void assert_fail_exception<std::string>(const char *file, int line, 574 const char *func, 575 std::string message, 576 const char *assertion, 577 bool) 578 { 579 assert_fail_exception(file, line, func, message.c_str(), assertion, true); 548 580 } 549 581 -
tools/dim_to_lgf.cc
r2404 r2410 19 19 ///\ingroup demos 20 20 ///\file 21 ///\brief DIMACS to LGF converter (demo).21 ///\brief DIMACS to LGF converter. 22 22 /// 23 23 /// This program converts various DIMACS formats to the LEMON Graph Format … … 34 34 #include <lemon/graph_writer.h> 35 35 36 #include <lemon/arg_parser.h> 37 36 38 using namespace std; 37 39 using namespace lemon; 38 39 const char* versionString =40 "dim_to_lgf - part of lemon library\n";41 42 const char* helpString =43 "DIMACS to LGF converter\n"44 "Usage: dim_to_lgf [OPTIONS]\n"45 "\n"46 "Examples:\n"47 " dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n"48 "\n"49 "Options:\n"50 " -i FILE, --input FILE use FILE as input instead of standard input\n"51 " -o FILE, --output FILE use FILE as output instead of standard output\n"52 " -t TYPE, --type TYPE set up the type of the graph\n"53 " Possible types:\n"54 " mincostflow\n"55 " maxflow (default)\n"56 " shortestpath\n"57 " capacitated\n"58 " plain\n"59 " -v, --version shows the version of the converter\n"60 " -h, --help shows the help of the converter\n";61 40 62 41 … … 74 53 std::string typeName; 75 54 76 bool help = false; 77 bool version = false; 55 bool mincostflow; 56 bool maxflow; 57 bool shortestpath; 58 bool capacitated; 59 bool plain; 78 60 79 for (int arg = 1; arg < argc; ++arg) { 80 if (strcmp(argv[arg], "--type") == 0 || 81 strcmp(argv[arg], "-t") == 0) { 82 if (!typeName.empty()) { 83 cerr << "Multiple type description" << endl; 84 return -1; 85 } 86 if (arg + 1 == argc) { 87 cerr << "Parameter without value" << endl; 88 return -1; 89 } 90 typeName = argv[++arg]; 91 } 92 else if (strcmp(argv[arg], "--input") == 0 || 93 strcmp(argv[arg], "-i") == 0) { 94 if (!inputName.empty()) { 95 cerr << "Multiple input description" << endl; 96 return -1; 97 } 98 if (arg + 1 == argc) { 99 cerr << "Parameter without value" << endl; 100 return -1; 101 } 102 inputName = argv[++arg]; 103 } 104 else if (strcmp(argv[arg], "--output") == 0 || 105 strcmp(argv[arg], "-o") == 0) { 106 if (!outputName.empty()) { 107 cerr << "Multiple input description" << endl; 108 return -1; 109 } 110 if (arg + 1 == argc) { 111 cerr << "Parameter without value" << endl; 112 return -1; 113 } 114 outputName = argv[++arg]; 115 } else if (strcmp(argv[arg], "--help") == 0 || 116 strcmp(argv[arg], "-h") == 0) { 117 help = true; 118 } else if (strcmp(argv[arg], "--version") == 0 || 119 strcmp(argv[arg], "-v") == 0) { 120 version = true; 121 } else { 122 cerr << "Invalid option: " << argv[arg] << endl; 123 return -1; 124 } 125 } 61 bool version; 126 62 127 if (version) { 128 cout << versionString; 129 } 130 if (help) { 131 cout << helpString; 132 } 133 if (help || version) { 134 return 0; 135 } 63 ArgParser ap(argc, argv); 64 ap.refOption("-input", 65 "use FILE as input instead of standard input", 66 inputName).synonym("i", "-input") 67 .refOption("-output", 68 "use FILE as output instead of standard output", 69 outputName).synonym("o", "-output") 70 .refOption("-mincostflow", 71 "set the type of the graph to \"mincostflow\" graph", 72 mincostflow) 73 .optionGroup("type", "-mincostflow").synonym("mcf", "-mincostflow") 74 .refOption("-maxflow", 75 "set the type of the graph to \"maxflow\" graph", 76 maxflow) 77 .optionGroup("type", "-maxflow").synonym("mf", "-maxflow") 78 .refOption("-shortestpath", 79 "set the type of the graph to \"shortestpath\" graph", 80 shortestpath) 81 .optionGroup("type", "-shortestpath").synonym("sp", "-shortestpath") 82 .refOption("-capacitated", 83 "set the type of the graph to \"capacitated\" graph", 84 capacitated) 85 .optionGroup("type", "-capacitated").synonym("cap", "-capacitated") 86 .refOption("-plain", 87 "set the type of the graph to \"plain\" graph", 88 plain) 89 .optionGroup("type", "-plain").synonym("pl", "-plain") 90 .onlyOneGroup("type") 91 .mandatoryGroup("type") 92 .refOption("-version", "show version information", version) 93 .synonym("v", "-version") 94 .run(); 136 95 137 96 ifstream input; … … 155 114 ostream& os = (outputName.empty() ? cout : output); 156 115 157 if (typeName.empty()) { 158 typeName = "maxflow"; 159 } 160 161 if (typeName == "mincostflow") { 116 if (mincostflow) { 162 117 Graph graph; 163 118 Node s, t; … … 170 125 writeEdgeMap("cost", cost). 171 126 run(); 172 } else if ( typeName == "maxflow") {127 } else if (maxflow) { 173 128 Graph graph; 174 129 Node s, t; … … 180 135 writeNode("target", t). 181 136 run(); 182 } else if ( typeName == "shortestpath") {137 } else if (shortestpath) { 183 138 Graph graph; 184 139 Node s; … … 189 144 writeNode("source", s). 190 145 run(); 191 } else if ( typeName == "capacitated") {146 } else if (capacitated) { 192 147 Graph graph; 193 148 DoubleMap capacity(graph); … … 196 151 writeEdgeMap("capacity", capacity). 197 152 run(); 198 } else if ( typeName == "plain") {153 } else if (plain) { 199 154 Graph graph; 200 155 readDimacs(is, graph); -
tools/lgf-gen.cc
r2402 r2410 280 280 281 281 282 int main(int argc,c har **argv)282 int main(int argc,const char **argv) 283 283 { 284 284 ArgParser ap(argc,argv);
Note: See TracChangeset
for help on using the changeset viewer.