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

📄 mfcstl_list_adaptor.h

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

public:
    /// Non-mutating (const) iterator for the list_adaptor 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 list_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.
# ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
        typedef ss_typename_type_k list_adaptor<C, 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(container_type *c, POSITION pos)
            : m_c(c)
            , m_pos(pos)
        {
            operator ++();
        }
    public:
        /// Default constructor
        const_iterator()
            : m_c(0)
            , m_pos(NULL)
        {}
# 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_c(rhs.m_c)
            , m_pos(rhs.m_pos)
        {
            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_c     =   rhs.m_c;
            m_pos   =   rhs.m_pos;

            move_lhs_from_rhs(rhs).m_pos = NULL;

            return *this;
        }
# endif /* _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */

    // Operators
    public:
        /// Dereference operator
        value_type operator *() const
        {
            MFCSTL_MESSAGE_ASSERT("", m_c != 0);

            return m_value;
        }

        /// \brief Pre-increment operator
        const_iterator &operator ++()
        {
            if(m_pos == NULL)
            {
                MFCSTL_MESSAGE_ASSERT("operator ++() called on invalid iterator", m_c != 0);

                m_c = 0;
            }
            else
            {
                m_value = m_c->GetNext(m_pos);
            }

            return *this;
        }

        /// \brief Post-increment operator
# ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
        const_iterator operator ++(int)
# else /* ? _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */
        void operator ++(int)
# endif /* _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */
        {
# ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
            class_type  ret(*this);
# endif /* _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */

            operator ++();

# ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
            return ret;
# endif /* _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR */
        }

        /// Evaluates whether \c this is equivalent to \c rhs
        ///
        /// \param rhs The instance from which to copy construct
        /// \retval true The two iterators refer to the same position in the same container
        /// \retval false The two iterators do not refer to the same position in the same container
        ms_bool_t operator ==(const_iterator const &rhs) const
        {
            // Because the C<Type><Container> containers, e.g. CStringList
            // work on the basis of get-and-advance, m_pos alone cannot be
            // the sentinel for an ended sequence. Hence, combining the
            // implementation of op++ to set m_c to 0 when m_pos is NULL, we
            // can test both members, which results in the after-the-fact
            // equality evaluating correctly.

            MFCSTL_MESSAGE_ASSERT("invalid comparison between iterators from different ranges", m_c == 0 || rhs.m_c == 0 || m_c == rhs.m_c);

            return m_pos == rhs.m_pos && m_c == rhs.m_c;
        }
        /// Evaluates whether \c this is not equivalent to \c rhs
        ///
        /// \param rhs The instance from which to copy construct
        /// \retval true The two iterators do not refer to the same position in the same container
        /// \retval false The two iterators refer to the same position in the same container
        ms_bool_t operator !=(const_iterator const &rhs) const
        {
            return !operator ==(rhs);
        }

    // Members
    private:
        container_type  *m_c;
        POSITION        m_pos;
        value_type      m_value;
    };

// Construction
public:
    /// Constructs an instance of the list adaptor
    ///
    /// \param c An instance of the list class
    ss_explicit_k list_adaptor(C &c)
        : m_c(c)
    {}

// State
public:
    /// Returns the number of elements in the sequence
    size_type size() const
    {
        return static_cast<size_type>(m_c.GetCount());
    }
    /// Indicates whether the search sequence is empty
    ms_bool_t empty() const
    {
        return m_c.GetCount() == 0;
    }
    /// Returns the maximum number of elements in the sequence
    static size_type max_size()
    {
        return static_cast<size_type>(-1) / sizeof(value_type);
    }

// Iteration
public:
    /// Begins the iteration
    ///
    /// \return An iterator representing the start of the sequence
    const_iterator  begin() const
    {
        return const_iterator(&m_c, m_c.GetHeadPosition());
    }
    /// Ends the iteration
    ///
    /// \return An iterator representing the end of the sequence
    const_iterator  end() const
    {
        return const_iterator();
    }

// Members
private:
    container_type  &m_c;
};

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

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

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

⌨️ 快捷键说明

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