Kitlist  1.1.0
item.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of Kitlist, a program to maintain a simple list
4  of items and assign items to one or more categories.
5 
6  Copyright (C) 2008,2009 Frank Dean
7 
8  Kitlist is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  Kitlist is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Kitlist. If not, see <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifndef ITEM_H
24 #define ITEM_H 1
25 
26 #include <iostream>
27 #include <list>
28 #include <string>
29 #include <vector>
30 #include <sigc++/signal.h>
31 
32 class ItemCompareName;
33 
37 class Item {
38  long m_id;
39  std::string m_desc;
40  bool m_checked;
41  public:
42  Item() : m_checked(true), m_id(-1) {}
44  Item(const Item& i) : m_id(i.m_id), m_desc(i.m_desc), m_checked(i.m_checked) {}
45  void set_id(long id) { m_id = id; }
46  long get_id() { return m_id; }
47  void set_description(const std::string description) { m_desc = description; }
48  std::string get_description() { return m_desc; }
49  virtual void set_checked(bool checked) { m_checked = checked; }
50  bool get_checked() { return m_checked; }
51  friend class ItemCompareName;
52  friend class ItemCompareId;
53  friend std::ostream& operator<<(std::ostream& os, const Item& i) { return os << i.m_id; }
54 };
55 
56 
62  public:
64  int operator()(Item* i1, Item* i2) { return (i1->m_desc < i2->m_desc); }
65 };
66 
67 
73  public:
75  int operator()(Item* i1, Item* i2) { return (i1->m_id < i2->m_id); }
76 };
77 
78 
85 class ItemFunctor {
86  public:
87  virtual bool operator()(Item& item) = 0;
88 };
89 
90 
91 typedef std::vector<Item*> ItemContainer;
92 typedef ItemContainer::iterator ItemIter;
93 
94 typedef std::list<Item> ItemList;
95 typedef ItemList::iterator ItemListIter;
96 
97 typedef sigc::slot<bool, Item&> SlotForeachItem;
98 
99 #endif // ITEM_H
long get_id()
Definition: item.hpp:46
bool m_checked
Whether checked/ticked or not.
Definition: item.hpp:40
ItemContainer::iterator ItemIter
Definition: item.hpp:92
Item(const Item &i)
Creates a copy of this item based on the passed item.
Definition: item.hpp:44
Item()
Definition: item.hpp:42
Comparator used for comparing Items by id.
Definition: item.hpp:72
std::vector< Item * > ItemContainer
Definition: item.hpp:91
virtual void set_checked(bool checked)
Definition: item.hpp:49
int operator()(Item *i1, Item *i2)
Definition: item.hpp:75
Comparator used for sorting Items by name.
Definition: item.hpp:61
std::string m_desc
The item&#39;s description.
Definition: item.hpp:39
sigc::slot< bool, Item & > SlotForeachItem
Definition: item.hpp:97
Represents an Item.
Definition: item.hpp:37
friend std::ostream & operator<<(std::ostream &os, const Item &i)
Definition: item.hpp:53
void set_id(long id)
Definition: item.hpp:45
std::string get_description()
Definition: item.hpp:48
int operator()(Item *i1, Item *i2)
Definition: item.hpp:64
ItemCompareName()
Definition: item.hpp:63
bool get_checked()
Definition: item.hpp:50
ItemCompareId()
Definition: item.hpp:74
void set_description(const std::string description)
Definition: item.hpp:47
Functor for processing items.
Definition: item.hpp:85
ItemList::iterator ItemListIter
Definition: item.hpp:95
std::list< Item > ItemList
Definition: item.hpp:94
long m_id
Unique ID.
Definition: item.hpp:38

Copyright 2008-2021 Frank Dean