All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  \brief Header of ...
36 
37  \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __LOOPMACROS_HPP__
42 #define __LOOPMACROS_HPP__
43 
44 
45 
46 // =====================================================================
47 // =====================================================================
48 
49 
50 #define _UNITID(_id) _M_##_id##_Unit
51 
52 #define _UNITSLISTID(_id) _M_##_id##_UList
53 
54 #define _UNITSPTRLISTID(_id) _M_##_id##_UList
55 
56 #define _PCSORDID(_id) _M_##_id##_PcsOrd
57 
58 #define _UNITSLISTITERID(_id) _M_##_id##_UListit
59 
60 #define _UNITSPTRLISTITERID(_id) _M_##_id##_UPtrListit
61 
62 #define _EVENTSLISTITERID(_id) _M_##_id##_EListit
63 
64 
65 
66 #define _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitclass,unitptr,id) \
67  openfluid::core::UnitsList_t* _UNITSLISTID(id) = mp_CoreData->getUnits(unitclass)->getList(); \
68  if (_UNITSLISTID(id) != NULL && !(_UNITSLISTID(id)->empty())) \
69  for (openfluid::core::UnitsList_t::iterator _UNITSLISTITERID(id) = _UNITSLISTID(id)->begin(); \
70  unitptr = &(*_UNITSLISTITERID(id)),_UNITSLISTITERID(id) != _UNITSLISTID(id)->end(); \
71  ++_UNITSLISTITERID(id))
72 
73 /**
74  Macro for a loop processing all units of a class, following their process order
75  @param[in] unitclass name of the unit class
76  @param[out] unitptr pointer to a openfluid::core::Unit objects, automatically pointing to the current processed unit
77 */
78 #define OPENFLUID_UNITS_ORDERED_LOOP(unitclass,unitptr) \
79  _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitclass,unitptr,__LINE__)
80 
81 
82 
83 
84 #define _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,id) \
85  openfluid::core::UnitsPtrList_t* _UNITSPTRLISTID(id) = mp_CoreData->getUnitsGlobally(); \
86  for (openfluid::core::UnitsPtrList_t::iterator _UNITSPTRLISTITERID(id) = _UNITSPTRLISTID(id)->begin(); \
87  unitptr = (*_UNITSPTRLISTITERID(id)),_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end(); \
88  ++_UNITSPTRLISTITERID(id))
89 
90 /**
91  Macro for a loop processing all units, following their process order
92  @param[out] unitptr pointer to a openfluid::core::Unit objects, 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 != NULL) \
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 pointer to a openfluid::core::Unit objects, pointing to the current processed unit
109 */#define OPENFLUID_UNITSLIST_LOOP(unitslist,unitptr) \
110  _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,__LINE__)
111 
112 
113 
114 #define _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(id,evlist,evobj) \
115  for(openfluid::core::EventsList_t::iterator _EVENTSLISTITERID(id) = (evlist)->begin(); \
116  evobj = &(*_EVENTSLISTITERID(id)), _EVENTSLISTITERID(id) != (evlist)->end(); \
117  ++_EVENTSLISTITERID(id))
118 
119 /**
120  Macro for a loop processing an events list from an event collection
121  @param[in] evlist pointer to a list of events
122  @param[out] evobj the current processed event
123 */
124 #define OPENFLUID_EVENT_COLLECTION_LOOP(evlist,evobj) \
125  _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(__LINE__,evlist,evobj)
126 
127 
128 // =====================================================================
129 // =====================================================================
130 
131 
132 #endif /* __LOOPMACROS_HPP__ */
#define OPENFLUID_UNITSLIST_LOOP(unitslist, unitptr)
Definition: LoopMacros.hpp:109
#define _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist, unitptr, id)
Definition: LoopMacros.hpp:99