⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfcstl_cstring_veneer.h

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 H
📖 第 1 页 / 共 2 页
字号:
            {
                return false;
            }

            if(NULL == s.c_str())
            {
                return false;
            }

            return true;
        }

        ss_bool_t test_mfcstl_cstring_veneer_equality(cstring_veneer const &s1, cstring_veneer const &s2)
        {
            if(s1.length() != s2.length())
            {
                return false;
            }

            if(s1.size() != s2.size())
            {
                return false;
            }

            if(s1.empty() != s2.empty())
            {
                return false;
            }

            if(s1 != s2)
            {
                return false;
            }

            if(!(s1 == s2))
            {
                return false;
            }

            return true;
        }

        ss_bool_t test_mfcstl_cstring_veneer(unittest_reporter *r)
        {
            using stlsoft::unittest::unittest_initialiser;

            ss_bool_t               bSuccess    =   true;

            unittest_initialiser    init(r, "MFCSTL", "cstring_veneer", __FILE__);

            cstring_veneer  cs1("Hello");
            cstring_veneer  cs2(cs1);

            if(!test_mfcstl_cstring_veneer_correctness(cs1))
            {
                r->report("Correctness test failed", __LINE__);
                bSuccess = false;
            }

            if(!test_mfcstl_cstring_veneer_correctness(cs2))
            {
                r->report("Correctness test failed", __LINE__);
                bSuccess = false;
            }

            if(!test_mfcstl_cstring_veneer_equality(cs1, cs2))
            {
                r->report("Equality between empty instances failed", __LINE__);
                bSuccess = false;
            }

            if(cs1 != cs2)
            {
                r->report("Copy construction failed", __LINE__);
                bSuccess = false;
            }

            cstring_veneer  cs3;

            if(!test_mfcstl_cstring_veneer_correctness(cs3))
            {
                r->report("Correctness test failed", __LINE__);
                bSuccess = false;
            }

            cs3 = cs1;

            if(cs1 != cs3)
            {
                r->report("Copy assignment failed", __LINE__);
                bSuccess = false;
            }

            if(cs1 != "Hello")
            {
                r->report("Comparison to LPCSTR failed", __LINE__);
                bSuccess = false;
            }

            if(cs1 != L"Hello")
            {
                r->report("Comparison to LPCWSTR failed", __LINE__);
                bSuccess = false;
            }

            return bSuccess;
        }

        unittest_registrar    unittest_mfcstl_cstring_veneer(test_mfcstl_cstring_veneer);
    } // anonymous namespace

} /* namespace unittest */

#endif /* STLSOFT_UNITTEST */

/* /////////////////////////////////////////////////////////////////////////
 * Implementation
 */

inline cstring_veneer::cstring_veneer()
    : parent_class_type()
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(class_type const &rhs)
    : parent_class_type(rhs.get_base_type())
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(CString const &rhs)
    : parent_class_type(rhs)
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(LPCSTR s)
    : parent_class_type(s)
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(LPCWSTR s)
    : parent_class_type(s)
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(unsigned char const *s)
    : parent_class_type(s)
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(LPCTSTR from, LPCTSTR to)
    : parent_class_type(from, static_cast<int>(to - from))
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(LPCTSTR from, cstring_veneer::size_type length)
    : parent_class_type(from, static_cast<int>(length))
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::cstring_veneer(ms_size_t cch, TCHAR ch)
    : parent_class_type(ch, static_cast<int>(cch))
{
    stlsoft_constraint_must_be_same_size(CString, class_type);
}

inline cstring_veneer::class_type const &cstring_veneer::operator =(cstring_veneer::class_type const &rhs)
{
    parent_class_type::operator =(rhs.get_base_type());

    return *this;
}

inline cstring_veneer::class_type const &cstring_veneer::operator =(CString const &rhs)
{
    parent_class_type::operator =(rhs);

    return *this;
}

inline cstring_veneer::class_type const &cstring_veneer::operator =(LPCSTR s)
{
    parent_class_type::operator =(s);

    return *this;
}

inline cstring_veneer::class_type const &cstring_veneer::operator =(LPCWSTR s)
{
    parent_class_type::operator =(s);

    return *this;
}

inline cstring_veneer::class_type const &cstring_veneer::operator =(unsigned char const *s)
{
    parent_class_type::operator =(s);

    return *this;
}

inline cstring_veneer::class_type &cstring_veneer::assign(cstring_veneer::value_type const *s)
{
    parent_class_type::operator =(s);

    return *this;
}

inline cstring_veneer::class_type &cstring_veneer::assign(cstring_veneer::value_type const *s, cstring_veneer::size_type n)
{
    parent_class_type::operator =(CString(s, n));

    return *this;
}

inline cstring_veneer::class_type &cstring_veneer::assign(cstring_veneer::class_type const &str, cstring_veneer::size_type pos, cstring_veneer::size_type n)
{
    MFCSTL_ASSERT(pos <= str.length());

    value_type const    *s  =   str;

    if(n > str.length() - pos)
    {
        n = str.length() - pos;
    }

    parent_class_type::operator =(CString(s + pos, n));

    return *this;
}


inline cstring_veneer::class_type &cstring_veneer::assign(cstring_veneer::class_type const &str)
{
    parent_class_type::operator =(str);

    return *this;
}


inline cstring_veneer::class_type &cstring_veneer::assign(cstring_veneer::size_type n, cstring_veneer::value_type c)
{
    parent_class_type::operator =(CString(c, n));

    return *this;
}

inline cstring_veneer::class_type &cstring_veneer::assign(cstring_veneer::const_iterator first, cstring_veneer::const_iterator last)
{
    parent_class_type::operator =(CString(first, last - first));

    return *this;
}

inline cstring_veneer::const_iterator cstring_veneer::begin() const
{
    return *this;
}

inline cstring_veneer::const_iterator cstring_veneer::end() const
{
    return begin() + GetLength();
}

inline cstring_veneer::reference cstring_veneer::operator [](cstring_veneer::size_type index)
{
    MFCSTL_MESSAGE_ASSERT("Index out of range", index < length());

    return const_cast<reference>(data()[index]);
}

inline cstring_veneer::const_reference cstring_veneer::operator [](cstring_veneer::size_type index) const
{
    MFCSTL_MESSAGE_ASSERT("Index out of range", index < length());

    return data()[index];
}

inline CString &cstring_veneer::get_base_type()
{
#if defined(STLSOFT_COMPILER_IS_DMC)
    CString *this_  =   stlsoft_ns_qual(sap_cast)<CString*>(this);
#else /* ? compiler */
    CString *this_  =   this;
#endif /* compiler */

    return *this_;
}

inline CString const &cstring_veneer::get_base_type() const
{
#if defined(STLSOFT_COMPILER_IS_DMC)
    CString const   *this_  =   stlsoft_ns_qual(sap_cast)<CString const*>(this);
#else /* ? compiler */
    CString const   *this_  =   this;
#endif /* compiler */

    return *this_;
}

inline cstring_veneer::size_type cstring_veneer::length() const
{
    return GetLength();
}

inline cstring_veneer::size_type cstring_veneer::size() const
{
    return length();
}

inline ms_bool_t cstring_veneer::empty() const
{
    return length() == 0;
}

inline cstring_veneer::const_pointer cstring_veneer::c_str() const
{
    return empty() ? _T("") : static_cast<const_pointer>(*this);
}

inline cstring_veneer::const_pointer cstring_veneer::data() const
{
    return empty() ? _T("") : static_cast<const_pointer>(*this);
}

/* ////////////////////////////////////////////////////////////////////// */

#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_H_MFCSTL_CSTRING_VENEER */

/* ////////////////////////////////////////////////////////////////////// */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -