tclap 1.6.0
ArgTraits.h
Go to the documentation of this file.
1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3/******************************************************************************
4 *
5 * file: ArgTraits.h
6 *
7 * Copyright (c) 2007, Daniel Aarno, 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// This is an internal tclap file, you should probably not have to
25// include this directly
26
27#ifndef TCLAP_ARG_TRAITS_H
28#define TCLAP_ARG_TRAITS_H
29
30namespace TCLAP {
31
32// We use two empty structs to get compile type specialization
33// function to work
34
39struct ValueLike {
41 virtual ~ValueLike() = default;
42};
43
49struct StringLike {
50 virtual ~StringLike() = default;
51};
52
62 virtual ~StringLikeTrait() = default;
63};
64
74 virtual ~ValueLikeTrait() = default;
75};
76
77namespace detail {
78// Satisfied iff C has a nested C::ValueCategory type.
79template <typename C>
80concept HasValueCategory = requires { typename C::ValueCategory; };
81} // namespace detail
82
91template <typename T>
92class ArgTraits {
93 // What we want to do is:
94 // 1) If there exists a specialization of ArgTraits for type X,
95 // use it.
96 //
97 // 2) If no specialization exists but X has the typename
98 // X::ValueCategory, use the specialization for X::ValueCategory.
99 //
100 // 3) If neither (1) nor (2) defines the trait, use the default
101 // which is ValueLike.
102 template <typename C, bool = detail::HasValueCategory<C>>
103 struct DefaultArgTrait {
104 using ValueCategory = ValueLike;
105 };
106
107 template <typename C>
108 struct DefaultArgTrait<C, true> {
109 using ValueCategory = typename C::ValueCategory;
110 };
111
112public:
114};
115
116} // namespace TCLAP
117
118#endif // TCLAP_ARG_TRAITS_H
Arg traits are used to get compile type specialization when parsing argument values.
Definition ArgTraits.h:92
typename DefaultArgTrait< T >::ValueCategory ValueCategory
Definition ArgTraits.h:113
Definition Arg.h:54
A class can inherit from this object to make it have string like traits.
Definition ArgTraits.h:60
virtual ~StringLikeTrait()=default
A string like argument value type is a value that can be set using operator=(string).
Definition ArgTraits.h:49
virtual ~StringLike()=default
A class can inherit from this object to make it have value like traits.
Definition ArgTraits.h:72
virtual ~ValueLikeTrait()=default
A value like argument value type is a value that can be set using operator>>.
Definition ArgTraits.h:39
virtual ~ValueLike()=default