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

📄 functionals.hpp

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 HPP
📖 第 1 页 / 共 2 页
字号:
    /// \note The comparison is determined by evaluation the full-paths of both \c s1 and \c s2
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
    template<ss_typename_param_k T1, ss_typename_param_k T2>
    result_type operator ()(T1 const &s1, T2 const &s2) const
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    result_type operator ()(first_argument_type s1, second_argument_type s2) const
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    {
        return are_paths_equal_envx_(stlsoft_ns_qual(c_str_ptr)(s1), stlsoft_ns_qual(c_str_ptr)(s2), false);
    }
/// @}
};

/// \brief Binary predicate object that compares two file-system paths,
/// after expanding environment variables in the compared path strings.
///
/// \note Does not expand environment variables in the argument passed to
/// the function call operator
///
/// \param C The character type
/// \param A1 The left-hand argument type; defaults to C const*
/// \param A2 The right-hand argument type; defaults to C const*
template<   ss_typename_param_k C
        ,   ss_typename_param_k A1 = C const *
        ,   ss_typename_param_k A2 = C const *
        >
// [[synesis:class:function-class:binary-predicate: path_compare_env<T<C>, T<A1>, T<A2>>]]
struct path_compare_env
    : public winstl_ns_qual_std(binary_function)<A1, A2, ws_bool_t>
{
/// \name Member Types
/// @{
private:
    typedef winstl_ns_qual_std(binary_function)<A1, A2, ws_bool_t>      parent_class_type;
public:
    /// The character type
    typedef C                                                           char_type;
    /// The first argument type
    typedef ss_typename_type_k parent_class_type::first_argument_type   first_argument_type;
    /// The second argument type
    typedef ss_typename_type_k parent_class_type::second_argument_type  second_argument_type;
    /// The result type
    typedef ss_typename_type_k parent_class_type::result_type           result_type;
    /// The current parameterisation of the type
    typedef path_compare_env<C, A1, A2>                                 class_type;
/// @}

/// \name Operations
/// @{
public:
    /// Function call, compares \c s1 with \c s2
    ///
    /// \note The comparison is determined by evaluation the full-paths of both \c s1 and \c s2
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
    template<ss_typename_param_k T1, ss_typename_param_k T2>
    result_type operator ()(T1 const &s1, T2 const &s2) const
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    result_type operator ()(first_argument_type s1, second_argument_type s2) const
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    {
        return are_paths_equal_envx_(stlsoft_ns_qual(c_str_ptr)(s1), stlsoft_ns_qual(c_str_ptr)(s2), true);
    }
/// @}
};

/// \brief Unary predicate that indicates whether a given path exists.
///
/// \note Does not expand environment variables in the argument passed to
/// the function call operator
///
/// \param C The character type
/// \param A The argument type; defaults to C const*
template<   ss_typename_param_k C
        ,   ss_typename_param_k A = C const *
        >
// [[synesis:class:function-class:unary-predicate: path_exists<T<C>, T<A>>]]
struct path_exists
    : public winstl_ns_qual_std(unary_function)<A, ws_bool_t>
{
/// \name Member Types
/// @{
private:
    typedef winstl_ns_qual_std(unary_function)<A, ws_bool_t>    parent_class_type;
public:
    /// The character type
    typedef C                                                   char_type;
    /// The argument type
    typedef A                                                   argument_type;
    /// The current parameterisation of the type
    typedef path_exists<C, A>                                   class_type;
/// @}

/// \name Operations
/// @{
public:
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
    template <ss_typename_param_k S>
    ws_bool_t operator ()(S const &s) const
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    ws_bool_t operator ()(argument_type s) const
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    {
        return file_exists_envx_(stlsoft_ns_qual(c_str_ptr)(s), false);
    }
/// @}
};

/// \brief Unary predicate that indicates whether a given path exists, after
/// expanding environment variables in the path string.
///
/// \note Expands environment variables in the argument passed to
/// the function call operator
///
/// \param C The character type
/// \param A The argument type; defaults to C const*
template<   ss_typename_param_k C
        ,   ss_typename_param_k A = C const *
        >
// [[synesis:class:function-class:unary-predicate: path_exists_env<T<C>, T<A>>]]
struct path_exists_env
    : public winstl_ns_qual_std(unary_function)<A, ws_bool_t>
{
/// \name Member Types
/// @{
private:
    typedef winstl_ns_qual_std(unary_function)<A, ws_bool_t>    parent_class_type;
public:
    /// The character type
    typedef C                                                   char_type;
    /// The argument type
    typedef A                                                   argument_type;
    /// The current parameterisation of the type
    typedef path_exists_env<C, A>                               class_type;
/// @}

/// \name Operations
/// @{
public:
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
    template <ss_typename_param_k S>
    ws_bool_t operator ()(S const &s) const
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    ws_bool_t operator ()(argument_type s) const
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    {
        return file_exists_envx_(stlsoft_ns_qual(c_str_ptr)(s), true);
    }
/// @}
};


/// \brief Unary predicate that searches for the existance of a given file
///  in the directory presented in its function call argument.
///
/// \param C The character type
/// \param A The argument type; defaults to C const*

/// \note The file-name passed to the constructor is retained as a pointer,
///  rather than an instance of a string class. Consequently, the behaviour
///  is undefined if the memory pointed to by the constructor argument does
///  not persist for the lifetime of the function object.
template<   ss_typename_param_k C
        ,   ss_typename_param_k A = C const *
        >
// [[synesis:class:function-class:unary-predicate: path_contains_file<T<C>, T<A>>]]
struct path_contains_file
    : public winstl_ns_qual_std(unary_function)<A, ws_bool_t>
{
/// \name Member Types
/// @{
private:
    typedef winstl_ns_qual_std(unary_function)<A, ws_bool_t>    parent_class_type;
public:
    /// The character type
    typedef C                                                   char_type;
    /// The argument type
    typedef A                                                   argument_type;
    /// The current parameterisation of the type
    typedef path_contains_file<C, A>                            class_type;
/// @}

/// \name Construction
/// @{
public:
    path_contains_file(char_type const *file)
        : m_file(file)
    {}
/// @}

/// \name Operations
/// @{
public:
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
    template <ss_typename_param_k S>
    ws_bool_t operator ()(S const &s) const
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    ws_bool_t operator ()(argument_type s) const
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
    {
        return path_contains_file_(stlsoft_ns_qual(c_str_ptr)(s), m_file);
    }
/// @}

/// \name Implementation
/// @{
private:
    static ws_bool_t path_contains_file_(char_type const *directory, char_type const *file)
    {
        typedef filesystem_traits<char_type>            traits_t;
        typedef stlsoft_ns_qual(auto_buffer)<char_type> buffer_t;

        const size_t    cchDirectory    =   traits_t::str_len(directory);
        const size_t    cchFile         =   traits_t::str_len(file);
        buffer_t        path(1 + cchDirectory + 1 + cchFile + 1);

        traits_t::str_copy(&path[0], directory);
        traits_t::ensure_dir_end(&path[0]);
        traits_t::str_cat(&path[0], file);

        return traits_t::file_exists(path.data());
    }
/// @}

/// \name Members
/// @{
private:
    char_type const *m_file;
/// @}
};

////////////////////////////////////////////////////////////////////////////
// Unit-testing

#ifdef STLSOFT_UNITTEST
# include "./unittest/functionals_unittest_.h"
#endif /* STLSOFT_UNITTEST */

/* ////////////////////////////////////////////////////////////////////// */

#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace winstl
# else
} // namespace winstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */

/* ////////////////////////////////////////////////////////////////////// */

#endif /* WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FUNCTIONALS */

/* ////////////////////////////////////////////////////////////////////// */

⌨️ 快捷键说明

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