Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members

s11n::children_holder< PType, CType > Class Template Reference

EXPERIMENTAL! More...

#include <children_holder.h>

List of all members.

Public Types

typedef PType parent_type
 The type of this object's parents in parent-child relationships.
typedef CType child_type
 The type of this object's children in parent-child relationships.
typedef std::list< child_type * > list_type
 The container type used to store the lists of children.
typedef children_holder< parent_type,
child_type
ThisType
 A shortcut typedef to help ease the implementation code for this class.
typedef list_type::iterator iterator
 iterator which can be dereferenced to a (child_type *).
typedef list_type::const_iterator const_iterator
 iterator which can be dereferenced to a (const child_type *).

Static Public Member Functions

static ThisType::list_typechild_list (const ThisType::parent_type *parent, int creationPolicy=0)
 Returns the child list for the given parent object.
static bool unmap_parent (const ThisType::parent_type *parent)
 Removes parent from this object's internal map.
static bool cleanup_parent (const ThisType::parent_type *parent)
 Simlar as unmap_parent(), but also deletes the children in the list and then deletes the list.


Detailed Description

template<class PType, class CType>
class s11n::children_holder< PType, CType >

EXPERIMENTAL!

children_holder is an experimental object for creating pointer containers for arbitrary child types. The idea is that many objects i create have a heirarchical structure, and i'm looking for a generic way to code this pattern.

The interface should allow any given class, including non-modifiable 3rd-party classes, to have any number of child types.

This code does no automatic clean-up of children. Client code may free all child pointers by calling cleanup_parent(), and subclasses or proxies of this object should call that in their dtor.

Definition at line 31 of file children_holder.h.


Member Function Documentation

template<class PType, class CType>
static ThisType::list_type* s11n::children_holder< PType, CType >::child_list const ThisType::parent_type parent,
int  creationPolicy = 0
[inline, static]
 

Returns the child list for the given parent object.

If creationPolicy is non-zero then this function will create the child list if it does not yet exist (in that case, this function will never return NULL except on an out-of-memory error).

The caller takes ownership of the returned pointer. All children in the list can be deleted at once by calling cleanup_parent( parent ).

Different calls to this function will always return the same list (or the same NULL, depending on creationPolicy ;) until either unmap_parent() or cleanup_parent() are called, in which case further calls to this function may return a different pointer the next time it is called.

Definition at line 83 of file children_holder.h.

template<class PType, class CType>
static bool s11n::children_holder< PType, CType >::cleanup_parent const ThisType::parent_type parent  )  [inline, static]
 

Simlar as unmap_parent(), but also deletes the children in the list and then deletes the list.

Subclasses or proxies of this class should call this function from their dtor, in order to avoid leaving any dangling pointers in this class' internal data.

Definition at line 130 of file children_holder.h.

References s11n::children_holder< PType, CType >::unmap_parent().

template<class PType, class CType>
static bool s11n::children_holder< PType, CType >::unmap_parent const ThisType::parent_type parent  )  [inline, static]
 

Removes parent from this object's internal map.

This only removes the pointer to the parent's child list and the mapping which binds the parent to the children, but does not delete() anything.

Returns true if it unmaps the parent, else false. It will only fail if it doesn't have an entry for parent.

This is more of a maintenance detail than anything else.

Definition at line 111 of file children_holder.h.

Referenced by s11n::children_holder< PType, CType >::cleanup_parent().


The documentation for this class was generated from the following file:
Generated on Thu Jun 16 16:18:12 2005 for s11n by  doxygen 1.4.3-20050530