Debian Codegraph @

podofo/3rdparty/tclap/CmdLineOutput.h

raw symbols SCIP
1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3 /******************************************************************************
4 *
5 * file: CmdLineOutput.h
6 *
7 * Copyright (c) 2004, Michael E. Smoot
8 * Copyright (c) 2017, Google LLC
9 * All rights reserved.
10 *
11 * See the file COPYING in the top directory of this distribution for
12 * more information.
13 *
14 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
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 * The interface that any output object must implement.
51 */
52 class CmdLineOutput {
53 public:
54 /**
55 * Virtual destructor.
56 */
57 virtual ~CmdLineOutput() {}
58
59 /**
60 * Generates some sort of output for the USAGE.
61 * \param c - The CmdLine object the output is generated for.
62 */
63 virtual void usage(CmdLineInterface &c) = 0;
64
65 /**
66 * Generates some sort of output for the version.
67 * \param c - The CmdLine object the output is generated for.
68 */
69 virtual void version(CmdLineInterface &c) = 0;
70
71 /**
72 * Generates some sort of output for a failure.
73 * \param c - The CmdLine object the output is generated for.
74 * \param e - The ArgException that caused the failure.
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 } // namespace TCLAP
120
121 #endif // TCLAP_CMD_LINE_OUTPUT_H