#include <children_holder.h>
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 | |
ThisType::list_type * | child_list (const ThisType::parent_type *parent, int creationPolicy=0) |
Returns the child list for the given parent object. | |
bool | unmap_parent (const ThisType::parent_type *parent) |
Removes parent from this object's internal map. | |
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. |
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.
|
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. |
|
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. |
|
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. |