54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#ifndef V_RETURN_CODE_H
|
|
#define V_RETURN_CODE_H
|
|
#include <iostream>
|
|
#include <memory>
|
|
/**
|
|
* @brief
|
|
* The base return code.
|
|
* Attention: VReturnCOdeDefineStr must be added one item when define one new code.
|
|
*/
|
|
enum class VReturnCodeDefine
|
|
{
|
|
OK = 0,
|
|
NOT_OK_UNDEFINE_REASON,
|
|
NOT_OK_VIRTUAL_FUNCTION,
|
|
MAKE_SHARED_PTR_FAILED,
|
|
END
|
|
};
|
|
class VReturnCode
|
|
{
|
|
protected:
|
|
VReturnCode(const int &code) : mCode(code)
|
|
{
|
|
}
|
|
|
|
public:
|
|
virtual ~VReturnCode() = default;
|
|
virtual const int GetIntCode() { return mCode; }
|
|
bool IsCodeOK();
|
|
/**
|
|
* @brief
|
|
* Print the code translate into a readable string.
|
|
* @return int
|
|
*/
|
|
virtual std::string PrintStringCode();
|
|
void SetTips(const std::string &tips) { mTips = tips; }
|
|
const std::string &GetTips() { return mTips; }
|
|
/**
|
|
* @brief
|
|
* Create a new return code, which is the only way to create a code shared ptr.
|
|
* @param code
|
|
* @return std::make_shared<VReturnCode>
|
|
*/
|
|
static std::shared_ptr<VReturnCode> NewCode(const VReturnCodeDefine &code);
|
|
|
|
private:
|
|
const int mCode; // Can't be reset.
|
|
std::string mTips; // Give some tips for return code, such as the not OK detail.
|
|
};
|
|
/**
|
|
* @brief
|
|
* Define the VReturnCode as shared ptr, which other modules can redefine VReturnCode.
|
|
*/
|
|
using RETURN_CODE = std::shared_ptr<VReturnCode>;
|
|
#endif |