advgetopt 2.0.50
Parse complex command line arguments and configuration files in C++.
validator_duration.h
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#pragma once
20
32// advgetopt
33//
34#include "advgetopt/validator.h"
35
36
37// C++
38//
39#include <cstdint>
40#include <limits>
41
42
43
44namespace advgetopt
45{
46
47
48
50 : public validator
51{
52public:
53 typedef std::uint32_t flag_t;
54
56 static constexpr flag_t VALIDATOR_DURATION_LONG = 0x01;
57
59
60 // validator implementation
61 //
62 virtual std::string name() const override;
63 virtual bool validate(std::string const & value) const override;
64
65 static bool convert_string(
66 std::string const & duration
69 , double & result);
70
71 static double suffix_to_factor(
72 std::string const & suffix
74 , double suffix_default_factor);
75
76private:
77 struct range_t
78 {
79 typedef std::vector<range_t> vector_t;
80
81 double f_minimum = std::numeric_limits<double>::min();
82 double f_maximum = std::numeric_limits<double>::max();
83 };
84
86 double f_default_factor = 1.0;
88};
89
90
91
92} // namespace advgetopt
93// vim: ts=4 sw=4 et
static constexpr flag_t VALIDATOR_DURATION_DEFAULT_FLAGS
virtual std::string name() const override
Return the name of this validator.
virtual bool validate(std::string const &value) const override
Determine whether value is a valid duration.
static bool convert_string(std::string const &duration, flag_t flags, double suffix_default_factor, double &result)
Convert a string to a double value representing a duration.
static double suffix_to_factor(std::string const &suffix, flag_t flags, double suffix_default_factor)
Convert a duration suffix in a factor.
static constexpr flag_t VALIDATOR_DURATION_LONG
The advgetopt environment to parse command line options.
Definition version.h:37
constexpr flag_t option_flags_merge()
Definition flags.h:89
std::vector< std::string > string_list_t
Definition utils.h:41
Declaration of validators which can be used to verify the parameters.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.