tclap 1.4.0
CmdLineInterface.h
Go to the documentation of this file.
1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3/******************************************************************************
4 *
5 * file: CmdLineInterface.h
6 *
7 * Copyright (c) 2003, Michael E. Smoot .
8 * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
9 * Copyright (c) 2017, Google LLC
10 * All rights reserved.
11 *
12 * See the file COPYING in the top directory of this distribution for
13 * more information.
14 *
15 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 *****************************************************************************/
24
25#ifndef TCLAP_CMD_LINE_INTERFACE_H
26#define TCLAP_CMD_LINE_INTERFACE_H
27
28#include <tclap/ArgContainer.h>
29
30#include <algorithm>
31#include <iostream>
32#include <list>
33#include <string>
34#include <vector>
35
36namespace TCLAP {
37
38class Arg;
39class ArgGroup;
40class CmdLineOutput;
41
47 friend class ArgGroup;
48protected:
49 // Return true when the implementation handles the whole attachment.
50 // The default lets ArgGroup keep the legacy custom-parser path.
51 virtual bool attachGroup(ArgGroup &) { return false; }
52
53public:
57 virtual ~CmdLineInterface() {}
58
64 virtual ArgContainer &add(Arg &a) = 0;
65
71 virtual ArgContainer &add(Arg *a) = 0;
72
73 // TODO: Rename this to something smarter or refactor this logic so
74 // it's not needed.
75 // Internal - do not use
76 virtual void addToArgList(Arg *a) = 0;
77
88 virtual ArgContainer &add(ArgGroup &args) = 0;
89
93 virtual void xorAdd(Arg &a, Arg &b) = 0;
94
98 virtual void xorAdd(const std::vector<Arg *> &xors) = 0;
99
105 virtual void parse(int argc, const char *const *argv) = 0;
106
112 void parse(std::vector<std::string> &args);
113
117 virtual void setOutput(CmdLineOutput *co) = 0;
118
122 virtual std::string getVersion() const = 0;
123
127 virtual std::string getProgramName() const = 0;
128
132 virtual std::list<ArgGroup *> getArgGroups() = 0;
133 virtual std::list<Arg *> getArgList() const = 0; // TODO: get rid of this
134
138 virtual char getDelimiter() const = 0;
139
143 virtual std::string getMessage() const = 0;
144
148 virtual std::string translateMessage(const std::string &messageId,
149 const std::string &fallback) const = 0;
150
155 virtual bool hasHelpAndVersion() const = 0;
156
161 virtual void reset() = 0;
162
167 virtual void beginIgnoring() = 0;
168
173 virtual bool ignoreRest() = 0;
174};
175
176} // namespace TCLAP
177
178#endif // TCLAP_CMD_LINE_INTERFACE_H
Interface that allows adding an Arg to a "container".
ArgGroup is the base class for implementing groups of arguments that are mutually exclusive (it repla...
Definition ArgGroup.h:41
A virtual base class that defines the essential data for all arguments.
Definition Arg.h:66
The base class that manages the command line definition and passes along the parsing to the appropria...
void parse(std::vector< std::string > &args)
Parses the command line.
virtual bool ignoreRest()=0
Whether to ignore the rest.
virtual std::string getVersion() const =0
Returns the version string.
virtual ArgContainer & add(Arg *a)=0
Adds an argument.
virtual void beginIgnoring()=0
Begin ignoring arguments since the "--" argument was specified.
virtual bool attachGroup(ArgGroup &)
virtual void parse(int argc, const char *const *argv)=0
Parses the command line.
virtual void xorAdd(Arg &a, Arg &b)=0
virtual void reset()=0
Resets the instance as if it had just been constructed so that the instance can be reused.
virtual ~CmdLineInterface()
Destructor.
virtual std::string getMessage() const =0
Returns the message string.
virtual bool hasHelpAndVersion() const =0
Indicates whether or not the help and version switches were created automatically.
virtual std::string translateMessage(const std::string &messageId, const std::string &fallback) const =0
Translates a built-in message using the current translator.
virtual std::string getProgramName() const =0
Returns the program name string.
virtual ArgContainer & add(Arg &a)=0
Adds an argument.
virtual void setOutput(CmdLineOutput *co)=0
virtual void xorAdd(const std::vector< Arg * > &xors)=0
virtual ArgContainer & add(ArgGroup &args)=0
Adds an argument group to the list of arguments to be parsed.
virtual std::list< ArgGroup * > getArgGroups()=0
Returns the list of ArgGroups.
virtual char getDelimiter() const =0
Returns the delimiter string.
virtual std::list< Arg * > getArgList() const =0
virtual void addToArgList(Arg *a)=0
The interface that any output object must implement.
Definition Arg.h:52