DCMTK  Version 3.6.6
OFFIS DICOM Toolkit
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
DSRTree< T > Class Template Reference

Class managing a tree of nodes. More...

Public Member Functions

 DSRTree ()
 default constructor
 
 DSRTree (const DSRTree< T > &tree)
 copy constructor. More...
 
virtual ~DSRTree ()
 destructor
 
DSRTreeoperator= (DSRTree< T > tree)
 assignment operator. More...
 
virtual void clear ()
 clear all member variables, i.e. the tree with all nodes
 
void clearAnnotations ()
 clear annotations of all tree nodes
 
OFBool isEmpty () const
 check whether tree has any nodes More...
 
size_t countNodes () const
 count number of nodes in the tree. More...
 
size_t getNextNodeID () const
 get ID of the next node to be created. More...
 
size_t gotoRoot ()
 set internal cursor to root node More...
 
size_t gotoNode (const size_t searchID, const OFBool startFromRoot=OFTrue)
 set internal cursor to specified node More...
 
size_t gotoNode (const OFString &reference, const OFBool startFromRoot=OFTrue)
 set internal cursor to specified node More...
 
size_t gotoNode (const DSRTreeNodeAnnotation &annotation, const OFBool startFromRoot=OFTrue)
 set internal cursor to specified node More...
 
size_t gotoNode (const T &nodeValue, const OFBool startFromRoot=OFTrue)
 set internal cursor to specified node (given by its value). More...
 
virtual size_t addNode (T *node, const E_AddMode addMode=AM_afterCurrent)
 add new node to the current one. More...
 
virtual size_t replaceNode (T *node)
 replace current node by the given one. More...
 
virtual T * extractNode ()
 extract current node from tree. More...
 
virtual T * getAndRemoveRootNode ()
 get pointer to root node and "forget" the internal reference to this node. More...
 
virtual size_t removeNode ()
 remove current node from tree. More...
 
virtual DSRTree< T > * extractSubTree ()
 extract a subtree, i.e. a fragment from this tree. More...
 
virtual DSRTree< T > * cloneSubTree (const size_t stopAfterNodeID=0) const
 clone a subtree, i.e. a fragment of this tree. More...
 

Protected Member Functions

 DSRTree (T *rootNode)
 special constructor that receives a pointer to the root node. More...
 
 DSRTree (const DSRTreeNodeCursor< T > &startCursor, size_t stopAfterNodeID)
 special copy constructor that clones a particular subtree only More...
 
void swap (DSRTree< T > &tree)
 fast, non-throwing swap function. More...
 
virtual T * getRoot () const
 get pointer to root node More...
 
virtual void deleteTreeFromRootNode (T *rootNode)
 delete a tree given by its root node. More...
 

Private Attributes

T * RootNode
 pointer to the root tree node
 

Detailed Description

template<typename T = DSRTreeNode>
class DSRTree< T >

Class managing a tree of nodes.

Constructor & Destructor Documentation

◆ DSRTree() [1/3]

template<typename T >
DSRTree< T >::DSRTree ( const DSRTree< T > &  tree)

copy constructor.

Please note that the internal cursor is not copied but reset, i.e. set to the root node.

Parameters
treetree to be copied

References DSRTree< T >::addNode(), OFStack< T >::empty(), DSRTree< T >::getRoot(), DSRTree< T >::gotoRoot(), DSRTree< T >::isEmpty(), OFStack< T >::pop(), OFStack< T >::push(), and OFStack< T >::top().

◆ DSRTree() [2/3]

template<typename T >
DSRTree< T >::DSRTree ( T *  rootNode)
protected

special constructor that receives a pointer to the root node.

Please note that the 'rootNode' and the associated tree is not copied!

Parameters
rootNodepointer to the root node of the "new" tree

References DSRTree< T >::gotoRoot().

◆ DSRTree() [3/3]

template<typename T >
DSRTree< T >::DSRTree ( const DSRTreeNodeCursor< T > &  startCursor,
size_t  stopAfterNodeID 
)
protected

special copy constructor that clones a particular subtree only

Parameters
startCursorcursor pointing to first node of the subtree to be copied
stopAfterNodeIDID of the node after which the cloning should stop

