feisty meow concerns codebase  2.140
tree.h
Go to the documentation of this file.
1 #ifndef TREE_CLASS
2 #define TREE_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : tree *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1992-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include "node.h"
19 #include "path.h"
20 
21 #include <basis/enhance_cpp.h>
22 
23 namespace nodes {
24 
26 
39 class tree : public node
40 {
41 public:
42  tree();
44 
45  virtual ~tree();
47 
49 
50  virtual tree *branch(int branch_number) const;
52 
55  virtual int which(tree *branch_to_find) const;
57 
59  virtual int branches() const;
61 
62  virtual tree *parent() const;
64 
66  virtual tree *root() const;
68 
70  virtual int depth() const;
72 
73  virtual void attach(tree *new_branch);
75 
76  virtual void insert(int branch_place, tree *new_branch);
78 
81  virtual basis::outcome prune(tree *branch_to_cut);
83 
88  virtual basis::outcome prune_index(int branch_to_cut);
90 
97 
116 
119  class iterator : public path
120  {
121  public:
122  iterator(const tree *initial, traversal_directions direction);
123  ~iterator();
124 
125  tree *next();
127 
129  void whack(tree *to_whack);
131 
138 
139  private:
140  bool next_node(tree *&to_return);
142 
147  };
148 
149  iterator start(traversal_directions direction) const;
151 
152  virtual bool generate_path(path &to_follow) const;
154 
155 private:
156  // unavailable.
157  tree(const tree &);
158  tree &operator =(const tree &);
159 };
160 
161 } // namespace.
162 
163 #endif
164 
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
An object representing the interstitial cell in most linked data structures.
Definition: node.h:41
A method for tracing a route from a tree's root to a particular node.
Definition: path.h:36
void whack(tree *to_whack)
destroys the tree "to_whack".
Definition: tree.cpp:221
tree * next()
Returns a pointer to the next tree in the direction of traversal.
Definition: tree.cpp:257
iterator(const tree *initial, traversal_directions direction)
Definition: tree.cpp:45
traversal_directions _order
Definition: tree.h:136
elevator_directions _aim
Definition: tree.h:137
A dynamically linked tree with an arbitrary number of branches.
Definition: tree.h:40
virtual int depth() const
Returns the distance of "this" from the root. The root's depth is 0.
Definition: tree.cpp:502
virtual void insert(int branch_place, tree *new_branch)
inserts "new_branch" before the branches starting at "branch_place".
Definition: tree.cpp:460
virtual basis::outcome prune_index(int branch_to_cut)
Removes the branch at the specified index from this tree.
Definition: tree.cpp:479
virtual int which(tree *branch_to_find) const
Returns the branch number for a particular branch in this tree.
Definition: tree.cpp:440
virtual ~tree()
destroys the tree by recursively destroying all child tree nodes.
Definition: tree.cpp:279
tree()
constructs a new tree with a root and zero branches.
Definition: tree.cpp:275
DEFINE_CLASS_NAME("tree")
virtual int branches() const
Returns the number of branches currently connected to this tree.
Definition: tree.cpp:431
virtual void attach(tree *new_branch)
Attaches the specified branch to the current tree.
Definition: tree.cpp:453
elevator_directions
Definition: tree.h:114
@ AWAY_FROM_ROOT
Definition: tree.h:114
@ TOWARD_ROOT
Definition: tree.h:114
virtual basis::outcome prune(tree *branch_to_cut)
Removes the specified branch from this tree.
Definition: tree.cpp:472
virtual tree * parent() const
Returns the tree node that is the immediate ancestor of this one.
Definition: tree.cpp:429
iterator start(traversal_directions direction) const
Returns a fresh iterator positioned at this tree node.
Definition: tree.cpp:542
traversal_directions
Definition: tree.h:94
@ postfix
Definition: tree.h:94
@ prefix
Definition: tree.h:94
@ to_branches
Definition: tree.h:94
@ reverse_branches
Definition: tree.h:95
@ infix
Definition: tree.h:94
virtual bool generate_path(path &to_follow) const
Returns the path to "this" path_tree from its root.
Definition: tree.cpp:516
virtual tree * root() const
Locates and returns the absolute root of the tree containing this tree.
Definition: tree.cpp:443
virtual tree * branch(int branch_number) const
Returns the specified branch of this tree.
Definition: tree.cpp:433