Manual for OpenFLUID 2.1.11

LoopMacros.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file LoopMacros.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_WARE_LOOPMACROS_HPP__
41 #define __OPENFLUID_WARE_LOOPMACROS_HPP__
42 
43 
44 // =====================================================================
45 // =====================================================================
46 
47 
48 #define _UNITID(_id) _M_##_id##_Unit
49 
50 #define _UNITSLISTID(_id) _M_##_id##_UList
51 
52 #define _UNITSPTRLISTID(_id) _M_##_id##_UList
53 
54 #define _PCSORDID(_id) _M_##_id##_PcsOrd
55 
56 #define _UNITSLISTITERID(_id) _M_##_id##_UListit
57 
58 #define _UNITSPTRLISTITERID(_id) _M_##_id##_UPtrListit
59 
60 #define _EVENTSLISTITERID(_id) _M_##_id##_EListit
61 
62 
63 #define _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitsclass,unitptr,id) \
64  openfluid::core::UnitsList_t* _UNITSLISTID(id) = mp_SpatialData->spatialUnits(unitsclass)->list(); \
65  if (_UNITSLISTID(id) != nullptr && !(_UNITSLISTID(id)->empty())) \
66  for (openfluid::core::UnitsList_t::iterator _UNITSLISTITERID(id) = _UNITSLISTID(id)->begin(); \
67  unitptr = &(*_UNITSLISTITERID(id)),_UNITSLISTITERID(id) != _UNITSLISTID(id)->end(); \
68  ++_UNITSLISTITERID(id))
69 
70 /**
71  Macro for a loop processing all units of a class, following their process order
72  @param[in] unitsclass name of the units class
73  @param[out] unitptr pointer to a openfluid::core::SpatialUnit object,
74  automatically pointing to the current processed unit
75 
76  @cond OpenFLUID:completion
77  {
78  "contexts" : ["SIMULATOR", "OBSERVER"],
79  "menupath" : ["Compute code", "Loops"],
80  "title" : "Ordered loop on spatial units of a class",
81  "text" : ["OPENFLUID_UNITS_ORDERED_LOOP(\"%%SEL_START%%unitsclass%%SEL_END%%\",UnitPtr)\n",
82  "%%INDENT%%{\n%%INDENT%%\n%%INDENT%%}"]
83  }
84  @endcond
85 */
86 #define OPENFLUID_UNITS_ORDERED_LOOP(unitsclass,unitptr) \
87  _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitsclass,unitptr,__LINE__)
88 
89 
90 #define _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,id) \
91  openfluid::core::UnitsPtrList_t* _UNITSPTRLISTID(id) = mp_SpatialData->allSpatialUnits(); \
92  for (openfluid::core::UnitsPtrList_t::iterator _UNITSPTRLISTITERID(id) = _UNITSPTRLISTID(id)->begin(); \
93  unitptr = (*_UNITSPTRLISTITERID(id)),_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end(); \
94  ++_UNITSPTRLISTITERID(id))
95 
96 /**
97  Macro for a loop processing all units, following their process order
98  @param[out] unitptr pointer to a openfluid::core::SpatialUnit object,
99  automatically pointing to the current processed unit
100 
101  @cond OpenFLUID:completion
102  {
103  "contexts" : ["SIMULATOR", "OBSERVER"],
104  "menupath" : ["Compute code", "Loops"],
105  "title" : "Ordered loop on all spatial units",
106  "text" : ["OPENFLUID_ALLUNITS_ORDERED_LOOP(%%SEL_START%%UnitPtrList%%SEL_END%%)\n",
107  "%%INDENT%%{\n%%INDENT%%\n%%INDENT%%}"]
108  }
109  @endcond
110 */
111 #define OPENFLUID_ALLUNITS_ORDERED_LOOP(unitptr) \
112  _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,__LINE__)
113 
114 
115 #define _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,id) \
116  if (unitslist != nullptr) \
117  for (openfluid::core::UnitsPtrList_t::iterator _UNITSLISTITERID(id) = unitslist->begin(); \
118  unitptr = *_UNITSLISTITERID(id),_UNITSLISTITERID(id) != unitslist->end(); \
119  ++_UNITSLISTITERID(id))
120 
121 /**
122  Macro for a loop processing a list of units
123  @param[in] unitslist pointer to a list of openfluid::core::Unit
124  @param[out] unitptr unitptr pointer to a openfluid::core::SpatialUnit object,
125  pointing to the current processed unit
126 
127  @cond OpenFLUID:completion
128  {
129  "contexts" : ["ANYWARE"],
130  "menupath" : ["Compute code", "Loops"],
131  "title" : "Loop on a spatial units list",
132  "text" : ["OPENFLUID_UNITSLIST_LOOP(%%SEL_START%%UnitsList%%SEL_END%%,UnitPtr)\n",
133  "%%INDENT%%{\n%%INDENT%%\n%%INDENT%%}"]
134  }
135  @endcond
136 */
137 #define OPENFLUID_UNITSLIST_LOOP(unitslist,unitptr) \
138  _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,__LINE__)
139 
140 
141 #define _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(id,evlist,evobj) \
142  for(openfluid::core::EventsList_t::iterator _EVENTSLISTITERID(id) = (evlist)->begin(); \
143  evobj = &(*_EVENTSLISTITERID(id)), _EVENTSLISTITERID(id) != (evlist)->end(); \
144  ++_EVENTSLISTITERID(id))
145 
146 /**
147  Macro for a loop processing an events list from an event collection
148  @param[in] evlist pointer to a list of events
149  @param[out] evobj the current processed event
150 
151  @cond OpenFLUID:completion
152  {
153  "contexts" : ["ANYWARE"],
154  "menupath" : ["Compute code", "Loops"],
155  "title" : "Loop on an events collection",
156  "text" : ["OPENFLUID_EVENT_COLLECTION_LOOP(%%SEL_START%%EvList%%SEL_END%%,Ev)",
157  "\n%%INDENT%%{\n%%INDENT%%\n%%INDENT%%}"]
158  }
159  @endcond
160 */
161 #define OPENFLUID_EVENT_COLLECTION_LOOP(evlist,evobj) \
162  _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(__LINE__,evlist,evobj)
163 
164 
165 #endif /* __OPENFLUID_WARE_LOOPMACROS_HPP__ */