Kitlist  1.1.0
category.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 CATEGORY_H
24 #define CATEGORY_H 1
25 #include <iostream>
26 #include <vector>
27 #include "item.hpp"
28 
29 
31 
37 class Category {
38  protected:
39  long m_id;
40  std::string m_name;
42  public:
43  ~Category() {}
44  void set_id(long id) { m_id = id; }
45  long get_id() { return m_id; }
46  void set_name (const std::string name) { m_name = name; }
47  std::string get_name() { return m_name; }
48  virtual void add_item(Item* item);
49  virtual void remove_item(Item* item);
51  virtual size_t item_count() { return m_items.size(); }
53  virtual bool has_items() { return !m_items.empty(); }
54  void foreach_item(const SlotForeachItem& slot);
55  void execute(ItemFunctor& functor);
56  friend class CategoryCompareName;
57  friend class CategoryCompareId;
58  friend class KitModel;
59 };
60 
61 
67  public:
69  int operator()(Category* c1, Category* c2) { return (c1->m_name < c2->m_name); }
70 };
71 
72 
78  public:
80  int operator()(Category* c1, Category* c2) { return (c1->m_id < c2->m_id); }
81 };
82 
83 
84 typedef std::vector<Category*> CategoryContainer;
85 typedef CategoryContainer::iterator CategoryIter;
86 
87 #endif // CATEGORY_H
std::string get_name()
Definition: category.hpp:47
virtual bool has_items()
Returns true if there are any items associated with this category.
Definition: category.hpp:53
ItemContainer m_items
List of associated items.
Definition: category.hpp:41
CategoryContainer::iterator CategoryIter
Definition: category.hpp:85
virtual void add_item(Item *item)
Associates the passed item with this Category.
Definition: category.cpp:29
long m_id
Unique id.
Definition: category.hpp:39
~Category()
Definition: category.hpp:43
int operator()(Category *c1, Category *c2)
Definition: category.hpp:80
std::vector< Item * > ItemContainer
Definition: item.hpp:91
void foreach_item(const SlotForeachItem &slot)
Executes a callback function for each associated item.
Definition: category.cpp:55
void set_name(const std::string name)
Definition: category.hpp:46
virtual size_t item_count()
Returns the number of items associated with this category.
Definition: category.hpp:51
void set_id(long id)
Definition: category.hpp:44
sigc::slot< bool, Item & > SlotForeachItem
Definition: item.hpp:97
Represents an Item.
Definition: item.hpp:37
std::string m_name
The category name.
Definition: category.hpp:40
Represents a Category.
Definition: category.hpp:37
virtual void remove_item(Item *item)
Removes the association of the passed item from this Category.
Definition: category.cpp:40
void execute(ItemFunctor &functor)
Executes the passed ItemFunctor.
Definition: category.cpp:71
Holds a rich graph of objects representing the application&#39;s data model.
Definition: kitmodel.hpp:135
Comparator used for sorting Categories by name.
Definition: category.hpp:66
long get_id()
Definition: category.hpp:45
std::vector< Category * > CategoryContainer
Definition: category.hpp:84
int operator()(Category *c1, Category *c2)
Definition: category.hpp:69
Functor for processing items.
Definition: item.hpp:85
Comparator used for comparing Categories by id.
Definition: category.hpp:77

Copyright 2008-2021 Frank Dean