📄 variant.hpp
字号:
return lhs != static_cast<LPCOLESTR>(rhs);
}
inline cs_bool_t operator !=(c_str_null_VARIANT_proxy const& lhs, LPCOLESTR rhs)
{
return static_cast<LPCOLESTR>(lhs) != rhs;
}
// c_str_VARIANT_proxy_a
inline cs_bool_t operator ==(LPCSTR lhs, c_str_VARIANT_proxy_a const& rhs)
{
return lhs == static_cast<LPCSTR>(rhs);
}
inline cs_bool_t operator ==(c_str_VARIANT_proxy_a const& lhs, LPCSTR rhs)
{
return static_cast<LPCSTR>(lhs) == rhs;
}
inline cs_bool_t operator !=(LPCSTR lhs, c_str_VARIANT_proxy_a const& rhs)
{
return lhs != static_cast<LPCSTR>(rhs);
}
inline cs_bool_t operator !=(c_str_VARIANT_proxy_a const& lhs, LPCSTR rhs)
{
return static_cast<LPCSTR>(lhs) != rhs;
}
// c_str_VARIANT_proxy_w
inline cs_bool_t operator ==(LPCOLESTR lhs, c_str_VARIANT_proxy_w const& rhs)
{
return lhs == static_cast<LPCOLESTR>(rhs);
}
inline cs_bool_t operator ==(c_str_VARIANT_proxy_w const& lhs, LPCOLESTR rhs)
{
return static_cast<LPCOLESTR>(lhs) == rhs;
}
inline cs_bool_t operator !=(LPCOLESTR lhs, c_str_VARIANT_proxy_w const& rhs)
{
return lhs != static_cast<LPCOLESTR>(rhs);
}
inline cs_bool_t operator !=(c_str_VARIANT_proxy_w const& lhs, LPCOLESTR rhs)
{
return static_cast<LPCOLESTR>(lhs) != rhs;
}
/* /////////////////////////////////////////////////////////////////////////
* IOStream compatibility
*/
template <ss_typename_param_k S>
inline S& operator <<(S& s, c_str_null_VARIANT_proxy const& shim)
{
s << static_cast<LPCOLESTR>(shim);
return s;
}
template <ss_typename_param_k S>
inline S& operator <<(S& s, c_str_VARIANT_proxy_w const& shim)
{
s << static_cast<LPCOLESTR>(shim);
return s;
}
template <ss_typename_param_k S>
inline S& operator <<(S& s, c_str_VARIANT_proxy_a const& shim)
{
s << static_cast<cs_char_a_t const*>(shim);
return s;
}
/* /////////////////////////////////////////////////////////////////////////
* c_str_data
*
* This can be applied to an expression, and the return value is either a
* pointer to the character string or to an empty string.
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
inline c_str_VARIANT_proxy_a c_str_data_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));
}
inline c_str_VARIANT_proxy_w c_str_data_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);
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief Returns the corresponding possibly unterminated C-string pointer of the VARIANT \c v
*
* \ingroup group__concept__shim__string_access
*
*/
#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.
*/
/* VARIANT */
/** \brief Returns the length (in characters) of the VARIANT \c v, <b><i>not</i></b> including the null-terminating character
*
* \ingroup group__concept__shim__string_access
*
*/
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
*
* \ingroup group__concept__shim__string_access
*
*/
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
*
* \ingroup group__concept__shim__string_access
*
*/
inline cs_size_t c_str_len_w(VARIANT const& v)
{
return c_str_len(v);
}
/* /////////////////////////////////////////////////////////////////////////
* c_str_ptr
*
* This can be applied to an expression, and the return value is either a
* pointer to the character string or to an empty string.
*/
/* VARIANT */
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
inline c_str_VARIANT_proxy_a c_str_ptr_a(VARIANT const& v)
{
return c_str_data_a(v);
}
inline c_str_VARIANT_proxy_w c_str_ptr_w(VARIANT const& v)
{
return c_str_data_w(v);
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief Returns the corresponding C-string pointer of the VARIANT \c v
*
* \ingroup group__concept__shim__string_access
*
*/
#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 */
}
/* /////////////////////////////////////////////////////////////////////////
* c_str_ptr_null
*
* This can be applied to an expression, and the return value is either a
* pointer to the character string or NULL.
*/
/* VARIANT */
/** \brief Returns the corresponding ANSI C-string pointer of the VARIANT \c v, or a null pointer
*
* \ingroup group__concept__shim__string_access
*
*/
//inline c_str_null_VARIANT_proxy<cs_char_a_t> c_str_ptr_null_a(VARIANT const& v);
//inline c_str_null_VARIANT_proxy<cs_char_w_t> c_str_ptr_null_w(VARIANT const& v);
//inline c_str_null_VARIANT_proxy<cs_char_o_t> c_str_ptr_null_o(VARIANT const& v);
inline c_str_null_VARIANT_proxy c_str_ptr_null_w(VARIANT const& v)
{
if(v.vt == VT_BSTR)
{
return c_str_null_VARIANT_proxy(v.bstrVal);
}
else if(v.vt == VT_NULL ||
v.vt == VT_EMPTY)
{
return c_str_null_VARIANT_proxy();
}
else
{
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_null_VARIANT_proxy(&vs.bstrVal);
}
}
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/variant_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_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;
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_ptr_null_a;
using ::comstl::c_str_ptr_null_w;
//using ::comstl::c_str_ptr_null_o;
//using ::comstl::c_str_ptr_null;
# 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 */
/* /////////////////////////////////////////////////////////////////////////
* Global namespace shims
*/
/* This defines stream inserter shim functions for the converters for use
* with the Visual C++ <7.1 standard library.
*/
#if defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC) && \
STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION < STLSOFT_CF_DINKUMWARE_VC_VERSION_7_1
# include <iosfwd>
inline comstl_ns_qual_std(basic_ostream)<char>& operator <<(comstl_ns_qual_std(basic_ostream)<char> &stm, comstl_ns_qual(c_str_VARIANT_proxy_a) const& v)
{
return stm << static_cast<char const*>(v);
}
inline comstl_ns_qual_std(basic_ostream)<wchar_t>& operator <<(comstl_ns_qual_std(basic_ostream)<wchar_t> &stm, comstl_ns_qual(c_str_VARIANT_proxy_w) const& v)
{
return stm << static_cast<wchar_t const*>(v);
}
#endif /* library */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !COMSTL_INCL_COMSTL_SHIMS_ACCESS_STRING_HPP_VARIANT */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -