qerr.cpp

来自「算断裂的」· C++ 代码 · 共 139 行

CPP
139
字号
// ------------------------------------------------------------------// qerr.cpp//// This file contains function QMG::throw_error which is the QMG// error handler. It prints the error to some streams and then// causes an exception.// ------------------------------------------------------------------// Author: Stephen A. Vavasis// Copyright (c) 1999 by Cornell University.  All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software.  // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------#include "qerr.h"QMG::Error_Message* QMG::Error_Message::base_ = 0;// This could cause a memory leak if things go wrong, but// if things go right the base will always be zero anyway// when this is called.voidQMG::Error_Message::init_error_message_list() { base_ = 0;}QMG::Error_Message::Error_Message() {  Error_Message* curr = base_;  Error_Message** pointer_to_curr = &base_;  while (curr != 0) {    pointer_to_curr = &(curr -> next_);    curr = curr -> next_;  }  *pointer_to_curr = this;  this -> next_ = 0;}QMG::Error_Message::~Error_Message() {  Error_Message* curr = base_;  Error_Message** pointer_to_curr = &base_;  while (curr != 0 && curr != this) {    pointer_to_curr = &(curr -> next_);    curr = curr -> next_;  }  if (curr == this) {    *pointer_to_curr = this -> next_;  }}voidQMG::Error_Message::put_error_messages_into_stream(ostream& os) {  Error_Message* curr = base_;  while (curr != 0) {    os << (curr -> s_) << '\n';    curr = curr -> next_;  }}QMG::Error_Task* QMG::Error_Task::base_;voidQMG::Error_Task::init_error_task_list() { base_ = 0;}QMG::Error_Task::Error_Task() {  Error_Task* curr = base_;  Error_Task** pointer_to_curr = &base_;  while (curr != 0) {    pointer_to_curr = &(curr -> next_);    curr = curr -> next_;  }  *pointer_to_curr = this;  this -> next_ = 0;}QMG::Error_Task::~Error_Task() {  Error_Task* curr = base_;  Error_Task** pointer_to_curr = &base_;  while (curr != 0 && curr != this) {    pointer_to_curr = &(curr -> next_);    curr = curr -> next_;  }  if (curr == this) {    *pointer_to_curr = this -> next_;  }}QMG::Error::Error(const string& msg) {  ostringstream ostr;  ostr << msg << '\n';  Error_Message::put_error_messages_into_stream(ostr);  string s = ostr.str();  int l = s.length();  if (l >= ERROR_BUF_LEN) {    l = ERROR_BUF_LEN - 1;  }  for (int i = 0; i < l; ++i)    concatenated_error_messages_[i] = s[i];  concatenated_error_messages_[l] = 0;}QMG::Error::Error(const Error& other) {  for (int i = 0; i < ERROR_BUF_LEN; ++i) {    concatenated_error_messages_[i] = other.concatenated_error_messages_[i];    if (concatenated_error_messages_[i] == 0) break;  }}QMG::Error::~Error() {}void QMG::throw_error(const string& msg) {  Error_Task* curr = Error_Task::base_;  while (curr != 0) {    curr -> on_error_do(msg);    curr = curr -> next_;  }  Error e(msg);  throw e;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?