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

📄 ccombstr_veneer.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        atlstl/string/ccombstr_veneer.hpp
 *
 * Purpose:     Contains the definition of the ccombstr_veneer template.
 *
 * Created:     1st October 2002
 * Updated:     19th August 2007
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 2002-2007, Matthew Wilson and Synesis Software
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
 *   any contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * ////////////////////////////////////////////////////////////////////// */


/** \file atlstl/string/ccombstr_veneer.hpp
 *
 * \brief [C++] Definition of the atlstl::ccombstr_veneer class
 *   (\ref group__library__string "String" Library).
 */

#ifndef ATLSTL_INCL_ATLSTL_STRING_HPP_CCOMBSTR_VENEER
#define ATLSTL_INCL_ATLSTL_STRING_HPP_CCOMBSTR_VENEER

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define ATLSTL_VER_ATLSTL_STRING_HPP_CCOMBSTR_VENEER_MAJOR    5
# define ATLSTL_VER_ATLSTL_STRING_HPP_CCOMBSTR_VENEER_MINOR    2
# define ATLSTL_VER_ATLSTL_STRING_HPP_CCOMBSTR_VENEER_REVISION 1
# define ATLSTL_VER_ATLSTL_STRING_HPP_CCOMBSTR_VENEER_EDIT     69
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Compatibility
 */

/*
[Incompatibilies-start]
STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1200
[Incompatibilies-end]
 */

/* /////////////////////////////////////////////////////////////////////////
 * Includes
 */

#ifndef ATLSTL_INCL_ATLSTL_HPP_ATLSTL
# include <atlstl/atlstl.hpp>
#endif /* !ATLSTL_INCL_ATLSTL_HPP_ATLSTL */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
# include <stlsoft/util/std/iterator_helper.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_CONSTRAINTS
# include <stlsoft/util/constraints.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_CONSTRAINTS */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
# include <stlsoft/memory/auto_buffer.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER */
#if defined(STLSOFT_COMPILER_IS_DMC)
# ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
#  include <stlsoft/conversion/sap_cast.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST */
#endif /* compiler */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD
# include <stlsoft/string/string_traits_fwd.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
# include <stlsoft/util/std/iterator_helper.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
# include <stlsoft/util/std_swap.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP */
#include <wchar.h>              // for wcscmp(), _wcsnset()

/* /////////////////////////////////////////////////////////////////////////
 * Namespace
 */

#ifndef _ATLSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::atlstl */
namespace atlstl
{
# else
/* Define stlsoft::atlstl_project */

namespace stlsoft
{

namespace atlstl_project
{

# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_ATLSTL_NO_NAMESPACE */

/* /////////////////////////////////////////////////////////////////////////
 * Classes
 */

/** \brief Applies standard string (std::basic_string) interface to the CComBSTR class
 *
 * \ingroup group__library__string
 *
 * This class adapts the ATL string type CComBSTR to express a standard String-like interface
 *
 * \ingroup concepts_veneer
 */
// [[synesis:class:string: atlstl::ccombstr_veneer]]
class ccombstr_veneer
#ifdef _ATLSTL_CCOMBSTR_VENEER_INHERIT_AS_PUBLIC
    : public CComBSTR
#else /* ? _ATLSTL_CCOMBSTR_VENEER_INHERIT_AS_PUBLIC */
# if defined(STLSOFT_COMPILER_IS_DMC)
    : protected CComBSTR
# else /* ? compiler */
    : private CComBSTR
# endif /* compiler */
#endif /* _ATLSTL_CCOMBSTR_VENEER_INHERIT_AS_PUBLIC */
{
private:
    typedef CComBSTR        parent_class_type;
    typedef ccombstr_veneer class_type;
public:
    /// The value type
    typedef OLECHAR         value_type;
    /// The mutating iterator type
    typedef LPOLESTR        iterator;
    /// The non-mutating (const) iterator type
    typedef LPCOLESTR       const_iterator;
    /// The pointer type
    typedef LPOLESTR        pointer;
    /// The pointer-to-const type
    typedef LPCOLESTR       const_pointer;
    /// The reference type
    typedef OLECHAR         &reference;
    /// The reference-to-const type
    typedef OLECHAR const   &const_reference;
    /// The size type
    typedef as_size_t       size_type;
    /// The difference type
    typedef as_ptrdiff_t    difference_type;
#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
//    typedef stlsoft_ns_qual(reverse_iterator_base)< iterator
//                                                ,   value_type
//                                                ,   reference
//                                                ,   pointer
//                                                ,   difference_type
//                                                >           reverse_iterator;

    typedef stlsoft_ns_qual(const_reverse_iterator_base)<   const_iterator
                                                    ,   value_type const
                                                    ,   const_reference
                                                    ,   const_pointer
                                                    ,   difference_type
                                                    >       const_reverse_iterator;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */

// Construction
public:
    /// Default constructor
    ccombstr_veneer();
    /// Copy constructor
    ccombstr_veneer(class_type const& rhs);
    /// Copy constructor
    ss_explicit_k ccombstr_veneer(CComBSTR const& rhs);
    /// Construct from an ANSI string
    ss_explicit_k ccombstr_veneer(LPCSTR s);
    /// Construct from a Unicode string
    ss_explicit_k ccombstr_veneer(LPCWSTR s);
    /// Construct from a range
    ccombstr_veneer(LPCOLESTR from, LPCOLESTR to);
    /// Construct from a range
    ccombstr_veneer(size_type length, LPCOLESTR from);
    ///
    ccombstr_veneer(as_size_t cch, OLECHAR ch);

    /// Copy assignment operator
    class_type const& operator =(class_type const& rhs);
    /// Copy assignment operator
    class_type const& operator =(CComBSTR const& rhs);
    /// Assignment operator
    class_type const& operator =(LPCSTR s);
    /// Assignment operator
    class_type const& operator =(LPCWSTR s);

// Iteration
public:
    /// Begins the iteration
    ///
    /// \return An iterator representing the start of the sequence
    const_iterator begin() const;
    /// Ends the iteration
    ///
    /// \return An iterator representing the end of the sequence
    const_iterator end() const;

#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
    /// Begins the reverse iteration
    ///
    /// \return A non-mutable (const) iterator representing the start of the reverse sequence
    const_reverse_iterator rbegin() const;
    /// Ends the reverse iteration
    ///
    /// \return A non-mutable (const) iterator representing the end of the reverse sequence
    const_reverse_iterator rend() const;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */

// Access
public:
    reference operator [](size_type index);
    const_reference operator [](size_type index) const;

// Operations
public:
    void swap(class_type& rhs);

// Attributes
public:
    /// Provides access to the underlying CComBSTR type
    CComBSTR        &get_base_type();
    /// Provides access to the underlying CComBSTR type
    CComBSTR const  &get_base_type() const;
    /// Returns the number of elements in the sequence
    size_type       length() const;
    /// Returns the number of elements in the sequence
    size_type       size() const;
    /// \brief Indicates whether the sequence is empty
    as_bool_t       empty() const;
    /// Returns a pointer to constant data representing the managed string
    const_pointer   c_str() const;
    /// Returns a pointer to constant data representing the managed string
    const_pointer   data() const;
};

/* /////////////////////////////////////////////////////////////////////////
 * Helper functions
 */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

// Because CComBSTR converts into BSTR, and because BSTR and BSTR are pointers
// which can be combined, and because LPCWSTR is *not* BSTR, and because
// CComBSTR can be implicitly constructed from LPCSTR, BSTR and LPCWSTR, it is
// incredibly easy to think you're doing value comparison but actually be doing
// identity comparison. Filth!!!!!!!
//
// Furthermore, old versions of CComBSTR don't have operator ==(), and even
// newer versions define it as a member function, instead of a free function.
// Triple filth!!!!!
//
// So, to ensure that CComBSTR is compared appropriately, all comparisons must
// filter through this function, which takes parameters by pointer (to avoid the
// implicit conversions) and explicitly calls the operator ==() to avoid identity
// comparison.

inline int atlstl_safe_wcscmp(LPCOLESTR s1, LPCOLESTR s2)
{
    return  (NULL == s1)
                ? (NULL == s2)
                    ? 0
                    : 1
                : (NULL == s2)
                    ? -1
                    : wcscmp(s1, s2);
}

inline int atlstl_safe_wcscmp(LPCOLESTR s1, LPCSTR s2)
{
    USES_CONVERSION;

    return atlstl_safe_wcscmp(s1, (NULL == s2) ? L"" : A2CW(s2));
}

inline int atlstl_safe_wcscmp(LPCSTR s1, LPCOLESTR s2)
{
    USES_CONVERSION;

    return atlstl_safe_wcscmp((NULL == s1) ? L"" : A2CW(s1), s2);
}

#if 0

// _ATL_VER 0x0800
bool CComBSTR::operator==(CComBSTR const& bstrSrc) const throw()
bool CComBSTR::operator==(LPCOLESTR pszSrc) const
bool CComBSTR::operator==(LPOLESTR pszSrc) const
bool CComBSTR::operator==(int nNull) const throw()  // Can you believe it!!
bool CComBSTR::operator==(LPCSTR pszSrc) const

// _ATL_VER 0x0710
bool CComBSTR::operator==(CComBSTR const& bstrSrc) const throw()
bool CComBSTR::operator==(LPCOLESTR pszSrc) const
bool CComBSTR::operator==(LPOLESTR pszSrc) const
bool CComBSTR::operator==(int nNull) const throw()  // Can you believe it!!
bool CComBSTR::operator==(LPCSTR pszSrc) const

// _ATL_VER  0x0700
bool CComBSTR::operator==(CComBSTR const& bstrSrc) const throw()
bool CComBSTR::operator==(LPCOLESTR pszSrc) const
bool CComBSTR::operator==(int nNull) const throw()
bool CComBSTR::operator==(LPCSTR pszSrc) const

// _ATL_VER  0x0300
bool CComBSTR::operator==(BSTR bstrSrc) const
bool CComBSTR::operator==(LPCSTR pszSrc) const

// _ATL_VER  0x0202

#endif /* 0 */


#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Operators
 */

inline as_bool_t operator ==(ccombstr_veneer const& lhs, ccombstr_veneer const& rhs)
{
    CComBSTR const&  lhs_   =   lhs.get_base_type();
    CComBSTR const&  rhs_   =   rhs.get_base_type();

#if _ATL_VER >= 0x0700
    return lhs_ == rhs_;
#else // ? _ATL_VER
    return 0 == atlstl_safe_wcscmp(lhs_, rhs_);
#endif // _ATL_VER
}

#if !defined(STLSOFT_COMPILER_IS_MSVC) || \
    _MSC_VER >= 1200

inline as_bool_t operator ==(LPCSTR lhs, ccombstr_veneer const& rhs)
{
    CComBSTR const&  rhs_ = rhs.get_base_type();

#if _ATL_VER >= 0x0300
    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, LPCSTR rhs)
{
    CComBSTR const&  lhs_ = lhs.get_base_type();

#if _ATL_VER >= 0x0300
    return lhs_ == rhs;
#else /* ? _ATL_VER */
    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) */

⌨️ 快捷键说明

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