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

📄 mfcstl_array_adaptor.h

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 H
📖 第 1 页 / 共 2 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        mfcstl_array_adaptor.h
 *
 * Purpose:     Contains the definition of the array_adaptor template, and the
 *              specialisations.
 *
 * Created:     1st December 2002
 * Updated:     18th June 2006
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 2002-2006, 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 mfcstl_array_adaptor.h
///
/// Contains the definition of the array_adaptor template, and the specialisations.

#ifndef MFCSTL_INCL_H_MFCSTL_ARRAY_ADAPTOR
#define MFCSTL_INCL_H_MFCSTL_ARRAY_ADAPTOR

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define MFCSTL_VER_H_MFCSTL_ARRAY_ADAPTOR_MAJOR    3
# define MFCSTL_VER_H_MFCSTL_ARRAY_ADAPTOR_MINOR    4
# define MFCSTL_VER_H_MFCSTL_ARRAY_ADAPTOR_REVISION 1
# define MFCSTL_VER_H_MFCSTL_ARRAY_ADAPTOR_EDIT     52
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Auto-generation and compatibility
 */

/*
[<[STLSOFT-AUTO:OBSOLETE]>]
[<[STLSOFT-AUTO:NO-UNITTEST]>]
*/

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

#ifndef MFCSTL_INCL_MFCSTL_HPP_MFCSTL
# include <mfcstl/mfcstl.hpp>
#endif /* !MFCSTL_INCL_MFCSTL_HPP_MFCSTL */

#if !defined(STLSOFT_OBSOLETE)
# error mfcstl::array_adaptor is now obsolete. Please include mfcstl/carray_adaptors.hpp, and use mfcstl::CArray_iadaptor
#endif /* !STLSOFT_OBSOLETE */

#ifndef STLSOFT_INCL_STLSOFT_HPP_ITERATOR
# include <stlsoft/iterator.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_ITERATOR */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS
# include <stlsoft/collections/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS */

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

#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
/* Define stlsoft::mfcstl_project */

namespace stlsoft
{

namespace mfcstl_project
{

# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_MFCSTL_NO_NAMESPACE */

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

// struct array_adaptor_traits
//
// Regrettably, since MFC's template classes do not define any member types,
// it is not possible to generalise the traits, so we must just use
// specialisations. Sigh!

template <class C>
struct array_adaptor_traits;

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// For CByteArray

STLSOFT_TEMPLATE_SPECIALISATION
struct array_adaptor_traits<CByteArray>
{
    typedef BYTE            value_type;
    typedef BYTE            arg_type;
};

// For CDWordArray

STLSOFT_TEMPLATE_SPECIALISATION
struct array_adaptor_traits<CDWordArray>
{
    typedef DWORD           value_type;
    typedef DWORD           arg_type;
};

// For CObArray

STLSOFT_TEMPLATE_SPECIALISATION
struct array_adaptor_traits<CObArray>
{
    typedef CObject         *value_type;
    typedef CObject         *arg_type;
};

// For CPtrArray

STLSOFT_TEMPLATE_SPECIALISATION
struct array_adaptor_traits<CPtrArray>
{
    typedef void            *value_type;
    typedef void            *arg_type;
};

// For CStringArray

STLSOFT_TEMPLATE_SPECIALISATION
struct array_adaptor_traits<CStringArray>
{
    typedef CString         value_type;
    typedef const CString   &arg_type;
};

// For CUIntArray

STLSOFT_TEMPLATE_SPECIALISATION
struct array_adaptor_traits<CUIntArray>
{
    typedef UINT            value_type;
    typedef UINT            arg_type;
};

// For CWordArray

STLSOFT_TEMPLATE_SPECIALISATION
struct array_adaptor_traits<CWordArray>
{
    typedef WORD            value_type;
    typedef WORD            arg_type;
};


// For CArray<, >

#ifdef __AFXTEMPL_H__
# ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
/* If your translator supports partial template specialisation, then
 * you should be fine with the following specialisation ...
 */

template <class V, class A>
struct array_adaptor_traits<CArray<V, A> >
{
    typedef V               value_type;
    typedef A               arg_type;
};

# else /* ? STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */

/* ... otherwise you will need to provide your own traits class, e.g
 *
 *  struct my_traits_type
 *  {
 *    typedef MyValType       value_type;
 *    typedef MyValType const &arg_type;
 *  };
 */

# endif // STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
#endif // __AFXTEMPL_H__
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/// \brief Adapts MFC Array class instances to the STL container concept
///
/// This class takes a container type, e.g. CStringArray, as its primary (and
/// only non-default) template argument, C. The second template parameter, T,
/// defaults to array_adaptor_traits<C>, for which specialisations are provided
/// for the following types
///
///  - CObArray      (stores pointers to CObject, or derived, instances)
///  - CPtrArray     (stores raw pointers, ie. void*)
///  - CStringArray  (stores strings, in the form of CString)
///
/// and for compilers that support partial specialisation
///
///  - CArray<V, A>  (stores instances of V, with argument type A)
///
/// \param C The container type
/// \param T The traits type. With translators that support default template arguments, this is defaulted to array_adaptor_traits<C>

template<   class C                             // The container type
        ,   class T = array_adaptor_traits<C>   // The traits type
        >
class array_adaptor
    : public stlsoft_ns_qual(stl_collection_tag)
{
public:
    /// The current parameterisation of the type
    typedef array_adaptor<C, T>                         class_type;
    /// The type of the adapted container
    typedef C                                           container_type;
private:
    typedef T                                           traits_type;
    typedef class_type                                  adapted_container_type;
public:
    // If you get a warning about a array_adaptor_traits<CArray<,> > parameterisation not
    // having a value_type on the next line, you need to include afxtempl.h _before_
    // this header file
    typedef ss_typename_type_k traits_type::value_type  value_type;
    /// The size type
    typedef ms_size_t                                   size_type;
    /// The difference type
    typedef ms_ptrdiff_t                                difference_type;

public:
    /// Non-mutating (const) iterator for the list_adaptor class
    ///
    /// \note This supports the Random-Access Iterator concept
    class const_iterator
        : public stlsoft_ns_qual(iterator_base)<mfcstl_ns_qual_std(random_access_iterator_tag)
                                            ,   value_type
                                            ,   ms_ptrdiff_t
                                            ,   void
                                            ,   value_type  // By-Value Temporary reference category
                                            >
    {
        friend class array_adaptor<C, T>;

        typedef const_iterator                                      class_type;
        // NOTE: If you get a compiler error on the next line, referring to
        // undefined 'value_type' then you need to provide a traits type
        // with the member type 'value_type' defined.
        typedef int                                                 index_type;
#ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
        typedef ss_typename_type_k array_adaptor<C, T>::value_type  value_type;
#endif /* !STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */

    // Construction
    private:
        friend class adapted_container_type;

        const_iterator(container_type *c, index_type index)
            : m_c(c)
            , m_index(index)
        {}
    public:
        /// Default constructor
        const_iterator()
            : m_c(0)
            , m_index(0)
        {}
        /// Copy constructor
        ///
        /// \param rhs The instance from which to copy construct
        const_iterator(class_type const &rhs)
            : m_c(rhs.m_c)

⌨️ 快捷键说明

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