LCOV - code coverage report
Current view: top level - ugbase/registry - class.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 34.7 % 121 42
Test Date: 2025-09-21 23:31:46 Functions: 26.5 % 34 9

            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 "class.h"
      34              : 
      35              : namespace ug{
      36              : namespace bridge{
      37              : 
      38              : ////////////////////////////////////////////////////////////////////////////////
      39              : // ExportedConstructor
      40              : ////////////////////////////////////////////////////////////////////////////////
      41              : 
      42         1727 : ExportedConstructor::
      43              : ExportedConstructor(ProxyFunc pf,
      44              :                     const std::string& className, const std::string& options,
      45              :                     const std::string& paramInfos,
      46         1727 :                     const std::string& tooltip, const std::string& help)
      47         1727 : : m_proxy_func(pf), m_className(className),
      48         5181 :   m_options(options), m_paramInfos(paramInfos), m_vvParamInfo(0),
      49         3454 :   m_tooltip(tooltip), m_help(help)
      50              : #ifdef PROFILE_BRIDGE
      51              :   ,m_dpi((m_className + "(...)").c_str(), true, "registry", false)
      52              : #endif
      53              : {
      54              : 
      55              : //      Tokenize string for parameters into infos per one parameter (separated by '#')
      56              :         std::vector<std::string> vParamInfoTmp;
      57         1727 :         tokenize(m_paramInfos, vParamInfoTmp, '#');
      58         1727 :         m_vvParamInfo.resize(vParamInfoTmp.size());
      59              : 
      60              : //      Tokenize each info-string of one parameter into single infos (separated by '|')
      61         3191 :         for(size_t i = 0; i < vParamInfoTmp.size(); ++i)
      62         1464 :                 tokenize(vParamInfoTmp[i], m_vvParamInfo[i], '|');
      63         1727 : };
      64              : 
      65            0 : bool ExportedConstructor::check_consistency(std::string classname) const
      66              : {
      67              : //      flag to indicate, that unnamed parameter is found
      68              :         bool bUndeclaredParameterFound = false;
      69              : 
      70              : //      loop method parameters
      71            0 :         for(int j=0; j<params_in().size(); j++)
      72              :         {
      73            0 :                 if(!params_in().parameter_named(j))
      74              :                 {
      75              :                 //      print error output, indicate parameter by 1, ..., NumParams
      76            0 :                         if(!bUndeclaredParameterFound)
      77              :                         {
      78              :                                 bUndeclaredParameterFound = true;
      79            0 :                                 UG_ERR_LOG("#### Registry ERROR: Unregistered Class used in ");
      80            0 :                                 UG_ERR_LOG("Constructor of class "<<classname.c_str());
      81            0 :                                 UG_ERR_LOG("': Parameter " << j+1);
      82              :                         }
      83              :                         else
      84            0 :                         {       UG_ERR_LOG(", " << j+1);        }
      85              :                 }
      86              :         }
      87              : 
      88              : //      check if undeclared parameter has been found
      89            0 :         if(bUndeclaredParameterFound) {UG_ERR_LOG("\n"); return false;}
      90              : 
      91              : //      everything ok
      92              :         return true;
      93              : }
      94              : 
      95         3191 : void ExportedConstructor::tokenize(const std::string& str,
      96              :                                     std::vector<std::string>& tokens,
      97              :                                     const char delimiter)
      98              : {
      99              :         tokens.clear();
     100         3191 :         std::stringstream tokenstream;
     101              :         tokenstream << str;
     102              :         std::string token;
     103              : 
     104         6233 :         while ( std::getline (tokenstream, token, delimiter ) )
     105              :         {
     106         6084 :                 tokens.push_back(TrimString(token));
     107              :         }
     108         3191 : }
     109              : 
     110              : ////////////////////////////////////////////////////////////////////////////////
     111              : // Interface Exported Class
     112              : ////////////////////////////////////////////////////////////////////////////////
     113              : 
     114            0 : bool IExportedClass::check_consistency() const
     115              : {
     116              : //      get class name vector of all parents
     117            0 :         const std::vector<const char*>* vClassNames = class_names();
     118              : 
     119              : //      check if class name vector correct
     120            0 :         if(vClassNames==NULL)
     121              :         {
     122            0 :                 UG_ERR_LOG("#### Registry ERROR:"
     123              :                                 " Class name vector of parent classes missing for "
     124              :                                 "class '"<<this->name()<<"'.\n");
     125            0 :                 return false;
     126              :         }
     127              : 
     128              : //      loop all base classes
     129            0 :         for(size_t i = 0; i < (*vClassNames).size(); ++i)
     130              :         {
     131              :         //      get name of base class
     132            0 :                 const char* baseName = (*vClassNames)[i];
     133              : 
     134              :         //      check the name
     135            0 :                 if(baseName == NULL || *baseName == '\0' || baseName[0] == '[')
     136              :                 {
     137            0 :                         if(i>0){
     138            0 :                         UG_ERR_LOG("#### Registry ERROR:"
     139              :                                         " base class "<<i<<" of class '"<<this->name()<<
     140              :                                         "' has not been named.\n");
     141            0 :                                 return false;
     142              :                         }
     143              :                         else{
     144            0 :                         UG_ERR_LOG("#### Registry ERROR:"
     145              :                                         " Class '"<<this->name()<<"' has not been named.\n");
     146            0 :                                 return false;
     147              :                         }
     148              :                 }
     149              :         }
     150              : 
     151              : //      everything ok
     152              :         return true;
     153              : }
     154              : 
     155              : ////////////////////////////////////////////////////////////////////////////////
     156              : // Implementation of ExportedClassBaseImpl
     157              : ////////////////////////////////////////////////////////////////////////////////
     158            0 : ExportedClassBaseImpl::
     159            0 : ExportedClassBaseImpl()
     160              : {
     161            0 : }
     162              : 
     163            0 : ExportedClassBaseImpl::
     164            0 : ExportedClassBaseImpl(const ExportedClassBaseImpl& other)
     165              : {
     166            0 : }
     167              : 
     168         1349 : ExportedClassBaseImpl::
     169         1349 : ExportedClassBaseImpl(const std::string& tooltip)
     170         1349 :         : m_destructor(NULL), m_tooltip(tooltip), m_constructAsSmartPtr(false)
     171              : {
     172         1349 : }
     173              : 
     174         1349 : ExportedClassBaseImpl::
     175         1349 : ~ExportedClassBaseImpl()
     176              : {
     177              : //      delete constructors
     178         3076 :         for(size_t i = 0; i < m_vConstructor.size(); ++i)
     179         1727 :                 delete (m_vConstructor[i].m_constructor);
     180              : 
     181              : //  delete methods
     182         4108 :         for(size_t i = 0; i < m_vMethod.size(); ++i)
     183         2759 :                 delete m_vMethod[i];
     184              : 
     185         1944 :         for(size_t i = 0; i < m_vConstMethod.size(); ++i)
     186          595 :                 delete m_vConstMethod[i];
     187         1349 : }
     188              : 
     189            0 : const std::string& ExportedClassBaseImpl::
     190              : tooltip() const
     191              : {
     192            0 :         return m_tooltip;
     193              : }
     194              : 
     195            0 : size_t ExportedClassBaseImpl::
     196              : num_methods() const
     197              : {
     198            0 :         return m_vMethod.size();
     199              : }
     200              : 
     201            0 : size_t ExportedClassBaseImpl::
     202              : num_const_methods() const
     203              : {
     204            0 :         return m_vConstMethod.size();
     205              : }
     206              : 
     207            0 : const ExportedMethod& ExportedClassBaseImpl::
     208              : get_method(size_t i) const
     209              : {
     210            0 :         return *m_vMethod.at(i)->get_overload(0);
     211              : }
     212              : 
     213            0 : const ExportedMethod& ExportedClassBaseImpl::
     214              : get_const_method(size_t i) const
     215              : {
     216            0 :         return *m_vConstMethod.at(i)->get_overload(0);
     217              : }
     218              : 
     219            0 : size_t ExportedClassBaseImpl::
     220              : num_overloads(size_t funcInd) const
     221              : {
     222            0 :         return m_vMethod.at(funcInd)->num_overloads();
     223              : }
     224              : 
     225            0 : size_t ExportedClassBaseImpl::
     226              : num_const_overloads(size_t funcInd) const
     227              : {
     228            0 :         return m_vConstMethod.at(funcInd)->num_overloads();
     229              : }
     230              : 
     231            0 : const ExportedMethod& ExportedClassBaseImpl::
     232              : get_overload(size_t funcInd, size_t oInd) const
     233              : {
     234            0 :         return *m_vMethod.at(funcInd)->get_overload(oInd);
     235              : }
     236              : 
     237            0 : const ExportedMethod& ExportedClassBaseImpl::
     238              : get_const_overload(size_t funcInd, size_t oInd) const
     239              : {
     240            0 :         return *m_vConstMethod.at(funcInd)->get_overload(oInd);
     241              : }
     242              : 
     243            0 : const ExportedMethodGroup& ExportedClassBaseImpl::
     244              : get_method_group(size_t ind) const
     245              : {
     246            0 :         return *m_vMethod.at(ind);
     247              : }
     248              : 
     249            0 : const ExportedMethodGroup& ExportedClassBaseImpl::
     250              : get_const_method_group(size_t ind) const
     251              : {
     252            0 :         return *m_vConstMethod.at(ind);
     253              : }
     254              : 
     255            0 : size_t ExportedClassBaseImpl::
     256              : num_constructors() const
     257              : {
     258            0 :         return m_vConstructor.size();
     259              : }
     260              : 
     261            0 : const ExportedConstructor& ExportedClassBaseImpl::
     262              : get_constructor(size_t i) const
     263              : {
     264            0 :         return *(m_vConstructor[i].m_constructor);
     265              : }
     266              : 
     267            0 : const boost::optional<ExportedConstructor&> ExportedClassBaseImpl::
     268              : get_json_constructor() const
     269              : {
     270            0 :         if(!is_json_constructible()) 
     271            0 :                 return boost::none;
     272              : 
     273            0 :         for(size_t i = 0; i < m_vConstructor.size(); ++i)
     274            0 :                 if(m_vConstructor[i].m_typeID == GetUniqueTypeID<void (*)(const char*)>())
     275            0 :                         return *(m_vConstructor[i].m_constructor);
     276              : 
     277            0 :         return boost::none;
     278              : }
     279              : 
     280            2 : bool ExportedClassBaseImpl::
     281              : construct_as_smart_pointer() const
     282              : {
     283            2 :         return m_constructAsSmartPtr;
     284              : }
     285              : 
     286         1040 : void ExportedClassBaseImpl::
     287              : set_construct_as_smart_pointer(bool enable)
     288              : {
     289         1040 :         m_constructAsSmartPtr = enable;
     290         1040 : }
     291              : 
     292            0 : bool ExportedClassBaseImpl::
     293              : is_instantiable() const
     294              : {
     295            0 :         return !m_vConstructor.empty();
     296              : }
     297              : 
     298            0 : void ExportedClassBaseImpl::
     299              : destroy(void* obj) const
     300              : {
     301            0 :         if(m_destructor != NULL)
     302            0 :                 (*m_destructor)(obj);
     303            0 : }
     304              : 
     305         1727 : bool ExportedClassBaseImpl::
     306              : constructor_type_id_registered(size_t typeID)
     307              : {
     308         3028 :         for(size_t i = 0; i < m_vConstructor.size(); ++i)
     309         1301 :                 if(typeID == m_vConstructor[i].m_typeID)
     310              :                         return true;
     311              : 
     312              :         return false;
     313              : }
     314              : 
     315            0 : bool ExportedClassBaseImpl::
     316              : constmethodname_registered(const std::string& name)
     317              : {
     318            0 :         for(size_t i = 0; i < m_vConstMethod.size(); ++i)
     319            0 :                 if(name == m_vConstMethod[i]->name())
     320              :                         return true;
     321              : 
     322              :         return false;
     323              : }
     324              : 
     325            0 : bool ExportedClassBaseImpl::
     326              : methodname_registered(const std::string& name)
     327              : {
     328            0 :         for(size_t i = 0; i < m_vMethod.size(); ++i)
     329            0 :                 if(name == m_vMethod[i]->name())
     330              :                         return true;
     331              : 
     332              :         return false;
     333              : }
     334              : 
     335         3578 : ExportedMethodGroup* ExportedClassBaseImpl::
     336              : get_exported_method_group(const std::string& name)
     337              : {
     338        17546 :         for(size_t i = 0; i < m_vMethod.size(); ++i)
     339        14787 :                 if(name == m_vMethod[i]->name())
     340              :                         return m_vMethod[i];
     341              : 
     342              :         return NULL;
     343              : }
     344              : 
     345            0 : const ExportedMethodGroup* ExportedClassBaseImpl::
     346              : get_exported_method_group(const std::string& name) const
     347              : {
     348            0 :         for(size_t i = 0; i < m_vMethod.size(); ++i)
     349            0 :                 if(name == m_vMethod[i]->name())
     350              :                         return m_vMethod[i];
     351              : 
     352              :         return NULL;
     353              : }
     354              : 
     355          620 : ExportedMethodGroup* ExportedClassBaseImpl::
     356              : get_const_exported_method_group(const std::string& name)
     357              : {
     358         1668 :         for(size_t i = 0; i < m_vConstMethod.size(); ++i)
     359         1073 :                 if(name == m_vConstMethod[i]->name())
     360              :                         return m_vConstMethod[i];
     361              : 
     362              :         return NULL;
     363              : }
     364              : 
     365            0 : const ExportedMethodGroup* ExportedClassBaseImpl::
     366              : get_const_exported_method_group(const std::string& name) const
     367              : {
     368            0 :         for(size_t i = 0; i < m_vConstMethod.size(); ++i)
     369            0 :                 if(name == m_vConstMethod[i]->name())
     370              :                         return m_vConstMethod[i];
     371              : 
     372              :         return NULL;
     373              : }
     374              : 
     375              : } // end namespace ug
     376              : } // end namespace bridge
        

Generated by: LCOV version 2.0-1