LCOV - code coverage report
Current view: top level - advgetopt - exception.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 14 100.0 %
Date: 2019-07-15 03:11:49 Functions: 11 19 57.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * File:
       3             :  *    advgetopt/exception.h -- a replacement to the Unix getopt() implementation
       4             :  *
       5             :  * License:
       6             :  *    Copyright (c) 2006-2019  Made to Order Software Corp.  All Rights Reserved
       7             :  *
       8             :  *    https://snapwebsites.org/
       9             :  *    contact@m2osw.com
      10             :  *
      11             :  *    This program is free software; you can redistribute it and/or modify
      12             :  *    it under the terms of the GNU General Public License as published by
      13             :  *    the Free Software Foundation; either version 2 of the License, or
      14             :  *    (at your option) any later version.
      15             :  *
      16             :  *    This program is distributed in the hope that it will be useful,
      17             :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  *    GNU General Public License for more details.
      20             :  *
      21             :  *    You should have received a copy of the GNU General Public License along
      22             :  *    with this program; if not, write to the Free Software Foundation, Inc.,
      23             :  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      24             :  *
      25             :  * Authors:
      26             :  *    Alexis Wilke   alexis@m2osw.com
      27             :  *    Doug Barbieri  doug@m2osw.com
      28             :  */
      29             : #pragma once
      30             : 
      31             : /** \file
      32             :  * \brief Definitions of the advanced getopt exceptions.
      33             :  *
      34             :  * The library generates exceptions which are defined here. These are
      35             :  * derived from the libexcept library so we get a stack trace whenever
      36             :  * an exception occurs.
      37             :  */
      38             : 
      39             : #include <libexcept/exception.h>
      40             : 
      41             : 
      42             : 
      43             : 
      44             : namespace advgetopt
      45             : {
      46             : 
      47             : 
      48             : 
      49             : // generic logic error (something's wrong in the library)
      50        2734 : class getopt_exception_logic : public libexcept::logic_exception_t
      51             : {
      52             : public:
      53        2734 :     getopt_exception_logic(std::string const & msg) : logic_exception_t(msg) {}
      54             : };
      55             : 
      56             : 
      57             : // generic getopt exception
      58         110 : class getopt_exception : public libexcept::exception_t
      59             : {
      60             : public:
      61         110 :     getopt_exception(std::string const & msg) : exception_t(msg) {}
      62             : };
      63             : 
      64             : 
      65             : // problem with a default argument
      66             : class getopt_exception_default : public getopt_exception
      67             : {
      68             : public:
      69             :     getopt_exception_default(std::string const & msg) : getopt_exception(msg) {}
      70             : };
      71             : 
      72             : 
      73             : // trying to get an undefined option
      74           4 : class getopt_exception_undefined : public getopt_exception
      75             : {
      76             : public:
      77           4 :     getopt_exception_undefined(std::string const & msg) : getopt_exception(msg) {}
      78             : };
      79             : 
      80             : 
      81             : // something wrong in the user options
      82         102 : class getopt_exception_invalid : public getopt_exception
      83             : {
      84             : public:
      85         102 :     getopt_exception_invalid(std::string const & msg) : getopt_exception(msg) {}
      86             : };
      87             : 
      88             : 
      89             : // some initialization failed at run-time
      90             : class getopt_exception_initialization : public getopt_exception                             // LCOV_EXCL_LINE
      91             : {
      92             : public:
      93             :     getopt_exception_initialization(std::string const & msg) : getopt_exception(msg) {}     // LCOV_EXCL_LINE
      94             : };
      95             : 
      96             : 
      97             : // the process is viewed as done, exit now
      98           4 : class getopt_exception_exit : public getopt_exception
      99             : {
     100             : public:
     101           4 :     getopt_exception_exit(std::string const & msg, int code)
     102             :         : getopt_exception(msg)
     103           4 :         , f_code(code)
     104             :     {
     105           4 :     }
     106             : 
     107           4 :     int code() const
     108             :     {
     109           4 :         return f_code;
     110             :     }
     111             : 
     112             : private:
     113             :     int             f_code;
     114             : };
     115             : 
     116             : 
     117             : 
     118             : 
     119             : }   // namespace advgetopt
     120             : 
     121             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12