error_desc.hpp
来自「用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、W」· HPP 代码 · 共 578 行 · 第 1/2 页
HPP
578 行
traits_type::free_library(hinstSource);
}
}
else
{
cch = FormatMessage(error, NULL, &message);
}
if(0 == cch)
{
message = NULL;
}
*length = cch;
return message;
}
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline basic_error_desc<C, T>::basic_error_desc(ws_dword_t error /* = ::GetLastError() */, char_type const *modulePath /* = NULL */)
: m_length(0)
, m_message(find_message_(error, modulePath, &m_length))
{
if(NULL == m_message)
{
if(0 == FormatMessage(error, NULL, &m_message))
{
m_message = NULL;
}
}
}
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline basic_error_desc<C, T>::basic_error_desc(HRESULT hr, char_type const *modulePath /* = NULL */)
: m_length(0)
, m_message(find_message_(static_cast<DWORD>(hr), modulePath, &m_length))
{
if(NULL == m_message)
{
if(0 == FormatMessage(static_cast<DWORD>(hr), NULL, &m_message))
{
m_message = NULL;
}
}
}
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline basic_error_desc<C, T>::~basic_error_desc() stlsoft_throw_0()
{
#ifdef STLSOFT_CF_USE_RAW_OFFSETOF_IN_STATIC_ASSERT
STLSOFT_STATIC_ASSERT(STLSOFT_RAW_OFFSETOF(class_type, m_length) < STLSOFT_RAW_OFFSETOF(class_type, m_message));
#endif /* STLSOFT_CF_USE_RAW_OFFSETOF_IN_STATIC_ASSERT */
if(m_message != NULL)
{
::LocalFree(m_message);
}
}
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline ss_typename_type_k basic_error_desc<C, T>::char_type const *basic_error_desc<C, T>::get_description() const
{
static const char_type s_nullMessage[1] = { '\0' };
return (NULL != m_message) ? m_message : s_nullMessage;
}
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline ss_typename_type_k basic_error_desc<C, T>::char_type const *basic_error_desc<C, T>::c_str() const
{
return get_description();
}
#if !defined(WINSTL_ERROR_DESC_NO_IMPLICIT_CONVERSION)
template< ss_typename_param_k C
, ss_typename_param_k T
>
#if defined(STLSOFT_COMPILER_IS_GCC)
inline basic_error_desc<C, T>::operator C const *() const
#else /* ? compiler */
inline basic_error_desc<C, T>::operator ss_typename_type_k basic_error_desc<C, T>::char_type const *() const
#endif /* compiler */
{
return get_description();
}
#endif /* !WINSTL_ERROR_DESC_NO_IMPLICIT_CONVERSION */
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline ss_typename_type_k basic_error_desc<C, T>::size_type basic_error_desc<C, T>::length() const stlsoft_throw_0()
{
return m_length;
}
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline ss_typename_type_k basic_error_desc<C, T>::size_type basic_error_desc<C, T>::size() const stlsoft_throw_0()
{
return length();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* String access shims
*/
#ifndef STLSOFT_CF_TEMPLATE_SHIMS_NOT_SUPPORTED
/// \brief Returns the corresponding C-string pointer of \c e
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline C const *c_str_ptr_null(basic_error_desc<C, T> const &e)
{
C const *p = e;
return ('\0' != *e) ? p : NULL;
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template <ss_typename_param_k T>
inline ws_char_a_t const *c_str_ptr_null_a(basic_error_desc<ws_char_a_t, T> const &e)
{
ws_char_a_t const *p = e;
return ('\0' != *e) ? p : NULL;
}
template <ss_typename_param_k T>
inline ws_char_w_t const *c_str_ptr_null_w(basic_error_desc<ws_char_w_t, T> const &e)
{
ws_char_w_t const *p = e;
return (L'\0' != *e) ? p : NULL;
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// \brief Returns the corresponding C-string pointer of \c e
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline C const *c_str_ptr(basic_error_desc<C, T> const &e)
{
return e.c_str();
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template <ss_typename_param_k T>
inline ws_char_a_t const *c_str_ptr_a(basic_error_desc<ws_char_a_t, T> const &e)
{
return e.c_str();
}
template <ss_typename_param_k T>
inline ws_char_w_t const *c_str_ptr_w(basic_error_desc<ws_char_w_t, T> const &e)
{
return e.c_str();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// \brief Returns the corresponding C-string pointer of \c e
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline C const *c_str_data(basic_error_desc<C, T> const &e)
{
return e.c_str();
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template <ss_typename_param_k T>
inline ws_char_a_t const *c_str_data_a(basic_error_desc<ws_char_a_t, T> const &e)
{
return e.c_str();
}
template <ss_typename_param_k T>
inline ws_char_w_t const *c_str_data_w(basic_error_desc<ws_char_w_t, T> const &e)
{
return e.c_str();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// \brief Overload of the \ref group__concept__shim__c_str_len "c_str_len" String Attribute Shim.
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline ws_size_t c_str_len(basic_error_desc<C, T> const &e)
{
return e.length();
}
/// \brief Returns the corresponding C-string pointer of \c e
template< ss_typename_param_k C
, ss_typename_param_k T
>
inline C const *get_ptr(basic_error_desc<C, T> const &e)
{
return e;
}
template< ss_typename_param_k S
, ss_typename_param_k C
, ss_typename_param_k T
>
inline S &operator <<(S &s, basic_error_desc<C, T> const &e)
{
s << e.get_description();
return s;
}
#endif /* !STLSOFT_CF_TEMPLATE_SHIMS_NOT_SUPPORTED */
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/error_desc_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace winstl
# else
} // namespace winstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*
* The string access shims exist either in the stlsoft namespace, or in the
* global namespace. This is required by the lookup rules.
*
*/
#ifndef _WINSTL_NO_NAMESPACE
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
namespace stlsoft
{
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
using ::winstl::c_str_ptr_null;
using ::winstl::c_str_ptr_null_a;
using ::winstl::c_str_ptr_null_w;
using ::winstl::c_str_ptr;
using ::winstl::c_str_ptr_a;
using ::winstl::c_str_ptr_w;
using ::winstl::c_str_data;
using ::winstl::c_str_data_a;
using ::winstl::c_str_data_w;
using ::winstl::c_str_len;
using ::winstl::get_ptr;
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace stlsoft
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* WINSTL_INCL_WINSTL_ERROR_HPP_ERROR_DESC */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?