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 ITEM_H 00024 #define ITEM_H 1 00025 00026 #include <iostream> 00027 #include <list> 00028 #include <string> 00029 #include <vector> 00030 #include <sigc++/signal.h> 00031 00032 class ItemCompareName; 00033 00037 class Item { 00038 long m_id; 00039 std::string m_desc; 00040 bool m_checked; 00041 public: 00042 Item() : m_checked(true), m_id(-1) {} 00044 Item(const Item& i) : m_id(i.m_id), m_desc(i.m_desc), m_checked(i.m_checked) {} 00045 void set_id(long id) { m_id = id; } 00046 long get_id() { return m_id; } 00047 void set_description(const std::string description) { m_desc = description; } 00048 std::string get_description() { return m_desc; } 00049 virtual void set_checked(bool checked) { m_checked = checked; } 00050 bool get_checked() { return m_checked; } 00051 friend class ItemCompareName; 00052 friend class ItemCompareId; 00053 friend std::ostream& operator<<(std::ostream& os, const Item& i) { return os << i.m_id; } 00054 }; 00055 00056 00061 class ItemCompareName { 00062 public: 00063 ItemCompareName() {} 00064 int operator()(Item* i1, Item* i2) { return (i1->m_desc < i2->m_desc); } 00065 }; 00066 00067 00072 class ItemCompareId { 00073 public: 00074 ItemCompareId() {} 00075 int operator()(Item* i1, Item* i2) { return (i1->m_id < i2->m_id); } 00076 }; 00077 00078 00085 class ItemFunctor { 00086 public: 00087 virtual bool operator()(Item& item) = 0; 00088 }; 00089 00090 00091 typedef std::vector<Item*> ItemContainer; 00092 typedef ItemContainer::iterator ItemIter; 00093 00094 typedef std::list<Item> ItemList; 00095 typedef ItemList::iterator ItemListIter; 00096 00097 typedef sigc::slot<bool, Item&> SlotForeachItem; 00098 00099 #endif // ITEM_H