mfcstl_array_veneer.h

来自「用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、W」· C头文件 代码 · 共 812 行 · 第 1/2 页

H
812
字号
        /// 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

        class_type &operator +=(difference_type index)
        {
            m_index += index;

            return *this;
        }

        class_type &operator -=(difference_type index)
        {
            m_index -= index;

            return *this;
        }

        class_type &operator -=(class_type const &rhs)
        {
            index_type  index   =   static_cast<index_type>(m_index) - static_cast<index_type>(rhs.m_index);

            return class_type(m_c, index);
        }

        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;
        }

    // Members
    protected:
        container_type const    *m_c;
        size_type               m_index;
    };

    /// Iterator class for the list_veneer class
    class iterator
        : public const_iterator
    {
    private:
        friend class array_veneer<C, T>;
    private:
        typedef const_iterator                                      parent_class_type;
        typedef iterator                                            class_type;
        typedef ss_typename_type_k parent_class_type::index_type    index_type;
        typedef container_type::pointer                             pointer;
        typedef container_type::reference                           reference;
    private:
        iterator(container_type *const c, index_type index)
            : parent_class_type(c, index)
        {}
    public:
        /// Default constructor
        iterator()
        {}
        /// Copy constructor
        ///
        /// \param rhs The instance from which to copy construct
        iterator(class_type const &rhs)
            : parent_class_type(rhs)
        {}

        /// Copy assignment operator
        ///
        /// \param rhs The instance from which to copy assign
        iterator const &operator =(class_type const &rhs)
        {
            MFCSTL_MESSAGE_ASSERT("Attempting to assign iterator from another container!", m_c == NULL || rhs.m_c == NULL || m_c == rhs.m_c);

            parent_class_type::operator =(rhs);

            return *this;
        }

        reference operator *()
        {
            MFCSTL_MESSAGE_ASSERT("", m_c != 0);

            return (*const_cast<container_type*>(m_c))[m_index];
        }

        const_reference operator *() const
        {
            return parent_class_type::operator *();
        }

        // Random access operations

        value_type &operator [](difference_type index)
        {
            return const_cast<container_type *>(m_c)->ElementAt(m_index + index);
        }

        value_type operator [](difference_type index) const
        {
            return parent_class_type::operator [](index);
        }

        class_type &operator -=(difference_type index)
        {
            m_index -= index;

            return *this;
        }

        class_type &operator -=(class_type const &rhs)
        {
            index_type  index   =   static_cast<index_type>(m_index) - static_cast<index_type>(rhs.m_index);

            return class_type(m_c, 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
    ss_explicit_k array_veneer()
    {
        stlsoft_constraint_must_be_same_size(C, class_type);
    }

// Operations
public:
    void push_back(value_type const &v)
    {
        Add(v);
    }

// State
public:
    /// Returns the number of elements in the sequence
    size_type size() const
    {
        return static_cast<size_type>(GetSize());
    }
    /// Indicates whether the search sequence is empty
    ms_bool_t empty() const
    {
        return 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(this, 0);
    }
    /// Ends the iteration
    ///
    /// \return An iterator representing the end of the sequence
    const_iterator end() const
    {
        return const_iterator(this, size());
    }

    /// Begins the iteration
    ///
    /// \return An iterator representing the start of the sequence
    iterator begin()
    {
        return iterator(this, 0);
    }
    /// Ends the iteration
    ///
    /// \return An iterator representing the end of the sequence
    iterator end()
    {
        return iterator(this, 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
    reference operator [](difference_type index)
    {
        return container_type::operator [](index);
    }

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

/* /////////////////////////////////////////////////////////////////////////
 * Implementation
 */

// array_veneer<>::const_iterator

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ss_typename_type_k array_veneer<C, T>::const_iterator operator +(ss_typename_type_k array_veneer<C, T>::const_iterator const &lhs, ss_typename_type_k array_veneer<C, T>::difference_type n)
{
    return ss_typename_type_k array_veneer<C, T>::const_iterator(lhs) += n;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ss_typename_type_k array_veneer<C, T>::const_iterator operator -(ss_typename_type_k array_veneer<C, T>::const_iterator const &lhs, ss_typename_type_k array_veneer<C, T>::difference_type n)
{
    return ss_typename_type_k array_veneer<C, T>::const_iterator(lhs) -= n;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ss_typename_type_k array_veneer<C, T>::const_iterator operator -(ss_typename_type_k array_veneer<C, T>::const_iterator const &lhs, ss_typename_type_k array_veneer<C, T>::const_iterator const &rhs)
{
    return ss_typename_type_k array_veneer<C, T>::const_iterator(lhs) -= rhs;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator <(ss_typename_type_k array_veneer<C, T>::const_iterator const &lhs, ss_typename_type_k array_veneer<C, T>::const_iterator const &rhs)
{
    return lhs.compare(rhs) < 0;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator >(ss_typename_type_k array_veneer<C, T>::const_iterator const &lhs, ss_typename_type_k array_veneer<C, T>::const_iterator const &rhs)
{
    return lhs.compare(rhs) > 0;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator <=(ss_typename_type_k array_veneer<C, T>::const_iterator const &lhs, ss_typename_type_k array_veneer<C, T>::const_iterator const &rhs)
{
    return lhs.compare(rhs) <= 0;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator >=(ss_typename_type_k array_veneer<C, T>::const_iterator const &lhs, ss_typename_type_k array_veneer<C, T>::const_iterator const &rhs)
{
    return lhs.compare(rhs) >= 0;
}

// array_veneer<>::iterator

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ss_typename_type_k array_veneer<C, T>::iterator operator +(ss_typename_type_k array_veneer<C, T>::iterator const &lhs, ss_typename_type_k array_veneer<C, T>::difference_type n)
{
    return ss_typename_type_k array_veneer<C, T>::iterator(lhs) += n;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ss_typename_type_k array_veneer<C, T>::iterator operator -(ss_typename_type_k array_veneer<C, T>::iterator const &lhs, ss_typename_type_k array_veneer<C, T>::difference_type n)
{
    return ss_typename_type_k array_veneer<C, T>::iterator(lhs) -= n;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ss_typename_type_k array_veneer<C, T>::iterator operator -(ss_typename_type_k array_veneer<C, T>::iterator const &lhs, ss_typename_type_k array_veneer<C, T>::iterator const &rhs)
{
    typedef ss_typename_type_k array_veneer<C, T>::iterator iter_t;

    return iter_t(lhs) -= rhs;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator <(ss_typename_type_k array_veneer<C, T>::iterator const &lhs, ss_typename_type_k array_veneer<C, T>::iterator const &rhs)
{
    return lhs.compare(rhs) < 0;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator >(ss_typename_type_k array_veneer<C, T>::iterator const &lhs, ss_typename_type_k array_veneer<C, T>::iterator const &rhs)
{
    return lhs.compare(rhs) > 0;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator <=(ss_typename_type_k array_veneer<C, T>::iterator const &lhs, ss_typename_type_k array_veneer<C, T>::iterator const &rhs)
{
    return lhs.compare(rhs) <= 0;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        >
inline ms_bool_t operator >=(ss_typename_type_k array_veneer<C, T>::iterator const &lhs, ss_typename_type_k array_veneer<C, T>::iterator const &rhs)
{
    return lhs.compare(rhs) >= 0;
}

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

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

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

⌨️ 快捷键说明

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