📄 clist_adaptors.hpp
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: mfcstl/collections/clist_adaptors.hpp
*
* Purpose: Contains the definition of the CList_cadaptor and CList_iadaptor
* class templates.
*
* Created: 1st December 2002
* Updated: 22nd March 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 mfcstl/collections/clist_adaptors.hpp
*
* \brief [C++ only] Definition of the mfcstl::CList_cadaptor and
* mfcstl::CList_iadaptor traits class templates
* (\ref group__library__collections "Collections" Library).
*/
#ifndef MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_CLIST_ADAPTORS
#define MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_CLIST_ADAPTORS
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_CLIST_ADAPTORS_MAJOR 3
# define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_CLIST_ADAPTORS_MINOR 0
# define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_CLIST_ADAPTORS_REVISION 4
# define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_CLIST_ADAPTORS_EDIT 57
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Compatibility
*/
/*
[Incompatibilies-start]
[Incompatibilies-end]
*/
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef MFCSTL_INCL_MFCSTL_HPP_MFCSTL
# include <mfcstl/mfcstl.hpp>
#endif /* !MFCSTL_INCL_MFCSTL_HPP_MFCSTL */
#ifndef MFCSTL_INCL_MFCSTL_MEMORY_HPP_AFX_ALLOCATOR
# include <mfcstl/memory/afx_allocator.hpp>
#endif /* !MFCSTL_INCL_MFCSTL_MEMORY_HPP_AFX_ALLOCATOR */
#ifndef MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_CLIST_SWAP
# include <mfcstl/collections/clist_swap.hpp>
#endif /* !MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_CLIST_SWAP */
#ifndef MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_CLIST_TRAITS
# include <mfcstl/collections/clist_traits.hpp>
#endif /* !MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_CLIST_TRAITS */
#ifndef MFCSTL_INCL_MFCSTL_UTIL_HPP_MEMORY_EXCEPTION_TRANSLATION_POLICIES
# include <mfcstl/util/memory_exception_translation_policies.hpp>
#endif /* !MFCSTL_INCL_MFCSTL_UTIL_HPP_MEMORY_EXCEPTION_TRANSLATION_POLICIES */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS
# include <stlsoft/util/std/iterator_generators.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_CAPABILITIES
# include <stlsoft/meta/capabilities.hpp>
#endif /* STLSOFT_INCL_STLSOFT_META_HPP_CAPABILITIES */
#ifdef STLSOFT_META_HAS_IS_SAME_TYPE
# ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_SAME_TYPE
# include <stlsoft/meta/is_same_type.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_SAME_TYPE */
#endif /* STLSOFT_META_HAS_IS_SAME_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
# include <stlsoft/collections/util/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
#if defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT) && \
!defined(MFCSTL_NO_INCLUDE_AFXTEMPL_BY_DEFAULT)
# include <afxtempl.h>
#endif /* STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT && !MFCSTL_NO_INCLUDE_AFXTEMPL_BY_DEFAULT */
#ifdef STLSOFT_UNITTEST
# include <afxtempl.h>
# include <stlsoft/string/simple_string.hpp>
#endif /* STLSOFT_UNITTEST */
/* /////////////////////////////////////////////////////////////////////////
* 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 CList_adaptor_base 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
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// Forward declarations
template< ss_typename_param_k L
, ss_typename_param_k I
, ss_typename_param_k T
>
class CList_adaptor_base;
// CList_cadaptor is not currently defined
template< ss_typename_param_k L
, ss_typename_param_k T
>
class CList_cadaptor;
template< ss_typename_param_k L
, ss_typename_param_k T
>
class CList_iadaptor;
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief Adaptor class, providing implementation for CList_cadaptor and
* CList_iadaptor classes
*
* \ingroup group__library__collections
*
* \param L The list class, e.g. CObList, CList<long>, etc.
* \param I The interface specialisation, e.g. CList_cadaptor<CObList>, CList_iadaptor<CList<long> >, etc.
* \param T The traits class, e.g. CList_traits<CObList>
*
*/
template< ss_typename_param_k L
, ss_typename_param_k I
, ss_typename_param_k T
>
class CList_adaptor_base
: public stlsoft_ns_qual(stl_collection_tag)
{
/// \name Member Types
/// @{
public:
/// The type of the underlying MFC list
typedef L list_type;
private:
typedef I interface_class_type;
typedef T list_traits_type;
#if defined(MFCSTL_CLIST_ADAPTORS_USE_BAD_ALLOC_POLICY)
typedef bad_alloc_throwing_policy exception_translation_policy_type;
#else /* ? MFCSTL_CLIST_ADAPTORS_USE_BAD_ALLOC_POLICY */
typedef CMemoryException_throwing_policy exception_translation_policy_type;
#endif /* MFCSTL_CLIST_ADAPTORS_USE_BAD_ALLOC_POLICY */
public:
/// The value type
///
/// \note If the compiler report "use of undefined type" when you're using the adaptor class(es)
/// with CList<>, ensure that you've included <b>afxtempl</b> <i>before</i> you include this file.
typedef ss_typename_type_k list_traits_type::value_type value_type;
/// The allocator type
typedef afx_allocator<value_type> allocator_type;
/// The mutating (non-const) reference type
typedef ss_typename_type_k allocator_type::reference reference;
/// The non-mutating (const) reference type
typedef ss_typename_type_k allocator_type::const_reference const_reference;
/// The mutating (non-const) pointer type
typedef ss_typename_type_k allocator_type::pointer pointer;
/// The non-mutating (const) pointer type
typedef ss_typename_type_k allocator_type::const_pointer const_pointer;
/// The size type
typedef ms_size_t size_type;
/// The difference type
typedef ms_ptrdiff_t difference_type;
/// The instantiation of the current type
typedef CList_adaptor_base<L, I, T> class_type;
public:
/// Non-mutating (const) iterator for the CList_adaptor_base class
///
/// \note This currently supports the Input Iterator concept only
class const_iterator
: public stlsoft_ns_qual(iterator_base)<mfcstl_ns_qual_std(input_iterator_tag)
, value_type
, ms_ptrdiff_t
, void // By-Value Temporary reference
, value_type // By-Value Temporary reference
>
{
friend class CList_adaptor_base<L, I, 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.
# ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
typedef ss_typename_type_k CList_adaptor_base<L, I, T>::value_type value_type;
# endif /* !STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */
# ifndef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
typedef stlsoft_define_move_rhs_type(class_type) rhs_type;
# endif /* !_MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */
// Construction
private:
/// Constructor
const_iterator(list_type const* list, POSITION pos)
: m_list(list)
, m_pos(pos)
, m_value()
{
operator ++();
}
public:
/// Default constructor
const_iterator()
: m_list(NULL)
, m_pos(NULL)
, m_value()
{}
# ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
// The copy constructor and copy assignment operator are not defined,
// which allows the class to support copy-semantics. See the
// description of _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR given for
// a discussion of the ramifications of this choice.
# else /* ? _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */
/// <a href = "http://synesis.com.au/resources/articles/cpp/movectors.pdf">Move constructor</a>
const_iterator(rhs_type rhs)
: m_list(rhs.m_list)
, m_pos(rhs.m_pos)
, m_value(rhs.m_value)
{
move_lhs_from_rhs(rhs).m_pos = NULL;
}
/// <a href = "http://synesis.com.au/resources/articles/cpp/movectors.pdf">Move assignment</a> operator
const_iterator const& operator =(rhs_type rhs)
{
m_list = rhs.m_list;
m_pos = rhs.m_pos;
m_value = rhs.m_value;
move_lhs_from_rhs(rhs).m_pos = NULL;
return *this;
}
# endif /* _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -