📄 findfile_sequence.hpp
字号:
* \ingroup group__library__filesystem
*/
typedef basic_findfile_sequence<ws_char_a_t, filesystem_traits<ws_char_a_t> > findfile_sequence_a;
/** \brief Specialisation of the basic_findfile_sequence template for the Unicode character type \c wchar_t
*
* \ingroup group__library__filesystem
*/
typedef basic_findfile_sequence<ws_char_w_t, filesystem_traits<ws_char_w_t> > findfile_sequence_w;
/** \brief Specialisation of the basic_findfile_sequence template for the Win32 character type \c TCHAR
*
* \ingroup group__library__filesystem
*/
typedef basic_findfile_sequence<TCHAR, filesystem_traits<TCHAR> > findfile_sequence;
/* ////////////////////////////////////////////////////////////////////// */
// class basic_findfile_sequence_value_type
/** \brief Value type for the basic_findfile_sequence
*
* \ingroup group__library__filesystem
*/
template< ss_typename_param_k C
, ss_typename_param_k T
>
class basic_findfile_sequence_value_type
{
/// \name Member Types
/// @{
private:
typedef basic_findfile_sequence<C, T> sequence_type;
public:
/// The character type
typedef C char_type;
/// The traits type
typedef T traits_type;
/// The current parameterisation of the type
typedef basic_findfile_sequence_value_type<C, T> class_type;
/// The find-data type
typedef ss_typename_type_k traits_type::find_data_type find_data_type;
/// The size type
typedef ss_typename_type_k sequence_type::size_type size_type;
private:
typedef ss_typename_type_k sequence_type::bool_type bool_type;
typedef ss_typename_type_k sequence_type::flags_type flags_type;
/// @}
/// \name Construction
/// @{
public:
/// Default constructor
basic_findfile_sequence_value_type();
private:
basic_findfile_sequence_value_type(find_data_type const& data, char_type const* directory, size_type cchDirectory)
: m_data(data)
{
WINSTL_ASSERT(NULL != directory);
WINSTL_ASSERT(0 != cchDirectory);
m_path[cchDirectory] = '\0';
traits_type::str_n_copy(&m_path[0], directory, cchDirectory);
traits_type::ensure_dir_end(&m_path[0] + ((cchDirectory > 0) ? (cchDirectory - 1) : cchDirectory));
traits_type::str_cat(&m_path[0] + cchDirectory, data.cFileName);
m_pathLen = cchDirectory + traits_type::str_len(&m_path[cchDirectory]);
WINSTL_ASSERT(traits_type::str_len(m_path.c_str()) == m_pathLen);
}
public:
/// Copy assignment operator
class_type& operator =(class_type const& rhs);
/// @}
/// \name Accessors
/// @{
public:
/// Returns a non-mutating reference to find-data
find_data_type const &get_find_data() const;
#ifdef STLSOFT_OBSOLETE
/// Returns a non-mutating reference to find-data
///
/// \deprecated This method may be removed in a future release. get_find_data() should be used instead
find_data_type const &GetFindData() const; // Deprecated
#endif /* STLSOFT_OBSOLETE */
/// Returns the filename part of the item
char_type const *get_filename() const;
/// Returns the short form of the filename part of the item
char_type const *get_short_filename() const;
/// Returns the full path of the item
///
/// \note The path is not canonicalised, so will not be in canonical form if the filename is a
/// dots directory. For this you should use winstl::path, and call canonicalise()
char_type const *get_path() const;
/// Returns the full path of the item
///
/// \note The path is not canonicalised, so will not be in canonical form if the filename is a
/// dots directory. For this you should use winstl::path, and call canonicalise()
char_type const *c_str() const;
/// Returns the length of the full path
ws_size_t length() const;
/// Implicit conversion to a pointer-to-const of the full path
///
/// \note The path is not canonicalised, so will not be in canonical form if the filename is a
/// dots directory. For this you should use winstl::path, and call canonicalise()
///
/// \deprecated This is provided for backwards compatibility with an earlier version, but since this
/// class does not have an implicit conversion constructor, it's pretty harmless.
operator char_type const* () const;
/// Indicates whether the entry is a directory
ws_bool_t is_directory() const;
/// Indicates whether the entry is a file
ws_bool_t is_file() const;
/// Indicates whether the entry is compressed
ws_bool_t is_compressed() const;
#ifdef FILE_ATTRIBUTE_REPARSE_POINT
/// Indicates whether the entry is a reparse point
ws_bool_t is_reparse_point() const;
#endif /* FILE_ATTRIBUTE_REPARSE_POINT */
/// Indicates whether the entry is read-only
ws_bool_t is_read_only() const;
/// Indicates whether the entry is a system file/directory
ws_bool_t is_system() const;
/// Indicates whether the entry is hidden
ws_bool_t is_hidden() const;
/// @}
/// \name Comparison
/// @{
public:
/// \brief Determines whether the instance is equal to the given path
ws_bool_t equal(char_type const* rhs) const;
/// \brief Determines whether two instances are equal
ws_bool_t equal(class_type const& rhs) const;
/// @}
/// \name Members
/// @{
private:
friend class basic_findfile_sequence_const_input_iterator<C, T, class_type>;
typedef basic_file_path_buffer<char_type> file_path_buffer_type_;
find_data_type m_data;
file_path_buffer_type_ m_path;
ws_size_t m_pathLen;
/// @}
};
// class basic_findfile_sequence_const_input_iterator
/** \brief Iterator type for the basic_findfile_sequence supporting the Input Iterator concept
*
* \ingroup group__library__filesystem
*/
template< ss_typename_param_k C
, ss_typename_param_k T
, ss_typename_param_k V
>
class basic_findfile_sequence_const_input_iterator
#ifndef STLSOFT_COMPILER_IS_WATCOM
: 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
>
#endif /* compiler */
{
/// \name Member Types
/// @{
private:
typedef basic_findfile_sequence<C, T> sequence_type;
public:
/// The character type
typedef C char_type;
/// The traits type
typedef T traits_type;
/// The value type
typedef V value_type;
/// The current parameterisation of the type
typedef basic_findfile_sequence_const_input_iterator<C, T, V> class_type;
/// The find-data type
typedef ss_typename_type_k traits_type::find_data_type find_data_type;
/// The size type
typedef ss_typename_type_k sequence_type::size_type size_type;
private:
typedef ss_typename_type_k sequence_type::bool_type bool_type;
typedef ss_typename_type_k sequence_type::flags_type flags_type;
/// @}
/// \name Utility classes
/// @{
private:
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
struct shared_handle
{
/// \name Member Types
/// @{
public:
typedef shared_handle class_type;
typedef HANDLE handle_type;
/// @}
/// \name Members
/// @{
public:
handle_type hSrch;
private:
ss_sint32_t m_refCount;
/// @}
/// \name Construction
/// @{
public:
ss_explicit_k shared_handle(handle_type h)
: hSrch(h)
, m_refCount(1)
{}
# 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 == m_refCount);
if(INVALID_HANDLE_VALUE != hSrch)
{
traits_type::find_file_close(hSrch);
}
}
/// @}
/// \name Operations
/// @{
public:
ss_sint32_t AddRef()
{
return ++m_refCount;
}
ss_sint32_t Release()
{
ss_sint32_t rc = --m_refCount;
if(0 == rc)
{
delete this;
}
return rc;
}
/// @}
/// \name Not to be implemented
/// @{
private:
shared_handle(class_type const&);
class_type& operator =(class_type const&);
/// @}
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// @}
/// \name Construction
/// @{
private:
basic_findfile_sequence_const_input_iterator( sequence_type const& l
, char_type const *patterns
, char_type delim
, flags_type flags);
basic_findfile_sequence_const_input_iterator(sequence_type const& l);
public:
/// Default constructor
basic_findfile_sequence_const_input_iterator();
/// <a href = "http://synesis.com.au/resources/articles/cpp/movectors.pdf">Move constructor</a>
basic_findfile_sequence_const_input_iterator(class_type const& rhs);
/// Destructor
~basic_findfile_sequence_const_input_iterator() stlsoft_throw_0();
// Copy assignment operator
basic_findfile_sequence_const_input_iterator& operator =(class_type const& rhs);
/// @}
/// \name Input Iterator methods
/// @{
public:
/// Pre-increment operator
class_type& operator ++();
/// Post-increment operator
class_type operator ++(int);
/// Dereference to return the value at the current position
const value_type operator *() const;
/// Evaluates whether \c this and \c rhs are equivalent
ws_bool_t equal(class_type const& rhs) const;
/// @}
/// \name Implementation
/// @{
private:
static HANDLE find_first_file_(char_type const* spec, flags_type flags, find_data_type *findData);
/// @}
/// \name Members
/// @{
private:
friend class basic_findfile_sequence<C, T>;
typedef basic_file_path_buffer<char_type> file_path_buffer_type_;
sequence_type const* const m_list;
shared_handle *m_handle;
ss_typename_type_k traits_type::find_data_type m_data;
file_path_buffer_type_ m_subpath;
size_type m_subPathLen;
char_type const *m_pattern0;
char_type const *m_pattern1;
char_type m_delim;
flags_type m_flags;
/// @}
};
////////////////////////////////////////////////////////////////////////////
// Operators
// basic_findfile_sequence_const_input_iterator
template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
inline ws_bool_t operator ==( basic_findfile_sequence_const_input_iterator<C, T, V> const& lhs
, basic_findfile_sequence_const_input_iterator<C, T, V> const& rhs)
{
return lhs.equal(rhs);
}
template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
inline ws_bool_t operator !=( basic_findfile_sequence_const_input_iterator<C, T, V> const& lhs
, basic_findfile_sequence_const_input_iterator<C, T, V> const& rhs)
{
return !lhs.equal(rhs);
}
// basic_findfile_sequence_value_type
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -