QxOrm  1.4.4
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 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
00005 **
00006 ** This file is part of the QxOrm library
00007 **
00008 ** This software is provided 'as-is', without any express or implied
00009 ** warranty. In no event will the authors be held liable for any
00010 ** damages arising from the use of this software
00011 **
00012 ** Commercial Usage
00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
00014 ** accordance with the commercial license agreement provided with the
00015 ** Software or, alternatively, in accordance with the terms contained in
00016 ** a written agreement between you and Lionel Marty
00017 **
00018 ** GNU General Public License Usage
00019 ** Alternatively, this file may be used under the terms of the GNU
00020 ** General Public License version 3.0 as published by the Free Software
00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
00022 ** packaging of this file. Please review the following information to
00023 ** ensure the GNU General Public License version 3.0 requirements will be
00024 ** met : http://www.gnu.org/copyleft/gpl.html
00025 **
00026 ** If you are unsure which license is appropriate for your use, or
00027 ** if you have questions regarding the use of this file, please contact :
00028 ** contact@qxorm.com
00029 **
00030 ****************************************************************************/
00031 
00032 #ifndef _QX_IS_SMART_PTR_BASE_OF_H_
00033 #define _QX_IS_SMART_PTR_BASE_OF_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #include <QxTraits/is_smart_ptr.h>
00047 
00048 #define qx_smart_ptr_base_of_test_0() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr(b, d)) == sizeof(char))
00049 #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))
00050 #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))
00051 #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))
00052 #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))
00053 #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))
00054 #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))
00055 #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))
00056 #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))
00057 
00058 #define qx_smart_ptr_base_of_test_9()  (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_std_unique_ptr), d)) == sizeof(char))
00059 #define qx_smart_ptr_base_of_test_10() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_std_shared_ptr), d)) == sizeof(char))
00060 #define qx_smart_ptr_base_of_test_11() (sizeof(qx::trait::is_smart_ptr_base_of<B, D>::removeSmartPtr((* b_std_weak_ptr), d)) == sizeof(char))
00061 
00062 #define qx_smart_ptr_base_of_all_test() \
00063 qx_smart_ptr_base_of_test_1() || qx_smart_ptr_base_of_test_2() || qx_smart_ptr_base_of_test_3() || \
00064 qx_smart_ptr_base_of_test_4() || qx_smart_ptr_base_of_test_5() || qx_smart_ptr_base_of_test_6() || \
00065 qx_smart_ptr_base_of_test_7() || qx_smart_ptr_base_of_test_8() || qx_smart_ptr_base_of_test_9() || \
00066 qx_smart_ptr_base_of_test_10() || qx_smart_ptr_base_of_test_11()
00067 
00068 namespace qx {
00069 namespace trait {
00070 
00075 template <typename B, typename D>
00076 class is_smart_ptr_base_of
00077 {
00078 
00079 private:
00080 
00081 #ifdef _QX_ENABLE_BOOST
00082 
00083    template <typename V, typename W>
00084    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::scoped_ptr<V> &, const boost::scoped_ptr<W> &);
00085 
00086    template <typename V, typename W>
00087    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::shared_ptr<V> &, const boost::shared_ptr<W> &);
00088 
00089    template <typename V, typename W>
00090    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::weak_ptr<V> &, const boost::weak_ptr<W> &);
00091 
00092    template <typename V, typename W>
00093    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const boost::intrusive_ptr<V> &, const boost::intrusive_ptr<W> &);
00094 
00095 #endif // _QX_ENABLE_BOOST
00096 
00097    template <typename V, typename W>
00098    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const QSharedDataPointer<V> &, const QSharedDataPointer<W> &);
00099 
00100    template <typename V, typename W>
00101    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const QSharedPointer<V> &, const QSharedPointer<W> &);
00102 
00103    template <typename V, typename W>
00104    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const QWeakPointer<V> &, const QWeakPointer<W> &);
00105 
00106    template <typename V, typename W>
00107    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const qx::dao::ptr<V> &, const qx::dao::ptr<W> &);
00108 
00109    template <typename V, typename W>
00110    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const std::unique_ptr<V> &, const std::unique_ptr<W> &);
00111 
00112    template <typename V, typename W>
00113    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const std::shared_ptr<V> &, const std::shared_ptr<W> &);
00114 
00115    template <typename V, typename W>
00116    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeSmartPtr(const std::weak_ptr<V> &, const std::weak_ptr<W> &);
00117 
00118    static int removeSmartPtr(...);
00119    static B b;
00120    static D d;
00121 
00122 #ifdef _QX_ENABLE_BOOST
00123 
00124    static boost::scoped_ptr<B> * b_boost_scoped_ptr;
00125    static boost::shared_ptr<B> * b_boost_shared_ptr;
00126    static boost::weak_ptr<B> * b_boost_weak_ptr;
00127    static boost::intrusive_ptr<B> * b_boost_intrusive_ptr;
00128 
00129 #endif // _QX_ENABLE_BOOST
00130 
00131    static QSharedDataPointer<B> * b_qt_shared_data_ptr;
00132    static QSharedPointer<B> * b_qt_shared_ptr;
00133    static QWeakPointer<B> * b_qt_weak_ptr;
00134    static qx::dao::ptr<B> * b_qx_dao_ptr;
00135 
00136    static std::unique_ptr<B> * b_std_unique_ptr;
00137    static std::shared_ptr<B> * b_std_shared_ptr;
00138    static std::weak_ptr<B> * b_std_weak_ptr;
00139 
00140    enum { value_0 = (qx::trait::is_smart_ptr<D>::value) };
00141    enum { value_1 = (qx::trait::is_smart_ptr<B>::value) };
00142    enum { value_2 = ((value_0 && value_1) ? qx_smart_ptr_base_of_test_0() : 0) };
00143    enum { value_3 = ((value_0 && ! value_1) ? qx_smart_ptr_base_of_all_test() : 0) };
00144 
00145 public:
00146 
00147    enum { value = (qx::trait::is_smart_ptr_base_of<B, D>::value_2 || qx::trait::is_smart_ptr_base_of<B, D>::value_3) };
00148 
00149    typedef typename std::conditional<qx::trait::is_smart_ptr_base_of<B, D>::value, std::true_type, std::false_type>::type type;
00150 
00151 };
00152 
00153 } // namespace trait
00154 } // namespace qx
00155 
00156 #endif // _QX_IS_SMART_PTR_BASE_OF_H_