References DSRTree< T >::addNode(), OFStack< T >::empty(), DSRTreeNodeCursor< T >::getNode(), DSRTree< T >::gotoRoot(), OFStack< T >::pop(), OFStack< T >::push(), and OFStack< T >::top().

Member Function Documentation

◆ addNode()

template<typename T >
size_t DSRTree< T >::addNode ( T *  node,
const E_AddMode  addMode = AM_afterCurrent 
)
virtual

add new node to the current one.

Please note that no copy of the given node is created. Therefore, the node should be created with new() - do not use a reference to a local variable. If the node could be added successfully, the cursor is set to it automatically.

Parameters
nodepointer to the new node to be added
addModeflag specifying at which position to add the new node
Returns
ID of the new node if successful, 0 otherwise

Reimplemented in DSRDocumentSubTree.

References DSRTreeNode::Down, DSRTreeNode::getIdent(), DSRTreeNode::Next, and DSRTreeNode::Prev.

Referenced by DSRTree< T >::DSRTree().

◆ cloneSubTree()

template<typename T >
DSRTree< T > * DSRTree< T >::cloneSubTree ( const size_t  stopAfterNodeID = 0) const
virtual

clone a subtree, i.e. a fragment of this tree.

The cloning starts with the current node and ends with the given node.

Parameters
stopAfterNodeIDID of the node after which the cloning should stop. By default (0), the process ends after cloning the current node with all of its child nodes (if any).
Returns
pointer to a copy of the specified subtree, NULL in case of error

Reimplemented in DSRDocumentSubTree.

◆ countNodes()

template<typename T >
size_t DSRTree< T >::countNodes

count number of nodes in the tree.

This method iterates over all nodes that are stored in the tree.

Returns
number of nodes, 0 if tree is empty

References DSRTreeNodeCursor< T >::isValid(), and DSRTreeNodeCursor< T >::iterate().

◆ deleteTreeFromRootNode()

template<typename T >
void DSRTree< T >::deleteTreeFromRootNode ( T *  rootNode)
protectedvirtual

delete a tree given by its root node.

Please note that the given 'rootNode' pointer becomes invalid afterwards.

Parameters
rootNodepointer to the root node of the tree to be deleted

◆ extractNode()

template<typename T >
T * DSRTree< T >::extractNode
virtual

extract current node from tree.

Please note that not only the specified node but also all of its child nodes are extracted from the tree. The cursor is set automatically to a new valid position.

Returns
pointer to extracted node, NULL in case of error (or the tree was empty)

Reimplemented in DSRDocumentSubTree.

References DSRTreeNode::Down, DSRTreeNode::getNext(), DSRTreeNode::getPrev(), DSRTreeNode::Next, and DSRTreeNode::Prev.

◆ extractSubTree()

template<typename T >
DSRTree< T > * DSRTree< T >::extractSubTree
virtual

extract a subtree, i.e. a fragment from this tree.

The subtree is specified by the current node, which becomes the root of the subtree.

Returns
pointer to the extracted subtree, NULL in case of error

Reimplemented in DSRDocumentSubTree.

◆ getAndRemoveRootNode()

template<typename T >
T * DSRTree< T >::getAndRemoveRootNode
virtual

get pointer to root node and "forget" the internal reference to this node.

In other words: after calling this method, the stored tree will be empty. This also means that the caller is responsible for deleting the allocated memory.

Returns
pointer to root node, might be NULL (empty tree)

Reimplemented in DSRDocumentSubTree.

◆ getNextNodeID()

template<typename T >
size_t DSRTree< T >::getNextNodeID
inline

get ID of the next node to be created.

The node ID uniquely identifies a content item in the document tree.

Returns
ID of the next node to be created (should never be 0)

References DSRTreeNode::getIdentCounter().

◆ getRoot()

template<typename T >
T * DSRTree< T >::getRoot
protectedvirtual

get pointer to root node

Returns
pointer to root node, might be NULL (empty tree)

Referenced by DSRTree< T >::DSRTree().

◆ gotoNode() [1/4]

template<typename T >
size_t DSRTree< T >::gotoNode ( const DSRTreeNodeAnnotation annotation,
const OFBool  startFromRoot = OFTrue 
)

