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

📄 mfcstl_list_adaptor.h

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 H
📖 第 1 页 / 共 2 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        mfcstl_list_adaptor.h
 *
 * Purpose:     Contains the definition of the list_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_list_adaptor.h
///
/// Contains the definition of the list_adaptor template, and the specialisations.

#ifndef MFCSTL_INCL_H_MFCSTL_LIST_ADAPTOR
#define MFCSTL_INCL_H_MFCSTL_LIST_ADAPTOR

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define MFCSTL_VER_H_MFCSTL_LIST_ADAPTOR_MAJOR     2
# define MFCSTL_VER_H_MFCSTL_LIST_ADAPTOR_MINOR     5
# define MFCSTL_VER_H_MFCSTL_LIST_ADAPTOR_REVISION  1
# define MFCSTL_VER_H_MFCSTL_LIST_ADAPTOR_EDIT      47
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

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

#ifndef MFCSTL_INCL_MFCSTL_HPP_MFCSTL
# include <mfcstl/mfcstl.hpp>
#endif /* !MFCSTL_INCL_MFCSTL_HPP_MFCSTL */
#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 */

/* /////////////////////////////////////////////////////////////////////////
 * Pre-processor options
 *
 * Because the CObList, CPtrList, CStringList and CList<,> implementations all
 * internally represent their logical position indicators (of type POSTION) as
 * pointers to the nodes within the lists, it is workable to be able to copy
 * these position variables.
 *
 * However, nothing in the MFC documentation stipulates this to be a reliable
 * and documented part of the classes' interfaces, so this is a potentially
 * unsafe assumption.
 *
 * Therefore, the iterator model for the list_adaptor class is Input Iterator.
 * If you wish to use forward iterators, you may specify the pre-processor
 * symbol _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR, in which case the iterator
 * classes will implement copy semantics, rather than the default move
 * semantics.
 */

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

// struct list_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 list_adaptor_traits;

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// For CObList

STLSOFT_TEMPLATE_SPECIALISATION
struct list_adaptor_traits<CObList>
{
    typedef CObject         *value_type;
    typedef CObject         *arg_type;
};

// For CPtrList

STLSOFT_TEMPLATE_SPECIALISATION
struct list_adaptor_traits<CPtrList>
{
    typedef void            *value_type;
    typedef void            *arg_type;
};

// For CStringList

STLSOFT_TEMPLATE_SPECIALISATION
struct list_adaptor_traits<CStringList>
{
    typedef CString         value_type;
    typedef const CString   &arg_type;
};

// For CList<, >

#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 list_adaptor_traits<CList<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 List class instances to the STL container concept
///
/// This class takes a container type, e.g. CStringList, as its primary (and
/// only non-default) template argument, C. The second template parameter, T,
/// defaults to list_adaptor_traits<C>, for which specialisations are provided
/// for the following types
///
///  - CObList       (stores pointers to CObject, or derived, instances)
///  - CPtrList      (stores raw pointers, ie. void*)
///  - CStringList   (stores strings, in the form of CString)
///
/// and for compilers that support partial specialisation
///
///  - CList<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 list_adaptor_traits<C>

template<   class C                             // The container type
        ,   class T = list_adaptor_traits<C>    // The traits type
        >
class list_adaptor
    : public stlsoft_ns_qual(stl_collection_tag)
{
public:
    typedef list_adaptor<C, T>                          class_type;
    typedef class_type                                  adapted_container_type;
private:
    typedef C                                           container_type;
    typedef T                                           traits_type;
public:
    // If you get a warning about a list_adaptor_traits<CList<,> > 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;

⌨️ 快捷键说明

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