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