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

📄 listbox_const_iterator.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:
            }

            // PA: -1 to account for the NULL character
            mutable_access(m_value).assign(&buffer[0], buffer.size() - 1);

            mutable_access(m_bRetrieved) = true;
        }

        return m_value;
    }

    /// Dereferences the iterator and returns a pointer to the current value
    const_pointer operator ->() const
    {
        return &operator *();
    }

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

        return *this;
    }

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

        operator ++();

        return ret;
    }

    /// Compares \c this and \c rhs for equivalence
    difference_type compare(class_type const& rhs) const
    {
        WINSTL_MESSAGE_ASSERT("invalid comparison between iterators from different ranges", m_hwnd == rhs.m_hwnd || NULL == m_hwnd || NULL == rhs.m_hwnd);

        return m_index - rhs.m_index;
    }

    /// Indicates whether \c this and \c rhs are equivalent
    bool operator == (class_type const& rhs) const
    {
        return 0 == compare(rhs);
    }

    /// Indicates whether \c this and \c rhs are not equivalent
    bool operator != (class_type const& rhs) const
    {
        return 0 != compare(rhs);
    }
/// @}

/// \name Bidirectional Iterator methods
/// @{
public:
    /// Pre-decrement operator
    class_type& operator --()
    {
        --m_index;
        m_bRetrieved = false;

        return *this;
    }

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

        operator --();

        return ret;
    }
/// @}

/// \name Random Access Iterator methods
/// @{
public:
    /// Offset
    class_type& operator +=(difference_type index)
    {
        m_index += index;
        m_bRetrieved = false;

        return *this;
    }

    /// Offset
    class_type& operator -=(difference_type index)
    {
        m_index -= index;
        m_bRetrieved = false;

        return *this;
    }

    /// Indexing operator
    value_type operator [](difference_type index) const
    {
        // PA: Emulate pointer-like operation where it[0] returns the current item's value
        return get_value_at_(m_hwnd, 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;
    }

    /// Pointer subtraction
    class_type operator -(difference_type n) const
    {
        return class_type(*this) -= n;
    }

    /// Pointer addition
    class_type operator +(difference_type n) const
    {
        return class_type(*this) += n;
    }

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

    /// Indicates whether \c this is less than \c rhs
    ws_bool_t operator <(class_type const& rhs) const
    {
        return compare(rhs) < 0;
    }

    /// Indicates whether \c this is greater than \c rhs
    ws_bool_t operator >(class_type const& rhs) const
    {
        return compare(rhs) > 0;
    }

    /// Indicates whether \c this is less than or equal \c rhs
    ws_bool_t operator <=(class_type const& rhs) const
    {
        return compare(rhs) <= 0;
    }

    /// Indicates whether \c this is greater than or equal \c rhs
    ws_bool_t operator >=(class_type const& rhs) const
    {
        return compare(rhs) >= 0;
    }
/// @}

/// \name Implementation
/// @{
public:
    static value_type get_value_at_(HWND hwnd, difference_type index)
    {
        WINSTL_MESSAGE_ASSERT("Invalid index", index >= 0);

        int len;

        if(control_traits_type::err_constant() == (len = control_traits_type::get_text_len(hwnd, index)))
        {
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
            STLSOFT_THROW_X(stlsoft_ns_qual(external_iterator_invalidation)("external iterator invalidation: control contents may have been altered externally"));
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
            len = 0;
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
        }

        buffer_type buffer(1 + len);

        if(control_traits_type::err_constant() == (len = control_traits_type::get_text(hwnd, index, &buffer[0])))
        {
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
            STLSOFT_THROW_X(stlsoft_ns_qual(external_iterator_invalidation)("external iterator invalidation: control contents may have been altered externally"));
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
            buffer.resize(1);
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
        }

        return value_type(&buffer[0], buffer.size() - 1);
    }
/// @}

/// \name Members
/// @{
private:
    HWND                    m_hwnd;
    int                     m_index;
    ss_mutable_k ws_bool_t  m_bRetrieved;
    ss_mutable_k value_type m_value;
/// @}
};

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

#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace winstl
# else
} // namespace winstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */

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

#endif /* WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR */

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

⌨️ 快捷键说明

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