12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include "Common.h"
- /// <summary>
- /// 析构函数
- /// </summary>
- ErrorMsg::~ErrorMsg()
- {
- if (_errorMsg)
- {
- delete _errorMsg;
- _errorMsg = nullptr;
- }
- }
- /// <summary>
- /// 设置错误信息
- /// </summary>
- /// <param name="code"></param>
- /// <param name="errorMsgs"></param>
- void ErrorMsg::SetErrorMsg(ErrorCode code, std::vector<const char*> errorMsgs)
- {
- if (_errorMsg)
- {
- delete _errorMsg;
- _errorMsg = NULL;
- }
- int count = errorMsgs.size();
- std::stringstream ss;
- for (int ni = 0; ni < count; ni++)
- {
- ss << errorMsgs[ni];
- }
- std::string msgCombined = ss.str();
- int len = msgCombined.length();
- _errorMsg = new char[msgCombined.length() + 1];
- msgCombined.copy(_errorMsg, len, 0);
- *(_errorMsg + len) = '\0';
- _errorCode = code;
- }
- /// <summary>
- /// 获取错误信息
- /// </summary>
- /// <param name="errorCode"></param>
- /// <param name="errorMsg"></param>
- /// <param name="errorMaxLen"></param>
- void ErrorMsg::GetErrorMsg(ErrorCode& errorCode, char* errorMsg, const int errorMaxLen)
- {
- errorCode = _errorCode;
- if (!_errorMsg)
- {
- return;
- }
- int errorLen = strlen(_errorMsg);
- if (errorMaxLen > errorLen)
- {
- wcscpy_s(errorMsg, errorLen + 1, _errorMsg);
- }
- else
- {
- wcscpy_s(errorMsg, errorMaxLen, _errorMsg, errorMaxLen - 1);
- }
- }
- /// <summary>
- /// 初始化静态成员变量_errorMsg
- /// </summary>
- char* ErrorMsg::_errorMsg = nullptr;
- /// <summary>
- /// 初始化静态成员变量 _errorCode
- /// </summary>
- ErrorCode ErrorMsg::_errorCode = None;
|