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 validators which can be used to verify the parameters.
23 : *
24 : * The library offers parameter validations using validator objects. You
25 : * can even make your own validator objects available before parsing your
26 : * data so that way it can be verified as expected.
27 : *
28 : * Validators are recognized by name. A value can be assigned a validator
29 : * by specify the \em type of data it supports.
30 : */
31 :
32 : // advgetopt lib
33 : //
34 : #include "advgetopt/validator.h"
35 :
36 :
37 :
38 : namespace advgetopt
39 : {
40 :
41 :
42 :
43 3 : class validator_size
44 : : public validator
45 : {
46 : public:
47 : typedef std::uint32_t flag_t;
48 :
49 : static constexpr flag_t VALIDATOR_SIZE_DEFAULT_FLAGS = 0x00;
50 : static constexpr flag_t VALIDATOR_SIZE_POWER_OF_TWO = 0x01;
51 :
52 : validator_size(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 : #pragma GCC diagnostic push
60 : #pragma GCC diagnostic ignored "-Wpedantic"
61 : static bool convert_string(std::string const & size
62 : , flag_t flags
63 : , __int128 & result);
64 : #pragma GCC diagnostic pop
65 :
66 : private:
67 : flag_t f_flags = VALIDATOR_SIZE_DEFAULT_FLAGS;
68 : };
69 :
70 :
71 :
72 : } // namespace advgetopt
73 : // vim: ts=4 sw=4 et
|