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

📄 mfcstl_array_adaptor.h

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 H
📖 第 1 页 / 共 2 页
字号:
            , m_index(rhs.m_index)
        {}

        /// Copy assignment operator
        ///
        /// \param rhs The instance from which to copy assign
        const_iterator const &operator =(class_type const &rhs)
        {
            m_c     =   rhs.m_c;
            m_index =   rhs.m_index;

            return *this;
        }

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

            return m_c->GetAt(m_index);
        }

        /// Pre-increment operator
        class_type &operator ++()
        {
            ++m_index;

            return *this;
        }

        /// Post-increment operator
        class_type operator ++(int)
        {
            class_type  ret(*this);

            operator ++();

            return ret;
        }

        /// Compares \c this with \c rhs
        ///
        /// \param rhs The instance against which to test
        /// \retval 0 if the two are equal
        /// \retval <0 if \c this is before \c rhs in the sequence
        /// \retval >0 if \c this is after \c rhs in the sequence
        difference_type compare(class_type const &rhs) const
        {
            // Because the C<Type><Container> containers, e.g. CStringArray
            // 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_index - rhs.m_index;
        }

        /// Evaluates whether \c this and \c rhs are equivalent
        ///
        /// \param rhs The instance against which to compare
        /// \retval true If \c this and \c rhs are equivalent
        /// \retval false If \c this and \c rhs are not equivalent
        ms_bool_t operator ==(class_type const &rhs) const
        {
            return compare(rhs) == 0;
        }

        /// Evaluates whether \c this and \c rhs are not equivalent
        ///
        /// \param rhs The instance against which to compare
        /// \retval true If \c this and \c rhs are not equivalent
        /// \retval false If \c this and \c rhs are equivalent
        ms_bool_t operator !=(class_type const &rhs) const
        {
            return compare(rhs) != 0;
        }

        // Bidirectional iterator operations

        /// Pre-decrement operator
        class_type &operator --()
        {
            --m_index;

            return *this;
        }

        /// Post-decrement operator
        class_type operator --(int)
        {
            class_type  ret(*this);

            operator --();

            return ret;
        }

        // Random access operations

        /// Moves the iterator forward
        ///
        /// \param inc The amount by which to increment the iterator's current position
        class_type &operator +=(difference_type inc)
        {
            m_index += inc;

            return *this;
        }

        /// Moves the iterator backward
        ///
        /// \param dec The amount by which to decrement the iterator's current position
        class_type &operator -=(difference_type dec)
        {
            m_index -= dec;

            return *this;
        }

        /// Access the element at the given index
        ///
        /// \param index The required offset from the iterator's position
        value_type &operator [](difference_type index)
        {
            return m_c->ElementAt(m_index + index);
        }

        /// Access the element at the given index
        ///
        /// \param index The required offset from the iterator's position
        value_type operator [](difference_type index) const
        {
            return m_c->GetAt(m_index + index);
        }

        /// Calculate the distance between \c this and \c rhs
        difference_type distance(class_type const &rhs) const
        {
            return m_index - rhs.m_index;
        }

        class_type operator -(difference_type n)
        {
            return class_type(*this) -= n;
        }

        class_type operator +(difference_type n)
        {
            return class_type(*this) += n;
        }

        difference_type operator -(class_type const &rhs)
        {
            return distance(rhs);
        }

        ms_bool_t operator <(class_type const &rhs)
        {
            return compare(rhs) < 0;
        }

        ms_bool_t operator >(class_type const &rhs)
        {
            return compare(rhs) > 0;
        }

        ms_bool_t operator <=(class_type const &rhs)
        {
            return compare(rhs) <= 0;
        }

        ms_bool_t operator >=(class_type const &rhs)
        {
            return compare(rhs) >= 0;
        }


    // Members
    private:
        container_type  *m_c;
        size_type       m_index;
    };

/// The reverse non-mutating (const) iterator type
#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
    typedef stlsoft_ns_qual(const_reverse_bidirectional_iterator_base)< const_iterator,
                                                                        value_type,
                                                                        value_type, // By-Value Temporary reference category
                                                                        void,       // By-Value Temporary reference category
                                                                        difference_type>    const_reverse_iterator;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */


// Construction
public:
    /// Constructs an instance of the array adaptor
    ///
    /// \param c An instance of the array class
    ss_explicit_k array_adaptor(container_type &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.GetSize());
    }
    /// Indicates whether the search sequence is empty
    ms_bool_t empty() const
    {
        return m_c.GetSize() == 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(const_cast<container_type*>(&m_c), 0);
    }
    /// Ends the iteration
    ///
    /// \return An iterator representing the end of the sequence
    const_iterator  end() const
    {
        return const_iterator(const_cast<container_type*>(&m_c), size());
    }

//  const_reverse_iterator
#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
    /// Begins the reverse iteration
    ///
    /// \return An iterator representing the start of the reverse sequence
    const_reverse_iterator  rbegin() const
    {
        return const_reverse_iterator(end());
    }
    /// Ends the reverse iteration
    ///
    /// \return An iterator representing the end of the reverse sequence
    const_reverse_iterator  rend() const
    {
        return const_reverse_iterator(begin());
    }
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */

// Accessors
public:
    /// Returns a mutable reference to the element at the given \c index
    value_type &operator [](difference_type index)
    {
        return m_c.ElementAt(index);
    }

    /// Returns a copy of the element at the given \c index
    value_type operator [](difference_type index) const
    {
        return m_c.GetAt(index);
    }

// Members
private:
    container_type const    &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_ARRAY_ADAPTOR */

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

⌨️ 快捷键说明

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