LCOV - code coverage report
Current view: top level - ugbase/common/util - parameter_parsing.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 40.7 % 27 11
Test Date: 2025-09-21 23:31:46 Functions: 42.9 % 7 3

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2011-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #include <cstring>
      34              : #include <cstdlib>
      35              : #include "parameter_parsing.h"
      36              : 
      37              : namespace ug{
      38              : 
      39              : ////////////////////////////////////////////////////////////////////////
      40            4 : int GetParamIndex(const char* param, int argc, const char * const * argv) {
      41           14 :         for (int i = 0; i < argc; ++i) {
      42           11 :                 if (strcmp(param, argv[i]) == 0) {
      43            1 :                         return i;
      44              :                 }
      45              :         }
      46              :         return -1;
      47              : }
      48              : 
      49              : ////////////////////////////////////////////////////////////////////////
      50            1 : bool FindParam(const char* param, int argc, const char * const * argv) {
      51            1 :         return GetParamIndex(param, argc, argv) != -1;
      52              : }
      53              : 
      54              : 
      55              : ////////////////////////////////////////////////////////////////////////
      56            0 : bool ParamToInt(int& iOut, const char* param, int argc, const char * const * argv) {
      57            0 :         int i = GetParamIndex(param, argc, argv);
      58            0 :         if (i == -1 || i + 1 >= argc) {
      59              :                 return false;
      60              :         }
      61            0 :         iOut = atoi(argv[i + 1]);
      62            0 :         return true;
      63              : }
      64              : 
      65              : ////////////////////////////////////////////////////////////////////////
      66            0 : bool ParamToDouble(double &dOut, const char *param, int argc, const char * const * argv)
      67              : {
      68            0 :         int i = GetParamIndex(param, argc, argv);
      69            0 :         if (i == -1 || i + 1 >= argc) {
      70              :                 return false;
      71              :         }
      72            0 :         dOut = atof(argv[i + 1]);
      73            0 :         return true;
      74              : }
      75              : 
      76              : 
      77              : ////////////////////////////////////////////////////////////////////////
      78            3 : bool ParamToString(const char ** strOut, const char* param, int argc, const char * const * argv) {
      79            3 :         int i = GetParamIndex(param, argc, argv);
      80            3 :         if (i == -1 || i + 1 >= argc) {
      81              :                 return false;
      82              :         }
      83            1 :         *strOut = argv[i + 1];
      84            1 :         return true;
      85              : }
      86              : 
      87            0 : int ParamToInt(const char* param, int argc, const char * const * argv, int iDefault)
      88              : {
      89              :         int i;
      90            0 :         if(ParamToInt(i, param, argc, argv) == true)
      91            0 :                 return i;
      92              :         else return iDefault;
      93              : }
      94            0 : double ParamToDouble(const char *param, int argc, const char * const * argv, double dDefault)
      95              : {
      96              :         double d;
      97            0 :         if(ParamToDouble(d, param, argc, argv) == true)
      98            0 :                 return d;
      99              :         else return dDefault;
     100              : }
     101              : 
     102              : }// end of namespace
        

Generated by: LCOV version 2.0-1