tclap 1.4.0
Constraint.h
Go to the documentation of this file.
1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3/******************************************************************************
4 *
5 * file: Constraint.h
6 *
7 * Copyright (c) 2005, 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_CONSTRAINT_H
25#define TCLAP_CONSTRAINT_H
26
27#include <algorithm>
28#include <iomanip>
29#include <iostream>
30#include <list>
31#include <stdexcept>
32#include <string>
33#include <vector>
34
35namespace TCLAP {
36
40template <class T>
42public:
46 virtual std::string description() const = 0;
47
51 virtual std::string shortID() const = 0;
52
58 virtual bool check(const T &value) const = 0;
59
65 virtual ~Constraint() { ; }
66
67 static std::string shortID(const Constraint<T> *constraint) {
68 if (!constraint)
69 throw std::logic_error(
70 "Cannot create a ValueArg with a NULL constraint");
71 return constraint->shortID();
72 }
73};
74
75} // namespace TCLAP
76
77#endif // TCLAP_CONSTRAINT_H
The interface that defines the interaction between the Arg and Constraint.
Definition Constraint.h:41
virtual std::string shortID() const =0
Returns the short ID for the Constraint.
static std::string shortID(const Constraint< T > *constraint)
Definition Constraint.h:67
virtual bool check(const T &value) const =0
The method used to verify that the value parsed from the command line meets the constraint.
virtual std::string description() const =0
Returns a description of the Constraint.
virtual ~Constraint()
Destructor.
Definition Constraint.h:65
Definition Arg.h:52