44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#include "VReturnCode.h"
|
|
#include "Log.h"
|
|
const std::string VReturnCOdeDefineStr[static_cast<int>(VReturnCodeDefine::END) + 1] = {
|
|
"OK",
|
|
"NOT_OK_UNDEFINE_REASON, undefine reason",
|
|
"NOT_OK_VIRTUAL_FUNCTION, do nothing function",
|
|
"MAKE_SHARED_PTR_FAILED, std::make_shared<T> failed",
|
|
"END"};
|
|
std::shared_ptr<VReturnCode> VReturnCode::NewCode(const VReturnCodeDefine &code)
|
|
{
|
|
// return std::make_shared<VReturnCode>(static_cast<int>(code));
|
|
class MakeShared : public VReturnCode
|
|
{
|
|
public:
|
|
MakeShared(const int &code) : VReturnCode(code) {}
|
|
};
|
|
return std::make_shared<MakeShared>(static_cast<int>(code));
|
|
}
|
|
bool VReturnCode::IsCodeOK()
|
|
{
|
|
bool result = mCode == static_cast<int>(VReturnCodeDefine::OK) ? true : false;
|
|
// if (!result)
|
|
// {
|
|
// PrintStringCode(); // Don't print code when run ok.
|
|
// }
|
|
return result;
|
|
}
|
|
std::string VReturnCode::PrintStringCode()
|
|
{
|
|
if (mCode < static_cast<long int>(VReturnCodeDefine::OK) || mCode > static_cast<long int>(VReturnCodeDefine::END))
|
|
{
|
|
LogError("Illegal code, cross the border.\n");
|
|
return "Illegal code.";
|
|
}
|
|
if (mCode > static_cast<long int>(VReturnCodeDefine::OK))
|
|
{
|
|
LogError("Return code:[ %s ]\n", VReturnCOdeDefineStr[mCode].c_str());
|
|
}
|
|
else
|
|
{
|
|
LogInfo("Return code:[ %s %s]\n", VReturnCOdeDefineStr[mCode].c_str(), GetTips().c_str());
|
|
}
|
|
return VReturnCOdeDefineStr[mCode];
|
|
} |