LCOV - code coverage report
Current view: top level - ugbase/registry - global_function.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 34.0 % 53 18
Test Date: 2025-09-21 23:31:46 Functions: 66.7 % 3 2

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2011-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Andreas Vogel
       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 "global_function.h"
      34              : #include <iostream>
      35              : #include <algorithm>
      36              : #include <string>
      37              : #include "class_helper.h"
      38              : #include "class_name_provider.h"
      39              : #include "common/util/string_util.h"
      40              : 
      41              : namespace ug
      42              : {
      43              : namespace bridge
      44              : {
      45              : 
      46         6017 : ExportedFunctionBase::
      47              : ExportedFunctionBase(   const std::string& funcName, const std::string& funcOptions,
      48              :                                                 const std::string& retValInfos, const std::string& paramInfos,
      49         6017 :                                                 const std::string& tooltip, const std::string& help)
      50         6017 : : m_name(funcName), m_methodOptions(funcOptions),
      51        12034 :   m_retValInfos(retValInfos), m_paramInfos(paramInfos),
      52        12034 :   m_tooltip(tooltip), m_help(help)
      53              : {
      54              : //      Tokenize string for return value (separated by '|')
      55         6017 :         tokenize(m_retValInfos, m_vRetValInfo, '|');
      56              : 
      57              : //      Tokenize string for parameters into infos per one parameter (separated by '#')
      58              :         std::vector<std::string> vParamInfoTmp;
      59         6017 :         tokenize(m_paramInfos, vParamInfoTmp, '#');
      60         6017 :         m_vvParamInfo.resize(vParamInfoTmp.size());
      61              : 
      62              : //      Tokenize each info-string of one parameter into single infos (separated by '|')
      63        12403 :         for(size_t i = 0; i < vParamInfoTmp.size(); ++i)
      64         6386 :                 tokenize(vParamInfoTmp[i], m_vvParamInfo[i], '|');
      65              : 
      66              : //      check name   //
      67              : ///////////////////
      68              : 
      69              : //      check for non-allowed character
      70              :         size_t found = m_name.find_first_not_of("abcdefghijklmnopqrstuvwxyz"
      71              :                                                                                          "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      72              :                                                                                          "_"
      73              :                                                                                          "0123456789");
      74         6017 :         if (found!=std::string::npos)
      75              :         {
      76            0 :                 UG_ERR_LOG("Non-allowed character '"<<m_name[found]<<"' "<<
      77              :                            "contained at position "<<int(found)<<" in registered function/method "
      78              :                            "'"<<m_name<<"'.\nFunction names must match the regular expression: "
      79              :                            "[a-zA-Z_][a-zA-Z_0-9]*, \ni.e. only alphabetic characters, numbers "
      80              :                            " and '_' are allowed; no numbers at the beginning.\n");
      81            0 :                 UG_THROW_REGISTRY_ERROR(m_name,"Function Name must only contain [a-zA-Z_][a-zA-Z_0-9]*.");
      82              :         }
      83              : 
      84              : //      check that no number at the beginning
      85              :         found = m_name.find_first_of("0123456789");
      86         6017 :         if (found!=std::string::npos && found == 0)
      87              :         {
      88            0 :                 UG_ERR_LOG("Function Name "<<m_name<<" starts with a number.\nThis is "
      89              :                                 " not allowed. Please change naming.\n");
      90            0 :                 UG_THROW_REGISTRY_ERROR(m_name, "Function Name must not start with number.");
      91              :         }
      92         6017 : };
      93              : 
      94            0 : bool ExportedFunctionBase::check_consistency(std::string classname) const
      95              : {
      96              : //      flag to indicate, that unnamed parameter is found
      97              :         bool bUndeclared = false, bUndeclaredParameter = false, bUndeclaredReturn = false;
      98              : 
      99              : //      loop method parameters
     100            0 :         for(int j=0; j<params_in().size(); j++)
     101            0 :                 if(!params_in().parameter_named(j))
     102              :                 {
     103              :                         bUndeclared = true;
     104              :                         bUndeclaredParameter = true;
     105              :                 }
     106              : 
     107              : //      loop return values
     108            0 :         for(int j=0; j<params_out().size(); j++)
     109            0 :                 if(!params_out().parameter_named(j))
     110              :                 {
     111              :                         bUndeclared = true;
     112              :                         bUndeclaredReturn = true;
     113              :                 }
     114              : 
     115              : //      print error message
     116            0 :         if(bUndeclared)
     117              :         {
     118            0 :                 UG_ERR_LOG("#### Registry ERROR: Unregistered Class used in ");
     119            0 :                 if(!classname.empty()){ UG_ERR_LOG("Method: '");}
     120            0 :                 else UG_ERR_LOG("global Function: '")
     121              : 
     122            0 :                 if(params_out().size() > 0){
     123            0 :                         UG_ERR_LOG(ParameterToString(params_out(), 0) << " ");
     124              :                 }
     125            0 :                 else { UG_ERR_LOG("void ");}
     126            0 :                 if(!classname.empty()) UG_ERR_LOG(classname << ":");
     127            0 :                 UG_ERR_LOG(name() << "(");
     128            0 :                 for(size_t i=0; i < (size_t)params_in().size(); ++i)
     129              :                 {
     130            0 :                         if(i>0) UG_ERR_LOG(", ");
     131            0 :                         UG_ERR_LOG(ParameterToString(params_in(), i));
     132            0 :                         if(i < num_parameter()) UG_ERR_LOG(" " << parameter_name(i));
     133              :                 }
     134            0 :                 UG_ERR_LOG(")':");
     135              :         }
     136              : 
     137              :         bool bNext = false;
     138            0 :         if(bUndeclaredParameter)
     139              :         {
     140            0 :                 UG_ERR_LOG(" for Parameter ");
     141            0 :                 for(int j=0; j<params_in().size(); j++)
     142            0 :                         if(!params_in().parameter_named(j))
     143              :                         {
     144            0 :                                 if(bNext) UG_ERR_LOG(", ")
     145            0 :                                 UG_ERR_LOG(j+1);
     146              :                                 bNext = true;
     147              :                         }
     148              :         }
     149              : 
     150            0 :         if(bNext) UG_ERR_LOG(", ")
     151            0 :         if(bUndeclaredReturn)
     152            0 :                 for(int j=0; j<params_out().size(); j++)
     153            0 :                         if(!params_out().parameter_named(j))
     154            0 :                                 UG_ERR_LOG("for Return value ");
     155              : 
     156              : //      check if undeclared parameter has been found
     157            0 :         if(bUndeclared) {UG_ERR_LOG("\n"); return false;}
     158              : 
     159              : //      everything ok
     160              :         return true;
     161              : }
     162              : 
     163        18420 : void ExportedFunctionBase::tokenize(const std::string& str,
     164              :                                     std::vector<std::string>& tokens,
     165              :                                     const char delimiter)
     166              : {
     167              :         tokens.clear();
     168        18420 :         std::stringstream tokenstream;
     169              :         tokenstream << str;
     170              :         std::string token;
     171              : 
     172        32811 :         while ( std::getline (tokenstream, token, delimiter ) )
     173              :         {
     174        28782 :                 tokens.push_back(TrimString(token));
     175              :         }
     176        18420 : }
     177              : 
     178              : } // end namespace bridge
     179              : } // end namespace ug
        

Generated by: LCOV version 2.0-1