LCOV - code coverage report
Current view: top level - advgetopt - validator_integer.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2022-05-26 21:41:34 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          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             : // C++ lib
      38             : //
      39             : #include    <limits>
      40             : 
      41             : 
      42             : 
      43             : namespace advgetopt
      44             : {
      45             : 
      46             : 
      47             : 
      48          48 : class validator_integer
      49             :     : public validator
      50             : {
      51             : public:
      52             :     typedef bool (*to_integer_t)(std::string const & number
      53             :                                , std::int64_t & result);
      54             : 
      55             :                                 validator_integer(string_list_t const & data);
      56             : 
      57             :     // validator implementation
      58             :     //
      59             :     virtual std::string         name() const override;
      60             :     virtual bool                validate(std::string const & value) const override;
      61             : 
      62             :     static bool                 convert_string(std::string const & number
      63             :                                              , std::int64_t & result);
      64             : 
      65             : private:
      66             :     struct range_t
      67             :     {
      68             :         typedef std::vector<range_t>    vector_t;
      69             : 
      70             :         std::int64_t            f_minimum = std::numeric_limits<std::int64_t>::min();
      71             :         std::int64_t            f_maximum = std::numeric_limits<std::int64_t>::max();
      72             :     };
      73             : 
      74             :     range_t::vector_t           f_allowed_values = range_t::vector_t();
      75             : };
      76             : 
      77             : 
      78             : 
      79             : }   // namespace advgetopt
      80             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13