00001 /* 00002 00003 This file is part of Kitlist, a program to maintain a simple list 00004 of items and assign items to one or more categories. 00005 00006 Copyright (C) 2008,2009 Frank Dean 00007 00008 Kitlist 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 Kitlist 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 Kitlist. If not, see <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #include <algorithm> 00024 // #include <iterator> 00025 #include "category.hpp" 00026 00027 00029 void Category::add_item(Item* item) { 00030 m_items.push_back(item); 00031 } 00032 00033 00040 void Category::remove_item(Item* item) { 00041 ItemIter i = std::find(m_items.begin(), m_items.end(), item); 00042 if (i != m_items.end()) { 00043 m_items.erase(i); 00044 } 00045 } 00046 00047 00055 void Category::foreach_item(const SlotForeachItem& slot) { 00056 for (ItemIter i = m_items.begin(); i != m_items.end(); ++i) { 00057 if (slot(*(*i))) 00058 break; 00059 } 00060 } 00061 00062 00071 void Category::execute(ItemFunctor& functor) { 00072 for (ItemIter i = m_items.begin(); i != m_items.end(); ++i) { 00073 if (functor(**i)) 00074 break; 00075 } 00076 }