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

📄 findfile_sequence.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 4 页
字号:
 */
template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        >
class basic_findfile_sequence_value_type
{
/// \name Member Types
/// @{
private:
    typedef basic_findfile_sequence<C, T, X>                        sequence_type;
public:
    /// The character type
    typedef C                                                       char_type;
    /// The exception policy type
    typedef X                                                       exception_policy_type;
    /// The type thrown
    typedef ss_typename_param_k exception_policy_type::thrown_type  thrown_type;
    /// The traits type
    typedef T                                                       traits_type;
    /// The current parameterisation of the type
    typedef basic_findfile_sequence_value_type<C, T, X>             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;
    typedef stlsoft_ns_qual(basic_simple_string)<char_type>         string_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* path)
        : m_data(data)
    {
        if('/' != data.cFileName[0])
        {
            traits_type::str_copy(m_path, path);
            traits_type::ensure_dir_end(m_path);
        }
        else
        {
            m_path[0] = '\0';
        }
        traits_type::str_cat(m_path, data.cFileName);
    }
// @}

/** \brief Accessors
 *
 * \ingroup group__library__filesystem
 */
// @{
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
    char_type const         *get_path() const;
    /// Returns the full path of the item
    char_type const         *c_str() const;

    /// Implicit conversion to a pointer-to-const of the full path
    operator char_type const* () const;

    /// Indicates whether the entry is a directory
    is_bool_t               is_directory() const;
    /// Indicates whether the entry is a file
    is_bool_t               is_file() const;
    /// Indicates whether the entry is read-only
    is_bool_t               is_read_only() const;

    is_bool_t               equal(char_type const* rhs) const;
    is_bool_t               equal(class_type const& rhs) const;
// @}

/// \name Members
/// @{
private:
    friend class basic_findfile_sequence_const_input_iterator<C, T, X, class_type>;

    find_data_type  m_data;
    char_type       m_path[1 + _MAX_PATH];
/// @}
};

// 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 X
        ,   ss_typename_param_k V
        >
class basic_findfile_sequence_const_input_iterator
#ifndef STLSOFT_COMPILER_IS_WATCOM
    : public stlsoft_ns_qual(iterator_base)<inetstl_ns_qual_std(input_iterator_tag)
                                        ,   V
                                        ,   is_ptrdiff_t
                                        ,   void    // By-Value Temporary reference
                                        ,   V       // By-Value Temporary reference
                                        >
#endif /* compiler */
{
/// \name Member Types
/// @{
private:
    typedef basic_findfile_sequence<C, T, X>                            sequence_type;
public:
    /// The character type
    typedef C                                                           char_type;
    /// The exception policy type
    typedef X                                                           exception_policy_type;
    /// The type thrown
    typedef ss_typename_param_k exception_policy_type::thrown_type      thrown_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, X, 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;
    typedef ss_typename_type_k sequence_type::string_type               string_type;
/// @}

/// \name Utility classes
/// @{
private:
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
    struct shared_handle
    {
    /// \name Member Types
    /// @{
    public:
        typedef shared_handle       class_type;
        typedef HINTERNET           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()
        {
            INETSTL_MESSAGE_ASSERT("Shared search handle being destroyed with outstanding references!", 0 == m_refCount);

            if(NULL != hSrch)
            {
                traits_type::find_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     *rootDir
                                                ,   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
    is_bool_t equal(class_type const& rhs) const;
/// @}

/// \name Implementation
/// @{
private:
    static int          find_next_pattern_(char_type const*& p0, char_type const*& p1, char_type delim);
    static HINTERNET    find_first_file_(HINTERNET hconn, char_type const* spec, flags_type flags, find_data_type *findData);
/// @}

/// \name Members
/// @{
private:
    friend class basic_findfile_sequence<C, T, X>;

    sequence_type const* const                      m_list;
    shared_handle                                   *m_handle;
    ss_typename_type_k traits_type::find_data_type  m_data;
    char_type const*                                m_rootDir;
    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 X
        ,   ss_typename_param_k V
        >
inline is_bool_t operator ==(   basic_findfile_sequence_const_input_iterator<C, T, X, V> const& lhs
                            ,   basic_findfile_sequence_const_input_iterator<C, T, X, V> const& rhs)
{
    return lhs.equal(rhs);
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        ,   ss_typename_param_k V
        >
inline is_bool_t operator !=(   basic_findfile_sequence_const_input_iterator<C, T, X, V> const& lhs
                            ,   basic_findfile_sequence_const_input_iterator<C, T, X, V> const& rhs)
{
    return !lhs.equal(rhs);
}

// basic_findfile_sequence_value_type

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        >
inline is_bool_t operator == (  basic_findfile_sequence_value_type<C, T, X> const&  lhs
                            ,   basic_findfile_sequence_value_type<C, T, X> const&  rhs)
{
    return lhs.equal(rhs);
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        >
inline is_bool_t operator == (  basic_findfile_sequence_value_type<C, T, X> const& lhs
                            ,   C const* rhs)
{
    return lhs.equal(rhs);
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        >
inline is_bool_t operator == (C const* lhs, basic_findfile_sequence_value_type<C, T, X> const& rhs)
{
    return rhs.equal(lhs);
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        >
inline is_bool_t operator != (  basic_findfile_sequence_value_type<C, T, X> const& lhs
                            ,   basic_findfile_sequence_value_type<C, T, X> const& rhs)
{
    return !lhs.equal(rhs);
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        >
inline is_bool_t operator != (  basic_findfile_sequence_value_type<C, T, X> const&  lhs
                            ,   C const* rhs)
{
    return !lhs.equal(rhs);
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k X
        >
inline is_bool_t operator != (  C const* lhs, basic_findfile_sequence_value_type<C, T, X> const& rhs)
{
    return !rhs.equal(lhs);
}

////////////////////////////////////////////////////////////////////////////
// Shims

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

template <ss_typename_param_k T, ss_typename_param_k X>
inline is_char_a_t const* c_str_data_a(inetstl_ns_qual(basic_findfile_sequence_value_type)<is_char_a_t, T, X> const& v)
{
    return v.get_path();

⌨️ 快捷键说明

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