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@supagro.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 
64 #define _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitsclass,unitptr,id) \
65  openfluid::core::UnitsList_t* _UNITSLISTID(id) = mp_SpatialData->spatialUnits(unitsclass)->list(); \
66  if (_UNITSLISTID(id) != nullptr && !(_UNITSLISTID(id)->empty())) \
67  for (openfluid::core::UnitsList_t::iterator _UNITSLISTITERID(id) = _UNITSLISTID(id)->begin(); \
68  unitptr = &(*_UNITSLISTITERID(id)),_UNITSLISTITERID(id) != _UNITSLISTID(id)->end(); \
69  ++_UNITSLISTITERID(id))
70 
71 /**
72  Macro for a loop processing all units of a class, following their process order
73  @param[in] unitsclass name of the units class
74  @param[out] unitptr pointer to a openfluid::core::SpatialUnit object,
75  automatically pointing to the current processed unit
76 */
77 #define OPENFLUID_UNITS_ORDERED_LOOP(unitsclass,unitptr) \
78  _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitsclass,unitptr,__LINE__)
79 
80 
81 
82 
83 #define _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,id) \
84  openfluid::core::UnitsPtrList_t* _UNITSPTRLISTID(id) = mp_SpatialData->allSpatialUnits(); \
85  for (openfluid::core::UnitsPtrList_t::iterator _UNITSPTRLISTITERID(id) = _UNITSPTRLISTID(id)->begin(); \
86  unitptr = (*_UNITSPTRLISTITERID(id)),_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end(); \
87  ++_UNITSPTRLISTITERID(id))
88 
89 /**
90  Macro for a loop processing all units, following their process order
91  @param[out] unitptr pointer to a openfluid::core::SpatialUnit object,
92  automatically pointing to the current processed unit
93 */
94 #define OPENFLUID_ALLUNITS_ORDERED_LOOP(unitptr) \
95  _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,__LINE__)
96 
97 
98 
99 #define _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,id) \
100  if (unitslist != nullptr) \
101  for (openfluid::core::UnitsPtrList_t::iterator _UNITSLISTITERID(id) = unitslist->begin(); \
102  unitptr = *_UNITSLISTITERID(id),_UNITSLISTITERID(id) != unitslist->end(); \
103  ++_UNITSLISTITERID(id))
104 
105 /**
106  Macro for a loop processing a list of units
107  @param[in] unitslist pointer to a list of openfluid::core::Unit
108  @param[out] unitptr unitptr pointer to a openfluid::core::SpatialUnit object,
109  pointing to the current processed unit
110 */#define OPENFLUID_UNITSLIST_LOOP(unitslist,unitptr) \
111  _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,__LINE__)
112 
113 
114 
115 #define _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(id,evlist,evobj) \
116  for(openfluid::core::EventsList_t::iterator _EVENTSLISTITERID(id) = (evlist)->begin(); \
117  evobj = &(*_EVENTSLISTITERID(id)), _EVENTSLISTITERID(id) != (evlist)->end(); \
118  ++_EVENTSLISTITERID(id))
119 
120 /**
121  Macro for a loop processing an events list from an event collection
122  @param[in] evlist pointer to a list of events
123  @param[out] evobj the current processed event
124 */
125 #define OPENFLUID_EVENT_COLLECTION_LOOP(evlist,evobj) \
126  _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(__LINE__,evlist,evobj)
127 
128 
129 // =====================================================================
130 // =====================================================================
131 
132 
133 #endif /* __OPENFLUID_WARE_LOOPMACROS_HPP__ */
#define _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist, unitptr, id)
Definition: LoopMacros.hpp:99
#define OPENFLUID_UNITSLIST_LOOP(unitslist, unitptr)
Definition: LoopMacros.hpp:110