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 #ifndef CATEGORY_H 00024 #define CATEGORY_H 1 00025 #include <iostream> 00026 #include <vector> 00027 #include "item.hpp" 00028 00029 00030 class CategoryCompareName; 00031 00037 class Category { 00038 protected: 00039 long m_id; 00040 std::string m_name; 00041 ItemContainer m_items; 00042 public: 00043 ~Category() {} 00044 void set_id(long id) { m_id = id; } 00045 long get_id() { return m_id; } 00046 void set_name (const std::string name) { m_name = name; } 00047 std::string get_name() { return m_name; } 00048 virtual void add_item(Item* item); 00049 virtual void remove_item(Item* item); 00051 virtual size_t item_count() { return m_items.size(); } 00053 virtual bool has_items() { return !m_items.empty(); } 00054 void foreach_item(const SlotForeachItem& slot); 00055 void execute(ItemFunctor& functor); 00056 friend class CategoryCompareName; 00057 friend class CategoryCompareId; 00058 friend class KitModel; 00059 }; 00060 00061 00066 class CategoryCompareName { 00067 public: 00068 CategoryCompareName() {} 00069 int operator()(Category* c1, Category* c2) { return (c1->m_name < c2->m_name); } 00070 }; 00071 00072 00077 class CategoryCompareId { 00078 public: 00079 CategoryCompareId() {} 00080 int operator()(Category* c1, Category* c2) { return (c1->m_id < c2->m_id); } 00081 }; 00082 00083 00084 typedef std::vector<Category*> CategoryContainer; 00085 typedef CategoryContainer::iterator CategoryIter; 00086 00087 #endif // CATEGORY_H