tree.h

Go to the documentation of this file.
00001 #ifndef TREE_CLASS
00002 #define TREE_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : tree                                                              *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1992-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "node.h"
00019 #include "path.h"
00020 
00021 #include <basis/enhance_cpp.h>
00022 
00023 namespace nodes {
00024 
00026 
00039 class tree : public node
00040 {
00041 public:
00042   tree();
00044 
00045   virtual ~tree();
00047 
00048   DEFINE_CLASS_NAME("tree");
00049 
00050   virtual tree *branch(int branch_number) const;
00052 
00055   virtual int which(tree *branch_to_find) const;
00057 
00059   virtual int branches() const;
00061 
00062   virtual tree *parent() const;
00064 
00066   virtual tree *root() const;
00068 
00070   virtual int depth() const;
00072 
00073   virtual void attach(tree *new_branch);
00075 
00076   virtual void insert(int branch_place, tree *new_branch);
00078 
00081   virtual basis::outcome prune(tree *branch_to_cut);
00083 
00088   virtual basis::outcome prune_index(int branch_to_cut);
00090 
00094   enum traversal_directions { prefix, infix, postfix, to_branches,
00095           reverse_branches };
00097 
00114   enum elevator_directions { TOWARD_ROOT, AWAY_FROM_ROOT };
00116 
00119   class iterator : public path
00120   {
00121   public:
00122     iterator(const tree *initial, traversal_directions direction);
00123     ~iterator();
00124 
00125     tree *next();
00127 
00129     void whack(tree *to_whack);
00131 
00136     traversal_directions _order;
00137     elevator_directions _aim;
00138 
00139   private:
00140     bool next_node(tree *&to_return);
00142 
00147   };
00148   
00149   iterator start(traversal_directions direction) const;
00151 
00152   virtual bool generate_path(path &to_follow) const;
00154 
00155 private:
00156   // unavailable.
00157   tree(const tree &);
00158   tree &operator =(const tree &);
00159 };
00160 
00161 } // namespace.
00162 
00163 #endif
00164 
Generated on Sat Jan 28 04:22:24 2012 for hoople2 project by  doxygen 1.6.3