/*************************************************************************** error.cpp ------------------- Class for error handling __________________________________________________________________________ begin : Thu Oct 9 2003 copyright : (C) 2003 by W. Michael Brown email : wmbrown@sandia.gov ***************************************************************************/ #include "error.h" #include #include Notice::Notice() { nullout=new ostream(NULL); noteout=&cout; notice_level=9; } Notice::~Notice() { if (nullout!=NULL) delete nullout; } // Returns a null stream if level is two high, else returns notice stream ostream & Notice::operator[] (const unsigned level) { if (level<=notice_level) return *noteout; else return *nullout; } void Notice::setostream(ostream &out) { noteout=&out; } void Notice::set_notice_level(unsigned l) { notice_level=l; } unsigned Notice::get_notice_level() { return notice_level; } void Notice::notice(unsigned level, const string calling_class, const string note) { if (level ¬es) { if (level<=notice_level) { *noteout << calling_class << "::"; for (unsigned i=0; i ¬es) { if (level<=notice_level) for (unsigned i=0; isecond.size(); } void Error::addwarning(unsigned ID, unsigned level, const string calling_class, const string warning) { if (levelmax_level) generate_error(ID,calling_class,warning); vector *e=&(warning_list[ID]); e->push_back(ErrCom()); e->back().level=level; e->back().calling_class=calling_class; e->back().message=warning; unhandled_warnings++; } void Error::generate_error(unsigned ID, const string calling_class, const string error) { ErrCom err; err.level=max_level+1; err.calling_class=calling_class; err.message=error; if (warnings()!=0) writewarnings(); write_err(ID,err); writetotals(1); #ifdef MUSE_MPI MPI_Abort ( MPI_COMM_WORLD, 1 ); #else exit(1); #endif } // Add an error/warning (Program termination if level >= max level ostringstream & Error::buffer() { return buffer_stream; } // Generate warning with message in buffer void Error::addbuf(unsigned ID, unsigned level, const string calling_class) { addwarning(ID,level,calling_class,buffer_stream.str()); buffer_stream.str(""); } // Generate serious error with message in buffer void Error::addbuf(unsigned ID, const string calling_class) { generate_error(ID,calling_class,buffer_stream.str()); } unsigned Error::warnings() { return unhandled_warnings; } void Error::writeline() { *errout << "+"; *logout << "+"; for (unsigned i=0; imax_level) { et="| Error: "; width1=width12-7; } else { et="| Warning: "; width1=width12-9; } *errout << et << setw(width1) << ID << " | Level: " << setw(width12-7) << err.level << " | " << setw(width3) << err.calling_class << " |\n"; *logout << et << setw(width1) << ID << " | Level: " << setw(width12-7) << err.level << " | " << setw(width3) << err.calling_class << " |\n"; writeline(); // Output the message vector messages; a::format_fit(column_width-3,err.message,messages); for (unsigned i=0; isecond.size()==1) warning_list.erase(m); else m->second.erase(m->second.end()--); } void Error::dismiss_all_warnings(unsigned ID) { warning_iter m; m=warning_list.find(ID); if (m==warning_list.end()) return; unhandled_warnings-=m->second.size(); warning_list.erase(m); } void Error::writewarnings() { while (warning_list.size()>0) writewarning(warning_list.begin()->first); return; } void Error::dismiss_warnings() { while (warning_list.size()>0) dismiss_warning(warning_list.begin()->first); return; } // Write out the total warnings and errors void Error::writetotals(unsigned errorcount) { *errout << "\n"; *logout << "\n"; writeline(); (*errout).setf(ios::left); (*errout).unsetf(ios::right); unsigned width1=(unsigned)floor((double)(column_width-7)/2.0); unsigned width2=column_width-7-width1; string swarnings="Total Warnings: "+a::itoa(handled_warnings+ unhandled_warnings); string serrors="Total Errors: "+a::itoa(errorcount); *errout << "| " << setw(width1) << swarnings << " | " << setw(width2) << serrors << " |\n"; *logout << "| " << setw(width1) << swarnings << " | " << setw(width2) << serrors << " |\n"; writeline(); }