QxOrm  1.4.8
C++ Object Relational Mapping library
is_container_base_of.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://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_CONTAINER_BASE_OF_H_
00033 #define _QX_IS_CONTAINER_BASE_OF_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00039 #include <QxTraits/is_container.h>
00040 
00041 #define qx_container_base_of_test_0() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer(b, d)) == sizeof(char))
00042 #define qx_container_base_of_test_1() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_vector), d)) == sizeof(char))
00043 #define qx_container_base_of_test_2() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_list), d)) == sizeof(char))
00044 #define qx_container_base_of_test_3() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_set), d)) == sizeof(char))
00045 #define qx_container_base_of_test_4() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_vector), d)) == sizeof(char))
00046 #define qx_container_base_of_test_5() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_list), d)) == sizeof(char))
00047 #define qx_container_base_of_test_6() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_set), d)) == sizeof(char))
00048 #define qx_container_base_of_test_7() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_linked_list), d)) == sizeof(char))
00049 #define qx_container_base_of_test_8() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_boost_unordered_set), d)) == sizeof(char))
00050 #define qx_container_base_of_test_9() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_boost_unordered_multi_set), d)) == sizeof(char))
00051 
00052 #define qx_container_base_of_test_10() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_unordered_set), d)) == sizeof(char))
00053 #define qx_container_base_of_test_11() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_unordered_multi_set), d)) == sizeof(char))
00054 
00055 #define qx_container_base_of_all_test() \
00056 qx_container_base_of_test_1() || qx_container_base_of_test_2() || qx_container_base_of_test_3() || \
00057 qx_container_base_of_test_4() || qx_container_base_of_test_5() || qx_container_base_of_test_6() || \
00058 qx_container_base_of_test_7() || qx_container_base_of_test_8() || qx_container_base_of_test_9() || \
00059 qx_container_base_of_test_10() || qx_container_base_of_test_11()
00060 
00061 namespace qx {
00062 namespace trait {
00063 
00064 template <typename B, typename D>
00065 class is_container_base_of
00066 {
00067 
00068 private:
00069 
00070    template <typename V, typename W>
00071    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::vector<V> &, const std::vector<W> &);
00072 
00073    template <typename V, typename W>
00074    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::list<V> &, const std::list<W> &);
00075 
00076    template <typename V, typename W>
00077    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::set<V> &, const std::set<W> &);
00078 
00079 #if (QT_VERSION < 0x060000)
00080    template <typename V, typename W>
00081    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QVector<V> &, const QVector<W> &);
00082 #endif // (QT_VERSION < 0x060000)
00083 
00084    template <typename V, typename W>
00085    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QList<V> &, const QList<W> &);
00086 
00087    template <typename V, typename W>
00088    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QSet<V> &, const QSet<W> &);
00089 
00090 #if (QT_VERSION < 0x060000)
00091    template <typename V, typename W>
00092    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QLinkedList<V> &, const QLinkedList<W> &);
00093 #endif // (QT_VERSION < 0x060000)
00094 
00095 #ifdef _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 removeContainer(const boost::unordered_set<V> &, const boost::unordered_set<W> &);
00099 
00100    template <typename V, typename W>
00101    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const boost::unordered_multiset<V> &, const boost::unordered_multiset<W> &);
00102 
00103 #endif // _QX_ENABLE_BOOST
00104 
00105    template <typename V, typename W>
00106    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::unordered_set<V> &, const std::unordered_set<W> &);
00107 
00108    template <typename V, typename W>
00109    static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::unordered_multiset<V> &, const std::unordered_multiset<W> &);
00110 
00111    static int removeContainer(...);
00112    static B b;
00113    static D d;
00114 
00115    static std::vector<B> * b_std_vector;
00116    static std::list<B> * b_std_list;
00117    static std::set<B> * b_std_set;
00118    static QVector<B> * b_qt_vector;
00119    static QList<B> * b_qt_list;
00120    static QSet<B> * b_qt_set;
00121 
00122 #if (QT_VERSION < 0x060000)
00123    static QLinkedList<B> * b_qt_linked_list;
00124 #endif // (QT_VERSION < 0x060000)
00125 
00126 #ifdef _QX_ENABLE_BOOST
00127 
00128    static boost::unordered_set<B> * b_boost_unordered_set;
00129    static boost::unordered_multiset<B> * b_boost_unordered_multi_set;
00130 
00131 #endif // _QX_ENABLE_BOOST
00132 
00133    static std::unordered_set<B> * b_std_unordered_set;
00134    static std::unordered_multiset<B> * b_std_unordered_multi_set;
00135 
00136    enum { value_0 = (qx::trait::is_container<D>::value) };
00137    enum { value_1 = (qx::trait::is_container<B>::value) };
00138    enum { value_2 = ((value_0 && value_1) ? qx_container_base_of_test_0() : 0) };
00139    enum { value_3 = ((value_0 && ! value_1) ? qx_container_base_of_all_test() : 0) };
00140 
00141 public:
00142 
00143    enum { value = (qx::trait::is_container_base_of<B, D>::value_2 || qx::trait::is_container_base_of<B, D>::value_3) };
00144 
00145    typedef typename std::conditional<qx::trait::is_container_base_of<B, D>::value, std::true_type, std::false_type>::type type;
00146 
00147 };
00148 
00149 } // namespace trait
00150 } // namespace qx
00151 
00152 #endif // _QX_IS_CONTAINER_BASE_OF_H_