For n-ary trees, cursors are used to point to nodes in the tree. Unlike cursors of flat collections, tree cursors stay defined when elements are added to the tree, or when elements othe than the one pointed to are removed. Cursors are used in operations to access the element information stored in a node. They are also used to designate a subtree of the tree, namely the subtree whose root node the cursor points to.
As for flat collections, a distinction is made between the abstract base class ITreeCursor, and cursor classes local to the tree classes themselves. The local, or nested, cursor classes are derived from the abstract base class.
Constructors & DestructorUse these member functions to construct or destruct objects of the class.
![]() |
public:
virtual ~ITreeCursor()
Removes all elements from this tree.
Side Effects
All cursors of the tree become undefined.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Constructs the cursor and associates it with the given tree. The cursor is initially invalid.
protected:
ITreeCursor(ITreeCursor const&)
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
protected:
ITreeCursor(Implementation*)
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
Cursor SettingsUse these member functions to set the cursor to required position.
![]() |
public:
bool setToChild(IPosition)
Sets the cursor to the child with the given position of the node denoted by the given cursor (of this tree). Invalidates the cursor if this child does not exist.
Preconditions
Return Value
Returns true if the child exists.
Exceptions
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool setToFirstExistingChild()
Sets the cursor to the first child of the node denoted by the given cursor (of this tree). Invalidates the cursor if the node has no child. A node with no child is a leaf node of the tree.
Preconditions
The cursor must point to an element of this tree.
Return Value
Returns true if the node has a child.
Exception
ICursorInvalidException
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool setToLastExistingChild()
Sets the cursor to the last child of the node denoted by the given cursor (of this tree). Invalidates the cursor if the node has no child. A node with no child is a leaf node of the tree.
Precondition
The cursor must point to an element of this tree.
Return Value
Returns true if the node has a child.
Exception
ICursorInvalidException
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool setToNextExistingChild()
Sets the cursor to the next existing sibling of the node denoted by the given cursor (of this tree). Invalidates the cursor if the node has no next sibling. A node with no next sibling is the last existing child of its parent.
Precondition
The cursor must point to an element of this tree.
Return Value
Returns true if the node has a next sibling.
Exception
ICursorInvalidException
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool setToParent()
Sets the cursor to the parent of the node denoted by the given cursor (of this tree). Invalidates the cursor if the node has no parent. A node with no parent is the root node of its tree.
Precondition
The cursor must point to an element of this tree.
Return Value
Returns true if the node has a parent.
Exception
ICursorInvalidException
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool setToPreviousExistingChild()
Sets the cursor to the previous existing sibling of the node denoted by the given cursor (of this tree). Invalidates the cursor if the node has no previous sibling. A node with no previous sibling is the first existing child of its parent.
Precondition
The cursor must point to an element of this tree.
Return Value
Returns true if the node has a previous sibling.
Exception
ICursorInvalidException
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool setToRoot()
Sets the cursor to the root node of the tree. Invalidates the cursor if the tree is empty (that is, if no root node exists).
Precondition
The cursor must belong to this tree.
Return Value
Returns true if the tree is not empty.
Exception
ICursorInvalidException
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
Cursor ValidationUse these members to validate the cursor.
![]() |
public:
void invalidate()
Invalidates the cursor so that it no longer points to a node of the associated tree.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool isValid() const
Returns true if the cursor points to a node of the associated tree.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
MiscellaneousUse these members to execute miscellaneous functions.
![]() |
public:
void copy(ITreeCursor const&)
Removes all elements from this tree, and copies the subtree denoted by the given cursor of the given tree to (the root of) this tree. The copy function (without a cursor argument) copies the whole given tree.
Preconditions
The cursor must point to an element of the given tree.
Exceptions
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
protected:
inline static Implementation& ImplOf(ITreeCursor const&)
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
OperatorsUse these members as operators.
![]() |
public:
bool operator !=(ITreeCursor const&) const
Returns true if the cursor does not point to the same node of the same tree as the given cursor.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
void operator =(ITreeCursor const&)
Copies all elements of the given tree to this tree.
Return Value
A reference to this tree.
Side Effects
All cursors of this tree become undefined.
Exception
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool operator ==(ITreeCursor const&) const
Returns true if the cursor points to the same node of the same tree as the given cursor.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |