C++宏实现的好的代码

来源:互联网 发布:工作流数据库设计思路 编辑:程序博客网 时间:2024/05/22 15:34
C++宏实现的好的代码

#include "errorcode_def.h"DEFINE_NUWA_ERRORCODE(RequestExecSuccess, 200, "OK");DEFINE_NUWA_ERRORCODE(ParameterInvalidExceptionError, 400, "ParameterInvalidException");DEFINE_NUWA_ERRORCODE(FileNotExistExceptionError, 401, "NOT_EXIST")#include "errorcode.h"#define DEFINE_ERRORCODE(errorName, httpcode, errorCodestr...) const int errorName = httpcode;#include "errorcode_def.h"#undef DEFINE_ERRORCODEconst char* GetErrorString(int errorName);int GetErrorHttpCode(int errorName);#include "errorcode.cpp"const char* GetErrorString(int errorName){    switch(errorName)    {    #define DEFINE_ERRORCODE(name, value, errorstr) \        case name: return errorstr;    #include "errorcode_def.h"    #undef DEFINE_NUWA_ERRORCODE        default:        {            return "Unknown_ErrorName";        }    }}