base/LoopMacros.hpp
Go to the documentation of this file.
00001 /*
00002   This file is part of OpenFLUID software
00003   Copyright (c) 2007-2010 INRA-Montpellier SupAgro
00004 
00005 
00006  == GNU General Public License Usage ==
00007 
00008   OpenFLUID is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012 
00013   OpenFLUID is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with OpenFLUID.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021   In addition, as a special exception, INRA gives You the additional right
00022   to dynamically link the code of OpenFLUID with code not covered
00023   under the GNU General Public License ("Non-GPL Code") and to distribute
00024   linked combinations including the two, subject to the limitations in this
00025   paragraph. Non-GPL Code permitted under this exception must only link to
00026   the code of OpenFLUID dynamically through the OpenFLUID libraries
00027   interfaces, and only for building OpenFLUID plugins. The files of
00028   Non-GPL Code may be link to the OpenFLUID libraries without causing the
00029   resulting work to be covered by the GNU General Public License. You must
00030   obey the GNU General Public License in all respects for all of the
00031   OpenFLUID code and other code used in conjunction with OpenFLUID
00032   except the Non-GPL Code covered by this exception. If you modify
00033   this OpenFLUID, you may extend this exception to your version of the file,
00034   but you are not obligated to do so. If you do not wish to provide this
00035   exception without modification, you must delete this exception statement
00036   from your version and license this OpenFLUID solely under the GPL without
00037   exception.
00038 
00039 
00040  == Other Usage ==
00041 
00042   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00043   license, and requires a written agreement between You and INRA.
00044   Licensees for Other Usage of OpenFLUID may use this file in accordance
00045   with the terms contained in the written agreement between You and INRA.
00046 */
00047 
00056 #ifndef __LOOPMACROS_HPP__
00057 #define __LOOPMACROS_HPP__
00058 
00059 
00060 
00061 // =====================================================================
00062 // =====================================================================
00063 
00069 #define DECLARE_UNITS_ORDERED_LOOP(loopid) \
00070   openfluid::core::UnitsList_t::iterator _M_##loopid##_ordit;\
00071   openfluid::core::UnitsList_t* _M_##loopid##_UList;
00072 
00073 
00079 #define DECLARE_GLOBAL_UNITS_ORDERED_LOOP(loopid) \
00080   openfluid::core::UnitsPtrList_t::iterator _M_##loopid##_ordit;\
00081   openfluid::core::UnitsPtrList_t* _M_##loopid##_GUList;
00082 
00083 
00091 #define BEGIN_UNITS_ORDERED_LOOP(loopid,unitclass,unit) \
00092   _M_##loopid##_UList = mp_CoreData->getUnits(unitclass)->getList(); \
00093   if (_M_##loopid##_UList != NULL) \
00094     { \
00095     for (_M_##loopid##_ordit = _M_##loopid##_UList->begin();_M_##loopid##_ordit != _M_##loopid##_UList->end();++_M_##loopid##_ordit) \
00096     { \
00097       unit = &(*_M_##loopid##_ordit);
00098 
00099 
00106 #define BEGIN_GLOBAL_UNITS_ORDERED_LOOP(loopid,unit) \
00107   { \
00108     _M_##loopid##_GUList = mp_CoreData->getUnitsGlobally(); \
00109     for (_M_##loopid##_ordit = _M_##loopid##_GUList->begin();_M_##loopid##_ordit != _M_##loopid##_GUList->end();++_M_##loopid##_ordit) \
00110     { \
00111       unit = (*_M_##loopid##_ordit);
00112 
00113 
00119 #define DECLARE_UNITS_LIST_LOOP(loopid) \
00120   openfluid::core::UnitsPtrList_t::iterator _M_##loopid##_lstit;\
00121 
00122 
00130 #define BEGIN_UNITS_LIST_LOOP(loopid,ulist,unit) \
00131   if ((ulist) != NULL) \
00132   { \
00133     for(_M_##loopid##_lstit=ulist->begin(); _M_##loopid##_lstit != ulist->end(); _M_##loopid##_lstit++) \
00134     { \
00135       unit = *_M_##loopid##_lstit; \
00136 
00137 
00142 #define DECLARE_EVENT_COLLECTION_LOOP \
00143   openfluid::core::EventsList_t::iterator _M_EvListiter;
00144 
00151 #define BEGIN_EVENT_COLLECTION_LOOP(evlist,evobj) \
00152   { \
00153     for(_M_EvListiter=(evlist)->begin(); _M_EvListiter != (evlist)->end(); _M_EvListiter++) \
00154     { \
00155       evobj = &(*_M_EvListiter);
00156 
00161 #define END_LOOP \
00162     } \
00163   }
00164 
00165 
00166 // =====================================================================
00167 // =====================================================================
00168 
00169 #define _UNITID(_id) _M_##_id##_Unit
00170 
00171 #define _UNITSLISTID(_id) _M_##_id##_UList
00172 
00173 #define _UNITSPTRLISTID(_id) _M_##_id##_UList
00174 
00175 #define _THREADPOOLID(_id) _M_##_id##_Pool
00176 
00177 #define _PCSORDID(_id) _M_##_id##_PcsOrd
00178 
00179 #define _UNITSLISTITERID(_id) _M_##_id##_UListit
00180 
00181 #define _UNITSPTRLISTITERID(_id) _M_##_id##_UPtrListit
00182 
00183 #define _EVENTSLISTITERID(_id) _M_##_id##_EListit
00184 
00185 
00186 
00187 #define _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitclass,unitptr,id) \
00188     openfluid::core::UnitsList_t* _UNITSLISTID(id) = mp_CoreData->getUnits(unitclass)->getList(); \
00189     if (_UNITSLISTID(id) != 0) \
00190       for (openfluid::core::UnitsList_t::iterator _UNITSLISTITERID(id) = _UNITSLISTID(id)->begin(); \
00191            unitptr = &(*_UNITSLISTITERID(id)),_UNITSLISTITERID(id) != _UNITSLISTID(id)->end(); \
00192            ++_UNITSLISTITERID(id))
00193 
00199 #define OPENFLUID_UNITS_ORDERED_LOOP(unitclass,unitptr) \
00200     _OPENFLUID_UNITS_ORDERED_LOOP_WITHID(unitclass,unitptr,__LINE__)
00201 
00202 
00203 
00204 #define _APPLY_UNITS_ORDERED_LOOP_THREADED_WITHID(id,unitclass,funcptr,...) \
00205   openfluid::core::UnitsList_t* _UNITSLISTID(id) = mp_CoreData->getUnits(unitclass)->getList(); \
00206   if (_UNITSLISTID(id) != NULL) \
00207   { \
00208     openfluid::core::UnitsList_t::iterator _UNITSLISTITERID(id) = _UNITSLISTID(id)->begin(); \
00209     if (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end()) \
00210     { \
00211       openfluid::core::PcsOrd_t _PCSORDID(id) = _UNITSLISTITERID(id)->getProcessOrder(); \
00212       while (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end()) \
00213       { \
00214         Glib::ThreadPool _THREADPOOLID(id)(OPENFLUID_GetFunctionMaxThreads(),true); \
00215         while (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end() && _UNITSLISTITERID(id)->getProcessOrder() == _PCSORDID(id)) \
00216         { \
00217           _THREADPOOLID(id).push(sigc::bind(sigc::mem_fun(*this,&funcptr),&(*_UNITSLISTITERID(id)), ## __VA_ARGS__)); \
00218           ++_UNITSLISTITERID(id); \
00219         } \
00220         _THREADPOOLID(id).shutdown(); \
00221         if (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end()) _PCSORDID(id) = _UNITSLISTITERID(id)->getProcessOrder(); \
00222       } \
00223     } \
00224   }
00225 
00232 #define APPLY_UNITS_ORDERED_LOOP_THREADED(unitclass,funcptr,...) \
00233     _APPLY_UNITS_ORDERED_LOOP_THREADED_WITHID(__LINE__,unitclass,funcptr,## __VA_ARGS__)
00234 
00235 
00236 
00237 #define _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,id) \
00238     openfluid::core::UnitsPtrList_t* _UNITSPTRLISTID(id) = mp_CoreData->getUnitsGlobally(); \
00239     for (openfluid::core::UnitsPtrList_t::iterator _UNITSPTRLISTITERID(id) = _UNITSPTRLISTID(id)->begin(); \
00240          unitptr = (*_UNITSPTRLISTITERID(id)),_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end(); \
00241          ++_UNITSPTRLISTITERID(id))
00242 
00247 #define OPENFLUID_ALLUNITS_ORDERED_LOOP(unitptr) \
00248     _OPENFLUID_ALLUNITS_ORDERED_LOOP_WITHID(unitptr,__LINE__)
00249 
00250 
00251 
00252 #define _APPLY_ALLUNITS_ORDERED_LOOP_THREADED_WITHID(id,funcptr,...) \
00253   openfluid::core::UnitsPtrList_t* _UNITSPTRLISTID(id) = mp_CoreData->getUnitsGlobally(); \
00254   if (_UNITSPTRLISTID(id) != NULL) \
00255   { \
00256     openfluid::core::UnitsPtrList_t::iterator _UNITSPTRLISTITERID(id) = _UNITSPTRLISTID(id)->begin(); \
00257     if (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end()) \
00258     { \
00259       openfluid::core::PcsOrd_t _PCSORDID(id) = (*_UNITSPTRLISTITERID(id))->getProcessOrder(); \
00260       while (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end()) \
00261       { \
00262         Glib::ThreadPool _THREADPOOLID(id)(OPENFLUID_GetFunctionMaxThreads(),true); \
00263         while (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end() && (*_UNITSPTRLISTITERID(id))->getProcessOrder() == _PCSORDID(id)) \
00264         { \
00265           _THREADPOOLID(id).push(sigc::bind(sigc::mem_fun(*this,&funcptr),(*_UNITSPTRLISTITERID(id)), ## __VA_ARGS__)); \
00266           ++_UNITSPTRLISTITERID(id); \
00267         } \
00268         _THREADPOOLID(id).shutdown(); \
00269         if (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end()) _PCSORDID(id) = (*_UNITSPTRLISTITERID(id))->getProcessOrder(); \
00270       } \
00271     } \
00272   }
00273 
00279 #define APPLY_ALLUNITS_ORDERED_LOOP_THREADED(funcptr,...) \
00280     _APPLY_ALLUNITS_ORDERED_LOOP_THREADED_WITHID(__LINE__,funcptr,## __VA_ARGS__)
00281 
00282 
00283 
00284 #define _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,id) \
00285     if (unitslist != 0) \
00286       for (openfluid::core::UnitsPtrList_t::iterator _UNITSLISTITERID(id) = unitslist->begin(); \
00287            unitptr = *_UNITSLISTITERID(id),_UNITSLISTITERID(id) != unitslist->end(); \
00288            ++_UNITSLISTITERID(id))
00289 #define OPENFLUID_UNITSLIST_LOOP(unitslist,unitptr) \
00295     _OPENFLUID_UNITSLIST_LOOP_WITHID(unitslist,unitptr,__LINE__)
00296 
00297 
00298 
00299 #define _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(id,evlist,evobj) \
00300     for(openfluid::core::EventsList_t::iterator _EVENTSLISTITERID(id) = (evlist)->begin(); \
00301         evobj = &(*_EVENTSLISTITERID(id)), _EVENTSLISTITERID(id) != (evlist)->end(); \
00302        ++_EVENTSLISTITERID(id))
00303 
00309 #define OPENFLUID_EVENT_COLLECTION_LOOP(evlist,evobj) \
00310     _OPENFLUID_EVENT_COLLECTION_LOOP_WITHID(__LINE__,evlist,evobj)
00311 
00312 
00313 // =====================================================================
00314 // =====================================================================
00315 
00316 
00317 #endif /* __LOOPMACROS_HPP__ */

Generated using Doxygen 1.7.6.1
Creative Commons License Creative Commons By-NC-ND license