string_access.hpp
来自「用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、W」· HPP 代码 · 共 883 行 · 第 1/2 页
HPP
883 行
/* /////////////////////////////////////////////////////////////////////////
* 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.
*/
/* CWnd */
/// \brief Returns the corresponding C-string pointer of the CWnd \c w, or a null pointer
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null(const CWnd &w)
{
return c_str_ptr_null_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_w(const CWnd &w)
#else /* ? UNICODE */
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_a(const CWnd &w)
#endif /* UNICODE */
{
return c_str_ptr_null(w);
}
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null(const CListBox &w)
{
return c_str_ptr_null_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_w(const CListBox &w)
#else /* ? UNICODE */
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_a(const CListBox &w)
#endif /* UNICODE */
{
return c_str_ptr_null(w);
}
#ifdef __AFXCMN_H__
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null(const CListCtrl &w)
{
return c_str_ptr_null_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_w(const CListCtrl &w)
#else /* ? UNICODE */
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_a(const CListCtrl &w)
#endif /* UNICODE */
{
return c_str_ptr_null(w);
}
# ifdef __AFXCVIEW_H__
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null(const CListView &w)
{
return c_str_ptr_null(w.GetListCtrl());
}
#if defined(UNICODE)
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_w(const CListView &w)
#else /* ? UNICODE */
inline c_str_ptr_null_CWnd_proxy c_str_ptr_null_a(const CListView &w)
#endif /* UNICODE */
{
return c_str_ptr_null(w);
}
# endif /* __AFXCVIEW_H__ */
#endif /* __AFXCMN_H__ */
/* CString */
/// \brief Returns the corresponding C-string pointer of the CString \c s, or a null pointer
inline LPCTSTR c_str_ptr_null(const CString &s)
{
/* CString always points to valid memory, whether its own
* CStringData or afxEmptyString.m_pchData
*/
return s.IsEmpty() ? NULL : (LPCTSTR)s;
}
#if defined(UNICODE)
inline LPCTSTR c_str_ptr_null_w(const CString &s)
#else /* ? UNICODE */
inline LPCTSTR c_str_ptr_null_w(const CString &s)
#endif /* UNICODE */
{
return c_str_ptr_null(s);
}
/* /////////////////////////////////////////////////////////////////////////
* 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.
*/
/* CWnd */
/// \brief Returns the corresponding C-string pointer of the CWnd \c w
inline c_str_ptr_CWnd_proxy c_str_ptr(const CWnd &w)
{
return c_str_ptr_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_ptr_w(const CWnd &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_ptr_a(const CWnd &w)
#endif /* UNICODE */
{
return c_str_ptr(w);
}
inline c_str_ptr_CWnd_proxy c_str_ptr(const CListBox &w)
{
return c_str_ptr_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_ptr_w(const CListBox &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_ptr_a(const CListBox &w)
#endif /* UNICODE */
{
return c_str_ptr(w);
}
#ifdef __AFXCMN_H__
inline c_str_ptr_CWnd_proxy c_str_ptr(const CListCtrl &w)
{
return c_str_ptr_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_ptr_w(const CListCtrl &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_ptr_a(const CListCtrl &w)
#endif /* UNICODE */
{
return c_str_ptr(w);
}
# ifdef __AFXCVIEW_H__
inline c_str_ptr_CWnd_proxy c_str_ptr(const CListView &w)
{
return c_str_ptr(w.GetListCtrl());
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_ptr_w(const CListView &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_ptr_a(const CListView &w)
#endif /* UNICODE */
{
return c_str_ptr(w);
}
# endif /* __AFXCVIEW_H__ */
#endif /* __AFXCMN_H__ */
/* CString */
/// \brief Returns the corresponding C-string pointer of the CString \c s
inline LPCTSTR c_str_ptr(const CString &s)
{
/* CString always points to valid memory, whether its own
* CStringData or afxEmptyString.m_pchData
*/
return s;
}
#if defined(UNICODE)
inline LPCTSTR c_str_ptr_w(const CString &s)
#else /* ? UNICODE */
inline LPCTSTR c_str_ptr_a(const CString &s)
#endif /* UNICODE */
{
return c_str_ptr(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.
*/
/* CWnd */
/// \brief Returns the corresponding C-string pointer of the CWnd \c w
inline c_str_ptr_CWnd_proxy c_str_data(const CWnd &w)
{
return c_str_ptr_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_data_w(const CWnd &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_data_a(const CWnd &w)
#endif /* UNICODE */
{
return c_str_data(w);
}
inline c_str_ptr_CWnd_proxy c_str_data(const CListBox &w)
{
return c_str_ptr_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_data_w(const CListBox &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_data_a(const CListBox &w)
#endif /* UNICODE */
{
return c_str_data(w);
}
#ifdef __AFXCMN_H__
inline c_str_ptr_CWnd_proxy c_str_data(const CListCtrl &w)
{
return c_str_ptr_CWnd_proxy(w);
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_data_w(const CListCtrl &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_data_a(const CListCtrl &w)
#endif /* UNICODE */
{
return c_str_data(w);
}
# ifdef __AFXCVIEW_H__
inline c_str_ptr_CWnd_proxy c_str_data(const CListView &w)
{
return c_str_data(w.GetListCtrl());
}
#if defined(UNICODE)
inline c_str_ptr_CWnd_proxy c_str_data_w(const CListView &w)
#else /* ? UNICODE */
inline c_str_ptr_CWnd_proxy c_str_data_a(const CListView &w)
#endif /* UNICODE */
{
return c_str_data(w);
}
# endif /* __AFXCVIEW_H__ */
#endif /* __AFXCMN_H__ */
/* CString */
/// \brief Returns the corresponding C-string pointer of the CString \c s
inline LPCTSTR c_str_data(const CString &s)
{
/* CString always points to valid memory, whether its own
* CStringData or afxEmptyString.m_pchData
*/
return s;
}
#if defined(UNICODE)
inline LPCTSTR c_str_data_w(const CString &s)
#else /* ? UNICODE */
inline LPCTSTR c_str_data_a(const CString &s)
#endif /* UNICODE */
{
return c_str_data(s);
}
/* /////////////////////////////////////////////////////////////////////////
* 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.
*/
/* CWnd */
/// \brief Returns the length (in characters) of the contents of the window \c w, <b><i>not</i></b> including the null-terminating character
inline ms_size_t c_str_len(const CWnd &w)
{
return GetWindowTextLength__(w);
}
inline ms_size_t c_str_len(const CListBox &w)
{
return GetWindowTextLength__(w);
}
#ifdef __AFXCMN_H__
inline ms_size_t c_str_len(const CListCtrl &w)
{
return GetWindowTextLength__(w);
}
# ifdef __AFXCVIEW_H__
inline ms_size_t c_str_len(const CListView &w)
{
return c_str_len(w.GetListCtrl());
}
# endif /* __AFXCVIEW_H__ */
#endif /* __AFXCMN_H__ */
/* CString */
/// \brief Returns the length (in characters) of the CString \c s, <b><i>not</i></b> including the null-terminating character
inline ms_size_t c_str_len(const CString &s)
{
return s.GetLength();
}
/* /////////////////////////////////////////////////////////////////////////
* 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.
*/
/* CWnd */
#if 0
/// \brief Returns the size (in bytes) of the contents of the window \c w, <b><i>not</i></b> including the null-terminating character
inline ms_size_t c_str_size(const CWnd &w)
{
return c_str_len(w) * sizeof(TCHAR);
}
#endif /* 0 */
#if 0
inline ms_size_t c_str_size(const CListBox &w)
{
return c_str_len(w) * sizeof(TCHAR);
}
#endif /* 0 */
#ifdef __AFXCMN_H__
#if 0
inline ms_size_t c_str_size(const CListCtrl &w)
{
return c_str_len(w) * sizeof(TCHAR);
}
#endif /* 0 */
# ifdef __AFXCVIEW_H__
#if 0
inline ms_size_t c_str_size(const CListView &w)
{
return c_str_size(w.GetListCtrl());
}
#endif /* 0 */
# endif /* __AFXCVIEW_H__ */
#endif /* __AFXCMN_H__ */
/* CString */
#if 0
/// \brief Returns the size (in bytes) of the CString \c s, <b><i>not</i></b> including the null-terminating character
inline ms_size_t c_str_size(const CString &s)
{
return c_str_len(s) * sizeof(TCHAR);
}
#endif /* 0 */
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/string_access_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _MFCSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace mfcstl
# else
} // namespace stlsoft::mfcstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_MFCSTL_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 _MFCSTL_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 ::mfcstl::c_str_ptr_null;
#if defined(UNICODE)
using ::mfcstl::c_str_ptr_null_w;
#else /* ? UNICODE */
using ::mfcstl::c_str_ptr_null_a;
#endif /* UNICODE */
using ::mfcstl::c_str_ptr;
#if defined(UNICODE)
using ::mfcstl::c_str_ptr_w;
#else /* ? UNICODE */
using ::mfcstl::c_str_ptr_a;
#endif /* UNICODE */
using ::mfcstl::c_str_data;
#if defined(UNICODE)
using ::mfcstl::c_str_data_w;
#else /* ? UNICODE */
using ::mfcstl::c_str_data_a;
#endif /* UNICODE */
using ::mfcstl::c_str_len;
#if 0
using ::mfcstl::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 /* !_MFCSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Global namespace shims
*/
/* This defines an inserter function template for CString for use with the
* Visual C++ <7.1 standard library.
*
* It cannot be defined as a template because that conflicts with operator << (CArchive &, CString const &)
*/
#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>
/* Has to be like this otherwise it conflicts with operator <<(class CArchive &,const class CString &) (at least with VC++ <7.1). */
inline mfcstl_ns_qual_std(basic_ostream)<TCHAR> &operator <<(mfcstl_ns_qual_std(basic_ostream)<TCHAR> &stm, CString const &shim)
{
return stm << static_cast<LPCTSTR>(shim);
}
#endif /* library */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !MFCSTL_INCL_MFCSTL_HPP_STRING_ACCESS */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?