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

📄 filesystem_traits.hpp

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 HPP
📖 第 1 页 / 共 3 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        inetstl/filesystem_traits.hpp (formerly inetstl_filesystem_traits.h; originally MInetEnm.h)
 *
 * Purpose:     Contains the filesystem_traits template class, and ANSI and
 *              Unicode specialisations thereof.
 *
 * Created:     30th April 1999
 * Updated:     11th June 2006
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 1999-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 inetstl/filesystem_traits.hpp
///
/// Contains the filesystem_traits template class, and ANSI and Unicode specialisations thereof.

#ifndef INETSTL_INCL_INETSTL_HPP_FILESYSTEM_TRAITS
#define INETSTL_INCL_INETSTL_HPP_FILESYSTEM_TRAITS

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define INETSTL_VER_INETSTL_HPP_FILESYSTEM_TRAITS_MAJOR    3
# define INETSTL_VER_INETSTL_HPP_FILESYSTEM_TRAITS_MINOR    3
# define INETSTL_VER_INETSTL_HPP_FILESYSTEM_TRAITS_REVISION 2
# define INETSTL_VER_INETSTL_HPP_FILESYSTEM_TRAITS_EDIT     55
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Includes
 */

#ifndef INETSTL_INCL_INETSTL_H_INETSTL
# include <inetstl/inetstl.h>
#endif /* !INETSTL_INCL_INETSTL_H_INETSTL */
#ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
# include <stlsoft/conversion/sap_cast.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST */
#ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_ANY_CAST
# include <stlsoft/conversion/any_cast.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_ANY_CAST */
#include <string.h>
#include <wchar.h>

/* /////////////////////////////////////////////////////////////////////////
 * Namespace
 */

#ifndef _INETSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::inetstl */
namespace inetstl
{
# else
/* Define stlsoft::inetstl_project */

namespace stlsoft
{

namespace inetstl_project
{

# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_INETSTL_NO_NAMESPACE */

/* /////////////////////////////////////////////////////////////////////////
 * Classes
 */

#ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
/// Traits for accessing the correct file-system functions for a given character type
///
/// filesystem_traits is a traits class for determining the correct file-system
/// structures and functions for a given character type.
///
/// \param C The character type
template <ss_typename_param_k C>
struct filesystem_traits
{
/// \name Member Types
/// @{
public:
    /// The character type
    typedef C                       char_type;
    /// The size type
    typedef is_size_t               size_type;
    /// The difference type
    typedef is_ptrdiff_t            difference_type;
    /// The find data type
    typedef WIN32_FIND_DATA         find_data_type;
    /// The stat data type
    typedef WIN32_FIND_DATA         stat_data_type;
    /// The current instantion of the type
    typedef filesystem_traits<C>    class_type;
    /// The (signed) integer type
    typedef is_int_t                int_type;
    /// The Boolean type
    typedef is_bool_t               bool_type;
    /// The type of system error codes
    typedef DWORD                   error_type;
/// @}

/// \name Constants
/// @{
public:
/// @}

/// \name General string handling
/// @{
public:
    /// Copies the contents of \c src to \c dest
    static char_type    *str_copy(char_type *dest, char_type const *src);
    /// Copies the contents of \c src to \c dest, up to cch \c characters
    static char_type    *str_n_copy(char_type *dest, char_type const *src, is_size_t cch);
    /// Appends the contents of \c src to \c dest
    static char_type    *str_cat(char_type *dest, char_type const *src);
    /// Comparies the contents of \c src and \c dest
    static is_int_t     str_compare(char_type const *s1, char_type const *s2);
    /// Comparies the contents of \c src and \c dest in a case-insensitive fashion
    static is_int_t     str_compare_no_case(char_type const *s1, char_type const *s2);
    /// Evaluates the length of \c src
    static size_type    str_len(char_type const *src);
    /// Finds the given character \c ch in \c s
    static char_type    *str_chr(char_type const *s, char_type ch);
    /// Finds the rightmost instance \c ch in \c s
    static char_type    *str_rchr(char_type const *s, char_type ch);
    /// Finds the given substring \c sub in \c s
    static char_type    *str_str(char_type const *s, char_type const *sub);
/// @}

/// \name File-system entry names
/// @{
public:
    /// Appends a path name separator to \c dir if one does not exist
    ///
    /// \see \link #path_name_separator path_name_separator() \endlink
    static char_type    *ensure_dir_end(char_type *dir);
    /// Removes the path name separator from the end of \c dir, if it has it
    ///
    /// \see \link #path_name_separator path_name_separator() \endlink
    static char_type    *remove_dir_end(char_type *dir);
    /// Returns \c true if \c dir has trailing path name separator
    ///
    /// \see \link #path_name_separator path_name_separator() \endlink
    static bool_type    has_dir_end(char_type const *dir);

    /// Returns \c true if dir is \c "." or \c ".."
    static bool_type    is_dots(char_type const *dir);
    /// Returns \c true if path is rooted
    static bool_type    is_path_rooted(char_type const *path);
    /// Returns \c true if path is an absolute path
    static bool_type    is_path_absolute(char_type const *path);

    /// Returns the path separator
    ///
    /// This is the separator that is used to separate multiple paths on the operating system. On UNIX it is ':'
    static char_type    path_separator();
    /// Returns the path name separator
    ///
    /// This is the separator that is used to separate parts of a path on the operating system. On UNIX it is '/'
    static char_type    path_name_separator();
    /// Returns the wildcard pattern that represents all possible matches
    ///
    /// \note It is '*'
    static char_type const *pattern_all();
    /// Gets the full path name into the given buffer, returning a pointer to the file-part
    static is_dword_t   get_full_path_name(HINTERNET hconn, char_type const *fileName, is_dword_t cchBuffer, char_type *buffer, char_type **ppFile);
    /// Gets the full path name into the given buffer
    static is_dword_t   get_full_path_name(HINTERNET hconn, char_type const *fileName, is_dword_t cchBuffer, char_type *buffer);
/// @}

/// \name Internet connectivity
/// @{
public:
    /// Opens a WinInet session
    static HINTERNET    internet_open(char_type const *agent, is_dword_t accessType, char_type const *proxy, char_type const *proxyBypass, is_dword_t flags);
    /// Makes a connection to a FTP or HTTP site
    static HINTERNET    internet_connect(HINTERNET hsess, char_type const *server, INTERNET_PORT port, char_type const *userName, char_type const *password, is_dword_t service, is_dword_t flags, is_dword_t context);
    /// Closes the connection to the FTP or HTTP site
    static void         close_connection(HINTERNET hconn);
/// @}

/// \name File-system enumeration
/// @{
public:
    /// Initiate a file-system search
    static HINTERNET    find_first_file(HINTERNET hconn, char_type const *spec, find_data_type *findData, is_dword_t flags = 0, is_dword_t context = 0);
    /// Advance a given file-system search
    static bool_type    find_next_file(HANDLE h, find_data_type *findData);
    /// Closes the file-search
    static void         find_close(HINTERNET hfind);
/// @}

/// \name File-system state
/// @{
public:
    /// Sets the current directory to \c dir
    static bool_type    set_current_directory(HINTERNET hconn, char_type const *dir);
    /// Retrieves the name of the current directory into \c buffer up to a maximum of \c cchBuffer characters
    static bool_type    get_current_directory(HINTERNET hconn, is_size_t &cchBuffer, char_type *buffer);

    /// Returns whether a file exists or not
    static bool_type    file_exists(HINTERNET hconn, char_type const *fileName);
    /// Returns whether the given path represents a file
    static bool_type    is_file(HINTERNET hconn, char_type const *path);
    /// Returns whether the given path represents a directory
    static bool_type    is_directory(HINTERNET hconn, char_type const *path);
    /// Gets the information for a particular file system entry
    static bool_type    stat(HINTERNET hconn, char_type const *path, stat_data_type *stat_data);

    /// Returns whether the given stat info represents a file
    static bool_type    is_file(stat_data_type const *stat_data);
    /// Returns whether the given stat info represents a directory
    static bool_type    is_directory(stat_data_type const *stat_data);
    /// Returns whether the given stat info represents a link
    static bool_type    is_link(stat_data_type const *stat_data);
    /// Returns whether the given stat info represents a read-only entry
    static bool_type    is_readonly(stat_data_type const *stat_data);
/// @}

/// \name File-system control
/// @{
public:
    /// Creates a directory
    static bool_type    create_directory(HINTERNET hconn, char_type const *dir);
    /// Deletes a directory
    static bool_type    remove_directory(HINTERNET hconn, char_type const *dir);

    /// Delete a file
    static bool_type    delete_file(HINTERNET hconn, char_type const *file);
    /// Rename a file
    static bool_type    rename_file(HINTERNET hconn, char_type const *currentName, char_type const *newName);
/// @}
};

#else /* ? STLSOFT_DOCUMENTATION_SKIP_SECTION */

template <ss_typename_param_k C>
struct filesystem_traits;

STLSOFT_TEMPLATE_SPECIALISATION
struct filesystem_traits<is_char_a_t>
{
public:
    typedef is_char_a_t                     char_type;
    typedef is_size_t                       size_type;
    typedef is_ptrdiff_t                    difference_type;
    typedef WIN32_FIND_DATAA                find_data_type;
    typedef WIN32_FIND_DATAA                stat_data_type;
    typedef filesystem_traits<is_char_a_t>  class_type;
    typedef is_int_t                        int_type;
    typedef is_bool_t                       bool_type;
    typedef DWORD                           error_type;

public:
    // General string handling
    static char_type *str_copy(char_type *dest, char_type const *src)
    {
        return ::lstrcpyA(dest, src);
    }

    static char_type *str_n_copy(char_type *dest, char_type const *src, is_size_t cch)
    {
        return strncpy(dest, src, cch);
    }

    static char_type *str_cat(char_type *dest, char_type const *src)
    {
        return ::lstrcatA(dest, src);
    }

    static is_int_t str_compare(char_type const *s1, char_type const *s2)
    {
        return ::lstrcmpA(s1, s2);
    }

    static is_int_t str_compare_no_case(char_type const *s1, char_type const *s2)

⌨️ 快捷键说明

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