![]() |
QxOrm
1.4.2
C++ Object Relational Mapping library
|
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_FOREACH_H_ 00033 #define _QX_FOREACH_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00055 #include <boost/foreach.hpp> 00056 00057 #ifndef BOOST_FOREACH_ID 00058 #define BOOST_FOREACH_ID(x) x 00059 #endif 00060 00061 #include <QxTraits/is_qx_collection.h> 00062 00063 namespace qx { 00064 00065 namespace foreach { 00066 00067 template<typename T, typename C, bool is_qx_collection = false> 00068 struct qx_deref_boost_or_qx 00069 { 00070 typedef typename boost::foreach_detail_::foreach_reference<T, C>::type type; 00071 }; 00072 00073 template<typename T, typename C> 00074 struct qx_deref_boost_or_qx<T, C, true> 00075 { 00076 typedef typename T::type_pair_key_value::second_type type; 00077 }; 00078 00079 template<typename T, typename C, bool is_qx_collection = false> 00080 struct qx_deref_deduce 00081 { 00082 static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, false>::type 00083 deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp) 00084 { return boost::foreach_detail_::deref(cur, ptmp); } 00085 00086 static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, false>::type 00087 rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp) 00088 { return boost::foreach_detail_::rderef(cur, ptmp); } 00089 }; 00090 00091 template<typename T, typename C> 00092 struct qx_deref_deduce<T, C, true> 00093 { 00094 static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, true>::type 00095 deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp) 00096 { return boost::foreach_detail_::deref(cur, ptmp).second; } 00097 00098 static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, true>::type 00099 rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp) 00100 { return boost::foreach_detail_::rderef(cur, ptmp).second; } 00101 }; 00102 00103 struct qx_deref 00104 { 00105 template<typename T, typename C> 00106 static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, qx::trait::is_qx_collection<T>::value>::type 00107 deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp) 00108 { return qx::foreach::qx_deref_deduce<T, C, qx::trait::is_qx_collection<T>::value>::deref(cur, ptmp); } 00109 00110 template<typename T, typename C> 00111 static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, qx::trait::is_qx_collection<T>::value>::type 00112 deref_reverse(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp) 00113 { return qx::foreach::qx_deref_deduce<T, C, qx::trait::is_qx_collection<T>::value>::rderef(cur, ptmp); } 00114 }; 00115 00116 } // namespace foreach 00117 00118 } // namespace qx 00119 00120 #define QX_FOREACH_DEREF(COL) \ 00121 qx::foreach::qx_deref::deref(BOOST_FOREACH_ID(_foreach_cur), BOOST_FOREACH_TYPEOF(COL)) 00122 00123 #define QX_FOREACH_DEREF_REVERSE(COL) \ 00124 qx::foreach::qx_deref::deref_reverse(BOOST_FOREACH_ID(_foreach_cur), BOOST_FOREACH_TYPEOF(COL)) 00125 00126 #define QX_FOREACH(VAR, COL) \ 00127 BOOST_FOREACH_PREAMBLE() \ 00128 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \ 00129 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_BEGIN(COL)) {} else \ 00130 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_END(COL)) {} else \ 00131 for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \ 00132 BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL); \ 00133 BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) : (void)0) \ 00134 if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \ 00135 for (VAR = QX_FOREACH_DEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true) 00136 00137 #define QX_FOREACH_REVERSE(VAR, COL) \ 00138 BOOST_FOREACH_PREAMBLE() \ 00139 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \ 00140 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_RBEGIN(COL)) {} else \ 00141 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_REND(COL)) {} else \ 00142 for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \ 00143 BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_RDONE(COL); \ 00144 BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_RNEXT(COL) : (void)0) \ 00145 if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \ 00146 for (VAR = QX_FOREACH_DEREF_REVERSE(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true) 00147 00148 #ifdef _foreach 00149 #undef _foreach 00150 #endif // _foreach 00151 00152 #ifdef _foreach_reverse 00153 #undef _foreach_reverse 00154 #endif // _foreach_reverse 00155 00156 #ifdef _foreach_if 00157 #undef _foreach_if 00158 #endif // _foreach_if 00159 00160 #ifdef _foreach_reverse_if 00161 #undef _foreach_reverse_if 00162 #endif // _foreach_reverse_if 00163 00164 #define _foreach QX_FOREACH 00165 #define _foreach_reverse QX_FOREACH_REVERSE 00166 00167 #define _foreach_if(VAR, COL, COND) _foreach(VAR, COL) if (COND) 00168 #define _foreach_reverse_if(VAR, COL, COND) _foreach_reverse(VAR, COL) if (COND) 00169 00170 #endif // _QX_FOREACH_H_