base/LoopMacros.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 
00033 /**
00034   \file LoopMacros.hpp
00035   \brief Header of ...
00036 
00037   \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00038  */
00039 
00040 
00041 #ifndef __LOOPMACROS_HPP__
00042 #define __LOOPMACROS_HPP__
00043 
00044 
00045 
00046 // =====================================================================
00047 // =====================================================================
00048 
00049 
00050 #define _UNITID(_id) _M_##_id##_Unit
00051 
00052 #define _UNITSLISTID(_id) _M_##_id##_UList
00053 
00054 #define _UNITSPTRLISTID(_id) _M_##_id##_UList
00055 
00056 #define _PCSORDID(_id) _M_##_id##_PcsOrd
00057 
00058 #define _UNITSLISTITERID(_id) _M_##_id##_UListit
00059 
00060 #define _UNITSPTRLISTITERID(_id) _M_##_id##_UPtrListit
00061 
00062 #define _EVENTSLISTITERID(_id) _M_##_id##_EListit
00063 
00064 
00065 
00066 #define _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitclass,unitptr,id) \
00067     openfluid::core::UnitsList_t* _UNITSLISTID(id) = mp_CoreData->getUnits(unitclass)->getList(); \
00068     if (_UNITSLISTID(id) != NULL && !(_UNITSLISTID(id)->empty())) \
00069       for (openfluid::core::UnitsList_t::iterator _UNITSLISTITERID(id) = _UNITSLISTID(id)->begin(); \
00070            unitptr = &(*_UNITSLISTITERID(id)),_UNITSLISTITERID(id) != _UNITSLISTID(id)->end(); \
00071            ++_UNITSLISTITERID(id))
00072 
00073 /**
00074   Macro for a loop processing all units of a class, following their process order
00075   @param[in] unitclass name of the unit class
00076   @param[out] unitptr pointer to a openfluid::core::Unit objects, automatically pointing to the current processed unit
00077 */
00078 #define OPENFLUID_UNITS_ORDERED_LOOP(unitclass,unitptr) \
00079     _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitclass,unitptr,__LINE__)
00080 
00081 
00082 
00083 
00084 #define _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,id) \
00085     openfluid::core::UnitsPtrList_t* _UNITSPTRLISTID(id) = mp_CoreData->getUnitsGlobally(); \
00086     for (openfluid::core::UnitsPtrList_t::iterator _UNITSPTRLISTITERID(id) = _UNITSPTRLISTID(id)->begin(); \
00087          unitptr = (*_UNITSPTRLISTITERID(id)),_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end(); \
00088          ++_UNITSPTRLISTITERID(id))
00089 
00090 /**
00091   Macro for a loop processing all units, following their process order
00092   @param[out] unitptr pointer to a openfluid::core::Unit objects, automatically pointing to the current processed unit
00093 */
00094 #define OPENFLUID_ALLUNITS_ORDERED_LOOP(unitptr) \
00095     _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,__LINE__)
00096 
00097 
00098 
00099 #define _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,id) \
00100     if (unitslist != NULL) \
00101       for (openfluid::core::UnitsPtrList_t::iterator _UNITSLISTITERID(id) = unitslist->begin(); \
00102            unitptr = *_UNITSLISTITERID(id),_UNITSLISTITERID(id) != unitslist->end(); \
00103            ++_UNITSLISTITERID(id))
00104 
00105 /**
00106   Macro for a loop processing a list of units
00107   @param[in] unitslist pointer to a list of openfluid::core::Unit
00108   @param[out] unitptr pointer to a openfluid::core::Unit objects, pointing to the current processed unit
00109 */#define OPENFLUID_UNITSLIST_LOOP(unitslist,unitptr) \
00110     _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,__LINE__)
00111 
00112 
00113 
00114 #define _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(id,evlist,evobj) \
00115     for(openfluid::core::EventsList_t::iterator _EVENTSLISTITERID(id) = (evlist)->begin(); \
00116         evobj = &(*_EVENTSLISTITERID(id)), _EVENTSLISTITERID(id) != (evlist)->end(); \
00117        ++_EVENTSLISTITERID(id))
00118 
00119 /**
00120   Macro for a loop processing an events list from an event collection
00121   @param[in] evlist pointer to a list of events
00122   @param[out] evobj the current processed event
00123 */
00124 #define OPENFLUID_EVENT_COLLECTION_LOOP(evlist,evobj) \
00125     _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(__LINE__,evlist,evobj)
00126 
00127 
00128 // =====================================================================
00129 // =====================================================================
00130 
00131 
00132 #endif /* __LOOPMACROS_HPP__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines