Kitlist  1.1.0
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
XmlDao Class Reference

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

#include <xmldao.hpp>

Inheritance diagram for XmlDao:
KitListDao

Public Member Functions

 XmlDao (int verbose=0)
 
KitModelget_model ()
 Loads the data model from the previously set filename. More...
 
KitModelget_model (Glib::ustring filename)
 
void save_model (KitModel *model)
 Saves the model as an XML document. More...
 
void save_model (KitModel *model, Glib::ustring filename)
 Saves the model as an XML document. More...
 
Categoryget_category (long cat_id, item_choice choice)
 Loads a category. More...
 
ItemContainerget_all_items (item_choice choice)
 Returns a list of all items. More...
 
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. More...
 
void associate_item_with_category (long id, long cat_id)
 Associates an existing item with an existing category. More...
 
CategoryContainer get_categories ()
 
long new_category (const std::string name)
 Creates a new category. More...
 
void delete_item (long id)
 
void update_item_checked_state (ItemContainer &items)
 Persists the state of the 'checked' flag of each item. More...
 
void remove_item_from_category (long id, long cat_id)
 
long get_next_item_id ()
 Returns the next unused unique id for items. More...
 
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. More...
 
- Public Member Functions inherited from KitListDao
 KitListDao (int verbose=0)
 Constructor which will use default database connection parameters. More...
 
virtual ~KitListDao ()
 
void set_verbose (int verbose_flag)
 
int is_verbose ()
 

Protected Attributes

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

Private Member Functions

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

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::XmlDao ( int  verbose = 0)
inline

Definition at line 67 of file xmldao.hpp.

References get_model().

Member Function Documentation

◆ add_category_item_to_dom()

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().

Referenced by add_category_to_dom().

◆ 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(), and GuiState::is_deleted().

Referenced by save_model().

◆ add_item() [1/2]

long XmlDao::add_item ( const std::string  name)
inlinevirtual

Creates a new item.

Parameters
nameThe name of the new item.

Implements KitListDao.

Definition at line 92 of file xmldao.hpp.

References NYI.

◆ add_item() [2/2]

long XmlDao::add_item ( const std::string  name,
long  cat_id 
)
inlinevirtual

Creates a new item and associates it with a category.

Parameters
nameThe name of the new item.

Implements KitListDao.

Definition at line 94 of file xmldao.hpp.

References NYI.

◆ add_item_to_dom()

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(), and GuiState::is_deleted().

Referenced by save_model().

◆ append_items_to_category()

void XmlDao::append_items_to_category ( long  to_cat_id,
long  from_cat_id,
item_choice  choice 
)
inlinevirtual

Copies items from one category to another.

Optionally, only checked or unchecked items are copied.

Parameters
from_cat_idThe ID of the source category.
to_cat_idThe ID of the target category.
choiceOne of ALL_ITEMS, CHECKED_ITEMS or UNCHECKED_ITEMS.

Implements KitListDao.

Definition at line 96 of file xmldao.hpp.

References NYI.

◆ associate_item_with_category()

void XmlDao::associate_item_with_category ( long  id,
long  cat_id 
)
inlinevirtual

Associates an existing item with an existing category.

Parameters
idThe Item ID
cat_idThe Category ID

Implements KitListDao.

Definition at line 98 of file xmldao.hpp.

References NYI.

◆ delete_category()

void XmlDao::delete_category ( long  id)
inlinevirtual

Deletes a category.

Implements KitListDao.

Definition at line 114 of file xmldao.hpp.

References NYI.

◆ delete_item()

void XmlDao::delete_item ( long  id)
inlinevirtual

Deletes an item by it's ID.

Parameters
idthe ID of the item to delete.

Implements KitListDao.

Definition at line 104 of file xmldao.hpp.

References NYI.

◆ get_all_items()

ItemContainer* XmlDao::get_all_items ( item_choice  choice)
inlinevirtual

Returns a list of all items.

Parameters
choiceWhich items to load. One of ALL_ITEMS, CHECKED_ITEMS or UNCHECKED_ITEMS.

Implements KitListDao.

Definition at line 90 of file xmldao.hpp.

References NYI.

◆ get_categories()

CategoryContainer XmlDao::get_categories ( )
inlinevirtual

Returns a list of all categories.

Implements KitListDao.

Definition at line 100 of file xmldao.hpp.

References NYI.

◆ get_category()

