📄 ccombstr_veneer.hpp
字号:
return 0 == atlstl_safe_wcscmp(lhs_, rhs);
#endif /* _ATL_VER */
}
#endif /* !(_MSC_VER < 1200) */
inline as_bool_t operator ==(LPCWSTR lhs, ccombstr_veneer const &rhs)
{
CComBSTR const &rhs_ = rhs.get_base_type();
#if _ATL_VER >= 0x0700
return rhs_ == lhs;
#else // ? _ATL_VER
return 0 == atlstl_safe_wcscmp(lhs, rhs_);
#endif // _ATL_VER
}
inline as_bool_t operator ==(ccombstr_veneer const &lhs, LPCWSTR rhs)
{
CComBSTR const &lhs_ = lhs.get_base_type();
#if _ATL_VER >= 0x0700
return lhs_ == rhs;
#else // ? _ATL_VER
return 0 == atlstl_safe_wcscmp(lhs_, rhs);
#endif // _ATL_VER
}
inline as_bool_t operator !=(ccombstr_veneer const &lhs, ccombstr_veneer const &rhs)
{
return !operator ==(lhs, rhs);
}
#if !defined(STLSOFT_COMPILER_IS_MSVC) || \
_MSC_VER >= 1200
inline as_bool_t operator !=(LPCSTR lhs, ccombstr_veneer const &rhs)
{
return !operator ==(lhs, rhs);
}
inline as_bool_t operator !=(ccombstr_veneer const &lhs, LPCSTR rhs)
{
return !operator ==(lhs, rhs);
}
#endif /* !(_MSC_VER < 1200) */
inline as_bool_t operator !=(LPCWSTR lhs, ccombstr_veneer const &rhs)
{
return !operator ==(lhs, rhs);
}
inline as_bool_t operator !=(ccombstr_veneer const &lhs, LPCWSTR rhs)
{
return !operator ==(lhs, rhs);
}
/* /////////////////////////////////////////////////////////////////////////
* swapping
*/
inline void swap(ccombstr_veneer &lhs, ccombstr_veneer &rhs)
{
lhs.swap(rhs);
}
/* /////////////////////////////////////////////////////////////////////////
* Shims
*/
inline LPCOLESTR c_str_ptr_null(ccombstr_veneer const &str)
{
return str.empty() ? NULL : str.c_str();
}
inline LPCOLESTR c_str_ptr(ccombstr_veneer const &str)
{
return str.c_str();
}
inline LPCOLESTR c_str_data(ccombstr_veneer const &str)
{
return str.data();
}
inline as_size_t c_str_len(ccombstr_veneer const &str)
{
return str.length();
}
#if 0
inline as_size_t c_str_size(ccombstr_veneer const &str)
{
return c_str_len(str) * sizeof(OLECHAR);
}
#endif /* 0 */
template<ss_typename_param_k S>
inline S &operator <<(S &s, ccombstr_veneer const &str)
{
s << str.c_str();
return s;
}
/* /////////////////////////////////////////////////////////////////////////
* Unit-testing
*/
#ifdef STLSOFT_UNITTEST
# include "./unittest/ccombstr_veneer_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* /////////////////////////////////////////////////////////////////////////
* Implementation
*/
inline ccombstr_veneer::ccombstr_veneer()
: parent_class_type()
{
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
}
inline ccombstr_veneer::ccombstr_veneer(class_type const &rhs)
: parent_class_type(rhs)
{
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
}
inline ccombstr_veneer::ccombstr_veneer(CComBSTR const &rhs)
: parent_class_type(rhs)
{
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
}
inline ccombstr_veneer::ccombstr_veneer(LPCSTR s)
/* There's a bug in some implementations of ATL 3.x, so we go for the assigment,
* doing the conversion ourselves
*/
#if _ATL_VER >= 0x0700
: parent_class_type(s)
#endif /* _ATL_VER */
{
#if _ATL_VER < 0x0700
USES_CONVERSION;
*this = A2COLE(s);
#endif /* _ATL_VER */
ATLSTL_ASSERT(s == NULL || length() == strlen(s));
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
}
inline ccombstr_veneer::ccombstr_veneer(LPCWSTR s)
#if _ATL_VER >= 0x0300
: parent_class_type(s)
#endif /* _ATL_VER */
{
#if _ATL_VER < 0x0300
USES_CONVERSION;
*this = s;
#endif /* _ATL_VER */
ATLSTL_ASSERT(s == NULL || length() == wcslen(s));
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
}
inline ccombstr_veneer::ccombstr_veneer(LPCOLESTR from, LPCOLESTR to)
: parent_class_type(static_cast<int>(to - from), from)
{
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
}
inline void ccombstr_veneer::swap(ccombstr_veneer::class_type &rhs)
{
std_swap(m_str, rhs.m_str);
}
inline ccombstr_veneer::ccombstr_veneer(ccombstr_veneer::size_type length, LPCOLESTR from)
: parent_class_type(static_cast<int>(length), from)
{
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
}
inline ccombstr_veneer::ccombstr_veneer(as_size_t cch, OLECHAR ch)
{
stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
typedef stlsoft_ns_qual(auto_buffer)<OLECHAR> buffer_t;
buffer_t buffer(cch);
_wcsnset(&buffer[0], ch, cch);
class_type(cch, &buffer[0]).swap(*this);
}
inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(ccombstr_veneer::class_type const &rhs)
{
parent_class_type::operator =(rhs);
return *this;
}
inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(CComBSTR const &rhs)
{
parent_class_type::operator =(rhs);
return *this;
}
inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(LPCSTR s)
{
/* There's a bug in some implementations of ATL 3.x, so we go for the assigment,
* doing the conversion ourselves
*/
#if _ATL_VER >= 0x0700
parent_class_type::operator =(s);
#else /* ? _ATL_VER */
USES_CONVERSION;
*this = A2COLE(s);
#endif /* _ATL_VER */
return *this;
}
inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(LPCWSTR s)
{
parent_class_type::operator =(s);
return *this;
}
inline ccombstr_veneer::const_iterator ccombstr_veneer::begin() const
{
return *this;
}
inline ccombstr_veneer::const_iterator ccombstr_veneer::end() const
{
return begin() + Length();
}
inline ccombstr_veneer::reference ccombstr_veneer::operator [](ccombstr_veneer::size_type index)
{
ATLSTL_MESSAGE_ASSERT("Index out of range", index < length());
return const_cast<reference>(data()[index]);
}
inline ccombstr_veneer::const_reference ccombstr_veneer::operator [](ccombstr_veneer::size_type index) const
{
ATLSTL_MESSAGE_ASSERT("Index out of range", index < length());
return data()[index];
}
inline CComBSTR &ccombstr_veneer::get_base_type()
{
#if defined(STLSOFT_COMPILER_IS_DMC)
CComBSTR *this_ = stlsoft_ns_qual(sap_cast)<CComBSTR*>(this);
#else /* ? compiler */
CComBSTR *this_ = this;
#endif /* compiler */
return *this_;
}
inline CComBSTR const &ccombstr_veneer::get_base_type() const
{
#if defined(STLSOFT_COMPILER_IS_DMC)
CComBSTR const *this_ = stlsoft_ns_qual(sap_cast)<CComBSTR const*>(this);
#else /* ? compiler */
CComBSTR const *this_ = this;
#endif /* compiler */
return *this_;
}
inline ccombstr_veneer::size_type ccombstr_veneer::length() const
{
return Length();
}
inline ccombstr_veneer::size_type ccombstr_veneer::size() const
{
return length();
}
inline as_bool_t ccombstr_veneer::empty() const
{
return length() == 0;
}
inline ccombstr_veneer::const_pointer ccombstr_veneer::c_str() const
{
return empty() ? L"" : static_cast<const_pointer>(*this);
}
inline ccombstr_veneer::const_pointer ccombstr_veneer::data() const
{
return empty() ? L"" : static_cast<const_pointer>(*this);
}
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _ATLSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace atlstl
# else
} // namespace atlstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_ATLSTL_NO_NAMESPACE */
#if defined(STLSOFT_CF_std_NAMESPACE)
namespace stlsoft
{
inline void swap(atlstl_ns_qual(ccombstr_veneer) &lhs, atlstl_ns_qual(ccombstr_veneer) &rhs)
{
lhs.swap(rhs);
}
} // namespace stlsoft
#endif /* STLSOFT_CF_std_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !ATLSTL_INCL_ATLSTL_HPP_CCOMBSTR_VENEER */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -