advgetopt 2.0.49
Parse complex command line arguments and configuration files in C++.
validator_list.cpp
Go to the documentation of this file.
1// Copyright (c) 2006-2025 Made to Order Software Corp. All Rights Reserved
2//
3// https://snapwebsites.org/project/advgetopt
4// contact@m2osw.com
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this program; if not, write to the Free Software Foundation, Inc.,
18// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
30// self
31//
33
34
35// cppthread
36//
37#include <cppthread/log.h>
38
39
40// last include
41//
42#include <snapdev/poison.h>
43
44
45
46
47namespace advgetopt
48{
49
50
51
52namespace
53{
54
55
56
58 : public validator_factory
59{
60public:
62 {
63 validator::register_validator(*this);
64 }
65
66 virtual std::string get_name() const override
67 {
68 return std::string("list");
69 }
70
71 virtual std::shared_ptr<validator> create(string_list_t const & data) const override
72 {
73 return std::make_shared<validator_list>(data);
74 }
75};
76
78
79
80
81} // no name namespace
82
83
84
85
86
88{
89 if(!param_list.empty())
90 {
91 cppthread::log << cppthread::log_level_t::error
92 << "validator_list() does not support any parameter."
93 << cppthread::end;
94 return;
95 }
96}
97
98
100{
101 if(v != nullptr)
102 {
103 f_validators.push_back(v);
104 }
105}
106
107
114std::string validator_list::name() const
115{
116 return std::string("list");
117}
118
119
130bool validator_list::validate(std::string const & value) const
131{
132 for(auto const & v : f_validators)
133 {
134 if(v->validate(value))
135 {
136 return true;
137 }
138 }
139
140 return false;
141}
142
143
144
145} // namespace advgetopt
146// vim: ts=4 sw=4 et
virtual std::shared_ptr< validator > create(string_list_t const &data) const override
void add_validator(validator::pointer_t v)
validator_list(string_list_t const &data)
validator::vector_t f_validators
virtual bool validate(std::string const &value) const override
Check the value against all the validators for one valid one.
virtual std::string name() const override
Return the name of this validator.
std::shared_ptr< validator > pointer_t
Definition validator.h:64
The advgetopt environment to parse command line options.
Definition version.h:37
constexpr flag_t option_flags_merge()
Definition flags.h:87
std::vector< std::string > string_list_t
Definition utils.h:41
Declaration of a validator handling multiple sub-validators.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.