Line data Source code
1 : // Copyright (c) 2006-2022 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 : #pragma once
20 :
21 : /** \file
22 : * \brief Declaration of the length validator.
23 : *
24 : * The advgetopt library offers a length validator which verifies that the
25 : * parameter has that many characters.
26 : *
27 : * The length are written as ranges separated by commas (,):
28 : *
29 : * \code
30 : * length(1...100,128)
31 : * \endcode
32 : *
33 : * A number by itself means the length can be that number of characters or
34 : * less.
35 : */
36 :
37 : // self
38 : //
39 : #include <advgetopt/validator.h>
40 :
41 :
42 :
43 : namespace advgetopt
44 : {
45 :
46 :
47 :
48 42 : class validator_length
49 : : public validator
50 : {
51 : public:
52 : validator_length(string_list_t const & data);
53 :
54 : // validator implementation
55 : //
56 : virtual std::string name() const override;
57 : virtual bool validate(std::string const & value) const override;
58 :
59 : private:
60 : struct range_t
61 : {
62 : typedef std::vector<range_t> vector_t;
63 :
64 : std::int64_t f_minimum = std::numeric_limits<std::int64_t>::min();
65 : std::int64_t f_maximum = std::numeric_limits<std::int64_t>::max();
66 : };
67 :
68 : range_t::vector_t f_allowed_lengths = range_t::vector_t();
69 : };
70 :
71 :
72 :
73 : } // namespace advgetopt
74 : // vim: ts=4 sw=4 et
|