added TypesErrorNumberToWcstr and TypesErrorNumberToMbstr

redefined QSE_MT() and QSE_WT()
This commit is contained in:
hyung-hwan 2020-08-09 19:08:47 +00:00
parent 77cb98ab5b
commit 0702fe331a
3 changed files with 93 additions and 29 deletions

View File

@ -80,11 +80,22 @@ private:
}; };
// the stock functor class to convert the Types::ErrorNumber to a string // the stock functor class to convert the Types::ErrorNumber to a string
struct TypesErrorNumberToStr struct TypesErrorNumberToWcstr
{ {
const qse_char_t* operator() (Types::ErrorNumber errnum); const qse_wchar_t* operator() (Types::ErrorNumber errnum);
}; };
struct TypesErrorNumberToMbstr
{
const qse_mchar_t* operator() (Types::ErrorNumber errnum);
};
#if defined(QSE_CHAR_IS_MCHAR)
typedef TypesErrorNumberToMbstr TypesErrorNumberToStr;
#else
typedef TypesErrorNumberToWcstr TypesErrorNumberToStr;
#endif
typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 64> ErrorGrab64; typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 64> ErrorGrab64;
typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 128> ErrorGrab128; typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 128> ErrorGrab128;
typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 256> ErrorGrab256; typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 256> ErrorGrab256;

View File

@ -279,27 +279,28 @@
/** /**
* The #QSE_MT macro maps a multi-byte literal string literal as it is. * The #QSE_MT macro maps a multi-byte literal string literal as it is.
*/ */
#define QSE_MT(txt) (txt) #define QSE_MT_I(txt) (txt)
#define QSE_MT(txt) QSE_MT_I(txt)
#if defined(QSE_WCHAR_IS_CHAR16_T) #if defined(QSE_WCHAR_IS_CHAR16_T)
# define QSE_WQ_I(val) (u ## #val) # define QSE_WQ_I(val) (u ## #val)
# define QSE_WQ(val) QSE_WQ_I(val)
#else #else
# define QSE_WQ_I(val) (L ## #val) # define QSE_WQ_I(val) (L ## #val)
# define QSE_WQ(val) QSE_WQ_I(val)
#endif #endif
#define QSE_WQ(val) QSE_WQ_I(val)
/** /**
* The #QSE_WT macro maps a multi-byte literal string to a wide character * The #QSE_WT macro maps a multi-byte literal string to a wide character
* string by prefixing it with \b L. * string by prefixing it with \b L.
*/ */
#if (QSE_SIZEOF_WCHAR_T == QSE_SIZEOF_MCHAR_T) #if (QSE_SIZEOF_WCHAR_T == QSE_SIZEOF_MCHAR_T)
# define QSE_WT(txt) (txt) # define QSE_WT_I(txt) (txt)
#elif defined(QSE_WCHAR_IS_CHAR16_T) #elif defined(QSE_WCHAR_IS_CHAR16_T)
# define QSE_WT(txt) (u ## txt) # define QSE_WT_I(txt) (u ## txt)
#else #else
# define QSE_WT(txt) (L ## txt) # define QSE_WT_I(txt) (L ## txt)
#endif #endif
#define QSE_WT(txt) QSE_WT_I(txt)
/** \def QSE_T /** \def QSE_T
* The #QSE_T macro maps to #QSE_MT if #QSE_CHAR_IS_MCHAR is defined, and to * The #QSE_T macro maps to #QSE_MT if #QSE_CHAR_IS_MCHAR is defined, and to

View File

@ -28,34 +28,86 @@
QSE_BEGIN_NAMESPACE(QSE) QSE_BEGIN_NAMESPACE(QSE)
static const qse_char_t* _errstr[] = #define MSG_ENOERR "no error"
#define MSG_EOTHER "other error"
#define MSG_ENOIMPL "not implemented"
#define MSG_ESYSERR "subsystem error"
#define MSG_EINTERN "internal error"
#define MSG_ENOMEM "insufficient memory"
#define MSG_ENARGS "wrong number of arguments"
#define MSG_EINVAL "invalid parameter or data"
#define MSG_EACCES "access denied"
#define MSG_EPERM "operation not allowed"
#define MSG_ENOENT "no such data"
#define MSG_EEXIST "data exists"
#define MSG_ENOTDIR "not directory"
#define MSG_EINTR "interrupted"
#define MSG_EPIPE "pipe error"
#define MSG_EINPROG "in progress"
#define MSG_EAGAIN "resource unavailable unavailable"
#define MSG_EEXCEPT "exception"
static const qse_mchar_t* _merrstr[] =
{ {
QSE_T("no error"), MSG_ENOERR,
QSE_T("other error"), MSG_EOTHER,
QSE_T("not implemented"), MSG_ENOIMPL,
QSE_T("subsystem error"), MSG_ESYSERR,
QSE_T("internal error"), MSG_EINTERN,
QSE_T("insufficient memory"), MSG_ENOMEM,
QSE_T("wrong number of arguments"), MSG_ENARGS,
QSE_T("invalid parameter or data"), MSG_EINVAL,
QSE_T("access denied"), MSG_EACCES,
QSE_T("operation not allowed"), MSG_EPERM,
QSE_T("data not found"), MSG_ENOENT,
QSE_T("existing data"), MSG_EEXIST,
QSE_T("not directory"), MSG_ENOTDIR,
QSE_T("interrupted"), MSG_EINTR,
QSE_T("pipe error"), MSG_EPIPE,
QSE_T("in progress"), MSG_EINPROG,
QSE_T("resource unavailable"), MSG_EAGAIN,
QSE_T("exception") MSG_EEXCEPT
}; };
const qse_char_t* TypesErrorNumberToStr::operator() (Types::ErrorNumber errnum) static const qse_wchar_t* _werrstr[] =
{ {
return errnum >= QSE_COUNTOF(_errstr)? QSE_T("unknown error"): _errstr[errnum]; QSE_WT(MSG_ENOERR),
QSE_WT(MSG_EOTHER),
QSE_WT(MSG_ENOIMPL),
QSE_WT(MSG_ESYSERR),
QSE_WT(MSG_EINTERN),
QSE_WT(MSG_ENOMEM),
QSE_WT(MSG_ENARGS),
QSE_WT(MSG_EINVAL),
QSE_WT(MSG_EACCES),
QSE_WT(MSG_EPERM),
QSE_WT(MSG_ENOENT),
QSE_WT(MSG_EEXIST),
QSE_WT(MSG_ENOTDIR),
QSE_WT(MSG_EINTR),
QSE_WT(MSG_EPIPE),
QSE_WT(MSG_EINPROG),
QSE_WT(MSG_EAGAIN),
QSE_WT(MSG_EEXCEPT)
};
const qse_wchar_t* TypesErrorNumberToWcstr::operator() (Types::ErrorNumber errnum)
{
return errnum >= QSE_COUNTOF(_werrstr)? QSE_WT("unknown error"): _werrstr[errnum];
}
const qse_mchar_t* TypesErrorNumberToMbstr::operator() (Types::ErrorNumber errnum)
{
return errnum >= QSE_COUNTOF(_merrstr)? QSE_MT("unknown error"): _merrstr[errnum];
} }
QSE_END_NAMESPACE(QSE) QSE_END_NAMESPACE(QSE)