📄 cstring_adaptors.hpp
字号:
typedef ss_size_t size_type;
typedef char_type const const_char_type;
typedef value_type string_type;
typedef LPCSTR pointer;
typedef LPCTSTR const_pointer;
typedef LPCSTR iterator;
typedef LPCTSTR const_iterator;
typedef value_type::reverse_iterator reverse_iterator;
typedef value_type::const_reverse_iterator const_reverse_iterator;
enum
{
is_pointer = false
, is_pointer_to_const = false
, char_type_size = sizeof(char_type)
};
static string_type empty_string()
{
return string_type();
}
static string_type construct(string_type const& src, size_type pos, size_type len)
{
return string_type(src, pos, len);
}
static string_type &assign_inplace(string_type &str, const_iterator first, const_iterator last)
{
return (str = string_type(first, last), str);
}
};
#ifndef _MFCSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::mfcstl */
namespace mfcstl
{
# else
namespace mfcstl_project
{
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_MFCSTL_NO_NAMESPACE */
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/cstring_adaptors_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* /////////////////////////////////////////////////////////////////////////
* Implementation
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// CString_adaptor_base
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::allocator_type CString_adaptor_base<I>::get_allocator() const
{
return allocator_type();
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(LPCSTR s)
{
get_CString() = s;
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(LPCWSTR s)
{
get_CString() = s;
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(unsigned char const* s)
{
get_CString() = s;
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(LPCSTR s, size_type n)
{
#ifdef UNICODE
get_CString() = CString(s).Left(n);
#else /* ? UNICODE */
get_CString() = CString(s, n);
#endif /* UNICODE */
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(LPCWSTR s, size_type n)
{
#ifdef UNICODE
get_CString() = CString(s, n);
#else /* ? UNICODE */
get_CString() = CString(s).Left(n);
#endif /* UNICODE */
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(unsigned char const* s, size_type n)
{
get_CString() = CString(s).Left(n);
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(class_type const& s)
{
get_CString() = s.get_CString();
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(class_type const& s, size_type pos, size_type index)
{
MFCSTL_MESSAGE_ASSERT("invalid index", index + pos <= s.size());
get_CString() = CString(s.c_str() + pos, index);
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(size_type n, value_type ch)
{
get_CString() = CString(ch, static_cast<int>(n));
return *this;
}
template<ss_typename_param_k I>
#if defined(STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION) && \
STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION == STLSOFT_CF_DINKUMWARE_VC_VERSION_7_0
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(LPCTSTR first, LPCTSTR last)
#else /* ? library */
inline ss_typename_type_k CString_adaptor_base<I>::class_type &CString_adaptor_base<I>::assign(const_iterator first, const_iterator last)
#endif /* library */
{
get_CString() = CString(first, static_cast<int>(last - first));
return *this;
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::iterator CString_adaptor_base<I>::begin()
{
return const_cast<pointer>(this->c_str());
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::iterator CString_adaptor_base<I>::end()
{
return this->begin() + this->size();
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_iterator CString_adaptor_base<I>::begin() const
{
return this->c_str();
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_iterator CString_adaptor_base<I>::end() const
{
return this->begin() + this->size();
}
#ifdef STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::reverse_iterator CString_adaptor_base<I>::rbegin()
{
return reverse_iterator(end());
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::reverse_iterator CString_adaptor_base<I>::rend()
{
return reverse_iterator(begin());
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_reverse_iterator CString_adaptor_base<I>::rbegin() const
{
return const_reverse_iterator(end());
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_reverse_iterator CString_adaptor_base<I>::rend() const
{
return const_reverse_iterator(begin());
}
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::reference CString_adaptor_base<I>::subscript_(size_type index)
{
MFCSTL_MESSAGE_ASSERT("invalid index", index < size());
return const_cast<pointer>(this->data())[index];
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_reference CString_adaptor_base<I>::subscript_(size_type index) const
{
MFCSTL_MESSAGE_ASSERT("invalid index", index < size());
return this->data()[index];
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::reference CString_adaptor_base<I>::at(size_type index)
{
if(index >= size())
{
STLSOFT_THROW_X(mfcstl_ns_qual_std(out_of_range)("invalid index"));
}
return subscript_(index);
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_reference CString_adaptor_base<I>::at(size_type index) const
{
if(index >= size())
{
STLSOFT_THROW_X(mfcstl_ns_qual_std(out_of_range)("invalid index"));
}
return subscript_(index);
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::size_type CString_adaptor_base<I>::length() const
{
return get_CString().GetLength();
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::size_type CString_adaptor_base<I>::size() const
{
return this->length();
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::bool_type CString_adaptor_base<I>::empty() const
{
return 0 == this->length();
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_pointer CString_adaptor_base<I>::c_str() const
{
// return empty() ? _T("") : static_cast<const_pointer>(get_CString());
return get_CString();
}
template<ss_typename_param_k I>
inline ss_typename_type_k CString_adaptor_base<I>::const_pointer CString_adaptor_base<I>::data() const
{
return this->c_str();
}
// CString_cadaptor
inline CString_cadaptor::CString_cadaptor()
{}
inline CString_cadaptor::CString_cadaptor(class_type const& rhs)
: CString(rhs)
{}
inline /* ss_explicit_k */ CString_cadaptor::CString_cadaptor(CString const& rhs)
: CString(rhs)
{}
inline /* ss_explicit_k */ CString_cadaptor::CString_cadaptor(LPCSTR s)
: CString(s)
{}
inline /* ss_explicit_k */ CString_cadaptor::CString_cadaptor(LPCWSTR s)
: CString(s)
{}
inline /* ss_explicit_k */ CString_cadaptor::CString_cadaptor(unsigned char const* s)
: CString(s)
{}
inline CString_cadaptor::CString_cadaptor(LPCTSTR from, LPCTSTR to)
: CString(from, static_cast<int>(to - from))
{}
inline CString_cadaptor::CString_cadaptor(LPCTSTR from, size_type length)
: CString(from, length)
{}
inline CString_cadaptor::CString_cadaptor(class_type const& str, size_type pos, size_type n)
: CString(static_cast<LPCTSTR>(str) + pos, n)
{}
inline CString_cadaptor::CString_cadaptor(ms_size_t cch, TCHAR ch)
: CString(ch, static_cast<int>(cch))
{}
inline CString_cadaptor::class_type const& CString_cadaptor::operator =(CString_cadaptor::class_type const& rhs)
{
assign(rhs);
return *this;
}
inline CString_cadaptor::class_type const& CString_cadaptor::operator =(CString const& rhs)
{
assign(rhs);
return *this;
}
inline CString_cadaptor::class_type const& CString_cadaptor::operator =(LPCSTR rhs)
{
assign(rhs);
return *this;
}
inline CString_cadaptor::class_type const& CString_cadaptor::operator =(LPCWSTR rhs)
{
assign(rhs);
return *this;
}
inline CString_cadaptor::class_type const& CString_cadaptor::operator =(unsigned char const* rhs)
{
assign(rhs);
return *this;
}
// CString_iadaptor
inline CString_iadaptor::CString_iadaptor(CString &str)
: m_str(&str)
{}
inline CString_iadaptor::CString_iadaptor(CString *str)
: m_str(str)
{}
inline CString_iadaptor::class_type const& CString_iadaptor::operator =(CString_iadaptor::class_type const& rhs)
{
assign(rhs);
return *this;
}
inline CString_iadaptor::class_type const& CString_iadaptor::operator =(CString const& rhs)
{
assign(rhs);
return *this;
}
inline CString_iadaptor::class_type const& CString_iadaptor::operator =(LPCSTR rhs)
{
assign(rhs);
return *this;
}
inline CString_iadaptor::class_type const& CString_iadaptor::operator =(LPCWSTR rhs)
{
assign(rhs);
return *this;
}
inline CString_iadaptor::class_type const& CString_iadaptor::operator =(unsigned char const* rhs)
{
assign(rhs);
return *this;
}
inline CString_iadaptor::reference CString_iadaptor::operator [](CString_iadaptor::size_type index)
{
return this->subscript_(index);
}
inline CString_iadaptor::const_reference CString_iadaptor::operator [](CString_iadaptor::size_type index) const
{
return this->subscript_(index);
}
// const_CString_iadaptor
inline const_CString_iadaptor::const_CString_iadaptor(CString const& str)
: m_str(&str)
{}
inline const_CString_iadaptor::const_CString_iadaptor(CString const* str)
: m_str(str)
{}
inline const_CString_iadaptor::const_reference const_CString_iadaptor::operator [](const_CString_iadaptor::size_type index) const
{
return this->subscript_(index);
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _MFCSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace mfcstl
# else
} // namespace mfcstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_MFCSTL_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_CSTRING_ADAPTORS */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -