XmlDao Class Reference

Implementation of a KitListDao using XML as the persistence store. More...

#include <xmldao.hpp>

Inheritance diagram for XmlDao:

KitListDao

List of all members.

Public Member Functions

 XmlDao (int verbose=0)
KitModelget_model ()
 Loads the data model from the previously set filename.
KitModelget_model (Glib::ustring filename)
void save_model (KitModel *model)
 Saves the model as an XML document.
void save_model (KitModel *model, Glib::ustring filename)
 Saves the model as an XML document.
Categoryget_category (long cat_id, item_choice choice)
 Loads a category.
ItemContainerget_all_items (item_choice choice)
 Returns a list of all items.
long add_item (const std::string name)
long add_item (const std::string name, long cat_id)
void append_items_to_category (long to_cat_id, long from_cat_id, item_choice choice)
 Copies items from one category to another.
void associate_item_with_category (long id, long cat_id)
 Associates an existing item with an existing category.
CategoryContainer get_categories ()
long new_category (const std::string name)
 Creates a new category.
void delete_item (long id)
void update_item_checked_state (ItemContainer &items)
 Persists the state of the 'checked' flag of each item.
void remove_item_from_category (long id, long cat_id)
long get_next_item_id ()
 Returns the next unused unique id for items.
long get_next_category_id ()
void delete_category (long id)
void set_item_flag (long id)
void unset_item_flag (long id)
void set_category_flag (long id)
void unset_category_flag (long id)
void set_all_flags ()
void unset_all_flags ()
void set_filename (Glib::ustring filename)
virtual bool require_filename ()
 Indicates that this implementation requires a filename.

Protected Attributes

Glib::ustring m_filename
 The filename to load or save the XML document from.
xmlpp::Element * m_items_node
 Temporary reference to the items' node.
xmlpp::Element * m_categories_node
 Temporary reference to the categories' node.
xmlpp::Element * m_cat_items_node
 Temporary reference to the categories' items' node.
long m_max_item_id
 The last used ID for items.
long m_max_category_id
 The last used ID for categories.

Private Member Functions

bool add_item_to_dom (ModelItem &item)
 Adds the passed item to the current items' node.
bool add_category_item_to_dom (Item &item)
 Adds the passed item to the current category's node.
bool add_category_to_dom (ModelCategory &item)
 Adds the passed item to the current categories' node.


Detailed Description

Implementation of a KitListDao using XML as the persistence store.

Definition at line 42 of file xmldao.hpp.


Constructor & Destructor Documentation

XmlDao::XmlDao ( int  verbose = 0  )  [inline]

Definition at line 67 of file xmldao.hpp.


Member Function Documentation

bool XmlDao::add_item_to_dom ( ModelItem item  )  [private]

Adds the passed item to the current items' node.

See also:
XmlDao::save_model(KitModel&)

Definition at line 87 of file xmldao.cpp.

References Item::get_checked(), Item::get_description(), Item::get_id(), GuiState::is_deleted(), and m_items_node.

Referenced by save_model().

bool XmlDao::add_category_item_to_dom ( Item item  )  [private]

Adds the passed item to the current category's node.

See also:
XmlDao::save_model(KitModel&)

Definition at line 106 of file xmldao.cpp.

References Item::get_id(), and m_cat_items_node.

Referenced by add_category_to_dom().

bool XmlDao::add_category_to_dom ( ModelCategory category  )  [private]

Adds the passed item to the current categories' node.

See also:
XmlDao::save_model(KitModel&)

Definition at line 123 of file xmldao.cpp.

References add_category_item_to_dom(), Category::foreach_item(), Category::get_id(), Category::get_name(), GuiState::is_deleted(), m_cat_items_node, and m_categories_node.

Referenced by save_model().

KitModel * XmlDao::get_model (  )  [virtual]

Loads the data model from the previously set filename.

The data model holds a rich graph of objects, representing the entire list of categories and items.

The filename must be set before calling this method by calling XmlDao::set_filename(), otherwise an empty model is returned.

Return values:
Returns a newly created data model. The caller is responsible for destroying the model.
See also:
KitModel

Implements KitListDao.

Definition at line 46 of file xmldao.cpp.

References KitModel::get_all_items(), KitModel::get_categories(), Category::get_id(), Item::get_id(), m_filename, m_max_category_id, m_max_item_id, and KitModel::reset().

Referenced by get_model().

KitModel* XmlDao::get_model ( Glib::ustring  filename  )  [inline]

Definition at line 76 of file xmldao.hpp.

References get_model(), and set_filename().

void XmlDao::save_model ( KitModel model  )  [virtual]

Saves the model as an XML document.

The filename must be set before calling this method by calling XmlDao::set_filename();

Parameters:
model The model to save.

Implements KitListDao.

Definition at line 163 of file xmldao.cpp.

References add_category_to_dom(), add_item_to_dom(), KitModel::foreach_category(), KitModel::foreach_item(), m_categories_node, m_filename, m_items_node, KitModel::purge(), and KitModel::reset().

Referenced by Service::save_as_xml(), and save_model().

void XmlDao::save_model ( KitModel model,
Glib::ustring  filename 
) [inline]

Saves the model as an XML document.

Parameters:
model The model to save.
filename The name of the file to save to.

Definition at line 86 of file xmldao.hpp.

References save_model(), and set_filename().

Category* XmlDao::get_category ( long  cat_id,
item_choice  choice 
) [inline, virtual]

Loads a category.

Parameters:
choice Which items to load for the category. One of ALL_ITEMS, CHECKED_ITEMS or UNCHECKED_ITEMS.

Implements KitListDao.

Definition at line 88 of file xmldao.hpp.

References NYI.

ItemContainer* XmlDao::get_all_items ( item_choice  choice  )  [inline, virtual]

Returns a list of all items.

Parameters:
choice Which items to load. One of ALL_ITEMS, CHECKED_ITEMS or UNCHECKED_ITEMS.

Implements KitListDao.

Definition at line 90 of file xmldao.hpp.

References NYI.

long XmlDao::add_item ( const std::string  name  )  [inline, virtual]

Creates a new item.

Parameters:
name The name of the new item.

Implements KitListDao.

Definition at line 92 of file xmldao.hpp.

References NYI.

long XmlDao::add_item ( const std::string  name,
long  cat_id 
) [inline, virtual]

Creates a new item and associates it with a category.

Parameters:
name The name of the new item.

Implements KitListDao.

Definition at line 94 of file xmldao.hpp.

References NYI.

void XmlDao::append_items_to_category ( long  to_cat_id,
long  from_cat_id,
item_choice  choice 
) [inline, virtual]

Copies items from one category to another.

Optionally, only checked or unchecked items are copied.

Parameters:
from_cat_id The ID of the source category.
to_cat_id The ID of the target category.
choice One of ALL_ITEMS, CHECKED_ITEMS or UNCHECKED_ITEMS.

Implements KitListDao.

Definition at line 96 of file xmldao.hpp.

References NYI.

void XmlDao::associate_item_with_category ( long  id,
long  cat_id 
) [inline, virtual]

Associates an existing item with an existing category.

Parameters:
id The Item ID
cat_id The Category ID

Implements KitListDao.

Definition at line 98 of file xmldao.hpp.

References NYI.

CategoryContainer XmlDao::get_categories (  )  [inline, virtual]

Returns a list of all categories.

Implements KitListDao.

Definition at line 100 of file xmldao.hpp.

References NYI.

long XmlDao::new_category ( const std::string  name  )  [inline, virtual]

Creates a new category.

Parameters:
name the name of the new category.

Implements KitListDao.

Definition at line 102 of file xmldao.hpp.

References NYI.

void XmlDao::delete_item ( long  id  )  [inline, virtual]

Deletes an item by it's ID.

Parameters:
id the ID of the item to delete.

Implements KitListDao.

Definition at line 104 of file xmldao.hpp.

References NYI.

void XmlDao::update_item_checked_state ( ItemContainer items  )  [inline, virtual]

Persists the state of the 'checked' flag of each item.

Implements KitListDao.

Definition at line 106 of file xmldao.hpp.

References NYI.

void XmlDao::remove_item_from_category ( long  id,
long  cat_id 
) [inline, virtual]

Un-associates the specified item from the specified category.

Parameters:
id The Item id.
cat_id The Category id.

Implements KitListDao.

Definition at line 108 of file xmldao.hpp.

References NYI.

long XmlDao::get_next_item_id (  )  [virtual]

Returns the next unused unique id for items.

Implements KitListDao.

Definition at line 142 of file xmldao.cpp.

References m_max_item_id.

long XmlDao::get_next_category_id (  )  [virtual]

Returns the next unused unique id for categories.

Implements KitListDao.

Definition at line 150 of file xmldao.cpp.

References m_max_category_id.

void XmlDao::delete_category ( long  id  )  [inline, virtual]

Deletes a category.

Implements KitListDao.

Definition at line 114 of file xmldao.hpp.

References NYI.

void XmlDao::set_item_flag ( long  id  )  [inline, virtual]

Sets the checked flag for an item.

Parameters:
id The id of the item to change.

Implements KitListDao.

Definition at line 116 of file xmldao.hpp.

References NYI.

void XmlDao::unset_item_flag ( long  id  )  [inline, virtual]

Clears the checked flag for an item.

Implements KitListDao.

Definition at line 118 of file xmldao.hpp.

References NYI.

void XmlDao::set_category_flag ( long  id  )  [inline, virtual]

Checks/ticks all items in the specified Category.

Implements KitListDao.

Definition at line 120 of file xmldao.hpp.

References NYI.

void XmlDao::unset_category_flag ( long  id  )  [inline, virtual]

Unchecks/unticks all items in the specified Category.

Implements KitListDao.

Definition at line 122 of file xmldao.hpp.

References NYI.

void XmlDao::set_all_flags (  )  [inline, virtual]

Checks/ticks all items.

Implements KitListDao.

Definition at line 124 of file xmldao.hpp.

References NYI.

void XmlDao::unset_all_flags (  )  [inline, virtual]

Unchecks/unticks all items.

Implements KitListDao.

Definition at line 126 of file xmldao.hpp.

References NYI.

void XmlDao::set_filename ( Glib::ustring  filename  )  [inline]

Definition at line 128 of file xmldao.hpp.

References m_filename.

Referenced by get_model(), and save_model().

virtual bool XmlDao::require_filename (  )  [inline, virtual]

Indicates that this implementation requires a filename.

This persistence model requires a filename to be chosen before the data can be persisted.

Returns:
Always returns true.

Reimplemented from KitListDao.

Definition at line 138 of file xmldao.hpp.


Member Data Documentation

Glib::ustring XmlDao::m_filename [protected]

The filename to load or save the XML document from.

Definition at line 54 of file xmldao.hpp.

Referenced by get_model(), save_model(), and set_filename().

xmlpp::Element* XmlDao::m_items_node [protected]

Temporary reference to the items' node.

Definition at line 56 of file xmldao.hpp.

Referenced by add_item_to_dom(), and save_model().

xmlpp::Element* XmlDao::m_categories_node [protected]

Temporary reference to the categories' node.

Definition at line 58 of file xmldao.hpp.

Referenced by add_category_to_dom(), and save_model().

xmlpp::Element* XmlDao::m_cat_items_node [protected]

Temporary reference to the categories' items' node.

Definition at line 60 of file xmldao.hpp.

Referenced by add_category_item_to_dom(), and add_category_to_dom().

long XmlDao::m_max_item_id [protected]

The last used ID for items.

Definition at line 62 of file xmldao.hpp.

Referenced by get_model(), and get_next_item_id().

long XmlDao::m_max_category_id [protected]

The last used ID for categories.

Definition at line 64 of file xmldao.hpp.

Referenced by get_model(), and get_next_category_id().


The documentation for this class was generated from the following files:

Copyright 2008, 2009 Frank Dean