| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef TCLAP_CMD_LINE_OUTPUT_H |
| 25 |
#define TCLAP_CMD_LINE_OUTPUT_H |
| 26 |
|
| 27 |
#include <tclap/Arg.h> |
| 28 |
#include <tclap/ArgGroup.h> |
| 29 |
|
| 30 |
#include <algorithm> |
| 31 |
#include <cstddef> |
| 32 |
#include <iomanip> |
| 33 |
#include <iostream> |
| 34 |
#include <list> |
| 35 |
#include <string> |
| 36 |
#include <vector> |
| 37 |
|
| 38 |
namespace TCLAP { |
| 39 |
const char PATH_SEPARATOR = |
| 40 |
#ifdef _WIN32 |
| 41 |
'\\'; |
| 42 |
#else |
| 43 |
'/'; |
| 44 |
#endif |
| 45 |
|
| 46 |
class CmdLineInterface; |
| 47 |
class ArgException; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
class CmdLineOutput { |
| 53 |
public: |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
virtual ~CmdLineOutput() {} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
virtual void usage(CmdLineInterface &c) = 0; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
virtual void version(CmdLineInterface &c) = 0; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
virtual void failure(CmdLineInterface &c, ArgException &e) = 0; |
| 77 |
}; |
| 78 |
|
| 79 |
inline bool isInArgGroup(const Arg *arg, const std::list<ArgGroup *> &argSets) { |
| 80 |
for (std::list<ArgGroup *>::const_iterator it = argSets.begin(); |
| 81 |
it != argSets.end(); ++it) { |
| 82 |
if (std::find((*it)->begin(), (*it)->end(), arg) != (*it)->end()) { |
| 83 |
return true; |
| 84 |
} |
| 85 |
} |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
inline void removeArgsInArgGroups(std::list<Arg *> &argList, |
| 90 |
const std::list<ArgGroup *> &argSets) { |
| 91 |
for (std::list<Arg *>::iterator it = argList.begin(); |
| 92 |
it != argList.end();) { |
| 93 |
if (isInArgGroup(*it, argSets)) { |
| 94 |
it = argList.erase(it); |
| 95 |
} else { |
| 96 |
++it; |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
inline std::string removeSuffix(std::string s, const std::string &suffix) { |
| 102 |
std::ptrdiff_t start = s.length() - suffix.length(); |
| 103 |
if (start >= 0 && s.substr(start) == suffix) { |
| 104 |
return s.substr(0, start); |
| 105 |
} |
| 106 |
|
| 107 |
return s; |
| 108 |
} |
| 109 |
|
| 110 |
inline std::string basename(std::string s) { |
| 111 |
size_t p = s.find_last_of(PATH_SEPARATOR); |
| 112 |
if (p != std::string::npos) { |
| 113 |
s.erase(0, p + 1); |
| 114 |
} |
| 115 |
|
| 116 |
return removeSuffix(s, ".exe"); |
| 117 |
} |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
#endif |