lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
win_errors.h
00001 /*****************************************************/
00002 /* lean Logging                 (c) Tobias Zirr 2011 */
00003 /*****************************************************/
00004 
00005 #ifndef LEAN_LOGGING_WIN_ERRORS
00006 #define LEAN_LOGGING_WIN_ERRORS
00007 
00008 #include "../lean.h"
00009 #include "../strings/types.h"
00010 #include "../strings/conversions.h"
00011 #include "../logging/errors.h"
00012 #include <sstream>
00013 #include "streamconv.h"
00014 
00015 namespace lean
00016 {
00017 namespace logging
00018 {
00019 
00021 LEAN_MAYBE_EXPORT size_t get_last_win_error_msg(utf16_t *buffer, size_t maxCount);
00022 
00024 template <class String>
00025 String get_last_win_error_msg();
00026 
00027 #ifndef DOXYGEN_SKIP_THIS
00028 
00030 template <>
00031 inline utf16_string get_last_win_error_msg()
00032 {
00033     utf16_string msg;
00034     msg.resize(1024);
00035     msg.erase(get_last_win_error_msg(&msg[0], msg.size()));
00036     return msg;
00037 }
00039 template <>
00040 inline utf8_string get_last_win_error_msg()
00041 {
00042     return utf_to_utf8(get_last_win_error_msg<utf16_string>());
00043 }
00044 
00045 #endif
00046 
00048 template <class String1>
00049 LEAN_NOTINLINE void log_last_win_error(const String1 &source)
00050 {
00051     log_error(source, get_last_win_error_msg<utf8_string>().c_str());
00052 }
00054 template <class String1, class String2>
00055 LEAN_NOTINLINE void log_last_win_error(const String1 &source, const String2 &reason)
00056 {
00057     log_error_ex(source, get_last_win_error_msg<utf8_string>().c_str(), reason);
00058 }
00060 template <class String1, class String2, class String3>
00061 LEAN_NOTINLINE void log_last_win_error(const String1 &source, const String2 &reason, const String3 &context)
00062 {
00063     log_error_ex(source, get_last_win_error_msg<utf8_string>().c_str(), reason, context);
00064 }
00065 
00067 template <class String1>
00068 LEAN_NOTINLINE void throw_last_win_error(const String1 &source)
00069 {
00070     throw_error(source, get_last_win_error_msg<utf8_string>().c_str());
00071 }
00073 template <class String1, class String2>
00074 LEAN_NOTINLINE void throw_last_win_error(const String1 &source, const String2 &reason)
00075 {
00076     throw_error_ex(source, get_last_win_error_msg<utf8_string>().c_str(), reason);
00077 }
00079 template <class String1, class String2, class String3>
00080 LEAN_NOTINLINE void throw_last_win_error(const String1 &source, const String2 &reason, const String3 &context)
00081 {
00082     throw_error_ex(source, get_last_win_error_msg<utf8_string>().c_str(), reason, context);
00083 }
00084 
00085 } // namespace
00086 
00087 using logging::log_last_win_error;
00088 using logging::throw_last_win_error;
00089 using logging::get_last_win_error_msg;
00090 
00091 } // namespace
00092 
00096 
00098 #define LEAN_LOG_WIN_ERROR() ::lean::logging::log_last_win_error(__FILE__ " (" LEAN_QUOTE_VALUE(__LINE__) ")")
00099 
00100 #define LEAN_LOG_WIN_ERROR_MSG(msg) ::lean::logging::log_last_win_error(__FILE__ " (" LEAN_QUOTE_VALUE(__LINE__) ")", msg)
00101 
00102 #define LEAN_LOG_WIN_ERROR_CTX(msg, ctx) ::lean::logging::log_last_win_error(__FILE__ " (" LEAN_QUOTE_VALUE(__LINE__) ")", msg, ctx)
00103 
00104 #define LEAN_LOG_WIN_ERROR_ANY(msg) LEAN_THROW_WIN_ERROR_MSG(static_cast<::std::ostringstream&>(::std::ostringstream() << msg).str().c_str())
00105 
00107 
00111 
00113 #define LEAN_THROW_WIN_ERROR() ::lean::logging::throw_last_win_error(__FILE__ " (" LEAN_QUOTE_VALUE(__LINE__) ")")
00114 
00115 #define LEAN_THROW_WIN_ERROR_MSG(msg) ::lean::logging::throw_last_win_error(__FILE__ " (" LEAN_QUOTE_VALUE(__LINE__) ")", msg)
00116 
00117 #define LEAN_THROW_WIN_ERROR_CTX(msg, ctx) ::lean::logging::throw_last_win_error(__FILE__ " (" LEAN_QUOTE_VALUE(__LINE__) ")", msg, ctx)
00118 
00119 #define LEAN_THROW_WIN_ERROR_ANY(msg) LEAN_THROW_WIN_ERROR_MSG(static_cast<::std::ostringstream&>(::std::ostringstream() << msg).str().c_str())
00120 
00122 
00123 #ifdef LEAN_INCLUDE_LINKED
00124 #include "source/win_errors.cpp"
00125 #endif
00126 
00127 #endif