FIFE 2008.0
|
00001 /*************************************************************************** 00002 * Copyright (C) 2005-2008 by the FIFE team * 00003 * http://www.fifengine.de * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 00023 // Delete pointers in an STL sequence container 00024 #ifndef PURGE_H 00025 #define PURGE_H 00026 #include <algorithm> 00027 00028 template<class Seq> void purge(Seq& c) { 00029 typename Seq::iterator i; 00030 for(i = c.begin(); i != c.end(); i++) { 00031 delete *i; 00032 *i = 0; 00033 } 00034 } 00035 00036 // Iterator version: 00037 template<class InpIt> 00038 void purge(InpIt begin, InpIt end) { 00039 while(begin != end) { 00040 delete *begin; 00041 *begin = 0; 00042 begin++; 00043 } 00044 } 00045 template<class Seq> void purge_map(Seq& c) { 00046 typename Seq::iterator i; 00047 for(i = c.begin(); i != c.end(); i++) { 00048 delete i->second; 00049 i->second = 0; 00050 } 00051 } 00052 00053 // Iterator version: 00054 template<class InpIt> 00055 void purge_map(InpIt begin, InpIt end) { 00056 while(begin != end) { 00057 delete begin->second; 00058 begin->second = 0; 00059 begin++; 00060 } 00061 } 00062 #endif // PURGE_H