QxOrm 1.1.9
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 ** 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_CONTAINER_BASE_OF_H_
00027 #define _QX_IS_CONTAINER_BASE_OF_H_
00028 
00029 #ifdef _MSC_VER
00030 #pragma once
00031 #endif
00032 
00033 #include <boost/mpl/if.hpp>
00034 #include <boost/mpl/logical.hpp>
00035 #include <boost/type_traits/is_base_of.hpp>
00036 
00037 #include <QxTraits/is_container.h>
00038 
00039 #define qx_container_base_of_test_0() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer(b, d)) == sizeof(char))
00040 #define qx_container_base_of_test_1() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_vector), d)) == sizeof(char))
00041 #define qx_container_base_of_test_2() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_list), d)) == sizeof(char))
00042 #define qx_container_base_of_test_3() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_set), d)) == sizeof(char))
00043 #define qx_container_base_of_test_4() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_vector), d)) == sizeof(char))
00044 #define qx_container_base_of_test_5() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_list), d)) == sizeof(char))
00045 #define qx_container_base_of_test_6() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_set), d)) == sizeof(char))
00046 #define qx_container_base_of_test_7() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_linked_list), d)) == sizeof(char))
00047 #define qx_container_base_of_test_8() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_boost_unordered_set), d)) == sizeof(char))
00048 #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))
00049 
00050 #define qx_container_base_of_all_test() \
00051 qx_container_base_of_test_1() || qx_container_base_of_test_2() || qx_container_base_of_test_3() || \
00052 qx_container_base_of_test_4() || qx_container_base_of_test_5() || qx_container_base_of_test_6() || \
00053 qx_container_base_of_test_7() || qx_container_base_of_test_8() || qx_container_base_of_test_9()
00054 
00055 namespace qx {
00056 namespace trait {
00057 
00058 template <typename B, typename D>
00059 class is_container_base_of
00060 {
00061 
00062 private:
00063 
00064    template <typename V, typename W>
00065    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> &);
00066 
00067    template <typename V, typename W>
00068    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> &);
00069 
00070    template <typename V, typename W>
00071    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> &);
00072 
00073    template <typename V, typename W>
00074    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeContainer(const QVector<V> &, const QVector<W> &);
00075 
00076    template <typename V, typename W>
00077    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeContainer(const QList<V> &, const QList<W> &);
00078 
00079    template <typename V, typename W>
00080    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeContainer(const QSet<V> &, const QSet<W> &);
00081 
00082    template <typename V, typename W>
00083    static typename boost::mpl::if_c<boost::is_base_of<V, W>::value, char, int>::type removeContainer(const QLinkedList<V> &, const QLinkedList<W> &);
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 boost::unordered_set<V> &, const boost::unordered_set<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 boost::unordered_multiset<V> &, const boost::unordered_multiset<W> &);
00090 
00091    static int removeContainer(...);
00092    static B b;
00093    static D d;
00094 
00095    static std::vector<B> * b_std_vector;
00096    static std::list<B> * b_std_list;
00097    static std::set<B> * b_std_set;
00098    static QVector<B> * b_qt_vector;
00099    static QList<B> * b_qt_list;
00100    static QSet<B> * b_qt_set;
00101    static QLinkedList<B> * b_qt_linked_list;
00102    static boost::unordered_set<B> * b_boost_unordered_set;
00103    static boost::unordered_multiset<B> * b_boost_unordered_multi_set;
00104 
00105    enum { value_0 = (qx::trait::is_container<D>::value) };
00106    enum { value_1 = (qx::trait::is_container<B>::value) };
00107    enum { value_2 = ((value_0 && value_1) ? qx_container_base_of_test_0() : 0) };
00108    enum { value_3 = ((value_0 && ! value_1) ? qx_container_base_of_all_test() : 0) };
00109 
00110 public:
00111 
00112    enum { value = (qx::trait::is_container_base_of<B, D>::value_2 || qx::trait::is_container_base_of<B, D>::value_3) };
00113 
00114    typedef typename boost::mpl::if_c<qx::trait::is_container_base_of<B, D>::value, boost::mpl::true_, boost::mpl::false_>::type type;
00115 
00116 };
00117 
00118 } // namespace trait
00119 } // namespace qx
00120 
00121 #endif // _QX_IS_CONTAINER_BASE_OF_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines