LCOV - code coverage report
Current view: top level - src/bindings/cpp/include - kdbio.hpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 4 34 11.8 %
Date: 2019-09-12 12:28:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #ifndef ELEKTRA_KDB_IO_HPP
      10             : #define ELEKTRA_KDB_IO_HPP
      11             : 
      12             : /*
      13             :  * @brief See examples/cpp_example_userio.cpp for how to use
      14             :  * USER_DEFINED_IO
      15             :  */
      16             : #ifndef USER_DEFINED_IO
      17             : 
      18             : #include <key.hpp>
      19             : 
      20             : #include <iomanip>
      21             : #include <ostream>
      22             : 
      23             : namespace kdb
      24             : {
      25             : 
      26           8 : inline std::ostream & printError (std::ostream & os, kdb::Key const & error, bool printVerbose, bool printDebug)
      27             : {
      28             :         try
      29             :         {
      30          56 :                 if (!error.getMeta<const kdb::Key> ("error"))
      31             :                 {
      32             :                         // no error available
      33             :                         return os;
      34             :                 }
      35             : 
      36           0 :                 os << "Sorry, module " << error.getMeta<std::string> ("error/module") << " issued the error "
      37           0 :                    << error.getMeta<std::string> ("error/number") << ":" << std::endl;
      38           0 :                 os << error.getMeta<std::string> ("error/description") << ": " << error.getMeta<std::string> ("error/reason") << std::endl;
      39           0 :                 if (printVerbose)
      40             :                 {
      41           0 :                         os << "Mountpoint: " << error.getMeta<std::string> ("error/mountpoint") << std::endl;
      42           0 :                         os << "Configfile: " << error.getMeta<std::string> ("error/configfile") << std::endl;
      43             :                 }
      44           0 :                 if (printDebug)
      45             :                 {
      46           0 :                         os << "At: " << error.getMeta<std::string> ("error/file") << ":" << error.getMeta<std::string> ("error/line")
      47           0 :                            << std::endl;
      48             :                 }
      49             :         }
      50           0 :         catch (kdb::KeyTypeConversion const & e)
      51             :         {
      52           0 :                 os << "Error metadata is not set correctly by a plugin: " << e.what () << std::endl;
      53             :         }
      54             : 
      55             :         return os;
      56             : }
      57             : 
      58          24 : inline std::ostream & printWarnings (std::ostream & os, kdb::Key const & error, bool printVerbose, bool printDebug)
      59             : {
      60             :         try
      61             :         {
      62         168 :                 if (!error.getMeta<const kdb::Key> ("warnings"))
      63             :                 {
      64             :                         // no warnings were issued
      65             :                         return os;
      66             :                 }
      67             : 
      68           0 :                 int nr = error.getMeta<int> ("warnings");
      69           0 :                 if (!nr)
      70             :                 {
      71           0 :                         os << "1 Warning was issued:" << std::endl;
      72             :                 }
      73             :                 else
      74             :                 {
      75           0 :                         os << nr + 1 << " Warnings were issued:" << std::endl;
      76             :                 }
      77             : 
      78           0 :                 for (int i = 0; i <= nr; i++)
      79             :                 {
      80           0 :                         std::ostringstream name;
      81           0 :                         name << "warnings/#" << std::setfill ('0') << std::setw (2) << i;
      82           0 :                         os << "\tSorry, module " << error.getMeta<std::string> (name.str () + "/module") << " issued the warning "
      83           0 :                            << error.getMeta<std::string> (name.str () + "/number") << ":" << std::endl;
      84           0 :                         os << "\t" << error.getMeta<std::string> (name.str () + "/description") << ": "
      85           0 :                            << error.getMeta<std::string> (name.str () + "/reason") << std::endl;
      86             :                         // os << "\t" << name.str() << ": " << error.getMeta<std::string>(name.str()) << std::endl;
      87           0 :                         if (printVerbose)
      88             :                         {
      89           0 :                                 os << "\tMountpoint: " << error.getMeta<std::string> (name.str () + "/mountpoint") << std::endl;
      90           0 :                                 os << "\tConfigfile: " << error.getMeta<std::string> (name.str () + "/configfile") << std::endl;
      91             :                         }
      92           0 :                         if (printDebug)
      93             :                         {
      94           0 :                                 os << "\tAt: " << error.getMeta<std::string> (name.str () + "/file") << ":"
      95           0 :                                    << error.getMeta<std::string> (name.str () + "/line") << std::endl;
      96             :                         }
      97             :                 }
      98             :         }
      99           0 :         catch (kdb::KeyTypeConversion const & e)
     100             :         {
     101           0 :                 os << "Warnings metadata not set correctly by a plugin: " << e.what () << std::endl;
     102             :         }
     103             : 
     104             :         return os;
     105             : }
     106             : } // namespace kdb
     107             : 
     108             : #endif
     109             : 
     110             : #endif

Generated by: LCOV version 1.13