📄 findvolume_sequence.hpp
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: winstl/filesystem/findvolume_sequence.hpp (formerly winstl_findvolume_sequence.h)
*
* Purpose: Contains the basic_findvolume_sequence template class, and ANSI
* and Unicode specialisations thereof.
*
* Notes: The original implementation of the class had the const_iterator
* and value_type as nested classes. Unfortunately, Visual C++ 5 &
* 6 both had either compilation or linking problems so these are
* regretably now implemented as independent classes.
*
* Created: 15th January 2002
* Updated: 10th June 2006
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2002-2006, 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/filesystem/findvolume_sequence.hpp
*
* \brief [C++ only] Definition of the winstl::basic_findvolume_sequence
* class template.
* (\ref group__library__file_system "File System" Library.)
*/
#ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FINDVOLUME_SEQUENCE
#define WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FINDVOLUME_SEQUENCE
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FINDVOLUME_SEQUENCE_MAJOR 4
# define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FINDVOLUME_SEQUENCE_MINOR 1
# define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FINDVOLUME_SEQUENCE_REVISION 2
# define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FINDVOLUME_SEQUENCE_EDIT 92
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef WINSTL_INCL_WINSTL_H_WINSTL
# include <winstl/winstl.h>
#endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
#ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
# include <winstl/filesystem/filesystem_traits.hpp>
#endif /* !WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS */
#ifndef STLSOFT_INCL_STLSOFT_HPP_ITERATOR
# include <stlsoft/iterator.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_ITERATOR */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS
# include <stlsoft/collections/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS */
/* /////////////////////////////////////////////////////////////////////////
* 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 */
/* /////////////////////////////////////////////////////////////////////////
* Enumerations
*/
// The FindNextVolume API is not well documented so assume _MAX_PATH
// is sufficient for volume names
enum
{
MAX_VOL_NAME = _MAX_PATH //!< The maximum number of characters in a volume name
};
/* /////////////////////////////////////////////////////////////////////////
* Forward declarations
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template <ss_typename_param_k C, ss_typename_param_k T>
class basic_findvolume_sequence_value_type;
template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
class basic_findvolume_sequence_const_iterator;
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Classes
*/
// class basic_findvolume_sequence
/// \brief Presents an STL-like sequence interface over the volumes on a system
///
/// \ingroup group__library__file_system
///
/// \note This class functions only on Windows 2000 and later
///
/// \param C The character type
/// \param T The traits type. On translators that support default template arguments this defaults to filesystem_traits<C>
template< ss_typename_param_k C
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k T = filesystem_traits<C>
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k T /* = filesystem_traits<C> */
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
class basic_findvolume_sequence
: public stlsoft_ns_qual(stl_collection_tag)
{
public:
/// The character type
typedef C char_type;
/// The traits type
typedef T traits_type;
/// The current parameterisation of the type
typedef basic_findvolume_sequence<C, T> class_type;
/// The value type
typedef basic_findvolume_sequence_value_type<C, T> value_type;
/// The non-mutating (const) iterator type
typedef basic_findvolume_sequence_const_iterator<C, T, value_type> const_iterator;
/// The reference type
typedef value_type &reference;
/// The non-mutable (const) reference type
typedef const value_type &const_reference;
// Iteration
public:
/// Begins the iteration
///
/// \return An iterator representing the start of the sequence
const_iterator begin() const;
/// Ends the iteration
///
/// \return An iterator representing the end of the sequence
const_iterator end() const;
// State
public:
/// Evalulates whether the sequence is empty
ws_bool_t empty() const;
};
/* /////////////////////////////////////////////////////////////////////////
* Typedefs for commonly encountered types
*/
/// Instantiation of the basic_findvolume_sequence template for the ANSI character type \c char
typedef basic_findvolume_sequence<ws_char_a_t, filesystem_traits<ws_char_a_t> > findvolume_sequence_a;
/// Instantiation of the basic_findvolume_sequence template for the Unicode character type \c wchar_t
typedef basic_findvolume_sequence<ws_char_w_t, filesystem_traits<ws_char_w_t> > findvolume_sequence_w;
/// Instantiation of the basic_findvolume_sequence template for the Win32 character type \c TCHAR
typedef basic_findvolume_sequence<TCHAR, filesystem_traits<TCHAR> > findvolume_sequence;
/* ////////////////////////////////////////////////////////////////////// */
// class basic_findvolume_sequence_value_type
/// Value type for the basic_findvolume_sequence
template< ss_typename_param_k C
, ss_typename_param_k T
>
class basic_findvolume_sequence_value_type
{
public:
/// The character type
typedef C char_type;
/// The traits type
typedef T traits_type;
/// The current parameterisation of the type
typedef basic_findvolume_sequence_value_type<C, T> class_type;
public:
/// Default constructor
basic_findvolume_sequence_value_type();
/// Copy constructor
basic_findvolume_sequence_value_type(class_type const &rhs);
private:
basic_findvolume_sequence_value_type(char_type const *vol_name);
public:
/// Copy assignment operator
class_type &operator =(class_type const &rhs);
// Attributes
public:
/// Implicit conversion to non-mutable pointer-to-const of the volume name
operator char_type const * () const
{
return m_name;
}
private:
friend class basic_findvolume_sequence_const_iterator<C, T, class_type>;
char_type m_name[MAX_VOL_NAME + 1];
};
// class basic_findvolume_sequence_const_iterator
/// Iterator type for the basic_findvolume_sequence, supporting the Input Iterator concept
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k V
>
class basic_findvolume_sequence_const_iterator
: public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(input_iterator_tag)
, V
, ws_ptrdiff_t
, void // By-Value Temporary reference
, V // By-Value Temporary reference
>
{
public:
/// The character type
typedef C char_type;
/// The traits type
typedef T traits_type;
/// The traits type
typedef V value_type;
/// The current parameterisation of the type
typedef basic_findvolume_sequence_const_iterator<C, T, V> class_type;
/// \name Utility classes
/// @{
private:
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
struct shared_handle
{
public:
typedef shared_handle class_type;
// Members
public:
HANDLE hSrch;
private:
ss_sint32_t cRefs;
public:
ss_explicit_k shared_handle(HANDLE h)
: hSrch(h)
, cRefs(1)
{}
void AddRef()
{
++cRefs;
}
void Release()
{
if(0 == --cRefs)
{
delete this;
}
}
#if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
protected:
#else /* ? STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
private:
#endif /* STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
~shared_handle() stlsoft_throw_0()
{
WINSTL_MESSAGE_ASSERT("Shared search handle being destroyed with outstanding references!", 0 == cRefs);
if(hSrch != INVALID_HANDLE_VALUE)
{
traits_type::find_volume_close(hSrch);
}
}
private:
shared_handle(class_type const &);
class_type &operator =(class_type const &);
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// @}
/// \name Construction
/// @{
private:
basic_findvolume_sequence_const_iterator(basic_findvolume_sequence<C, T> const &l, HANDLE hSrch, char_type const *vol_name)
: m_list(&l)
, m_handle(new shared_handle(hSrch))
{
WINSTL_ASSERT(INVALID_HANDLE_VALUE != hSrch);
if(NULL == m_handle)
{
traits_type::find_volume_close(hSrch);
m_name[0] = '\0';
}
else
{
traits_type::str_copy(m_name, vol_name);
}
}
basic_findvolume_sequence_const_iterator(basic_findvolume_sequence<C, T> const &l);
public:
/// Default constructor
basic_findvolume_sequence_const_iterator();
/// Copy constructor
basic_findvolume_sequence_const_iterator(class_type const &rhs);
/// Destructor
~basic_findvolume_sequence_const_iterator() stlsoft_throw_0();
/// Copy assignment operator
class_type &operator =(class_type const &rhs);
public:
/// Pre-increment operator
class_type &operator ++();
/// Post-increment operator
class_type operator ++(int);
/// Dereference to access the value at the current position
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -