QxOrm 1.1.8
C++ Object Relational Mapping library
is_smart_ptr_base_of.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** http://www.qxorm.com/
00004 ** http://sourceforge.net/projects/qxorm/
00005 ** Original file by Lionel Marty
00006 **
00007 ** This file is part of the QxOrm library
00008 **
00009 ** This software is provided 'as-is', without any express or implied
00010 ** warranty. In no event will the authors be held liable for any
00011 ** damages arising from the use of this software.
00012 **
00013 ** GNU Lesser General Public License Usage
00014 ** This file must be used under the terms of the GNU Lesser
00015 ** General Public License version 2.1 as published by the Free Software
00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
00017 ** packaging of this file.  Please review the following information to
00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00020 **
00021 ** If you have questions regarding the use of this file, please contact :
00022 ** contact@qxorm.com
00023 **
00024 ****************************************************************************/
00025 
00026 #ifndef _QX_IS_SMART_PTR_BASE_OF_H_
00027 #define _QX_IS_SMART_PTR_BASE_OF_H_
00028 
00029 #ifdef _MSC_VER
00030 #pragma once
00031 #endif
00032 
00040 #include <boost/mpl/if.hpp>
00041 #include <boost/mpl/logical.hpp>
00042 #include <boost/type_traits/is_base_of.hpp>
00043 
00044 #include <QxTraits/is_smart_ptr.h>
00045 
00046 #define qx_smart_ptr_base_of_test_0() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr(b, d)) == sizeof(char))
00047 #define qx_smart_ptr_base_of_test_1() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_boost_scoped_ptr), d)) == sizeof(char))
00048 #define qx_smart_ptr_base_of_test_2() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_boost_shared_ptr), d)) == sizeof(char))
00049 #define qx_smart_ptr_base_of_test_3() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_boost_weak_ptr), d)) == sizeof(char))
00050 #define qx_smart_ptr_base_of_test_4() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_boost_intrusive_ptr), d)) == sizeof(char))
00051 #define qx_smart_ptr_base_of_test_5() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_qt_shared_data_ptr), d)) == sizeof(char))
00052 #define qx_smart_ptr_base_of_test_6() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_qt_shared_ptr), d)) == sizeof(char))
00053 #define qx_smart_ptr_base_of_test_7() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_qt_weak_ptr), d)) == sizeof(char))
00054 #define qx_smart_ptr_base_of_test_8() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_qx_dao_ptr), d)) == sizeof(char))
00055 
00056 #define qx_smart_ptr_base_of_all_test() \
00057 qx_smart_ptr_base_of_test_1() || qx_smart_ptr_base_of_test_2() || qx_smart_ptr_base_of_test_3() || \
00058 qx_smart_ptr_base_of_test_4() || qx_smart_ptr_base_of_test_5() || qx_smart_ptr_base_of_test_6() || \
00059 qx_smart_ptr_base_of_test_7() || qx_smart_ptr_base_of_test_8()
00060 
00061 namespace qx {
00062 namespace trait {
00063 
00068 template <typename B, typename D>
00069 class is_smart_ptr_base_of
00070 {
00071 
00072 private:
00073 
00074    template <typename V, typename W>
00075    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::scoped_ptr<V> &, const boost::scoped_ptr<W> &);
00076 
00077    template <typename V, typename W>
00078    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::shared_ptr<V> &, const boost::shared_ptr<W> &);
00079 
00080    template <typename V, typename W>
00081    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::weak_ptr<V> &, const boost::weak_ptr<W> &);
00082 
00083    template <typename V, typename W>
00084    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::intrusive_ptr<V> &, const boost::intrusive_ptr<W> &);
00085 
00086    template <typename V, typename W>
00087    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const QSharedDataPointer<V> &, const QSharedDataPointer<W> &);
00088 
00089    template <typename V, typename W>
00090    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const QSharedPointer<V> &, const QSharedPointer<W> &);
00091 
00092    template <typename V, typename W>
00093    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const QWeakPointer<V> &, const QWeakPointer<W> &);
00094 
00095    template <typename V, typename W>
00096    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const qx::dao::ptr<V> &, const qx::dao::ptr<W> &);
00097 
00098    static int removeSmartPtr(...);
00099    static B b;
00100    static D d;
00101 
00102    static boost::scoped_ptr<B> * b_boost_scoped_ptr;
00103    static boost::shared_ptr<B> * b_boost_shared_ptr;
00104    static boost::weak_ptr<B> * b_boost_weak_ptr;
00105    static boost::intrusive_ptr<B> * b_boost_intrusive_ptr;
00106    static QSharedDataPointer<B> * b_qt_shared_data_ptr;
00107    static QSharedPointer<B> * b_qt_shared_ptr;
00108    static QWeakPointer<B> * b_qt_weak_ptr;
00109    static qx::dao::ptr<B> * b_qx_dao_ptr;
00110 
00111    enum { value_0 = (qx::trait::is_smart_ptr<D>::value) };
00112    enum { value_1 = (qx::trait::is_smart_ptr<B>::value) };
00113    enum { value_2 = ((value_0 && value_1) ? qx_smart_ptr_base_of_test_0() : 0) };
00114    enum { value_3 = ((value_0 && ! value_1) ? qx_smart_ptr_base_of_all_test() : 0) };
00115 
00116 public:
00117 
00118    enum { value = (qx::trait::is_smart_ptr_base_of<B, D>::value_2 || qx::trait::is_smart_ptr_base_of<B, D>::value_3) };
00119 
00120    typedef typename boost::mpl::if_c<qx::trait::is_smart_ptr_base_of<B, D>::value, boost::mpl::true_, boost::mpl::false_>::type type;
00121 
00122 };
00123 
00124 } // namespace trait
00125 } // namespace qx
00126 
00127 #endif // _QX_IS_SMART_PTR_BASE_OF_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines