soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
CSTree< T > Class Template Reference

Template class for a tree structure. More...

#include <STree.h>

Public Member Functions

 CSTree ()
 Constructor.
 
virtual ~CSTree ()
 Destructor.
 
void DeleteAllItems ()
 Delete all items in the tree.
 
HSTREEITEM GetChildItem (HSTREEITEM hItem, BOOL bFirst=TRUE) const
 Get the child item.
 
int GetChildrenCount (HSTREEITEM hItem) const
 Get the number of children.
 
virtual void DeleteItem (HSTREEITEM hItem)
 Delete an item.
 
BOOL DeleteItemEx (HSTREEITEM hItem)
 Delete an item and its branch.
 
HSTREEITEM InsertItem (const T &data, HSTREEITEM hParent=((HSTREEITEM) 0xFFFF0000), HSTREEITEM hInsertAfter=((HSTREEITEM) 0xFFFF0002))
 Insert a new item.
 
HSTREEITEM TraversingRecursion (HSTREEITEM hItem, CBTRAVERSING funTraversing, LPARAM lParam)
 Traverse the tree recursively.
 
HSTREEITEM TraversingSequence (HSTREEITEM hItem, CBTRAVERSING funTraversing, LPARAM lParam)
 Traverse the tree in sequence.
 
HSTREEITEM GetRootItem (BOOL bFirst=TRUE)
 Get the root item.
 
int GetDesendants (HSTREEITEM hItem)
 Get the number of descendants of a node.
 
HSTREEITEM GetNextItem (HSTREEITEM hItem) const
 Get the next item in the tree.
 
HSTREEITEM GetNextItem (HSTREEITEM hItem, int &nLevel) const
 Get the next item in the tree with level relationship.
 
void SortChildren (HSTREEITEM hItem, int(__cdecl *funSort)(void *, const void *, const void *), void *pCtx)
 Sort the children of a node.
 
void SetDataFreer (IDataFreer *cbFree)
 Set the data freer callback.
 

Static Public Member Functions

static HSTREEITEM GetNextSiblingItem (HSTREEITEM hItem)
 Get the next sibling item.
 
static HSTREEITEM GetPrevSiblingItem (HSTREEITEM hItem)
 Get the previous sibling item.
 
static HSTREEITEM GetParentItem (HSTREEITEM hItem)
 Get the parent item.
 
static int GetItemLevel (HSTREEITEM hItem)
 Get the level of the item.
 
static HSTREEITEM GetRootItem (HSTREEITEM hItem)
 Get the root item of the specified node.
 
static T GetItem (HSTREEITEM hItem)
 Get the item data.
 
static T & GetItemRef (HSTREEITEM hItem)
 Get the item data reference.
 
static T * GetItemPt (HSTREEITEM hItem)
 Get the item data pointer.
 

Protected Member Functions

virtual void OnNodeFree (T &data)
 Virtual function to handle the freeing of node data.
 

Protected Attributes

IDataFreer * m_dataFreer
 
HSTREENODE m_hRootFirst
 
HSTREENODE m_hRootLast
 

Detailed Description

template<class T>
class CSTree< T >

Template class for a tree structure.

This template class provides a tree structure for general data types.

Definition at line 56 of file STree.h.

Constructor & Destructor Documentation

◆ CSTree()

template<class T>
CSTree< T >::CSTree ( )
inline

Constructor.

Definition at line 109 of file STree.h.

◆ ~CSTree()

template<class T>
virtual CSTree< T >::~CSTree ( )
inlinevirtual

Destructor.

Definition at line 119 of file STree.h.

Member Function Documentation

◆ DeleteAllItems()

template<class T>
void CSTree< T >::DeleteAllItems ( )
inline

Delete all items in the tree.

< STVN_ROOT

Definition at line 127 of file STree.h.

◆ DeleteItem()

template<class T>
virtual void CSTree< T >::DeleteItem ( HSTREEITEM hItem)
inlinevirtual

Delete an item.

Parameters
HSTREEITEMhItem: Node handle

< STVN_ROOT

< STVN_ROOT

Definition at line 253 of file STree.h.

◆ DeleteItemEx()

template<class T>
BOOL CSTree< T >::DeleteItemEx ( HSTREEITEM hItem)
inline

Delete an item and its branch.

Parameters
HSTREEITEMhItem: Node handle
Returns
BOOL: TRUE if successful, FALSE otherwise

Definition at line 289 of file STree.h.

◆ GetChildItem()

template<class T>
HSTREEITEM CSTree< T >::GetChildItem ( HSTREEITEM hItem,
BOOL bFirst = TRUE ) const
inline

