tclap  1.4.0
CmdLineOutput.h
Go to the documentation of this file.
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 <iomanip>
32 #include <iostream>
33 #include <list>
34 #include <string>
35 #include <vector>
36 
37 namespace TCLAP {
38 
39 class CmdLineInterface;
40 class ArgException;
41 
46 public:
50  virtual ~CmdLineOutput() {}
51 
56  virtual void usage(CmdLineInterface &c) = 0;
57 
62  virtual void version(CmdLineInterface &c) = 0;
63 
69  virtual void failure(CmdLineInterface &c, ArgException &e) = 0;
70 };
71 
72 inline bool isInArgGroup(const Arg *arg, const std::list<ArgGroup *> &argSets) {
73  for (std::list<ArgGroup *>::const_iterator it = argSets.begin();
74  it != argSets.end(); ++it) {
75  if (std::find((*it)->begin(), (*it)->end(), arg) != (*it)->end()) {
76  return true;
77  }
78  }
79  return false;
80 }
81 
82 inline void removeArgsInArgGroups(std::list<Arg *> &argList,
83  const std::list<ArgGroup *> &argSets) {
84  for (std::list<Arg *>::iterator it = argList.begin();
85  it != argList.end();) {
86  if (isInArgGroup(*it, argSets)) {
87  it = argList.erase(it);
88  } else {
89  ++it;
90  }
91  }
92 }
93 
94 inline std::string basename(std::string s) {
95  // TODO(macbishop): See if we can make this more robust
96  size_t p = s.find_last_of("/\\");
97  if (p != std::string::npos) {
98  s.erase(0, p + 1);
99  }
100 
101  p = s.rfind(".exe");
102  if (p == s.length() - 4) {
103  s.erase(s.length() - 4);
104  }
105 
106  return s;
107 }
108 
109 } // namespace TCLAP
110 
111 #endif // TCLAP_CMD_LINE_OUTPUT_H
A virtual base class that defines the essential data for all arguments.
Definition: Arg.h:53
A simple class that defines and argument exception.
Definition: ArgException.h:36
virtual void failure(CmdLineInterface &c, ArgException &e)=0
Generates some sort of output for a failure.
void removeArgsInArgGroups(std::list< Arg *> &argList, const std::list< ArgGroup *> &argSets)
Definition: CmdLineOutput.h:82
bool isInArgGroup(const Arg *arg, const std::list< ArgGroup *> &argSets)
Definition: CmdLineOutput.h:72
virtual void usage(CmdLineInterface &c)=0
Generates some sort of output for the USAGE.
std::string basename(std::string s)
Definition: CmdLineOutput.h:94
virtual ~CmdLineOutput()
Virtual destructor.
Definition: CmdLineOutput.h:50
The base class that manages the command line definition and passes along the parsing to the appropria...
virtual void version(CmdLineInterface &c)=0
Generates some sort of output for the version.
Definition: Arg.h:46
The interface that any output object must implement.
Definition: CmdLineOutput.h:45