/// 判断当前状态 State LexicalAnalysis::analyseState(char *stream) { if (isalpha(*stream) || *stream == '_') { return Keyword; } else if (isdigit(*stream)) { return Number; } else if (*stream == '(' || *stream == ')' || *stream == '[' || *stream == ']' || *stream == '{' || *stream == '}' || *stream == ',' || *stream == ';' || *stream == '\'' || *stream == '\"' ) { return Limit; // 33-47 !"#$%&'()*+,-./ 58-64 :;<=>?@ 91-96 [\]^_` 123-126 {|}~} } else if ((*stream > 32 && *stream < 48) || (*stream > 57 && *stream < 65) || (*stream > 90 && *stream < 97) || (*stream > 122 && *stream < 127)) { return Iterator; } else if (*stream == '\0' || *stream == '\n' || (*stream == '\r' && *(stream+1) == '\n')) { return Endline; } else if (*stream == ' ' || *stream == '\t') { return Blank; } ErrorReport error; error.setErrorCode(ErrorReport::CHAR_ERROR); error.setErrorLine(lineno_); error_list_.push_back(error); return Error; }
extern "C" void test_chain_of_responsibility() { // Processing class for state ANALYZE class AnalyzeError : public Error { public: AnalyzeError() : Error(ANALYZE) { }; void ProcessError(ErrorReport& report) { if (report.GetState() == ANALYZE ) { std::cout << "AnalyzeError::Handled the command to analyze the error" << std::endl; m_state = ANALYZE; } else if (m_successor != 0){ std::cout << "AnalyzeError::Passing to my successor" << std::endl; m_successor->ProcessError(report); } else { std::cout << "AnalyzeError::No successor --> No action required" << std::endl; } } }; class FixError : public Error { public: FixError() : Error(FIX) { }; void ProcessError(ErrorReport& report) { if (report.GetState() == FIX) { std::cout << "FixError::Handled the command to fix the error" << std::endl; m_state = FIX; } else if (m_successor != 0) { std::cout << "FixError::Passing to my successor" << std::endl; m_successor->ProcessError(report); } else { std::cout << "FixError::No successor --> No action required" << std::endl; } } }; // Create instances for processing objects AnalyzeError* analyzeError = new AnalyzeError(); FixError* fixError = new FixError(); // Create the chain of responsibility analyzeError->SetSuccessor(fixError); // Issue commands ErrorReport* errorReport = new ErrorReport(ANALYZE); analyzeError->ProcessError(*errorReport); errorReport->SetState(FIX); analyzeError->ProcessError(*errorReport); // Cleanup delete errorReport; delete fixError; delete analyzeError; }
/** * @brief Deals with errors by displaying a message box. * * @exception Error Thrown when error. * * @param error If true then an error has occurred and an exception will be thrown. * @param operation Operation that was being performed at the time of the error. * @param errorCode Error code associated with error. * @param line Line at which error occurred. * @param file File within which the error occurred. * * @throws ErrorReport When @a error is true. */ void _ErrorMessageBox(bool error, const char * operation, __int64 errorCode, unsigned __int64 line, const char * file) { if(error == true) { ErrorReport errorReport; errorReport.LoadReport(operation,errorCode,line,file); errorReport.DoMessageBox(); } }
/** * @brief Deals with errors by throwing an exception. * * @exception Error Thrown when error. * * @param error If true then an error has occurred and an exception will be thrown. * @param operation Operation that was being performed at the time of the error. * @param errorCode Error code associated with error. * @param line Line at which error occurred. * @param file File within which the error occurred. * * @throws ErrorReport When @a error is true. */ void _ErrorException(bool error, const char * operation, __int64 errorCode, unsigned __int64 line, const char * file) { if(error == true) { ErrorReport errorReport; errorReport.LoadReport(operation,errorCode,line,file); errorReport.DoRethrow(); } }
bool ErrorReport::GenerateReport(ErrorReport::IProgressNotifier* pProgressNotifier) { ErrorReport* report = this; BOOST_SCOPE_EXIT((report)) { // Allow the crashed process to exit report->ReleaseApplicationLock(); } BOOST_SCOPE_EXIT_END pProgressNotifier->taskStarted("Generating crash report", 3); // Initialize shared memory pProgressNotifier->taskStepStarted("Connecting to crashed application"); bool bInit = Initialize(); pProgressNotifier->taskStepEnded(); if(!bInit) { pProgressNotifier->setError("Could not generate the crash dump."); pProgressNotifier->setDetailedError(m_DetailedError); return false; } if(m_pCrashInfo->architecture != ARX_ARCH) { pProgressNotifier->setError("Architecture mismatch between the crashed process and the crash reporter."); pProgressNotifier->setDetailedError(m_DetailedError); return false; } // Generate minidump pProgressNotifier->taskStepStarted("Generating crash dump"); bool bCrashDump = GetCrashDump("crash.dmp"); pProgressNotifier->taskStepEnded(); if(!bCrashDump) { pProgressNotifier->setError("Could not generate the crash dump."); pProgressNotifier->setDetailedError(m_DetailedError); return false; } // Generate manifest pProgressNotifier->taskStepStarted("Generating report manifest"); bool bCrashXml = WriteReport("crash.xml"); pProgressNotifier->taskStepEnded(); if(!bCrashXml) { pProgressNotifier->setError("Could not generate the manifest."); pProgressNotifier->setDetailedError(m_DetailedError); return false; } return true; }
bool ErrorReport::operator==( const ErrorReport& other ) const { bool result = false; if ( message == other.getMessage()){ result = true; } return result; }
bool ErrorReport::GenerateReport(ErrorReport::IProgressNotifier* pProgressNotifier) { ErrorReport* report = this; BOOST_SCOPE_EXIT((report)) { // Allow the crashed process to exit report->ReleaseApplicationLock(); } BOOST_SCOPE_EXIT_END pProgressNotifier->taskStarted("Generating crash report", 3); // Initialize shared memory pProgressNotifier->taskStepStarted("Connecting to crashed application"); bool bInit = Initialize(); pProgressNotifier->taskStepEnded(); if(!bInit) { pProgressNotifier->setError("Could not generate the crash dump."); pProgressNotifier->setDetailedError(m_DetailedError); return false; } // Wait for crash to be processed pProgressNotifier->taskStepStarted("Processing crash information"); while(platform::isProcessRunning(m_pCrashInfo->processorProcessId)) { boost::posix_time::ptime timeout = boost::posix_time::microsec_clock::universal_time() + boost::posix_time::milliseconds(100); if(m_pCrashInfo->processorDone.timed_wait(timeout)) { break; } } pProgressNotifier->taskStepEnded(); // Generate minidump pProgressNotifier->taskStepStarted("Retrieving crash information"); bool bCrashInfo = getCrashInfo(); pProgressNotifier->taskStepEnded(); if(!bCrashInfo) { pProgressNotifier->setError("Could not retrieve crash information."); pProgressNotifier->setDetailedError(m_DetailedError); return false; } return true; }
void Environment::DispatchReport(const ErrorReport &report) { FrameIterator iter; // If this fires, someone forgot to propagate an error. assert(!hasPendingException()); // Save the exception state. if (eh_top_) { exception_code_ = report.Code(); UTIL_Format(exception_message_, sizeof(exception_message_), "%s", report.Message()); } // For now, we always report exceptions even if they might be handled. if (debugger_) debugger_->ReportError(report, iter); }
void ProcessError(ErrorReport& report) { if (report.GetState() == FIX) { std::cout << "FixError::Handled the command to fix the error" << std::endl; m_state = FIX; } else if (m_successor != 0) { std::cout << "FixError::Passing to my successor" << std::endl; m_successor->ProcessError(report); } else { std::cout << "FixError::No successor --> No action required" << std::endl; } }
void ProcessError(ErrorReport& report) { if (report.GetState() == ANALYZE ) { std::cout << "AnalyzeError::Handled the command to analyze the error" << std::endl; m_state = ANALYZE; } else if (m_successor != 0){ std::cout << "AnalyzeError::Passing to my successor" << std::endl; m_successor->ProcessError(report); } else { std::cout << "AnalyzeError::No successor --> No action required" << std::endl; } }
int main( int nArgc, char **papszArgv ) { ErrorReport er; if(nArgc <= 1) er.checkErrors(er.NO_INPUT); std::deque<char *> pszFilename; std::deque<std::string> outfilename_str; for( int iArg = 1; iArg < nArgc; iArg++ ) { if(NULL == papszArgv[iArg] ) er.checkErrors(er.NO_INPUT); pszFilename.push_back(papszArgv[iArg]); std::stringstream outfilename; outfilename << pszFilename.back() << ".txt"; outfilename_str.push_back(outfilename.str()); } std::deque<char *>::iterator cb = pszFilename.begin(), ce = pszFilename.end(); std::deque<std::string>::iterator ob = outfilename_str.begin(), oe = outfilename_str.end(); for( unsigned iArg = 0; iArg < pszFilename.size(); iArg++, cb++, ob++) { std::ofstream outfs(ob->c_str(), std::ofstream::out); if(outfs) { outfs << "比如2302\n23号02:00-02:59区间的耗电量和电费\n02:59时刻的电表读数和总价格" << std::endl; outfs << "日时\t小时末电表读数\t小时末总价格\t该小时耗电量\t该小时的电费" << std::endl; std::ifstream infs(*cb, std::ifstream::in | std::ifstream::binary); if(infs) { //while(!infs.eof()) while(infs.good()) { infs.read(reinterpret_cast<char *>(&Everyhour), sizeof(struct EVERYHOUR)); outfs << std::setw(4) << std::setfill('0') << Everyhour.HourTime << "\t"; outfs << Everyhour.HourSumElect << "\t" << Everyhour.HourSumPrice << "\t" << Everyhour.HourConsumeElect << "\t" << Everyhour.HourConsumePrice << std::endl; } infs.close(); infs.clear(); outfs.close(); outfs.clear(); } else { outfs.close(); outfs.clear(); er.checkErrors(er.UNREAD_FILE); } } else er.checkErrors(er.UNWRITE_FILE); } }