Line data Source code
1 : /*! 2 : * \file esys/repo/errorstack.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/errorstack.h" 20 : 21 : #include <sstream> 22 : 23 : namespace esys::repo 24 : { 25 : 26 0 : ErrorStack::ErrorStack() = default; 27 : 28 2 : ErrorStack::ErrorStack(const Result *result) 29 2 : : m_result(result) 30 : { 31 2 : } 32 : 33 2 : ErrorStack::~ErrorStack() = default; 34 : 35 3 : int ErrorStack::analyze() 36 : { 37 3 : if (get_result()->ok()) return 0; 38 : 39 3 : m_error_infos.clear(); 40 : 41 3 : std::shared_ptr<ErrorInfo> cur_error_info = get_result()->get_error_info(); 42 : 43 9 : while (cur_error_info != nullptr) 44 : { 45 6 : m_error_infos.push_back(cur_error_info); 46 : 47 12 : cur_error_info = cur_error_info->get_prev(); 48 : } 49 : 50 3 : return print(); 51 3 : } 52 : 53 0 : int ErrorStack::analyze(const Result *result) 54 : { 55 0 : set_result(result); 56 0 : return analyze(); 57 : } 58 : 59 3 : int ErrorStack::print() 60 : { 61 3 : if (get_result() == nullptr) return -1; 62 3 : if (get_result()->ok()) return 0; 63 : 64 3 : std::ostringstream oss; 65 : 66 3 : get_result()->print(oss); 67 : 68 9 : for (auto err_info : get_error_infos()) 69 : { 70 6 : oss << *err_info.get(); 71 6 : } 72 : 73 3 : m_output = oss.str(); 74 3 : return 0; 75 3 : } 76 : 77 3 : const std::string &ErrorStack::get_output() const 78 : { 79 3 : return m_output; 80 : } 81 : 82 0 : void ErrorStack::set_result(const Result *result) 83 : { 84 0 : m_result = result; 85 0 : } 86 : 87 15 : const Result *ErrorStack::get_result() const 88 : { 89 15 : return m_result; 90 : } 91 : 92 6 : const std::vector<std::shared_ptr<ErrorInfo>> &ErrorStack::get_error_infos() const 93 : { 94 6 : return m_error_infos; 95 : } 96 : 97 : } // namespace esys::repo