BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Tree_base.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  ETH Zurich (Switzerland).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/SearchStructures/include/CGAL/Tree_base.h $
00015 // $Id: Tree_base.h 41371 2007-12-30 16:55:25Z spion $
00016 // 
00017 //
00018 // Author(s)     : Gabriele Neyer
00019 
00020 #ifndef CGAL_TREE_BASE_H
00021 #define CGAL_TREE_BASE_H
00022 
00023 #include <iterator>
00024 #include <iostream>
00025 #include <functional>
00026 #include <list>
00027 #include <vector>
00028 #include <CGAL/assertions.h>
00029 #include <CGAL/Tree_assertions.h>
00030 
00031 #ifndef TREE_BASE_NULL
00032 #define TREE_BASE_NULL 0
00033 #endif
00034 
00035 #define stlvector
00036 
00037 CGAL_BEGIN_NAMESPACE
00038 
00039 //link type definition of an ordinary vertex of the tree
00040 template < typename Node >
00041 struct Tree_node_base {
00042   Node *parent_link;
00043   Node *left_link;
00044   Node *right_link;
00045   Tree_node_base()
00046     : parent_link(0), left_link(0), right_link(0)
00047   {}
00048   Tree_node_base(Node* ll, Node* rl)
00049     : parent_link(0), left_link(ll), right_link(rl)
00050   {}
00051 };
00052 
00053 
00054 // -------------------------------------------------------------------
00055 // pure virtual abstract base class.
00056 // Designed according to the Prototype Design Pattern 
00057 // A tree class has to be derived from this class.
00058 
00059 template <class C_Data, class C_Window>
00060 class Tree_base
00061 {
00062 
00063 protected:
00064   Tree_base(Tree_base const &); // prevent access
00065   void operator= (Tree_base const &); // prevent access
00066 
00067 public:
00068   typedef double vit;
00069   typedef int lit;
00070   typedef int lbit;
00071   typedef double vbit;
00072   typedef char oit;
00073   //  typedef std::vector<C_Data>::iterator vit;
00074   //typedef std::list<C_Data>::iterator lit;
00075   //typedef std::back_insert_iterator<lit>  lbit;
00076   //typedef std::back_insert_iterator<vit>  vbit;
00077   typedef Tree_base<C_Data, C_Window> Tree_base_type;
00078   Tree_base() {}
00079   virtual ~Tree_base() {}
00080 
00081   // 'clone()' returns an object which can be used as argument to 'delete'
00082   virtual Tree_base<C_Data, C_Window>  *clone() const = 0;
00083   //virtual Tree_base_type   *clone() const = 0;
00084 
00085   // 'make_tree()' returns an object which can be used as argument to 'delete'
00086   virtual bool make_tree(const typename std::list<C_Data>::iterator& beg, 
00087                          const typename std::list<C_Data>::iterator& end,
00088                          lit *dummy=0) =0;
00089 #ifdef stlvector
00090   virtual bool make_tree(const typename std::vector<C_Data>::iterator& beg, 
00091                          const typename std::vector<C_Data>::iterator& end,
00092                          vit *dummy=0) =0;
00093 #endif
00094 #ifdef carray
00095   virtual bool make_tree(const C_Data *beg, 
00096                          const C_Data *end) =0;
00097 #endif
00098   virtual std::back_insert_iterator< std::list<C_Data> > 
00099     window_query(C_Window const &win,  std::back_insert_iterator<
00100                  std::list<C_Data> > out,lbit *dummy=0 ) = 0; 
00101   virtual std::back_insert_iterator< std::vector<C_Data> >
00102     window_query(C_Window const &win,  std::back_insert_iterator<
00103                   std::vector<C_Data> > out,vbit *dummy=0) = 0; 
00104 #ifdef carray
00105   virtual C_Data * window_query( C_Window const &win, 
00106                                 C_Data * out) = 0; 
00107 #endif
00108 #ifdef ostreamiterator
00109   typedef std::ostream_iterator< C_Data> oit;
00110   virtual  std::ostream_iterator< C_Data> window_query( C_Window const &win, 
00111                                      std::ostream_iterator< C_Data> out,
00112                                         oit *dummy=0           ) = 0; 
00113 #endif
00114   virtual  std::back_insert_iterator< std::list< C_Data> > 
00115     enclosing_query( C_Window const &win,  std::back_insert_iterator<
00116                      std::list< C_Data> > out, lbit *dummy=0 ) = 0; 
00117   virtual  std::back_insert_iterator< std::vector< C_Data> > 
00118     enclosing_query( C_Window const &win,  std::back_insert_iterator<
00119                      std::vector< C_Data> > out,vbit *dummy=0 ) = 0; 
00120 #ifdef carray
00121   virtual   C_Data * enclosing_query( C_Window const &win, 
00122                                     C_Data *out) = 0; 
00123 #endif
00124 #ifdef ostreamiterator
00125   virtual  std::ostream_iterator< C_Data> enclosing_query( C_Window const &win, 
00126                                            std::ostream_iterator< C_Data> out,
00127                                            oit *dummy=0) = 0; 
00128 #endif
00129   virtual bool is_inside( C_Window const &win,
00130                           C_Data const& object) const =0;  
00131   virtual bool is_anchor()const =0;
00132   virtual bool is_valid()const =0;
00133 };
00134 
00135 
00136 // -------------------------------------------------------------------
00137 // Tree Anchor: this class is used as a recursion anchor.
00138 // The derived tree classes can be nested. Use this class as the
00139 // most inner class. This class is doing nothin exept stopping the recursion
00140 
00141 template <class C_Data, class C_Window>
00142 class Tree_anchor: public Tree_base< C_Data,  C_Window>
00143 {
00144 public:
00145   // Construct a factory with the given factory as sublayer
00146   Tree_anchor() {}
00147   virtual ~Tree_anchor(){}
00148   Tree_base<C_Data, C_Window> *clone() const { return new Tree_anchor(); }
00149   typedef Tree_base<C_Data, C_Window> tbt;
00150 //  Tree_base_type *clone() const { return new Tree_anchor(); }
00151 
00152   bool make_tree(const typename std::list< C_Data>::iterator& /*beg*/, 
00153                  const typename std::list< C_Data>::iterator& /*end*/, 
00154                  typename tbt::lit * =0) 
00155   {
00156     return true;
00157   }
00158 #ifdef stlvector
00159   bool make_tree(const typename std::vector< C_Data>::iterator& /*beg*/, 
00160                  const typename std::vector< C_Data>::iterator& /*end*/, 
00161                  typename tbt::vit * =0) 
00162   {
00163     return true;
00164   }
00165 #endif
00166 #ifdef carray
00167   bool make_tree(const C_Data * /*beg*/, 
00168                  const C_Data * /*end*/) 
00169   {
00170     return true;
00171   }
00172 #endif
00173    std::back_insert_iterator< std::list< C_Data> > 
00174       window_query( 
00175        C_Window const &, 
00176        std::back_insert_iterator< std::list< C_Data> > out,
00177        typename tbt::lbit * =0){
00178     return out;
00179   }
00180    
00181   std::back_insert_iterator< std::vector< C_Data> >  
00182       window_query( C_Window const &, 
00183                     std::back_insert_iterator< std::vector< C_Data> > out, 
00184                     typename tbt::vbit * =0){
00185     return out;
00186   }
00187 #ifdef carray
00188    C_Data * window_query( C_Window const &, 
00189                      C_Data * out){
00190     return out;
00191   }
00192 #endif
00193 #ifdef ostreamiterator
00194    std::ostream_iterator< C_Data> window_query( C_Window const &,
00195                                         std::ostream_iterator< C_Data> out, 
00196                                         typename tbt::oit *dummy=0){
00197     return out;
00198   }
00199 #endif
00200    std::back_insert_iterator< std::list< C_Data> > enclosing_query( C_Window const &,
00201                                    std::back_insert_iterator< std::list< C_Data> > out,
00202                                    typename tbt::lbit * =0){
00203     return out;
00204   }
00205    std::back_insert_iterator< std::vector< C_Data> > enclosing_query( C_Window const &,
00206                                    std::back_insert_iterator< std::vector< C_Data> > out,
00207                                    typename tbt::vbit * =0){
00208     return out;
00209   }
00210 #ifdef carray
00211    C_Data * enclosing_query( C_Window const &, 
00212                         C_Data * out){
00213     return out;
00214   }
00215 #endif
00216 #ifdef ostreamiterator
00217    std::ostream_iterator< C_Data> enclosing_query( C_Window const &, 
00218                                            std::ostream_iterator< C_Data> out,
00219                                            typename tbt::oit *dummy=0){
00220     return out;
00221   }
00222 #endif
00223   bool is_valid()const{ return true;}
00224 
00225 protected:
00226 
00227   bool is_inside( C_Window const &, 
00228                   C_Data const&) const
00229   {     
00230     return true;
00231   }
00232   bool is_anchor()const {return true;}
00233 };
00234 
00235 CGAL_END_NAMESPACE
00236 
00237 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines