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

📄 reg_key_sequence.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 4 页
字号:
    ///
    /// \return An iterator representing the start of the reverse sequence
    reverse_iterator  rbegin();
    /// \brief Ends the reverse iteration
    ///
    /// \return An iterator representing the end of the reverse sequence
    reverse_iterator  rend();
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
/// @}

/// \name Attributes
/// @{
public:
    /// \brief Returns the number of sub-keys
    ///
    /// \note This gives a result valid only at the epoch of the call. A
    /// subsequent call may return a different result.
    size_type               current_size() const;
    /// \brief Returns the number of sub-keys
    ///
    /// \deprecated This is equivalent to current_size()
    size_type               size() const;
    /// \brief Evalulates whether there are no sub-keys
    ws_bool_t               empty() const;

    /// \brief The key handle
    hkey_type               get_key_handle() const;
    /// \brief The key handle
    hkey_type               get() const;
/// @}

/// \name Implementation
/// @{
private:
    registry_util::shared_handle    *create_shared_handle_(result_type &res);
    static REGSAM                   validate_access_mask_(REGSAM accessMask, bool_type bMonitorExternalInvalidation);
    static hkey_type                dup_key_(hkey_type hkey, REGSAM accessMask/* , result_type *result */);
/// @}

/// \name Members
/// @{
private:
    hkey_type       m_hkey;
    const REGSAM    m_accessMask;
    const bool_type m_bMonitorExternalInvalidation;
/// @}

/// \name Not to be implemented
/// @{
private:
    basic_reg_key_sequence(class_type const&);
    class_type& operator =(class_type const&);
/// @}
};

/* Typedefs to commonly encountered types. */
/** \brief Specialisation of the basic_reg_key_sequence template for the ANSI character type \c char
 *
 * \ingroup group__library__windows_registry
 */
typedef basic_reg_key_sequence<ws_char_a_t, reg_traits<ws_char_a_t>, processheap_allocator<ws_char_a_t> > reg_key_sequence_a;
/** \brief Specialisation of the basic_reg_key_sequence template for the Unicode character type \c wchar_t
 *
 * \ingroup group__library__windows_registry
 */
typedef basic_reg_key_sequence<ws_char_w_t, reg_traits<ws_char_w_t>, processheap_allocator<ws_char_w_t> > reg_key_sequence_w;
/** \brief Specialisation of the basic_reg_key_sequence template for the Win32 character type \c TCHAR
 *
 * \ingroup group__library__windows_registry
 */
typedef basic_reg_key_sequence<TCHAR, reg_traits<TCHAR>, processheap_allocator<TCHAR> >                   reg_key_sequence;

// class basic_reg_key_sequence_iterator
/** \brief Iterator for the basic_reg_key_sequence class
 *
 * \ingroup group__library__windows_registry
 *
 * \param C The character type
 * \param T The traits type
 * \param V The value type
 * \param A The allocator type
 */
template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k V
        ,   ss_typename_param_k A
        >
class basic_reg_key_sequence_iterator
    : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(bidirectional_iterator_tag)
                                        ,   V
                                        ,   ws_ptrdiff_t
                                        ,   void    // By-Value Temporary reference
                                        ,   V       // By-Value Temporary reference
                                        >
{
/// \name Member Types
/// @{
public:
    /// \brief The character type
    typedef C                                                           char_type;
    /// \brief The traits type
    typedef T                                                           traits_type;
    /// \brief The value type
    typedef V                                                           value_type;
    /// \brief The allocator type
    typedef A                                                           allocator_type;
    /// \brief The current parameterisation of the type
    typedef basic_reg_key_sequence_iterator<C, T, V, A>                 class_type;
    /// \brief The size type
    typedef ss_typename_type_k traits_type::size_type                   size_type;
    /// \brief The difference type
    typedef ss_typename_type_k traits_type::difference_type             difference_type;
    /// \brief The string type
    typedef ss_typename_type_k traits_type::string_type                 string_type;
    /// \brief The index type
    typedef ws_sint32_t                                                 index_type;
    /// \brief The hkey type
    typedef ss_typename_type_k traits_type::hkey_type                   hkey_type;
private:
    /// \brief The results type of the Registry API
    typedef ss_typename_type_k traits_type::result_type                 result_type;
    /// \brief The Boolean type
    typedef ws_bool_t                                                   bool_type;
private:
    typedef stlsoft_ns_qual(auto_buffer_old)<   char_type
                                            ,   allocator_type
                                            ,   CCH_REG_API_AUTO_BUFFER
                                            >                           buffer_type_;
/// @}

/// \name Construction
/// @{
private:
    friend class basic_reg_key_sequence<C, T, A>;

    /// \note Eats the key, rather than taking a copy
    basic_reg_key_sequence_iterator(registry_util::shared_handle *handle, char_type const* name, size_type cchName, index_type index, REGSAM accessMask)
        : m_handle(handle)
        , m_index(index)
        , m_name(name, cchName)
        , m_accessMask(accessMask)
    {
        WINSTL_ASSERT(NULL != m_handle);
        m_handle->test_reset_and_throw();
        m_handle->AddRef();
    }
public:
    /// \brief Default constructor
    basic_reg_key_sequence_iterator();
    /// \brief Copy constructor
    basic_reg_key_sequence_iterator(class_type const& rhs);
    /// \brief Destructor
    ~basic_reg_key_sequence_iterator() stlsoft_throw_0();

    /// \brief Copy assignment operator
    class_type& operator =(class_type const& rhs);
/// @}

/// \name Accessors
/// @{
public:
    string_type const   &get_key_name() const;
/// @}

/// \name Operators
/// @{
public:
    /// \brief Pre-increment operator
    class_type& operator ++();
    /// \brief Pre-decrement operator
    class_type& operator --();
    /// \brief Post-increment operator
    const class_type operator ++(int);
    /// \brief Post-decrement operator
    const class_type operator --(int);
    /// \brief Dereference to return the value representing the current position
    const value_type operator *() const;
    /// \brief Evaluates whether \c this and \c rhs are equivalent
    ws_bool_t equal(class_type const& rhs) const;
    /// \brief Evaluates whether \c this and \c rhs are equivalent
    ws_bool_t operator ==(class_type const& rhs) const;
    /// \brief Evaluates whether \c this and \c rhs are not equivalent
    ws_bool_t operator !=(class_type const& rhs) const;
/// @}

/// \name Implementation
/// @{
private:
    static index_type sentinel_() stlsoft_throw_0();
/// @}

/// \name Members
/// @{
private:
    registry_util::shared_handle    *m_handle;      // Shared context for registry key and event object
    index_type                      m_index;        // Current iteration index
    string_type                     m_name;         // The value name
    REGSAM                          m_accessMask;   // Security access mask
/// @}
};

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

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

////////////////////////////////////////////////////////////////////////////
// Implementation

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

// basic_reg_key_sequence

template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k A>
inline registry_util::shared_handle *basic_reg_key_sequence<C, T, A>::create_shared_handle_(result_type &res)
{
    // 1. Duplicate the registry handle
    //
    // 2. create the shared_handle

    hkey_type   hkey2   =   traits_type::key_dup(m_hkey, m_accessMask, &res);

    if(NULL == hkey2)
    {
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
        STLSOFT_THROW_X(registry_exception("Failed to take duplicate of key", static_cast<DWORD>(res)));
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
    ; // This will fall through to the end() call at the end of the function
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
    }
    else
    {
        // Pop it in a scoped handle for RAII
        scoped_handle<HKEY>             sh(hkey2, ::RegCloseKey);
        registry_util::shared_handle    *handle =   registry_util::create_shared_handle(hkey2, m_bMonitorExternalInvalidation, REG_NOTIFY_CHANGE_NAME);

        if(NULL == handle)
        {
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
            STLSOFT_THROW_X(registry_exception("Failed to create shared enumeration context", ::GetLastError()));
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
            ; // This will fall through to the end() call at the end of the function
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
        }
        else
        {
            sh.detach();

            return handle;
        }
    }

    return NULL;
}

template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k A>
inline /* static */ REGSAM basic_reg_key_sequence<C, T, A>::validate_access_mask_(REGSAM accessMask, ss_typename_type_k basic_reg_key_sequence<C, T, A>::bool_type bMonitorExternalInvalidation)
{
    if(bMonitorExternalInvalidation)
    {
        return accessMask | KEY_NOTIFY;
    }
    else
    {
        return accessMask & ~(KEY_NOTIFY);
    }
}

template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k A>
inline /* static */ ss_typename_type_k basic_reg_key_sequence<C, T, A>::hkey_type basic_reg_key_sequence<C, T, A>::dup_key_(ss_typename_type_k basic_reg_key_sequence<C, T, A>::hkey_type hkey, REGSAM accessMask/* , ss_typename_type_k basic_reg_key_sequence<C, T, A>::result_type *result */)
{
    result_type result;
    HKEY        hkeyDup =   traits_type::key_dup(hkey, accessMask, &result);

    if(ERROR_SUCCESS != result)
    {
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
        STLSOFT_THROW_X(registry_exception("Could not duplicate key", result));
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
        hkeyDup = NULL;
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
    }

    return hkeyDup;
}

template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k A>
inline basic_reg_key_sequence<C, T, A>::basic_reg_key_sequence( ss_typename_type_k basic_reg_key_sequence<C, T, A>::hkey_type           hkey

⌨️ 快捷键说明

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