📄 warerror.cpp
字号:
#include "StdAfx.h"#include "WarError.h" // class implemented#ifndef WAR_ERRNO_H_INCLUDED# define WAR_ERRNO_H_INCLUDED# include <errno.h>#endif#ifndef WAR_STDIO_H_INCLUDED# define WAR_STDIO_H_INCLUDED# include <stdio.h>#endif/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarError::WarError(const war_error_definitions local_error, const int system_error, war_ccstr_t source_file, const int source_line) : mpSpecialExplanation(NULL), mLocalError(local_error), mSystemError(system_error), mpSourceFile(source_file), mSourceLine(source_line){} WarError::~WarError() throw(){ if (mpSpecialExplanation) delete mpSpecialExplanation;}//============================= OPERATORS ====================================WarError& WarError::operator=(const WarError& from){ mSystemError = from.mSystemError; mLocalError = from.mLocalError; mpSourceFile = from.mpSourceFile; mSourceLine = from.mSourceLine; if (mpSpecialExplanation) { delete mpSpecialExplanation; mpSpecialExplanation = NULL; } if (from.mpSpecialExplanation) { mpSpecialExplanation = new char[strlen(from.mpSpecialExplanation) + 1]; strcpy(mpSpecialExplanation, from.mpSpecialExplanation); } return *this;};WarError& WarError::operator =(const int system_error){ mSystemError = system_error; return *this;};WarError& WarError::operator =(const war_error_t& from){ mSystemError = from.mSystemError; mLocalError = (war_error_definitions)from.mLocalError; mpSourceFile = from.mpSourceFile; mSourceLine = from.mSourceLine; return *this;};WarError& WarError::operator =(const war_error_definitions local_error){ mLocalError = local_error; return *this;};//============================= OPERATIONS ===================================const WarError& WarError::Capture(const war_error_definitions local_error){#ifdef _WIN32 mSystemError = ::GetLastError(); // We must reset the error after calling GetLastError() ::SetLastError(mSystemError);#else mSystemError = errno;#endif if ((mLocalError = local_error) == WAR_ERR_SYSTEM_ERROR) { // Try to map system errors to local errors switch(mSystemError) { case ENOTDIR: mLocalError = WAR_FERR_NOT_A_DIRECTORY; break; case ENAMETOOLONG: mLocalError = WAR_ERR_BUFFER_OVERFLOW; break; case ENOENT: mLocalError = WAR_FERR_NO_SUCH_PATH; break; case EACCES: mLocalError = WAR_ERR_ACCESS_DENIED; break; } } return *this;}const std::string& WarError::Explain() const{ if (mMessageBuf.empty()) { char buf[64]; if (WAR_ERR_OK != mLocalError) { sprintf(buf, "Error %d/%d [", mLocalError, mSystemError); (std::string &)mMessageBuf = buf; (std::string &)mMessageBuf += ::war_get_local_error_text(mLocalError); (std::string &)mMessageBuf += ']'; if (0 != mSystemError) OnExplainSystemError((std::string &)mMessageBuf); } else (std::string &)mMessageBuf = "No error"; } return mMessageBuf;}void WarError::OnExplainSystemError(std::string& appendExplanation)const{ if (mpSpecialExplanation) appendExplanation += mpSpecialExplanation; char buf[256]; appendExplanation += " ["; appendExplanation += ::war_get_system_error_text(mSystemError, buf, sizeof(buf)); appendExplanation += " ]";}//============================= ACCESS ===================================//============================= INQUIRY ===================================/////////////////////////////// PROTECTED ////////////////////////////////////////////////////////////////// PRIVATE ///////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -