29 #ifndef CMAPPEDTREE_HPP_
30 #define CMAPPEDTREE_HPP_
32 #include <sutil/CMappedList.hpp>
65 template <
typename TIdx,
typename TNode>
104 virtual TNode*
create(
const TIdx& arg_idx,
const TNode & arg_node2add,
105 const bool arg_is_root_);
113 virtual TNode*
create(
const TIdx& arg_idx,
const bool arg_is_root_);
121 virtual TNode*
insert(
const TIdx& arg_idx, TNode *arg_node2add,
122 const bool arg_is_root_);
129 {
return static_cast<const TNode*
>(
root_node_); }
136 virtual bool isAncestor(
const TIdx& arg_idx_child,
137 const TIdx& arg_idx_ancestor)
const;
140 virtual bool isAncestor(
const TNode* arg_node_child,
141 const TNode* arg_node_ancestor)
const;
145 const TIdx& arg_idx_descendant)
const;
149 const TNode* arg_node_descendant)
const;
154 template <
typename TIdx,
typename TNode>
173 child_addrs_.clear();
185 template <
typename TIdx,
typename TNode>
189 has_been_init_ =
false;
198 template <
typename TIdx,
typename TNode>
202 template <
typename TIdx,
typename TNode>
228 template <
typename TIdx,
typename TNode>
230 const TIdx& arg_idx,
const TNode & arg_node2add,
231 const bool arg_is_root_)
233 if((arg_is_root_)&&(NULL!=root_node_))
236 std::cerr<<
"\nCMappedTree::create() : Error. Tried to insert a root node when one already exists.";
245 if((arg_is_root_) && (root_node_==NULL))
246 { root_node_ = tLnk; }
257 template <
typename TIdx,
typename TNode>
259 const TIdx& arg_idx,
const bool arg_is_root_)
261 if((arg_is_root_)&&(NULL!=root_node_))
264 std::cerr<<
"\nCMappedTree::create() : Error. Tried to insert a root node when one already exists.";
272 if((arg_is_root_) && (NULL==root_node_))
273 { root_node_ = tLnk; }
286 template <
typename TIdx,
typename TNode>
288 const TIdx& arg_idx, TNode *arg_node2add,
289 const bool arg_is_root_)
291 if((arg_is_root_)&&(NULL!=root_node_))
294 std::cerr<<
"\nCMappedTree::create() : Error. Tried to insert a root node when one already exists.";
302 if((arg_is_root_) && (root_node_==NULL))
303 { root_node_ = tLnk; }
315 template <
typename TIdx,
typename TNode>
318 if(NULL == getRootNodeConst())
327 TNode& tmp_node = *it;
328 tmp_node.parent_addr_ = NULL;
329 tmp_node.child_addrs_.clear();
337 TNode& tmp_node = *it;
340 if(&tmp_node == root_node_)
342 has_been_init_ =
true;
347 tmp_node.parent_addr_ =
349 if(tmp_node.parent_addr_ == NULL)
352 std::cerr<<
"\nCMappedTree::linkNodes(): Warning.";
353 std::cerr<<
"Orphan node found: "<<tmp_node.name_<<
". Ignoring.";
357 tmp_node.parent_addr_->child_addrs_.push_back(&tmp_node);
360 std::cerr<<
"\n\tAdding child "<<tmp_node.name_
361 <<
" to (parent) "<<tmp_node.parent_addr_->name_;
362 std::cerr<<std::flush;
366 return has_been_init_;
371 template <
typename TIdx,
typename TNode>
373 const TIdx& arg_idx_ancestor)
const
374 {
return isAncestor(this->at_const(arg_idx_child), this->at_const(arg_idx_child)); }
377 template <
typename TIdx,
typename TNode>
379 const TNode* arg_node_ancestor)
const
381 const TNode *child = arg_node_child;
382 if( NULL == child || NULL == arg_node_ancestor)
387 if(arg_node_ancestor == child)
389 child = child->parent_addr_;
395 template <
typename TIdx,
typename TNode>
397 const TIdx& arg_idx_descendant)
const
398 {
return isDescendant(this->at_const(arg_idx_parent), this->at_const(arg_idx_descendant)); }
401 template <
typename TIdx,
typename TNode>
403 const TNode* arg_node_descendant)
const
405 const TNode *parent = arg_node_parent;
406 if( NULL == parent || NULL == arg_node_descendant)
411 if(arg_node_descendant == parent)
414 typename std::vector<TNode*>::const_iterator it,ite;
415 for(it = parent->child_addrs_.begin(), ite = parent->child_addrs_.end(); it!=ite; ++it)
417 if(isDescendant(*it, arg_node_descendant))
virtual TNode * create(const TIdx &arg_idx, const TNode &arg_node2add, const bool arg_is_root_)
Definition: CMappedTree.hpp:229
virtual bool deepCopy(const CMappedTree< TIdx, TNode > *arg_mt)
Definition: CMappedTree.hpp:204
Definition: CMappedTree.hpp:155
SMTNodeBase()
Definition: CMappedTree.hpp:168
virtual bool isAncestor(const TIdx &arg_idx_child, const TIdx &arg_idx_ancestor) const
Definition: CMappedTree.hpp:372
TNode * parent_addr_
Definition: CMappedTree.hpp:163
TNode * root_node_
Definition: CMappedTree.hpp:70
CMappedTree()
Definition: CMappedTree.hpp:186
virtual CMappedTree< TIdx, TNode > & operator=(const CMappedTree< TIdx, TNode > &arg_rhs)
Definition: CMappedTree.hpp:90
Definition: CMappedList.hpp:85
virtual bool deepCopy(const CMappedList< Idx, T > *const arg_pmap)
Definition: CMappedList.hpp:572
virtual TNode * insert(const TIdx &arg_idx, TNode *arg_node2add, const bool arg_is_root_)
Definition: CMappedTree.hpp:287
bool has_been_init_
Definition: CMappedTree.hpp:73
virtual bool linkNodes()
Definition: CMappedTree.hpp:316
virtual T * at(const std::size_t arg_idx)
Definition: CMappedList.hpp:832
TIdx parent_name_
Definition: CMappedTree.hpp:161
Definition: CMappedTree.hpp:66
TIdx name_
Definition: CMappedTree.hpp:159
virtual TNode * getRootNode()
Definition: CMappedTree.hpp:132
virtual T * create(const Idx &arg_idx, const bool insert_at_start=true)
Definition: CMappedList.hpp:714
std::vector< TNode * > child_addrs_
Definition: CMappedTree.hpp:165
virtual const TNode * getRootNodeConst() const
Definition: CMappedTree.hpp:128
virtual bool isDescendant(const TIdx &arg_idx_parent, const TIdx &arg_idx_descendant) const
Definition: CMappedTree.hpp:396
virtual ~CMappedTree()
Definition: CMappedTree.hpp:199