Index: ext/libicpf/src/exception.cpp =================================================================== diff -u -r2446443341715955423610c01b43fe7841a10e3e -raba7605f4821e4a65dd64cb5118f4f44d65155eb --- ext/libicpf/src/exception.cpp (.../exception.cpp) (revision 2446443341715955423610c01b43fe7841a10e3e) +++ ext/libicpf/src/exception.cpp (.../exception.cpp) (revision aba7605f4821e4a65dd64cb5118f4f44d65155eb) @@ -26,15 +26,10 @@ BEGIN_ICPF_NAMESPACE -#ifdef _WIN32 - #define snprintf _snprintf - #define vsnprintf _vsnprintf -#endif - /// Defines max length of the exception description #define MAX_EXCEPTION 4096 -/** Constructor that takes the const description. The description (along with other char_t* parameters) +/** Constructor that takes the const description. The description (along with other tchar_t* parameters) * are copied to the internal members (so there is some memory allocation). * \param[in] pszDesc - exception description (currently should be in english) * \param[in] pszFilename - source file name from which the exception is thrown @@ -44,7 +39,7 @@ * \param[in] uiSystemCode - system error code (platform dependent) * \param[in] uiReserved - currently unused; must be 0 */ -exception::exception(const char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : +exception::exception(const tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : m_pszDesc(NULL), m_pszFilename(NULL), m_pszFunction(NULL), @@ -59,7 +54,7 @@ } /** Constructor that takes the ptr to a buffer as a description. The pointer to a buffer is - * stored in the internal member and will be deleted in the destructor. Other char_t* parameters + * stored in the internal member and will be deleted in the destructor. Other tchar_t* parameters * are copied to the internal members (so there is some memory allocated). * \param[in] pszDesc - ptr to exception description (currently should be in english) allocated with new operator * \param[in] pszFilename - source file name from which the exception is thrown @@ -69,7 +64,7 @@ * \param[in] uiSystemCode - system error code (platform dependent) * \param[in] uiReserved - currently unused; must be 0 */ -exception::exception(char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : +exception::exception(tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : m_pszDesc(pszDesc), m_pszFilename(NULL), m_pszFunction(NULL), @@ -91,43 +86,17 @@ delete [] m_pszFunction; } -/** Throws an exception as the arguments specify. Function made to provide a mean to throw an exception - * without worrying about the exception deletion. This function allocates an exception using this' dll - * stack, so the exception may be safely removed using ::del() member. - * All the parameters are being passed to the constructor without changes. - * \param[in] pszDesc - ptr to exception description (currently should be in english) allocated with new operator - * \param[in] pszFilename - source file name from which the exception is thrown - * \param[in] pszFunction - function name from which the exception is thrown - * \param[in] uiLine - line in the source file from which the exception is thrown - * \param[in] uiAppCode - application defined error code - * \param[in] uiSystemCode - system error code (platform dependent) - * \param[in] uiReserved - currently unused; must be 0 - */ -void exception::raise(const char* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) -{ - throw new exception(pszDesc, pszFilename, pszFunction, uiLine, uiAppCode, uiSystemCode, uiReserved); -} - -/** Deletes this class (deallocates the memory). This class must be allocated by - * the 'new' operator. Use only if the exception object has been allocated within - * the library. - */ -void exception::del() -{ - delete this; -} - /** Function retrieves the full information about the exception into * the string buffer specified by user. * \param[out] pszInfo - buffer fot the full exception description * \param[in] tMaxLen - size of the specified buffer * \return Pointer to the exception description (to the pszInfo to be specific) */ -const char_t* exception::get_info(char_t* pszInfo, intptr_t tMaxLen) +const tchar_t* exception::get_info(tchar_t* pszInfo, intptr_t tMaxLen) { - snprintf(pszInfo, (size_t)tMaxLen, "description: " STRFMT "\nfile: " STRFMT "\nfunction: " STRFMT "\nline: " ULFMT "\napp code: " ULFMT "\nsys code: " ULFMT "\nreserved: " ULFMT "\n", + _sntprintf(pszInfo, (size_t)tMaxLen, _t("description: ") TSTRFMT _t("\nfile: ") TSTRFMT _t("\nfunction: ") TSTRFMT _t("\nline: ") ULFMT _t("\napp code: ") ULFMT _t("\nsys code: ") ULFMT _t("\nreserved: ") ULFMT _t("\n"), m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); - pszInfo[tMaxLen-1]='\0'; + pszInfo[tMaxLen-1]=_t('\0'); return pszInfo; } @@ -136,9 +105,9 @@ * \param[in] pszDesc - additional description of the exception object * \param[in] plog - pointer to a log file to log the exception to */ -void exception::log(const char_t* pszDesc, log_file* plog) +void exception::log(const tchar_t* pszDesc, log_file* plog) { - plog->loge(STRFMT "\n\tdesc: " STRFMT "\n\tfile: " STRFMT "\n\tfunc: " STRFMT "\n\tline: " ULFMT "\n\tapp code: " ULFMT "\n\tsys code: " ULFMT "\n\treserved: " ULFMT "\n", + plog->loge(TSTRFMT _t("\n\tdesc: ") TSTRFMT _t("\n\tfile: ") TSTRFMT _t("\n\tfunc: ") TSTRFMT _t("\n\tline: ") ULFMT _t("\n\tapp code: ") ULFMT _t("\n\tsys code: ") ULFMT _t("\n\treserved: ") ULFMT _t("\n"), pszDesc, m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); } @@ -148,42 +117,42 @@ * \param[in] pszDesc2 - the second part of an additional description * \param[in] plog - pointer to a log file to log the exception to */ -void exception::log(const char_t* pszDesc, const char_t* pszDesc2, log_file* plog) +void exception::log(const tchar_t* pszDesc, const tchar_t* pszDesc2, log_file* plog) { - plog->loge(STRFMT " " STRFMT "\n\tdesc: " STRFMT "\n\tfile: " STRFMT "\n\tfunc: " STRFMT "\n\tline: " ULFMT "\n\tapp code: " ULFMT "\n\tsys code: " ULFMT "\n\treserved: " ULFMT "\n", + plog->loge(TSTRFMT _t(" ") TSTRFMT _t("\n\tdesc: ") TSTRFMT _t("\n\tfile: ") TSTRFMT _t("\n\tfunc: ") TSTRFMT _t("\n\tline: ") ULFMT _t("\n\tapp code: ") ULFMT _t("\n\tsys code: ") ULFMT _t("\n\treserved: ") ULFMT _t("\n"), pszDesc, pszDesc2, m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); } /** Exception's description formatting routine. Acts just as normal sprintf * function, but allocates a buffer for the output result and returns a pointer * to it. Used for formatting the exception description - usage: - * THROW(exception::format("test " STRFMT , "abc"), ...). + * THROW(exception::format(_t("test ") TSTRFMT , _t("abc")), ...). * It will enforce compiler to use the second constructor (non-const description). * And the allocated buffer (result of this func) will be freed. * \param[in] pszFormat - format string followed by some additional data (as in printf) * \return Pointer to the newly allocated buffer with formatted output. */ -char_t* exception::format(const char_t* pszFormat, ...) +tchar_t* exception::format(const tchar_t* pszFormat, ...) { va_list vl; va_start(vl, pszFormat); // alloc some space - no more than MAX_EXCEPTION chracters - char_t* psz=new char_t[(size_t)MAX_EXCEPTION]; - vsnprintf(psz, (size_t)MAX_EXCEPTION, pszFormat, vl); - psz[MAX_EXCEPTION-1]='\0'; + tchar_t* psz=new tchar_t[(size_t)MAX_EXCEPTION]; + _vsnprintf(psz, (size_t)MAX_EXCEPTION, pszFormat, vl); + psz[MAX_EXCEPTION-1]=_t('\0'); return psz; } /** Allocates a string buffer and makes a copy of an input data. Used to * make a copy of the constructor string parameteres. - * \param[out] pszOut - pointer to char_t* which will receive the new buffer address + * \param[out] pszOut - pointer to tchar_t* which will receive the new buffer address * \param[in] pszIn - string to make a copy of */ -void exception::set_string(char_t** pszOut, const char_t* pszIn) const +void exception::set_string(tchar_t** pszOut, const tchar_t* pszIn) const { - *pszOut=new char_t[strlen(pszIn)+(uint_t)1]; - strcpy(*pszOut, pszIn); + *pszOut=new tchar_t[_tcslen(pszIn)+(uint_t)1]; + _tcscpy(*pszOut, pszIn); } END_ICPF_NAMESPACE Index: ext/libicpf/src/exception.h =================================================================== diff -u -r2446443341715955423610c01b43fe7841a10e3e -raba7605f4821e4a65dd64cb5118f4f44d65155eb --- ext/libicpf/src/exception.h (.../exception.h) (revision 2446443341715955423610c01b43fe7841a10e3e) +++ ext/libicpf/src/exception.h (.../exception.h) (revision aba7605f4821e4a65dd64cb5118f4f44d65155eb) @@ -39,12 +39,11 @@ * \param[in] reserved_code - currently unused; must be 0 */ #undef THROW -//#define THROW(desc,app_code,sys_code,reserved_code) throw new icpf::exception(desc, __FILE__, __FUNCTION__, __LINE__,app_code,sys_code,reserved_code) -#define THROW(desc,app_code,sys_code,reserved_code) icpf::exception::raise(desc, __FILE__, __FUNCTION__, __LINE__, app_code, sys_code, reserved_code) +#define THROW(desc,app_code,sys_code,reserved_code) throw icpf::exception(desc, _t(__FILE__), _t(__FUNCTION__), __LINE__, app_code, sys_code, reserved_code) /// Logs an exception in a log file -#define LOG_EXCEPTION(except, ptr_log) (except)->log("Caught an exception in ", __FUNCTION__, ptr_log) +#define LOG_EXCEPTION(except, ptr_log) (except)->log("Caught an exception in ", _t(__FUNCTION__), ptr_log) /// Logs an unknown exception in a log file -#define LOG_UEXCEPTION(ptr_log) (ptr_log)->loge("Caught an unknown exception in " STRFMT, __FUNCTION__) +#define LOG_UEXCEPTION(ptr_log) (ptr_log)->loge("Caught an unknown exception in " TSTRFMT, _t(__FUNCTION__)) BEGIN_ICPF_NAMESPACE @@ -59,43 +58,39 @@ /** \name Construction/destruction */ /**@{*/ /// Standard constructor that takes the const description - exception(const char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); + exception(const tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); /// Standard constructor that takes non-const ptr to a buffer as the description - exception(char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); + exception(tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); /// Standard destructor ~exception(); - - /// Raises an exception - static void raise(const char* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); - void del(); ///< Deletes this class (if allocated with new operator) /**@}*/ /** \name Outputting */ /**@{*/ - const char_t* get_info(char_t* pszInfo, intptr_t tMaxLen); ///< Retrieves the exception information to a specified string buffer - const char_t* get_desc() const { return m_pszDesc; }; - const char_t* get_filename() const { return m_pszFilename; }; - const char_t* get_function() const { return m_pszFunction; }; + const tchar_t* get_info(tchar_t* pszInfo, intptr_t tMaxLen); ///< Retrieves the exception information to a specified string buffer + const tchar_t* get_desc() const { return m_pszDesc; }; + const tchar_t* get_filename() const { return m_pszFilename; }; + const tchar_t* get_function() const { return m_pszFunction; }; uint_t get_line() const { return m_uiLine; }; uint_t get_appcode() const { return m_uiAppCode; }; uint_t get_syscode() const { return m_uiSystemCode; }; - void log(const char_t* pszDesc, log_file* plog); ///< Logs the exception information to the log file - void log(const char_t* pszDesc, const char_t* pszDesc2, log_file* plog); ///< Logs the exception to the log file with an additional description + void log(const tchar_t* pszDesc, log_file* plog); ///< Logs the exception information to the log file + void log(const tchar_t* pszDesc, const tchar_t* pszDesc2, log_file* plog); ///< Logs the exception to the log file with an additional description /**@}*/ /** \name Formatting */ /**@{*/ - static char_t* format(const char_t* pszFormat, ...); ///< Description formatting function + static tchar_t* format(const tchar_t* pszFormat, ...); ///< Description formatting function /**@}*/ protected: - void set_string(char_t** pszOut, const char_t* pszIn) const; ///< Makes a copy of an input string + void set_string(tchar_t** pszOut, const tchar_t* pszIn) const; ///< Makes a copy of an input string protected: - char_t* m_pszDesc; ///< Exception description - char_t* m_pszFilename; ///< Source file in which the exception has been thrown - char_t* m_pszFunction; ///< Function name in the source file in which the exception has been thrown + tchar_t* m_pszDesc; ///< Exception description + tchar_t* m_pszFilename; ///< Source file in which the exception has been thrown + tchar_t* m_pszFunction; ///< Function name in the source file in which the exception has been thrown uint_t m_uiLine; ///< Line in the source file in which the exception has been thrown uint_t m_uiAppCode; ///< Application error code uint_t m_uiSystemCode; ///< System error code (platform dependent)