QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxForeach.h
Go to the documentation of this file.
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
32#ifdef _QX_ENABLE_BOOST
33#ifndef _QX_FOREACH_H_
34#define _QX_FOREACH_H_
35
36#ifdef _MSC_VER
37#pragma once
38#endif
39
56#include <boost/foreach.hpp>
57
58#ifndef BOOST_FOREACH_ID
59#define BOOST_FOREACH_ID(x) x
60#endif
61
63
64namespace qx {
65
66namespace foreach {
67
68template<typename T, typename C, bool is_qx_collection = false>
70{
71 typedef typename boost::foreach_detail_::foreach_reference<T, C>::type type;
72};
73
74template<typename T, typename C>
75struct qx_deref_boost_or_qx<T, C, true>
76{
77 typedef typename T::type_pair_key_value::second_type type;
78};
79
80template<typename T, typename C, bool is_qx_collection = false>
82{
84 deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp)
85 { return boost::foreach_detail_::deref(cur, ptmp); }
86
88 rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp)
89 { return boost::foreach_detail_::rderef(cur, ptmp); }
90};
91
92template<typename T, typename C>
93struct qx_deref_deduce<T, C, true>
94{
96 deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp)
97 { return boost::foreach_detail_::deref(cur, ptmp).second; }
98
100 rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp)
101 { return boost::foreach_detail_::rderef(cur, ptmp).second; }
102};
103
105{
106 template<typename T, typename C>
108 deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp)
110
111 template<typename T, typename C>
113 deref_reverse(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> * ptmp)
115};
116
117} // namespace foreach
118
119} // namespace qx
120
121#define QX_FOREACH_DEREF(COL) \
122 qx::foreach::qx_deref::deref(BOOST_FOREACH_ID(_foreach_cur), BOOST_FOREACH_TYPEOF(COL))
123
124#define QX_FOREACH_DEREF_REVERSE(COL) \
125 qx::foreach::qx_deref::deref_reverse(BOOST_FOREACH_ID(_foreach_cur), BOOST_FOREACH_TYPEOF(COL))
126
127#define QX_FOREACH(VAR, COL) \
128 BOOST_FOREACH_PREAMBLE() \
129 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \
130 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_BEGIN(COL)) {} else \
131 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_END(COL)) {} else \
132 for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \
133 BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL); \
134 BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) : (void)0) \
135 if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \
136 for (VAR = QX_FOREACH_DEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
137
138#define QX_FOREACH_REVERSE(VAR, COL) \
139 BOOST_FOREACH_PREAMBLE() \
140 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \
141 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_RBEGIN(COL)) {} else \
142 if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_REND(COL)) {} else \
143 for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \
144 BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_RDONE(COL); \
145 BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_RNEXT(COL) : (void)0) \
146 if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \
147 for (VAR = QX_FOREACH_DEREF_REVERSE(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
148
149#ifdef _foreach
150#undef _foreach
151#endif // _foreach
152
153#ifdef _foreach_reverse
154#undef _foreach_reverse
155#endif // _foreach_reverse
156
157#ifdef _foreach_if
158#undef _foreach_if
159#endif // _foreach_if
160
161#ifdef _foreach_reverse_if
162#undef _foreach_reverse_if
163#endif // _foreach_reverse_if
164
165#define _foreach QX_FOREACH
166#define _foreach_reverse QX_FOREACH_REVERSE
167
168#define _foreach_if(VAR, COL, COND) _foreach(VAR, COL) if (COND)
169#define _foreach_reverse_if(VAR, COL, COND) _foreach_reverse(VAR, COL) if (COND)
170
171#endif // _QX_FOREACH_H_
172#endif // _QX_ENABLE_BOOST
qx::trait::is_qx_collection<T>::value : return true if T is a qx::QxCollection<> container of QxOrm l...
Root namespace for all QxOrm library features.
T::type_pair_key_value::second_type type
Definition QxForeach.h:77
boost::foreach_detail_::foreach_reference< T, C >::type type
Definition QxForeach.h:71
static qx::foreach::qx_deref_boost_or_qx< T, C, true >::type rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type< T, C > *ptmp)
Definition QxForeach.h:100
static qx::foreach::qx_deref_boost_or_qx< T, C, true >::type deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type< T, C > *ptmp)
Definition QxForeach.h:96
static qx::foreach::qx_deref_boost_or_qx< T, C, false >::type deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type< T, C > *ptmp)
Definition QxForeach.h:84
static qx::foreach::qx_deref_boost_or_qx< T, C, false >::type rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type< T, C > *ptmp)
Definition QxForeach.h:88
static qx::foreach::qx_deref_boost_or_qx< T, C, qx::trait::is_qx_collection< T >::value >::type deref_reverse(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type< T, C > *ptmp)
Definition QxForeach.h:113
static qx::foreach::qx_deref_boost_or_qx< T, C, qx::trait::is_qx_collection< T >::value >::type deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type< T, C > *ptmp)
Definition QxForeach.h:108