| 456 | } |
| 457 | |
| 458 | void CommandLineArguments::GenerateHelp() |
| 459 | { |
| 460 | std::ostringstream str; |
| 461 | |
| 462 | // Collapse all arguments into the map of vectors of all arguments that do |
| 463 | // the same thing. |
| 464 | CommandLineArguments::Internal::CallbacksMap::iterator it; |
| 465 | using MapArgs = std::map<CommandLineArguments::Internal::String, |
| 466 | CommandLineArguments::Internal::SetOfStrings>; |
| 467 | MapArgs mp; |
| 468 | MapArgs::iterator mpit, smpit; |
| 469 | for (it = this->Internals->Callbacks.begin(); |
| 470 | it != this->Internals->Callbacks.end(); ++it) { |
| 471 | CommandLineArgumentsCallbackStructure* cs = &(it->second); |
| 472 | mpit = mp.find(cs->Help); |
| 473 | if (mpit != mp.end()) { |
| 474 | mpit->second.insert(it->first); |
| 475 | mp[it->first].insert(it->first); |
| 476 | } else { |
| 477 | mp[it->first].insert(it->first); |
| 478 | } |
| 479 | } |
| 480 | for (it = this->Internals->Callbacks.begin(); |
| 481 | it != this->Internals->Callbacks.end(); ++it) { |
| 482 | CommandLineArgumentsCallbackStructure* cs = &(it->second); |
| 483 | mpit = mp.find(cs->Help); |
| 484 | if (mpit != mp.end()) { |
| 485 | mpit->second.insert(it->first); |
| 486 | smpit = mp.find(it->first); |
| 487 | CommandLineArguments::Internal::SetOfStrings::iterator sit; |
| 488 | for (sit = smpit->second.begin(); sit != smpit->second.end(); ++sit) { |
| 489 | mpit->second.insert(*sit); |
| 490 | } |
| 491 | mp.erase(smpit); |
| 492 | } else { |
| 493 | mp[it->first].insert(it->first); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | // Find the length of the longest string |
| 498 | CommandLineArguments::Internal::String::size_type maxlen = 0; |
| 499 | for (mpit = mp.begin(); mpit != mp.end(); ++mpit) { |
| 500 | CommandLineArguments::Internal::SetOfStrings::iterator sit; |
| 501 | for (sit = mpit->second.begin(); sit != mpit->second.end(); ++sit) { |
| 502 | CommandLineArguments::Internal::String::size_type clen = sit->size(); |
| 503 | switch (this->Internals->Callbacks[*sit].ArgumentType) { |
| 504 | case CommandLineArguments::NO_ARGUMENT: |
| 505 | clen += 0; |
| 506 | break; |
| 507 | case CommandLineArguments::CONCAT_ARGUMENT: |
| 508 | clen += 3; |
| 509 | break; |
| 510 | case CommandLineArguments::SPACE_ARGUMENT: |
| 511 | clen += 4; |
| 512 | break; |
| 513 | case CommandLineArguments::EQUAL_ARGUMENT: |
| 514 | clen += 4; |
| 515 | break; |