LCOV - code coverage report
Current view: top level - src/esys/repo - errorinfo.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 68 71 95.8 %
Date: 2026-08-01 10:43:40 Functions: 24 25 96.0 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/errorinfo.cpp
       3             :  * \brief
       4             :  *
       5             :  * \cond
       6             :  * __legal_b__
       7             :  *
       8             :  * Copyright (c) 2022 Michel Gillet
       9             :  * Distributed under the MIT License.
      10             :  * (See accompanying file LICENSE.txt or
      11             :  * copy at https://opensource.org/licenses/MIT)
      12             :  *
      13             :  * __legal_e__
      14             :  * \endcond
      15             :  *
      16             :  */
      17             : 
      18             : #include "esys/repo/esysrepo_prec.h"
      19             : #include "esys/repo/errorinfo.h"
      20             : 
      21             : namespace esys::repo
      22             : {
      23             : 
      24         152 : ErrorInfo::ErrorInfo() = default;
      25             : 
      26         194 : ErrorInfo::~ErrorInfo() = default;
      27             : 
      28          42 : void ErrorInfo::set_index(int index)
      29             : {
      30          42 :     m_index = index;
      31          42 : }
      32             : 
      33          54 : int ErrorInfo::get_index() const
      34             : {
      35          54 :     return m_index;
      36             : }
      37             : 
      38         152 : void ErrorInfo::set_result_code(ResultCode result_code)
      39             : {
      40         152 :     m_result_code = result_code;
      41         152 : }
      42             : 
      43          12 : ResultCode ErrorInfo::get_result_code() const
      44             : {
      45          12 :     return m_result_code;
      46             : }
      47             : 
      48          12 : int ErrorInfo::get_result_code_int() const
      49             : {
      50          12 :     return static_cast<int>(m_result_code);
      51             : }
      52             : 
      53          70 : void ErrorInfo::set_raw_error(int raw_error)
      54             : {
      55          70 :     m_raw_error = raw_error;
      56          70 : }
      57             : 
      58          12 : int ErrorInfo::get_raw_error() const
      59             : {
      60          12 :     return m_raw_error;
      61             : }
      62             : 
      63         151 : void ErrorInfo::set_file(const std::string &file)
      64             : {
      65         151 :     m_file = file;
      66         151 : }
      67             : 
      68          14 : const std::string &ErrorInfo::get_file() const
      69             : {
      70          14 :     return m_file;
      71             : }
      72             : 
      73         151 : void ErrorInfo::set_line_number(int line_number)
      74             : {
      75         151 :     m_line_number = line_number;
      76         151 : }
      77             : 
      78          20 : int ErrorInfo::get_line_number() const
      79             : {
      80          20 :     return m_line_number;
      81             : }
      82             : 
      83         151 : void ErrorInfo::set_function(const std::string &function)
      84             : {
      85         151 :     m_function = function;
      86         151 : }
      87             : 
      88          12 : const std::string &ErrorInfo::get_function() const
      89             : {
      90          12 :     return m_function;
      91             : }
      92             : 
      93          94 : void ErrorInfo::set_text(const std::string &text)
      94             : {
      95          94 :     m_text = text;
      96          94 : }
      97             : 
      98          14 : const std::string &ErrorInfo::get_text() const
      99             : {
     100          14 :     return m_text;
     101             : }
     102             : 
     103          42 : void ErrorInfo::set_prev(std::shared_ptr<ErrorInfo> prev)
     104             : {
     105          42 :     m_prev = prev;
     106          42 : }
     107             : 
     108          12 : std::shared_ptr<ErrorInfo> ErrorInfo::get_prev()
     109             : {
     110          12 :     return m_prev;
     111             : }
     112             : 
     113           2 : void ErrorInfo::add_prev(std::shared_ptr<ErrorInfo> prev)
     114             : {
     115           2 :     get_prevs().push_back(prev);
     116           2 : }
     117             : 
     118           2 : std::vector<std::shared_ptr<ErrorInfo>> &ErrorInfo::get_prevs()
     119             : {
     120           2 :     return m_prevs;
     121             : }
     122             : 
     123          12 : const std::vector<std::shared_ptr<ErrorInfo>> &ErrorInfo::get_prevs() const
     124             : {
     125          12 :     return m_prevs;
     126             : }
     127             : 
     128          12 : void ErrorInfo::print(std::ostream &os, int depth) const
     129             : {
     130          12 :     std::string name = ResultCode::s_find_name(get_result_code());
     131          12 :     std::string depth_str = "";
     132             : 
     133          12 :     for (int idx = 0; idx < depth; ++idx) depth_str += "    ";
     134             : 
     135          12 :     os << depth_str << "[" << get_index() << "] ";
     136          12 :     if (name.empty()) name = "???";
     137          12 :     os << name << "(" << get_result_code_int() << ")" << std::endl;
     138             : 
     139          12 :     os << depth_str << "    file : " << get_file() << std::endl;
     140          12 :     os << depth_str << "    line : " << get_line_number() << std::endl;
     141          12 :     os << depth_str << "    fct  : " << get_function() << std::endl;
     142          12 :     os << depth_str << "    text : " << get_text() << std::endl;
     143          12 :     os << depth_str << "    err  : " << get_raw_error() << std::endl;
     144             : 
     145          12 :     if (get_prevs().size() == 0) return;
     146             : 
     147           0 :     for (auto error_info : get_prevs())
     148             :     {
     149           0 :         error_info->print(os, depth + 1);
     150           0 :     }
     151          12 : }
     152             : 
     153             : } // namespace esys::repo
     154             : 
     155             : namespace std
     156             : {
     157             : 
     158          12 : ESYSREPO_API ostream &operator<<(ostream &os, const esys::repo::ErrorInfo &error_info)
     159             : {
     160          12 :     error_info.print(os);
     161             : 
     162          12 :     return os;
     163             : }
     164             : 
     165             : } // namespace std

Generated by: LCOV version 1.14