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