|
| 1 | +/* |
| 2 | + * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or |
| 5 | + * modify it under the terms of the GNU General Public License |
| 6 | + * as published by the Free Software Foundation; either version 2 |
| 7 | + * of the License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software Foundation, |
| 16 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | + * |
| 18 | + * Contributor(s): Tristan Porteries. |
| 19 | + * |
| 20 | + * ***** END GPL LICENSE BLOCK ***** |
| 21 | + */ |
| 22 | + |
| 23 | +/** \file CM_List.h |
| 24 | + * \ingroup common |
| 25 | + */ |
| 26 | + |
| 27 | +#ifndef __CM_LIST_H__ |
| 28 | +#define __CM_LIST_H__ |
| 29 | + |
| 30 | +#include <algorithm> |
| 31 | + |
| 32 | +template <class Item, class List> |
| 33 | +inline bool CM_ListRemoveIfFound(List& list, const Item& item) |
| 34 | +{ |
| 35 | + const typename List::iterator it = std::find(list.begin(), list.end(), item); |
| 36 | + if (it != list.end()) { |
| 37 | + list.erase(it); |
| 38 | + return true; |
| 39 | + } |
| 40 | + return false; |
| 41 | +} |
| 42 | + |
| 43 | +template <class Item, class List> |
| 44 | +inline bool CM_ListAddIfNotFound(List& list, const Item& item) |
| 45 | +{ |
| 46 | + if (std::find(list.begin(), list.end(), item) == list.end()) { |
| 47 | + list.push_back(item); |
| 48 | + return true; |
| 49 | + } |
| 50 | + return false; |
| 51 | +} |
| 52 | + |
| 53 | +#endif // __CM_LIST_H__ |
0 commit comments