is_container_base_of.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /****************************************************************************
  2. **
  3. ** https://www.qxorm.com/
  4. ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
  5. **
  6. ** This file is part of the QxOrm library
  7. **
  8. ** This software is provided 'as-is', without any express or implied
  9. ** warranty. In no event will the authors be held liable for any
  10. ** damages arising from the use of this software
  11. **
  12. ** Commercial Usage
  13. ** Licensees holding valid commercial QxOrm licenses may use this file in
  14. ** accordance with the commercial license agreement provided with the
  15. ** Software or, alternatively, in accordance with the terms contained in
  16. ** a written agreement between you and Lionel Marty
  17. **
  18. ** GNU General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU
  20. ** General Public License version 3.0 as published by the Free Software
  21. ** Foundation and appearing in the file 'license.gpl3.txt' included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU General Public License version 3.0 requirements will be
  24. ** met : http://www.gnu.org/copyleft/gpl.html
  25. **
  26. ** If you are unsure which license is appropriate for your use, or
  27. ** if you have questions regarding the use of this file, please contact :
  28. ** contact@qxorm.com
  29. **
  30. ****************************************************************************/
  31. #ifndef _QX_IS_CONTAINER_BASE_OF_H_
  32. #define _QX_IS_CONTAINER_BASE_OF_H_
  33. #ifdef _MSC_VER
  34. #pragma once
  35. #endif
  36. #include <QxTraits/is_container.h>
  37. #define qx_container_base_of_test_0() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer(b, d)) == sizeof(char))
  38. #define qx_container_base_of_test_1() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_vector), d)) == sizeof(char))
  39. #define qx_container_base_of_test_2() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_list), d)) == sizeof(char))
  40. #define qx_container_base_of_test_3() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_set), d)) == sizeof(char))
  41. #define qx_container_base_of_test_4() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_vector), d)) == sizeof(char))
  42. #define qx_container_base_of_test_5() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_list), d)) == sizeof(char))
  43. #define qx_container_base_of_test_6() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_set), d)) == sizeof(char))
  44. #define qx_container_base_of_test_7() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_qt_linked_list), d)) == sizeof(char))
  45. #define qx_container_base_of_test_8() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_boost_unordered_set), d)) == sizeof(char))
  46. #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))
  47. #define qx_container_base_of_test_10() (sizeof(qx::trait::is_container_base_of<B, D>::removeContainer((* b_std_unordered_set), d)) == sizeof(char))
  48. #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))
  49. #define qx_container_base_of_all_test() \
  50. qx_container_base_of_test_1() || qx_container_base_of_test_2() || qx_container_base_of_test_3() || \
  51. qx_container_base_of_test_4() || qx_container_base_of_test_5() || qx_container_base_of_test_6() || \
  52. qx_container_base_of_test_7() || qx_container_base_of_test_8() || qx_container_base_of_test_9() || \
  53. qx_container_base_of_test_10() || qx_container_base_of_test_11()
  54. namespace qx {
  55. namespace trait {
  56. template <typename B, typename D>
  57. class is_container_base_of
  58. {
  59. private:
  60. template <typename V, typename W>
  61. static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::vector<V> &, const std::vector<W> &);
  62. template <typename V, typename W>
  63. static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::list<V> &, const std::list<W> &);
  64. template <typename V, typename W>
  65. static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const std::set<V> &, const std::set<W> &);
  66. template <typename V, typename W>
  67. static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QVector<V> &, const QVector<W> &);
  68. template <typename V, typename W>
  69. static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QList<V> &, const QList<W> &);
  70. template <typename V, typename W>
  71. static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QSet<V> &, const QSet<W> &);
  72. template <typename V, typename W>
  73. static typename std::conditional<std::is_base_of<V, W>::value, char, int>::type removeContainer(const QLinkedList<V> &, const QLinkedList<W> &);
  74. #ifdef _QX_ENABLE_BOOST
  75. template <typename V, typename W>
  76. 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> &);
  77. template <typename V, typename W>
  78. 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> &);
  79. #endif // _QX_ENABLE_BOOST
  80. template <typename V, typename W>
  81. 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> &);
  82. template <typename V, typename W>
  83. 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> &);
  84. static int removeContainer(...);
  85. static B b;
  86. static D d;
  87. static std::vector<B> * b_std_vector;
  88. static std::list<B> * b_std_list;
  89. static std::set<B> * b_std_set;
  90. static QVector<B> * b_qt_vector;
  91. static QList<B> * b_qt_list;
  92. static QSet<B> * b_qt_set;
  93. static QLinkedList<B> * b_qt_linked_list;
  94. #ifdef _QX_ENABLE_BOOST
  95. static boost::unordered_set<B> * b_boost_unordered_set;
  96. static boost::unordered_multiset<B> * b_boost_unordered_multi_set;
  97. #endif // _QX_ENABLE_BOOST
  98. static std::unordered_set<B> * b_std_unordered_set;
  99. static std::unordered_multiset<B> * b_std_unordered_multi_set;
  100. enum { value_0 = (qx::trait::is_container<D>::value) };
  101. enum { value_1 = (qx::trait::is_container<B>::value) };
  102. enum { value_2 = ((value_0 && value_1) ? qx_container_base_of_test_0() : 0) };
  103. enum { value_3 = ((value_0 && ! value_1) ? qx_container_base_of_all_test() : 0) };
  104. public:
  105. enum { value = (qx::trait::is_container_base_of<B, D>::value_2 || qx::trait::is_container_base_of<B, D>::value_3) };
  106. typedef typename std::conditional<qx::trait::is_container_base_of<B, D>::value, std::true_type, std::false_type>::type type;
  107. };
  108. } // namespace trait
  109. } // namespace qx
  110. #endif // _QX_IS_CONTAINER_BASE_OF_H_