📄 listbox_const_iterator.hpp
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: winstl/controls/listbox_const_iterator.hpp
*
* Purpose: Contains the listbox_const_iterator class.
*
* Created: 10th November 2002
* Updated: 22nd March 2007
*
* Thanks: To Pablo Aguilar for some patches.
*
* 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 winstl/controls/listbox_const_iterator.hpp
*
* \brief [C++ only] Definition of the winstl::listbox_const_iterator class
* (\ref group__library__windows_controls "Windows Controls" Library).
*/
#ifndef WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR
#define WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_MAJOR 4
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_MINOR 2
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_REVISION 4
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_EDIT 68
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef WINSTL_INCL_WINSTL_H_WINSTL
# include <winstl/winstl.h>
#endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
# include <stlsoft/memory/auto_buffer.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER */
#ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
# include <winstl/memory/processheap_allocator.hpp>
#endif /* !WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
# include <stlsoft/util/std/iterator_helper.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS
# include <stlsoft/string/string_traits.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS */
#ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXTERNAL_ITERATOR_INVALIDATION
# include <stlsoft/error/external_iterator_invalidation.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_ERROR_HPP_EXTERNAL_ITERATOR_INVALIDATION */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::winstl */
namespace winstl
{
# else
/* Define stlsoft::winstl_project */
namespace stlsoft
{
namespace winstl_project
{
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Classes
*/
/** \brief Iterator for listbox_sequence class
*
* \ingroup group__library__windows_controls
*
* This class acts as the iterator for the listbox_sequence class, and implements
* the Random Access Iterator concept
*
* \param S The string type
*/
template< ss_typename_param_k S
, ss_typename_param_k BT
>
class listbox_const_iterator
: public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(random_access_iterator_tag)
, S
, ws_ptrdiff_t
, S const*
, S const&
>
{
/// \name Member Types
/// @{
public:
/// The string type
typedef S value_type;
/// The current parameterisation of the type
typedef listbox_const_iterator<S, BT> class_type;
#if defined(STLSOFT_COMPILER_IS_BORLAND)
private:
typedef stlsoft_ns_qual(string_traits)<S> string_traits_type_;
typedef ss_typename_type_k string_traits_type_::char_type char_type;
public:
#else /* ? compiler */
/// The character type
typedef ss_typename_type_k stlsoft_ns_qual(string_traits)<S>::char_type char_type;
#endif /* ? compiler */
/// The size type
typedef ws_size_t size_type;
/// The difference type
typedef ws_ptrdiff_t difference_type;
/// The non-mutating (const) reference type
typedef value_type const &const_reference;
/// The non-mutating (const) pointer type
typedef value_type const *const_pointer;
/// The allocator type
typedef processheap_allocator<char_type> allocator_type;
#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
/// \brief The non-mutating (const) reverse iterator type
///
/// This typedef is provided as a convenience for the sequence.
///
/// \note Even though the iterator supports Transient semantics, the
/// reverse iterator <b>must</b> be <i>By-Value Temporary</i>, since
/// there is no underlying range of values of which the offset-by-one
/// mechanism of the std::reverse_iterator adaptor can access and
/// return a valid reference.
typedef stlsoft_ns_qual(const_reverse_iterator_base)< class_type
, value_type
, value_type // By-Value Temporary element references
, void // By-Value Temporary element references
, difference_type
> const_reverse_iterator_type;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
/// The auto-buffer type
typedef stlsoft_ns_qual(auto_buffer_old)< char_type
, allocator_type
, 256
> buffer_type;
/// The control traits type
typedef BT control_traits_type;
/// @}
/// \name Construction
/// @{
public:
/// Construct an instance from the list-box \c hwndListBox at the given \c index
listbox_const_iterator(HWND hwndListBox, int index)
: m_hwnd(hwndListBox)
, m_index(index)
, m_bRetrieved(false)
{}
/// @}
/// \name Forward Iterator Methods
/// @{
public:
/// Dereferences the iterator and returns a reference to the current value
const_reference operator *() const
{
if(!m_bRetrieved)
{
int len;
if(control_traits_type::err_constant() == (len = control_traits_type::get_text_len(m_hwnd, m_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(m_hwnd, m_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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -