<
classTData>
179 template<
classTNode>
247{
return m_Nodes[size_t(idx)].GetValue(); }
249{
return m_Nodes[size_t(idx)].GetValue(); }
354 template<
classTTreeModel,
classFun>
357 typedef typenameTTreeModel::TNodeType TNodeType;
362stop_scan = func(tree_model, node_idx, delta_level);
372TNodeType* tr = &tree_model[node_idx];
374 typedef typenameTNodeType::TNodeList_I TTreeNodeIterator;
376TTreeNodeIterator it = tr->SubNodeBegin();
377TTreeNodeIterator it_end = tr->SubNodeEnd();
382stack<TTreeNodeIterator> tree_stack;
385tr = &tree_model[*it];
386stop_scan = func(tree_model, *it, delta_level);
395(delta_level >= 0) &&
398it = tr->SubNodeBegin();
399it_end = tr->SubNodeEnd();
405 if(tree_stack.empty()) {
408it = tree_stack.top();
410tr = &tree_model[*it];
411it_end = tree_model[tr->GetParent()].SubNodeEnd();
420func(tree_model, node_idx, -1);
427 template<
classTTreeModel,
classFun>
430 return TreeDepthFirst(tree_model, tree_model.GetRootIdx(), func);
437 template<
classTTreeModel>
462 template<
classTTreeModel,
classFun>
465 typedef typenameTTreeModel::TNodeType TNodeType;
466 typedef typenameTNodeType::TNodeList_I TTreeNodeIterator;
471stop_scan = func(tree_model, node_idx, delta_level);
481TNodeType* tr = &tree_model[node_idx];
485TTreeNodeIterator it_end = node_iter.
m_node_list.end();
487 if(node_iter.
m_it== it_end)
490stack<NodeListIter<TTreeModel> > tree_stack;
493tr = &tree_model[*node_iter.
m_it];
494stop_scan = func(tree_model, *node_iter.
m_it, delta_level);
503(delta_level >= 0) &&
505tree_stack.push(node_iter);
513 if(node_iter.
m_it== it_end) {
514 if(tree_stack.empty()) {
517node_iter = tree_stack.top();
519tr = &tree_model[*node_iter.
m_it];
529func(tree_model, node_idx, -1);
535 template<
classTTreeModel,
classFun>
559 template<
classTTreeModel,
classFun>
562 typedef typenameTTreeModel::TNodeType TNodeType;
568stop_scan = func(tree_model, node_idx, delta_level);
577 typedef typenameTNodeType::TNodeList_I TTreeNodeIterator;
579queue<TTreeIdx> node_queue;
580node_queue.push(node_idx);
584 while(!node_queue.empty()) {
585 TTreeIdxnode_idx = node_queue.front();
588TNodeType* tr = &tree_model[node_idx];
590TTreeNodeIterator it = tr->SubNodeBegin();
591TTreeNodeIterator it_end = tr->SubNodeEnd();
592 for(; it != it_end; ++it) {
593stop_scan = func(tree_model, *it, delta_level);
602node_queue.push(*it);
609 if(--level_count == 0) {
610level_count = node_queue.size();
616func(tree_model, node_idx, -1);
622 template<
classTTreeModel,
classFun>
635 template<
classTData>
639 template<
classTData>
643 if(HasChild(child_idx)) {
644 LOG_POST(
"Trying to add duplicate child node: "<< child_idx <<
" to another node");
649m_ChildNodes.push_back(child_idx);
652 template<
classTData>
655vector<TTreeIdx>::iterator iter = find(m_ChildNodes.begin(), m_ChildNodes.end(), child_idx);
657 if(iter==m_ChildNodes.end()) {
661m_ChildNodes.erase(iter);
664 template<
classTData>
667 return( std::find(m_ChildNodes.begin(), m_ChildNodes.end(), child_idx) != m_ChildNodes.end());
677 template<
classTNode>
680 template<
classTNode>
689 template<
classTNode>
692 if(node.GetParent() == TNodeType::Null())
695 returnm_Nodes[node.GetParent()];
698 template<
classTNode>
701 if(node.GetParent() == TNodeType::Null())
704 returnm_Nodes[node.GetParent()];
707 template<
classTNode>
710m_Nodes[size_t(parent_idx)].RemoveChild(child_idx);
711m_Nodes[size_t(child_idx)].SetParent(Null());
714 template<
classTNode>
717m_Nodes[size_t(parent_idx)].AddChild(child_idx);
718m_Nodes[size_t(child_idx)].SetParent(parent_idx);
721 template<
classTNode>
724 if(m_RootIdx == idx)
727 if(idx >= m_Nodes.size())
730x_ConvertUpstream(idx);
735 template<
classTNode>
738 TTreeIdxparent_idx = m_Nodes[node_idx].GetParent();
740 if(parent_idx != Null()) {
741RemoveChild(parent_idx, node_idx);
742x_ConvertUpstream(parent_idx);
743AddChild(node_idx, parent_idx);
748 template<
classTNode>
751m_Nodes.push_back(TNode());
752 size_tidx = m_Nodes.size()-1;
757 template<
classTNode>
760 size_tidx = m_Nodes.size();
762m_Nodes.push_back(node);
766 template<
classTNode>
770m_Nodes.reserve(target_size);
Base class for nodes in the tree.
const TData & operator*() const
const TData & GetValue() const
void RemoveChild(TTreeIdx child_idx)
Remove child node if it is a child of this node.
TData m_Data
Data object.
void RemoveParent()
Set the parent index to Null() e.g. for root node.
TNodeList::reverse_iterator TNodeList_RI
TNodeList_RI SubNodeRBegin()
Return reverse iterator to (reverse) begin of subnode array.
TTreeIdx GetParent() const
Get node's parent.
void ClearConnections()
Remove connections to parent and children of this node.
TTreeIdx m_ParentNode
Index of parent node to this node. ==Null() if this is the root node.
TData & operator*()
Return the value object for the node using de-referenceing semantics.
TNodeList_CI SubNodeEnd() const
Return const iterator to end of subnode list.
TNodeList & GetChildren()
Return the indices of this node's child nodes.
TNodeList::iterator TNodeList_I
void SetParent(TTreeIdx parent_idx)
Set index of nodes parent.
TNodeList_CRI SubNodeRBegin() const
Return const reverse iterator to (reverse) of begin of subnode array.
TNodeList_CRI SubNodeREnd() const
Return const reverse iterator to (reverse) end of subnode array.
bool HasChild(TTreeIdx child_idx) const
Check if another node is a child of this node.
CTreeModelNode()
Construct an empty node (null parent)
TData & GetValue()
Return the value object for the node.
TNodeList_I SubNodeBegin()
Return iterator to first subnode index.
TNodeList_RI SubNodeREnd()
Return reverse iterator to (reverse) end of subnode array.
TNodeList::const_reverse_iterator TNodeList_CRI
bool HasParent() const
Check if the node has a parent.
TNodeList::const_iterator TNodeList_CI
const TNodeList & GetChildren() const
const TData * operator->() const
vector< TTreeIdx > TNodeList
TNodeList_I SubNodeEnd()
Return iterator to end of subnode list.
bool IsLeaf() const
Report whether this is a leaf node.
static TTreeIdx Null()
Static function that returns the null value.
TNodeList_CI SubNodeBegin() const
Return const iterator to first subnode index.
vector< TTreeIdx > m_ChildNodes
Indices of all the children of this node.
void AddChild(TTreeIdx child_idx)
Add a child node.
void SetValue(const TData &data)
Set the value-object for the node.
int m_NumNodes
Number of nodes in tree (not including collapsed/hidden nodes)
const TNode & operator[](TTreeIdx idx) const
void ReRoot(TTreeIdx idx)
Sets the root idx to be 'idx' and updates the tree so that all nodes above the new root become childr...
virtual void x_ConvertUpstream(TTreeIdx node_idx)
Convert parents of node_idx to be its children.
const TValueType & GetNodeValue(TTreeIdx idx) const
const TNode & GetRoot() const
TNodeType & GetParent(TNodeType &node)
Return a reference to the parent node of the given node.
TNodeType::TNodeList_I TNodeList_I
TNodeVecType m_Nodes
The list of nodes in the tree.
TTreeIdx AddNode(const TNode &node)
Add a copy of node 'node' to the tree and return its index.
TValueType & GetNodeValue(TTreeIdx idx)
Return a reference to the 'value' object of a node.
const TNodeType & GetParent(TNodeType &node) const
TNodeType & operator[](TTreeIdx idx)
Use operator[] to return a reference to the node at 'idx'.
void Reserve(size_t target_size)
Allocate the memory in advance, if you know how big the tree will be.
size_t GetNumNodes() const
Get the number of displayed nodes in current tree layout.
static TTreeIdx Null()
Return the index value that represents a NULL node.
size_t GetSize() const
Get the number of nodes currently in the array.
void SetNumNodes(int count)
Set the number of displayed nodes in current tree layout.
CTreeModel()
Create empty tree. Tree is not valid at this point (no nodes)
TNodeType & GetNode(TTreeIdx idx)
Return a reference to the node at the given index.
TNodeType::TNodeList_CRI TNodeList_CRI
TNodeType::TNodeList_CI TNodeList_CI
void Clear()
Remove all nodes (empty array) and set root index to Null.
TNodeType::TNodeList_RI TNodeList_RI
TNodeType & GetRoot()
Return a reference to the root node of the tree.
void AddChild(TTreeIdx parent_idx, TTreeIdx child_idx)
Add the node at 'child_idx' to the children 'parent_idx'.
TNodeType::TNodeList TNodeList
const TNode & GetNode(TTreeIdx idx) const
std::vector< TNodeType > TNodeVecType
TTreeIdx GetRootIdx() const
Return the index of the root node.
TNode::TValueType TValueType
TTreeIdx AddNode()
Add a new default node to the tree and return its index.
void RemoveChild(TTreeIdx parent_idx, TTreeIdx child_idx)
Remove the node at 'child_idx' from its parent 'parent_idx' Nothing is done if the node 'child_idx' i...
void SetRootIdx(TTreeIdx idx)
Set the index of the root node of the tree.
TTreeIdx m_RootIdx
The index of the root node within the tree.
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
@ eTreeTraverseStop
Stop traversal (return form algorithm)
@ eTreeTraverse
Keep traversal.
@ eTreeTraverseStepOver
Do not traverse current node (pick the next one)
Depth-first tree traversal which allows the traversed tree to update the list of child nodes at the c...
NodeListIter(const NodeListIter &rhs)
void SetNode(TNodeType *tr)
TTreeModel::TNodeType TNodeType
TTreeModel::TNodeList TNodeList
NodeListIter & operator=(const NodeListIter &rhs)
TNodeType::TNodeList_I TTreeNodeIterator
NodeListIter(TNodeType *tr)
Fun TreeBreadthFirst(TTreeModel &tree_model, typename TTreeModel::TTreeIdx node_idx, Fun func)
Breadth-first tree traversall.
#define NULL_TREE_IDX
Global define for a NULL link in the tree used for comparison.
Fun TreeDepthFirst(TTreeModel &tree_model, typename TTreeModel::TTreeIdx node_idx, Fun func)
Depth-first tree traversal algorithm.
size_t TTreeIdx
Bi-directionaly linked N way tree allocated in a contiguous memory block.
Fun TreeDepthFirstInvarient(TTreeModel &tree_model, typename TTreeModel::TTreeIdx node_idx, Fun func)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4