Get the child item.

Parameters
HSTREEITEMhItem: Node handle
BOOLbFirst: Whether to get the first child
Returns
HSTREEITEM: Child node handle

< STVN_ROOT

Definition at line 212 of file STree.h.

◆ GetChildrenCount()

template<class T>
int CSTree< T >::GetChildrenCount ( HSTREEITEM hItem) const
inline

Get the number of children.

Parameters
HSTREEITEMhItem: Node handle
Returns
int: Number of child nodes

Definition at line 237 of file STree.h.

◆ GetDesendants()

template<class T>
int CSTree< T >::GetDesendants ( HSTREEITEM hItem)
inline

Get the number of descendants of a node.

Parameters
HSTREEITEMhItem: Starting node handle
Returns
int: Number of descendant nodes

Recursively counts the number of descendant nodes starting from the specified node.

Definition at line 516 of file STree.h.

◆ GetItem()

template<class T>
static T CSTree< T >::GetItem ( HSTREEITEM hItem)
inlinestatic

Get the item data.

Parameters
HSTREEITEMhItem: Node handle
Returns
T: Data stored in the node

Definition at line 307 of file STree.h.

◆ GetItemLevel()

template<class T>
static int CSTree< T >::GetItemLevel ( HSTREEITEM hItem)
inlinestatic

Get the level of the item.

Parameters
HSTREEITEMhItem: Node handle
Returns
int: Level of the node

< STVI_ROOT

Definition at line 178 of file STree.h.

◆ GetItemPt()

template<class T>
static T * CSTree< T >::GetItemPt ( HSTREEITEM hItem)
inlinestatic

Get the item data pointer.

Parameters
HSTREEITEMhItem: Node handle
Returns
T*: Pointer to data stored in the node

Definition at line 333 of file STree.h.

◆ GetItemRef()

template<class T>
static T & CSTree< T >::GetItemRef ( HSTREEITEM hItem)
inlinestatic

Get the item data reference.

Parameters
HSTREEITEMhItem: Node handle
Returns
T&: Reference to data stored in the node

Definition at line 320 of file STree.h.

◆ GetNextItem() [1/2]

template<class T>
HSTREEITEM CSTree< T >::GetNextItem ( HSTREEITEM hItem) const
inline

Get the next item in the tree.

Parameters
HSTREEITEMhItem: Current node handle
Returns
HSTREEITEM: Handle of the next node

Returns the next node in the tree. The traversal order is:

  • First child of the current node
  • Next sibling of the current node
  • Next sibling of the parent node, if no children or siblings are available

< STVI_ROOT

Definition at line 538 of file STree.h.

◆ GetNextItem() [2/2]

template<class T>
HSTREEITEM CSTree< T >::GetNextItem ( HSTREEITEM hItem,
int & nLevel ) const
inline

Get the next item in the tree with level relationship.

Parameters
HSTREEITEMhItem: Current node handle
int&nLevel: Level relationship between the current node and the returned node
Returns
HSTREEITEM: Handle of the next node

Returns the next node in the tree and sets the level relationship:

  • 1: Parent-child relationship
  • 0: Sibling relationship
  • -n: Child to parent's sibling relationship

< STVI_ROOT

Definition at line 568 of file STree.h.

◆ GetNextSiblingItem()

template<class T>
static HSTREEITEM CSTree< T >::GetNextSiblingItem ( HSTREEITEM hItem)
inlinestatic

Get the next sibling item.

Parameters
HSTREEITEMhItem: Node handle
Returns
HSTREEITEM: Next sibling node handle

Definition at line 142 of file STree.h.

◆ GetParentItem()

template<class T>
static HSTREEITEM CSTree< T >::GetParentItem ( HSTREEITEM hItem)
inlinestatic

Get the parent item.

Parameters
HSTREEITEMhItem: Node handle
Returns
HSTREEITEM: Parent node handle

Definition at line 166 of file STree.h.

◆ GetPrevSiblingItem()

template<class T>
static HSTREEITEM CSTree< T >::GetPrevSiblingItem ( HSTREEITEM hItem)
inlinestatic

Get the previous sibling item.

Parameters
HSTREEITEMhItem: Node handle
Returns
HSTREEITEM: Previous sibling node handle

Definition at line 154 of file STree.h.

◆ GetRootItem() [1/2]

template<class T>
HSTREEITEM CSTree< T >::GetRootItem ( BOOL bFirst = TRUE)
inline

Get the root item.

Parameters
BOOLbFirst: Whether to get the first root item (default is TRUE)
Returns
HSTREEITEM: Handle of the root item

