00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 #include "w_defines.h"
00054 
00055 
00056 
00057 #ifdef __GNUC__
00058 #pragma implementation "w_rc.h"
00059 #endif
00060 
00061 #include <w_base.h>
00062 #include <vector>
00063 #include <sstream>
00064 
00065 bool w_rc_t::do_check = true; 
00066 
00067 bool w_rc_t::unchecked_is_fatal = true; 
00068 
00069 const w_rc_t w_rc_t::rc_ok(w_error_t::no_error);
00070 
00071 void
00072 w_rc_t::set_return_check(bool on_off, bool is_fatal)
00073 {
00074     do_check = on_off;
00075     unchecked_is_fatal = is_fatal;
00076 }
00077 
00078 NORET
00079 w_rc_t::w_rc_t(
00080     const char* const    filename,
00081     w_base_t::uint4_t    line_num,
00082     w_rc_t::errcode_t    err_num)
00083     : _err( w_error_t::make(filename, line_num, err_num) )
00084 {
00085   set_unchecked();
00086 }
00087 
00088 NORET
00089 w_rc_t::w_rc_t(
00090     const char* const    filename,
00091     w_base_t::uint4_t    line_num,
00092     w_rc_t::errcode_t    err_num,
00093     w_base_t::int4_t     sys_err)
00094 : _err( w_error_t::make(filename, line_num, err_num, sys_err) )
00095 {
00096   set_unchecked();
00097 }
00098 
00099 w_rc_t&
00100 w_rc_t::push(
00101     const char* const    filename,
00102     w_base_t::uint4_t    line_num,
00103     w_rc_t::errcode_t    err_num)
00104 {
00105     _err = w_error_t::make(filename, line_num,
00106                    err_num, ptr());
00107     set_unchecked();
00108     return *this;
00109 }
00110 
00111 void
00112 w_rc_t::fatal()
00113 {
00114     stringstream s;
00115     s << *this << endl;
00116     fprintf(stderr, "FATAL ERROR: %s\n", s.str().c_str());
00117     w_base_t::abort();
00118 }
00119 
00120 w_rc_t&
00121 w_rc_t::add_trace_info(
00122     const char* const   filename,
00123     w_base_t::uint4_t   line_num)
00124 {
00125     ptr()->add_trace_info(filename, line_num);
00126     set_unchecked();
00127     return *this;
00128 }
00129 
00130 void 
00131 w_rc_t::error_not_checked()
00132 {
00133     cerr << "Error not checked: rc=" << (*this) << endl;
00134     if(unchecked_is_fatal)
00135         W_FATAL(fcINTERNAL);
00136 }
00137 
00138 ostream&
00139 operator<<(
00140     ostream&            o,
00141     const w_rc_t&       obj)
00142 {
00143     return o << *obj;
00144 }
00145 
00146 
00147 
00148 w_error_t *w_rc_t::_clone() const 
00149 {
00150     
00151     w_assert2( ptr() != w_error_t::no_error );
00152 
00153     
00154 
00155     std::vector<w_error_t const*> trace;
00156     w_rc_i it(*this);
00157     while(w_error_t const* e = it.next()) {
00158 #if W_DEBUG_LEVEL > 2
00159         (void) e->get_more_info_msg(); 
00160 #endif
00161         trace.push_back(e);
00162     }
00163 
00164     w_error_t* head = 0;
00165     while(!trace.empty()) {
00166         w_error_t const* e = trace.back();
00167         trace.pop_back();
00168         
00169         head = w_error_t::make(e->file, e->line, e->err_num, e->sys_err_num, head);
00170 
00171         for(unsigned int t=0; t<e->_trace_cnt; t++) {
00172             head->_trace_file[t] = e->_trace_file[t];
00173             head->_trace_line[t] = e->_trace_line[t];
00174         }
00175         head->_trace_cnt = e->_trace_cnt;
00176 
00177         head->clear_more_info_msg();
00178         const char *c=e->get_more_info_msg();
00179         if(c) head->append_more_info_msg(c);
00180     }
00181 
00182     return head;
00183 }