set internal cursor to specified node

Parameters
annotationannotation of the node to set the cursor to
startFromRootflag indicating whether to start from the root node or the current one
Returns
ID of the new current node if successful, 0 otherwise

References DSRTreeNodeCursor< T >::gotoNode(), and DSRTreeNodeAnnotation::isEmpty().

◆ gotoNode() [2/4]

template<typename T >
size_t DSRTree< T >::gotoNode ( const OFString reference,
const OFBool  startFromRoot = OFTrue 
)

set internal cursor to specified node

Parameters
referenceposition string of the node to set the cursor to. (the format is e.g. "1.2.3" for the third child of the second child of the first node - see DSRTreeNodeCursor).
startFromRootflag indicating whether to start from the root node or the current one
Returns
ID of the new current node if successful, 0 otherwise

References OFString::empty(), and DSRTreeNodeCursor< T >::gotoNode().

◆ gotoNode() [3/4]

template<typename T >
size_t DSRTree< T >::gotoNode ( const size_t  searchID,
const OFBool  startFromRoot = OFTrue 
)

set internal cursor to specified node

Parameters
searchIDID of the node to set the cursor to
startFromRootflag indicating whether to start from the root node or the current one
Returns
ID of the new current node if successful, 0 otherwise

References DSRTreeNodeCursor< T >::gotoNode().

◆ gotoNode() [4/4]

template<typename T >
size_t DSRTree< T >::gotoNode ( const T &  nodeValue,
const OFBool  startFromRoot = OFTrue 
)

set internal cursor to specified node (given by its value).

This method requires that T implements the comparison operator "not equal".

Parameters
nodeValuevalue of the node to set the cursor to
startFromRootflag indicating whether to start from the root node or the current one
Returns
ID of the new current node if successful, 0 otherwise

References DSRTreeNodeCursor< T >::gotoNode().

◆ gotoRoot()

template<typename T >
size_t DSRTree< T >::gotoRoot
inline

set internal cursor to root node

Returns
ID of root node if successful, 0 otherwise

Referenced by DSRTree< T >::DSRTree().

◆ isEmpty()

template<typename T >
OFBool DSRTree< T >::isEmpty
inline

check whether tree has any nodes

Returns
OFTrue if tree is empty, OFFalse otherwise

Referenced by DSRTree< T >::DSRTree().

◆ operator=()

template<typename T >
DSRTree< T > & DSRTree< T >::operator= ( DSRTree< T >  tree)

assignment operator.

Please note that internally the copy constructor is used, so the same comments apply.

Parameters
treetree to be copied
Returns
reference to this tree after copying

◆ removeNode()

template<typename T >
size_t DSRTree< T >::removeNode
virtual

remove current node from tree.

Please note that not only the specified node but also all of its child nodes are removed from the tree and then deleted. The cursor is set automatically to a new valid position.

Returns
ID of the node which became the current one after deletion, 0 if an error occurred or the tree is now empty.

Reimplemented in DSRDocumentSubTree.

References OFStack< T >::empty(), OFStack< T >::pop(), OFStack< T >::push(), and OFStack< T >::top().

◆ replaceNode()

template<typename T >
size_t DSRTree< T >::replaceNode ( T *  node)
virtual

replace current node by the given one.

Please note that no copy of the given node is created. Therefore, the node should be created with new() - do not use a reference to a local variable. If the node could be replaced successfully, the "old" node (and all of its child nodes) are deleted, and the cursor is set to the new one.

Parameters
nodepointer to the new node to replace the current one
Returns
ID of the new node if successful, 0 otherwise

Reimplemented in DSRDocumentSubTree.

References DSRTreeNode::Down, and DSRTreeNode::Next.

◆ swap()

template<typename T >
void DSRTree< T >::swap ( DSRTree< T > &  tree)
protected

fast, non-throwing swap function.

The time complexity of this function is constant.

Parameters
treetree to swap with

References OFswap(), DSRTree< T >::RootNode, and DSRTreeNodeCursor< T >::swap().


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


Generated on Thu Jan 14 2021 for DCMTK Version 3.6.6 by Doxygen 1.8.18