Returns the root item of the tree. If bFirst is TRUE, it returns the first root item; otherwise, it returns the last root item.

Definition at line 504 of file STree.h.

◆ GetRootItem() [2/2]

template<class T>
static HSTREEITEM CSTree< T >::GetRootItem ( HSTREEITEM hItem)
inlinestatic

Get the root item of the specified node.

Parameters
HSTREEITEMhItem: Current node handle
Returns
HSTREEITEM: Root node handle

Definition at line 196 of file STree.h.

◆ InsertItem()

template<class T>
HSTREEITEM CSTree< T >::InsertItem ( const T & data,
HSTREEITEM hParent = ((HSTREEITEM)0xFFFF0000),
HSTREEITEM hInsertAfter = ((HSTREEITEM)0xFFFF0002) )
inline

Insert a new item.

Parameters
constT &data: Data to insert
HSTREEITEMhParent: Parent node handle
HSTREEITEMhInsertAfter: Insert after this node
Returns
HSTREEITEM: Handle of the inserted node

< STVN_ROOT

< STVN_FIRST

< STVN_LAST

< STVN_LAST

< STVN_FIRST

< STVN_LAST

Parameters
hParentSTVI_ROOT
hInsertAfterSTVI_LAST

Definition at line 348 of file STree.h.

◆ OnNodeFree()

template<class T>
virtual void CSTree< T >::OnNodeFree ( T & data)
inlineprotectedvirtual

Virtual function to handle the freeing of node data.

Parameters
T&data: Reference to the data stored in the node.

This function is intended to be overridden in derived classes to implement specific data cleanup logic. If a data freer callback (m_dataFreer) is set, it will call the callback's OnDataFree method to handle the data cleanup.

Definition at line 710 of file STree.h.

◆ SetDataFreer()

template<class T>
void CSTree< T >::SetDataFreer ( IDataFreer * cbFree)
inline

Set the data freer callback.

Parameters
IDataFreer*cbFree: Data freer callback object

Sets the callback object for freeing node data.

Definition at line 666 of file STree.h.

◆ SortChildren()

template<class T>
void CSTree< T >::SortChildren ( HSTREEITEM hItem,
int(__cdecl *funSort)(void *, const void *, const void *) ,
void * pCtx )
inline

Sort the children of a node.

Parameters
HSTREEITEMhItem: Node handle
int(__cdecl*funSort)(void *, const void *, const void *): Comparison function
void*pCtx: Context for the comparison function

Sorts the children of the specified node using the provided comparison function. The comparison function should have the signature int(__cdecl *)(void *, const void *, const void *).

< STVI_ROOT

Definition at line 604 of file STree.h.

◆ TraversingRecursion()

template<class T>
HSTREEITEM CSTree< T >::TraversingRecursion ( HSTREEITEM hItem,
CBTRAVERSING funTraversing,
LPARAM lParam )
inline

Traverse the tree recursively.

Parameters
HSTREEITEMhItem: Starting node handle
CBTRAVERSINGfunTraversing: Callback function
LPARAMlParam: Additional parameter for the callback
Returns
HSTREEITEM: Handle of the node where traversal stopped

< STVI_ROOT

Definition at line 438 of file STree.h.

◆ TraversingSequence()

template<class T>
HSTREEITEM CSTree< T >::TraversingSequence ( HSTREEITEM hItem,
CBTRAVERSING funTraversing,
LPARAM lParam )
inline

Traverse the tree in sequence.

Parameters
HSTREEITEMhItem: Starting node handle
CBTRAVERSINGfunTraversing: Callback function
LPARAMlParam: Additional parameter for the callback
Returns
HSTREEITEM: Handle of the node where traversal stopped

Traverses the tree in sequence starting from the specified node. If the callback function returns TRUE, the traversal stops and the current node is returned. Otherwise, it continues to the next node.

< STVI_ROOT

Definition at line 477 of file STree.h.

Member Data Documentation

◆ m_dataFreer

template<class T>
IDataFreer* CSTree< T >::m_dataFreer
protected

Pointer to an object implementing the IDataFreer interface for custom data cleanup.

Definition at line 715 of file STree.h.

◆ m_hRootFirst

template<class T>
HSTREENODE CSTree< T >::m_hRootFirst
protected

Pointer to the first root node of the tree.

Definition at line 716 of file STree.h.

◆ m_hRootLast

template<class T>
HSTREENODE CSTree< T >::m_hRootLast
protected

Pointer to the last root node of the tree.

Definition at line 717 of file STree.h.


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