Category* XmlDao::get_category ( long  cat_id,
item_choice  choice 
)
inlinevirtual

Loads a category.

Parameters
choiceWhich 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.

◆ get_model() [1/2]

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
Returnsa 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(), and KitModel::reset().

Referenced by XmlDao().

◆ get_model() [2/2]

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

Definition at line 76 of file xmldao.hpp.

References get_model(), save_model(), and set_filename().

Referenced by get_model().

◆ get_next_category_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.

Referenced by remove_item_from_category().

◆ get_next_item_id()

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.

Referenced by remove_item_from_category().

◆ new_category()

long XmlDao::new_category ( const std::string  name)
inlinevirtual

Creates a new category.

Parameters
namethe name of the new category.

Implements KitListDao.

Definition at line 102 of file xmldao.hpp.

References NYI.

◆ remove_item_from_category()

void XmlDao::remove_item_from_category ( long  id,
long  cat_id 
)
inlinevirtual

Un-associates the specified item from the specified category.

Parameters
idThe Item id.
cat_idThe Category id.

Implements KitListDao.

Definition at line 108 of file xmldao.hpp.

References get_next_category_id(), get_next_item_id(), and NYI.

◆ require_filename()

virtual bool XmlDao::require_filename ( )
inlinevirtual

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.

◆ save_model() [1/2]

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
modelThe 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(), KitModel::purge(), and KitModel::reset().

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

◆ save_model() [2/2]

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

Saves the model as an XML document.

Parameters
modelThe model to save.
filenameThe name of the file to save to.

Definition at line 86 of file xmldao.hpp.

References save_model(), and set_filename().

Referenced by save_model().

◆ set_all_flags()

void XmlDao::set_all_flags ( )
inlinevirtual

Checks/ticks all items.

Implements KitListDao.

Definition at line 124 of file xmldao.hpp.

References NYI.

◆ set_category_flag()

void XmlDao::set_category_flag ( long  id)
inlinevirtual

Checks/ticks all items in the specified Category.

Implements KitListDao.

Definition at line 120 of file xmldao.hpp.

References NYI.

◆ set_filename()

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

Definition at line 128 of file xmldao.hpp.

Referenced by get_model(), and save_model().

◆ set_item_flag()

void XmlDao::set_item_flag ( long  id)
inlinevirtual

Sets the checked flag for an item.

Parameters
idThe id of the item to change.

Implements KitListDao.

Definition at line 116 of file xmldao.hpp.

References NYI.

◆ unset_all_flags()

void XmlDao::unset_all_flags ( )
inlinevirtual

Unchecks/unticks all items.

Implements KitListDao.

Definition at line 126 of file xmldao.hpp.

References NYI.

◆ unset_category_flag()

void XmlDao::unset_category_flag ( long  id)
inlinevirtual

Unchecks/unticks all items in the specified Category.

Implements KitListDao.

Definition at line 122 of file xmldao.hpp.

References NYI.

◆ unset_item_flag()

void XmlDao::unset_item_flag ( long  id)
inlinevirtual

Clears the checked flag for an item.

Implements KitListDao.

Definition at line 118 of file xmldao.hpp.

References NYI.

◆ update_item_checked_state()

void XmlDao::update_item_checked_state ( ItemContainer items)
inlinevirtual

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

Implements KitListDao.

Definition at line 106 of file xmldao.hpp.

References NYI.

Member Data Documentation

◆ m_cat_items_node

xmlpp::Element* XmlDao::m_cat_items_node
protected

Temporary reference to the categories' items' node.

Definition at line 60 of file xmldao.hpp.

◆ m_categories_node

xmlpp::Element* XmlDao::m_categories_node
protected

Temporary reference to the categories' node.

Definition at line 58 of file xmldao.hpp.

◆ m_filename

Glib::ustring XmlDao::m_filename
protected

The filename to load or save the XML document from.

Definition at line 54 of file xmldao.hpp.

◆ m_items_node

xmlpp::Element* XmlDao::m_items_node
protected

Temporary reference to the items' node.

Definition at line 56 of file xmldao.hpp.

◆ m_max_category_id

long XmlDao::m_max_category_id
protected

The last used ID for categories.

Definition at line 64 of file xmldao.hpp.

◆ m_max_item_id

long XmlDao::m_max_item_id
protected

The last used ID for items.

Definition at line 62 of file xmldao.hpp.


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

Copyright 2008-2021 Frank Dean