Kitlist  1.1.0
xmldao.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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #ifndef XMLDAO_H
28 #define XMLDAO_H 1
29 
30 #include <cassert>
31 #include <libxml++/libxml++.h>
32 #include "kitlistdao.hpp"
33 #include "kitmodel.hpp"
34 
35 #define NYI assert(false/* == "Method not implemented"*/)
36 
37 
42 class XmlDao : public KitListDao {
43 private:
44 
45  bool add_item_to_dom(ModelItem& item);
46 
47  bool add_category_item_to_dom(Item& item);
48 
50 
51 
52 protected:
54  Glib::ustring m_filename;
56  xmlpp::Element* m_items_node;
58  xmlpp::Element* m_categories_node;
60  xmlpp::Element* m_cat_items_node;
65 
66 public :
67  XmlDao(int verbose = 0) : KitListDao(verbose),
68  m_filename(""),
69  m_max_item_id(-1),
70  m_max_category_id(-1),
71  m_categories_node(NULL),
72  m_items_node(NULL) {}
73 
75 
76  KitModel* get_model(Glib::ustring filename) { set_filename(filename); return get_model(); }
77 
78  void save_model(KitModel* model);
79 
86  void save_model(KitModel* model, Glib::ustring filename) { set_filename(filename); save_model(model); }
87 
88  Category* get_category(long cat_id, item_choice choice) { NYI; }
89 
91 
92  long add_item(const std::string name) { NYI; }
93 
94  long add_item(const std::string name, long cat_id) { NYI; }
95 
96  void append_items_to_category(long to_cat_id, long from_cat_id, item_choice choice) { NYI; }
97 
98  void associate_item_with_category(long id, long cat_id) { NYI; }
99 
101 
102  long new_category(const std::string name) { NYI; }
103 
104  void delete_item(long id) { NYI; }
105 
107 
108  void remove_item_from_category(long id, long cat_id) { NYI; }
109 
110  long get_next_item_id();
111 
112  long get_next_category_id();
113 
114  void delete_category(long id) { NYI; }
115 
116  void set_item_flag(long id) { NYI; }
117 
118  void unset_item_flag(long id) { NYI; }
119 
120  void set_category_flag(long id) { NYI; }
121 
122  void unset_category_flag(long id) { NYI; }
123 
124  void set_all_flags() { NYI; }
125 
126  void unset_all_flags() { NYI; }
127 
128  void set_filename(Glib::ustring filename) { m_filename = filename; }
129 
138  virtual bool require_filename() { return true; }
139 
140 };
141 
142 #endif // XMLDAO_H
CategoryContainer get_categories()
Definition: xmldao.hpp:100
void set_item_flag(long id)
Definition: xmldao.hpp:116
long get_next_category_id()
Definition: xmldao.cpp:150
Represents a Category combined with GuiState attributes.
Definition: kitmodel.hpp:94
xmlpp::Element * m_items_node
Temporary reference to the items&#39; node.
Definition: xmldao.hpp:56
#define NYI
Definition: xmldao.hpp:35
bool add_category_item_to_dom(Item &item)
Adds the passed item to the current category&#39;s node.
Definition: xmldao.cpp:106
KitModel * get_model(Glib::ustring filename)
Definition: xmldao.hpp:76
void unset_item_flag(long id)
Definition: xmldao.hpp:118
void append_items_to_category(long to_cat_id, long from_cat_id, item_choice choice)
Copies items from one category to another.
Definition: xmldao.hpp:96
void delete_item(long id)
Definition: xmldao.hpp:104
std::vector< Item * > ItemContainer
Definition: item.hpp:91
virtual bool require_filename()
Indicates that this implementation requires a filename.
Definition: xmldao.hpp:138
void remove_item_from_category(long id, long cat_id)
Definition: xmldao.hpp:108
long add_item(const std::string name)
Definition: xmldao.hpp:92
void delete_category(long id)
Definition: xmldao.hpp:114
long m_max_item_id
The last used ID for items.
Definition: xmldao.hpp:62
void save_model(KitModel *model)
Saves the model as an XML document.
Definition: xmldao.cpp:163
KitModel * get_model()
Loads the data model from the previously set filename.
Definition: xmldao.cpp:46
long add_item(const std::string name, long cat_id)
Definition: xmldao.hpp:94
xmlpp::Element * m_categories_node
Temporary reference to the categories&#39; node.
Definition: xmldao.hpp:58
void associate_item_with_category(long id, long cat_id)
Associates an existing item with an existing category.
Definition: xmldao.hpp:98
bool add_item_to_dom(ModelItem &item)
Adds the passed item to the current items&#39; node.
Definition: xmldao.cpp:87
long m_max_category_id
The last used ID for categories.
Definition: xmldao.hpp:64
XmlDao(int verbose=0)
Definition: xmldao.hpp:67
Defines the methods that an implementation of this class must implement.
Definition: kitlistdao.hpp:46
Represents an Item.
Definition: item.hpp:37
void set_all_flags()
Definition: xmldao.hpp:124
bool add_category_to_dom(ModelCategory &item)
Adds the passed item to the current categories&#39; node.
Definition: xmldao.cpp:123
Category * get_category(long cat_id, item_choice choice)
Loads a category.
Definition: xmldao.hpp:88
Represents a Category.
Definition: category.hpp:37
Represents an Item combined with GuiState attributes.
Definition: kitmodel.hpp:60
Holds a rich graph of objects representing the application&#39;s data model.
Definition: kitmodel.hpp:135
void set_filename(Glib::ustring filename)
Definition: xmldao.hpp:128
Glib::ustring m_filename
The filename to load or save the XML document from.
Definition: xmldao.hpp:54
void save_model(KitModel *model, Glib::ustring filename)
Saves the model as an XML document.
Definition: xmldao.hpp:86
void unset_category_flag(long id)
Definition: xmldao.hpp:122
long new_category(const std::string name)
Creates a new category.
Definition: xmldao.hpp:102
Implementation of a KitListDao using XML as the persistence store.
Definition: xmldao.hpp:42
std::vector< Category * > CategoryContainer
Definition: category.hpp:84
void set_category_flag(long id)
Definition: xmldao.hpp:120
item_choice
Definition: kitlistdao.hpp:36
ItemContainer * get_all_items(item_choice choice)
Returns a list of all items.
Definition: xmldao.hpp:90
void update_item_checked_state(ItemContainer &items)
Persists the state of the &#39;checked&#39; flag of each item.
Definition: xmldao.hpp:106
long get_next_item_id()
Returns the next unused unique id for items.
Definition: xmldao.cpp:142
void unset_all_flags()
Definition: xmldao.hpp:126
xmlpp::Element * m_cat_items_node
Temporary reference to the categories&#39; items&#39; node.
Definition: xmldao.hpp:60

Copyright 2008-2021 Frank Dean