Changeset 1246 in SHVCSoftware for branches/SHM-dev/source/Lib/TAppCommon/program_options_lite.cpp
- Timestamp:
- 14 Jul 2015, 00:26:07 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/Lib/TAppCommon/program_options_lite.cpp
r1029 r1246 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 6 * Copyright (c) 2010-2014, ITU/ISO/IEC … … 50 50 namespace program_options_lite 51 51 { 52 52 53 53 Options::~Options() 54 54 { … … 58 58 } 59 59 } 60 60 61 61 void Options::addOption(OptionBase *opt) 62 62 { … … 64 64 names->opt = opt; 65 65 string& opt_string = opt->opt_string; 66 66 67 67 size_t opt_start = 0; 68 68 for (size_t opt_end = 0; opt_end != string::npos;) … … 96 96 return OptionSpecific(*this); 97 97 } 98 98 99 99 static void setOptions(Options::NamesPtrList& opt_list, const string& value) 100 100 { … … 108 108 109 109 static const char spaces[41] = " "; 110 110 111 111 /* format help text for a single option: 112 112 * using the formatting: "-x, --long", … … 138 138 } 139 139 } 140 140 141 141 /* format the help text */ 142 142 void doHelp(ostream& out, Options& opts, unsigned columns) … … 154 154 unsigned opt_width = min(max_width+2, 28u + pad_short) + 2; 155 155 unsigned desc_width = columns - opt_width; 156 156 157 157 /* second pass: write out formatted option and help text. 158 158 * - align start of help text to start at opt_width … … 209 209 split_pos = opt_desc.find_last_not_of(' ', split_pos) + 1; 210 210 } 211 211 212 212 /* bad split if no suitable space to split at. fall back to width */ 213 213 bool bad_split = split_pos == string::npos || split_pos <= cur_pos; … … 217 217 } 218 218 line << opt_desc.substr(cur_pos, split_pos - cur_pos); 219 219 220 220 /* eat up any space for the start of the next line */ 221 221 if (!bad_split) … … 224 224 } 225 225 cur_pos = newline_pos = split_pos; 226 226 227 227 if (cur_pos >= opt_desc.size()) 228 228 { … … 235 235 } 236 236 } 237 237 238 238 bool storePair(Options& opts, bool allow_long, bool allow_short, const string& name, const string& value) 239 239 { … … 248 248 } 249 249 } 250 250 251 251 /* check for the short list */ 252 252 if (allow_short && !(found && allow_long)) … … 269 269 return true; 270 270 } 271 271 272 272 bool storePair(Options& opts, const string& name, const string& value) 273 273 { 274 274 return storePair(opts, true, true, name, value); 275 275 } 276 276 277 277 /** 278 278 * returns number of extra arguments consumed … … 288 288 size_t arg_opt_sep = arg.find_first_of('='); 289 289 string option = arg.substr(arg_opt_start, arg_opt_sep - arg_opt_start); 290 290 291 291 unsigned extra_argc_consumed = 0; 292 292 if (arg_opt_sep == string::npos) … … 299 299 * booleans */ 300 300 if (argc == 1) 301 { 301 302 return 0; /* run out of argv for argument */ 303 } 302 304 extra_argc_consumed = 1; 303 305 #endif … … 339 341 return 1; 340 342 } 341 343 342 344 list<const char*> 343 345 scanArgv(Options& opts, unsigned argc, const char* argv[]) … … 376 378 /* a lone double dash ends option processing */ 377 379 while (++i < argc) 380 { 378 381 non_option_arguments.push_back(argv[i]); 382 } 379 383 break; 380 384 } … … 386 390 return non_option_arguments; 387 391 } 388 392 389 393 void scanLine(Options& opts, string& line) 390 394 { … … 441 445 * any trailing whitespace will be removed shortly */ 442 446 value_end = line.find_first_not_of(" \t\n\r", value_end); 443 } 444 while (value_end != string::npos); 447 } while (value_end != string::npos); 445 448 /* strip any trailing space from value*/ 446 449 value_end = line.find_last_not_of(" \t\n\r", value_end); … … 468 471 getline(in, line); 469 472 scanLine(opts, line); 470 } 471 while(!!in); 473 } while(!!in); 472 474 } 473 475
Note: See TracChangeset for help on using the changeset viewer.