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

📄 conversion_veneer.hpp

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        stlsoft/obsolete/conversion_veneer.hpp (formerly stlsoft_conversion_veneer.h)
 *
 * Purpose:     Raw conversion veneer class.
 *
 * Created:     30th July 2002
 * Updated:     10th June 2006
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 2002-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 stlsoft/obsolete/conversion_veneer.hpp
///
/// Raw conversion veneer class.

#ifndef STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_CONVERSION_VENEER
#define STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_CONVERSION_VENEER

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_CONVERSION_VENEER_MAJOR      3
# define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_CONVERSION_VENEER_MINOR      2
# define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_CONVERSION_VENEER_REVISION   1
# define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_CONVERSION_VENEER_EDIT       40
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

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

#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
#ifndef STLSOFT_INCL_STLSOFT_HPP_CONSTRAINTS
# include <stlsoft/constraints.hpp>   // for must_be_same_size constraint
#endif /* !STLSOFT_INCL_STLSOFT_HPP_CONSTRAINTS */

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

#ifndef _STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* _STLSOFT_NO_NAMESPACE */

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

// class invalid_conversion
/// Prevents any conversion
///
/// \param T The value type
/// \param C The conversion type
template<   ss_typename_param_k T
        ,   ss_typename_param_k C
        >
struct invalid_conversion
{
protected:
    /// The invalid type
    typedef void    invalid_type;
public:
    /// The value type
    typedef T       value_type;
    /// The conversion type
    typedef C       conversion_type;

public:
    /// Converts a pointer to the \c value_type to a pointer to the \c conversion_type
    static invalid_type convert_pointer(value_type * /* pv */)
    {}

    /// Converts a pointer-to-const to the \c value_type to a pointer-to-const to the \c conversion_type
    static invalid_type convert_const_pointer(value_type const * /* pv */)
    {}

    /// Converts a reference to the \c value_type to a reference to the \c conversion_type
    static invalid_type convert_reference(value_type &/* v */)
    {}

    /// Converts a reference-to-const to the \c value_type to a reference-to-const to the \c conversion_type
    static invalid_type convert_const_reference(value_type const &/* v */)
    {}

    /// Pointer conversion type
    struct pointer_conversion
    {
        invalid_type operator ()(value_type * /* pv */)
        {}
    };

    /// Pointer-to-const conversion type
    struct pointer_const_conversion
    {
        invalid_type operator ()(value_type const * /* pv */)
        {}
    };

    /// Reference conversion type
    struct reference_conversion
    {
        invalid_type operator ()(value_type &/* v */)
        {}
    };

    /// Reference-to-const conversion type
    struct reference_const_conversion
    {
        invalid_type operator ()(value_type const &/* v */)
        {}
    };

};

// class static_conversion
/// Implements conversion via C++'s <code>static_cast</code>
///
/// \param T The value type
/// \param C The conversion type
template<   ss_typename_param_k T
        ,   ss_typename_param_k C
        >
struct static_conversion
{
public:
    /// The value type
    typedef T       value_type;
    /// The conversion type
    typedef C       conversion_type;

public:
    /// Converts a pointer to the \c value_type to a pointer to the \c conversion_type
    static conversion_type *convert_pointer(value_type *pv)
    {
        return static_cast<conversion_type*>(pv);
    }

    /// Converts a pointer-to-const to the \c value_type to a pointer-to-const to the \c conversion_type
    static conversion_type const *convert_const_pointer(value_type const *pv)
    {
        return static_cast<conversion_type const*>(pv);
    }

    /// Converts a reference to the \c value_type to a reference to the \c conversion_type
    static conversion_type &convert_reference(value_type &v)
    {
        return static_cast<conversion_type&>(v);
    }

    /// Converts a reference-to-const to the \c value_type to a reference-to-const to the \c conversion_type
    static conversion_type const &convert_const_reference(value_type const &v)
    {
        return static_cast<conversion_type const&>(v);
    }

    /// Pointer conversion type
    struct pointer_conversion
    {
        conversion_type *operator ()(value_type *pv)
        {
            return convert_pointer(pv);
        }
    };

    /// Pointer-to-const conversion type
    struct pointer_const_conversion
    {
        conversion_type const *operator ()(value_type const *pv)
        {
            return convert_const_pointer(pv);
        }
    };

    /// Reference conversion type
    struct reference_conversion
    {
        conversion_type &operator ()(value_type &v)
        {
            return convert_reference(v);
        }
    };

    /// Reference-to-const conversion type
    struct reference_const_conversion
    {
        conversion_type const &operator ()(value_type const &v)
        {
            return convert_const_reference(v);
        }
    };

};

// class dynamic_conversion
/// Implements conversion via C++'s <code>dynamic_cast</code>
///
/// \param T The value type
/// \param C The conversion type
template<   ss_typename_param_k T
        ,   ss_typename_param_k C
        >
struct dynamic_conversion
{
public:
    /// The value type
    typedef T       value_type;
    /// The conversion type
    typedef C       conversion_type;

public:
    /// Converts a pointer to the \c value_type to a pointer to the \c conversion_type
    static conversion_type *convert_pointer(value_type *pv)
    {
        return dynamic_cast<conversion_type*>(pv);
    }

    /// Converts a pointer-to-const to the \c value_type to a pointer-to-const to the \c conversion_type
    static conversion_type const *convert_const_pointer(value_type const *pv)
    {
        return dynamic_cast<conversion_type const*>(pv);
    }

    /// Converts a reference to the \c value_type to a reference to the \c conversion_type
    static conversion_type &convert_reference(value_type &v)
    {
        return dynamic_cast<conversion_type&>(v);
    }

    /// Converts a reference-to-const to the \c value_type to a reference-to-const to the \c conversion_type
    static conversion_type const &convert_const_reference(value_type const &v)
    {
        return dynamic_cast<conversion_type const&>(v);
    }

    /// Pointer conversion type
    struct pointer_conversion
    {
        conversion_type *operator ()(value_type *pv)
        {
            return convert_pointer(pv);
        }
    };

    /// Pointer-to-const conversion type
    struct pointer_const_conversion
    {
        conversion_type const *operator ()(value_type const *pv)
        {
            return convert_const_pointer(pv);
        }
    };

    /// Reference conversion type
    struct reference_conversion
    {
        conversion_type &operator ()(value_type &v)
        {
            return convert_reference(v);
        }
    };

    /// Reference-to-const conversion type
    struct reference_const_conversion
    {
        conversion_type const &operator ()(value_type const &v)
        {
            return convert_const_reference(v);
        }
    };

};

// class reinterpret_conversion
/// Implements conversion via C++'s <code>reinterpret_cast</code>
///
/// \param T The value type
/// \param C The conversion type
template<   ss_typename_param_k T
        ,   ss_typename_param_k C
        >
struct reinterpret_conversion
{
public:
    /// The value type
    typedef T       value_type;
    /// The conversion type
    typedef C       conversion_type;

public:
    /// Converts a pointer to the \c value_type to a pointer to the \c conversion_type
    static conversion_type *convert_pointer(value_type *pv)
    {
        return reinterpret_cast<conversion_type*>(pv);
    }

    /// Converts a pointer-to-const to the \c value_type to a pointer-to-const to the \c conversion_type
    static conversion_type const *convert_const_pointer(value_type const *pv)
    {
        return reinterpret_cast<conversion_type const*>(pv);
    }

    /// Converts a reference to the \c value_type to a reference to the \c conversion_type
    static conversion_type &convert_reference(value_type &v)

⌨️ 快捷键说明

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