⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qerr.cpp

📁 算断裂的
💻 CPP
字号:
// ------------------------------------------------------------------// 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.// Matlab version// ------------------------------------------------------------------// 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"extern "C" {#include "mex.h"}#ifdef USE_MEX_MALLOC#include <new>void* operator new(std::size_t size) {  void* ptr = mxMalloc(size);  if (size > 0 && ptr == 0)    mexErrMsgTxt("Out of memory");  return ptr;}void  operator delete(void* ptr) {  mxFree(ptr);}void* operator new[](std::size_t size)  {  void* ptr = mxMalloc(size);  if (size > 0 && ptr == 0)    mexErrMsgTxt("Out of memory");  return ptr;}    void operator delete[](void* ptr)  {  mxFree(ptr);}#endifQMG::Error_Message* QMG::Error_Message::base_ = 0;namespace {  QMG::ostream* matlab_error_ostream = 0;}namespace QMG {  namespace FrontEnd {    using namespace QMG;    void set_matlab_error_ostream(ostream* os) {      matlab_error_ostream = os;    }  }}// 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_;  }  if (matlab_error_ostream) {    QMG::Error_Message::put_error_messages_into_stream(*matlab_error_ostream);#ifndef EXCEPTIONS_ENABLED    delete matlab_error_ostream;#endif  }#ifdef EXCEPTIONS_ENABLED  Error e(msg);  throw e;#else  int l = msg.length();  char* buf = static_cast<char*>(mxMalloc(l + 1));  msg.copy(buf, l);  buf[l] = 0;  mexErrMsgTxt(buf);#endif}

⌨️ 快捷键说明

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