string_access.hpp
来自「用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、W」· HPP 代码 · 共 1,042 行 · 第 1/3 页
HPP
1,042 行
return c_str_ptr_w(guid);
#else /* ? UNICODE */
return c_str_ptr_a(guid);
#endif /* UNICODE */
}
/// \brief Returns the corresponding possibly unterminated ANSI C-string pointer of the GUID \c guid
inline c_str_ptr_GUID_proxy<cs_char_a_t> c_str_data_a(GUID const &guid)
{
return c_str_ptr_a(guid);
}
/// \brief Returns the corresponding possibly unterminated Unicode C-string pointer of the GUID \c guid
inline c_str_ptr_GUID_proxy<cs_char_w_t> c_str_data_w(GUID const &guid)
{
return c_str_ptr_w(guid);
}
/// \brief Returns the corresponding possibly unterminated C-string pointer of the GUID \c guid
inline c_str_ptr_GUID_proxy<cs_char_o_t> c_str_data_o(GUID const &guid)
{
return c_str_ptr_o(guid);
}
/// \brief Returns the corresponding possibly unterminated C-string pointer of the GUID \c guid
inline c_str_ptr_GUID_proxy<TCHAR> c_str_data(GUID const &guid)
{
#ifdef UNICODE
return c_str_data_w(guid);
#else /* ? UNICODE */
return c_str_data_a(guid);
#endif /* UNICODE */
}
/* VARIANT */
/// \brief Returns the corresponding ANSI C-string pointer of the VARIANT \c v
inline c_str_VARIANT_proxy_a c_str_ptr_a(VARIANT const &v)
{
VARIANT vs;
HRESULT hr;
::VariantInit(&vs);
hr = ::VariantChangeTypeEx(&vs, const_cast<VARIANT *>(&v), LOCALE_USER_DEFAULT, 0, VT_BSTR);
if(FAILED(hr))
{
vs.bstrVal = NULL;
}
return c_str_VARIANT_proxy_a(c_str_VARIANT_proxy_w(vs.bstrVal));
}
/// \brief Returns the corresponding Unicode C-string pointer of the VARIANT \c v
inline c_str_VARIANT_proxy_w c_str_ptr_w(VARIANT const &v)
{
VARIANT vs;
HRESULT hr;
::VariantInit(&vs);
hr = ::VariantChangeTypeEx(&vs, const_cast<VARIANT *>(&v), LOCALE_USER_DEFAULT, VARIANT_ALPHABOOL, VT_BSTR);
if(FAILED(hr))
{
vs.bstrVal = NULL;
}
return c_str_VARIANT_proxy_w(vs.bstrVal);
}
/// \brief Returns the corresponding possibly unterminated ANSI C-string pointer of the GUID \c guid
inline c_str_VARIANT_proxy_a c_str_data_a(VARIANT const &v)
{
return c_str_ptr_a(v);
}
/// \brief Returns the corresponding possibly unterminated Unicode C-string pointer of the GUID \c guid
inline c_str_VARIANT_proxy_w c_str_data_w(VARIANT const &v)
{
return c_str_ptr_w(v);
}
/// \brief Returns the corresponding C-string pointer of the VARIANT \c v
#ifdef UNICODE
inline c_str_VARIANT_proxy_w c_str_ptr(VARIANT const &v)
#else /* ? UNICODE */
inline c_str_VARIANT_proxy_a c_str_ptr(VARIANT const &v)
#endif /* UNICODE */
{
#ifdef UNICODE
return c_str_ptr_w(v);
#else /* ? UNICODE */
return c_str_ptr_a(v);
#endif /* UNICODE */
}
/// \brief Returns the corresponding possibly unterminated C-string pointer of the VARIANT \c v
#ifdef UNICODE
inline c_str_VARIANT_proxy_w c_str_data(VARIANT const &v)
#else /* ? UNICODE */
inline c_str_VARIANT_proxy_a c_str_data(VARIANT const &v)
#endif /* UNICODE */
{
#ifdef UNICODE
return c_str_data_w(v);
#else /* ? UNICODE */
return c_str_data_a(v);
#endif /* UNICODE */
}
/* /////////////////////////////////////////////////////////////////////////
* c_str_len
*
* This can be applied to an expression, and the return value is the number of
* characters in the character string in the expression.
*/
/* GUID */
/// \brief Returns the length (in characters) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_len_a(GUID const &/* guid */)
{
return COMSTL_CCH_GUID;
}
/// \brief Returns the length (in characters) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_len_w(GUID const &/* guid */)
{
return COMSTL_CCH_GUID;
}
/// \brief Returns the length (in characters) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_len_o(GUID const &/* guid */)
{
return COMSTL_CCH_GUID;
}
/// \brief Returns the length (in characters) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_len(GUID const &/* guid */)
{
return COMSTL_CCH_GUID;
}
/* VARIANT */
/// \brief Returns the length (in characters) of the VARIANT \c v, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_len(VARIANT const &v)
{
cs_size_t len;
if(v.vt == VT_BSTR)
{
len = v.bstrVal != NULL ? ::SysStringLen(v.bstrVal) : 0;
}
else if(v.vt == VT_NULL ||
v.vt == VT_EMPTY)
{
len = 0;
}
else
{
VARIANT vs;
HRESULT hr;
::VariantInit(&vs);
hr = ::VariantChangeTypeEx(&vs, const_cast<VARIANT *>(&v), LOCALE_USER_DEFAULT, 0, VT_BSTR);
if(FAILED(hr))
{
len = 0;
}
else
{
len = vs.bstrVal ? ::SysStringLen(vs.bstrVal) : 0;
::VariantClear(&vs);
}
}
return len;
}
/// \brief Returns the length (in characters) of the VARIANT \c v, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_len_a(VARIANT const &v)
{
return c_str_len(v);
}
/// \brief Returns the length (in characters) of the VARIANT \c v, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_len_w(VARIANT const &v)
{
return c_str_len(v);
}
/* /////////////////////////////////////////////////////////////////////////
* c_str_size
*
* This can be applied to an expression, and the return value is the number of
* bytes required to store the character string in the expression, NOT including
* the null-terminating character.
*/
/* GUID */
#if 0
/// \brief Returns the size (in bytes) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_size_a(GUID const &guid)
{
return c_str_len_a(guid) *sizeof(cs_char_a_t);
}
#endif /* 0 */
#if 0
/// \brief Returns the size (in bytes) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_size_w(GUID const &guid)
{
return c_str_len_w(guid) * sizeof(cs_char_w_t);
}
#endif /* 0 */
#if 0
/// \brief Returns the size (in bytes) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_size_o(GUID const &guid)
{
return c_str_len_o(guid) * sizeof(cs_char_o_t);
}
#endif /* 0 */
#if 0
/// \brief Returns the size (in bytes) of the GUID \c guid, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_size(GUID const &guid)
{
#ifdef UNICODE
return c_str_size_w(guid);
#else /* ? UNICODE */
return c_str_size_a(guid);
#endif /* UNICODE */
}
#endif /* 0 */
/* VARIANT */
#if 0
/// \brief Returns the size (in bytes) of the VARIANT \c v, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_size_a(VARIANT const &v)
{
return c_str_len(v) * sizeof(cs_char_a_t);
}
#endif /* 0 */
#if 0
/// \brief Returns the size (in bytes) of the VARIANT \c v, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_size_w(VARIANT const &v)
{
return c_str_len(v) * sizeof(OLECHAR);
}
#endif /* 0 */
#if 0
/// \brief Returns the size (in bytes) of the VARIANT \c v, <b><i>not</i></b> including the null-terminating character
inline cs_size_t c_str_size(VARIANT const &v)
{
#ifdef UNICODE
return c_str_size_w(v);
#else /* ? UNICODE */
return c_str_size_a(v);
#endif /* UNICODE */
}
#endif /* 0 */
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/string_access_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _COMSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace comstl
# else
} // namespace stlsoft::comstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_COMSTL_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 _COMSTL_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 ::comstl::c_str_ptr_null_a;
using ::comstl::c_str_ptr_null_w;
using ::comstl::c_str_ptr_null_o;
using ::comstl::c_str_ptr_null;
using ::comstl::c_str_ptr_a;
using ::comstl::c_str_ptr_w;
using ::comstl::c_str_ptr_o;
using ::comstl::c_str_ptr;
using ::comstl::c_str_data_a;
using ::comstl::c_str_data_w;
using ::comstl::c_str_data_o;
using ::comstl::c_str_data;
using ::comstl::c_str_len_a;
using ::comstl::c_str_len_w;
using ::comstl::c_str_len_o;
using ::comstl::c_str_len;
#if 0
using ::comstl::c_str_size_a;
using ::comstl::c_str_size_w;
using ::comstl::c_str_size_o;
using ::comstl::c_str_size;
#endif /* 0 */
# 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 /* !_COMSTL_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !COMSTL_INCL_COMSTL_HPP_STRING_ACCESS */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?