dust3d/thirdparty/cgal/CGAL-5.1/include/CGAL/Tree_base.h

234 lines
7.5 KiB
C
Raw Normal View History

// Copyright (c) 1997 ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
2020-10-13 12:44:25 +00:00
// $URL: https://github.com/CGAL/cgal/blob/v5.1/SearchStructures/include/CGAL/Tree_base.h $
// $Id: Tree_base.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Gabriele Neyer
#ifndef CGAL_TREE_BASE_H
#define CGAL_TREE_BASE_H
#include <CGAL/license/SearchStructures.h>
#include <iterator>
#include <iostream>
#include <functional>
#include <list>
#include <vector>
#include <CGAL/assertions.h>
#include <CGAL/Tree_assertions.h>
2020-10-13 12:44:25 +00:00
#ifndef CGAL_TREE_BASE_nullptr
#define CGAL_TREE_BASE_nullptr 0
#endif
#define stlvector
namespace CGAL {
//link type definition of an ordinary vertex of the tree
template < typename Node >
struct Tree_node_base {
Node *parent_link;
Node *left_link;
Node *right_link;
Tree_node_base()
: parent_link(0), left_link(0), right_link(0)
{}
Tree_node_base(Node* ll, Node* rl)
: parent_link(0), left_link(ll), right_link(rl)
{}
};
// -------------------------------------------------------------------
// pure virtual abstract base class.
2020-10-13 12:44:25 +00:00
// Designed according to the Prototype Design Pattern
// A tree class has to be derived from this class.
template <class C_Data, class C_Window>
class Tree_base
{
protected:
Tree_base(Tree_base const &); // prevent access
void operator= (Tree_base const &); // prevent access
public:
typedef double vit;
typedef int lit;
typedef int lbit;
typedef double vbit;
typedef char oit;
// typedef std::vector<C_Data>::iterator vit;
//typedef std::list<C_Data>::iterator lit;
//typedef std::back_insert_iterator<lit> lbit;
//typedef std::back_insert_iterator<vit> vbit;
typedef Tree_base<C_Data, C_Window> Tree_base_type;
Tree_base() {}
virtual ~Tree_base() {}
// 'clone()' returns an object which can be used as argument to 'delete'
virtual Tree_base<C_Data, C_Window> *clone() const = 0;
//virtual Tree_base_type *clone() const = 0;
// 'make_tree()' returns an object which can be used as argument to 'delete'
2020-10-13 12:44:25 +00:00
virtual bool make_tree(const typename std::list<C_Data>::iterator& beg,
const typename std::list<C_Data>::iterator& end,
lit *dummy=0) =0;
#ifdef stlvector
2020-10-13 12:44:25 +00:00
virtual bool make_tree(const typename std::vector<C_Data>::iterator& beg,
const typename std::vector<C_Data>::iterator& end,
vit *dummy=0) =0;
#endif
#ifdef carray
2020-10-13 12:44:25 +00:00
virtual bool make_tree(const C_Data *beg,
const C_Data *end) =0;
#endif
2020-10-13 12:44:25 +00:00
virtual std::back_insert_iterator< std::list<C_Data> >
window_query(C_Window const &win, std::back_insert_iterator<
2020-10-13 12:44:25 +00:00
std::list<C_Data> > out,lbit *dummy=0 ) = 0;
virtual std::back_insert_iterator< std::vector<C_Data> >
window_query(C_Window const &win, std::back_insert_iterator<
2020-10-13 12:44:25 +00:00
std::vector<C_Data> > out,vbit *dummy=0) = 0;
#ifdef carray
2020-10-13 12:44:25 +00:00
virtual C_Data * window_query( C_Window const &win,
C_Data * out) = 0;
#endif
#ifdef ostreamiterator
typedef std::ostream_iterator< C_Data> oit;
2020-10-13 12:44:25 +00:00
virtual std::ostream_iterator< C_Data> window_query( C_Window const &win,
std::ostream_iterator< C_Data> out,
oit *dummy=0 ) = 0;
#endif
2020-10-13 12:44:25 +00:00
virtual std::back_insert_iterator< std::list< C_Data> >
enclosing_query( C_Window const &win, std::back_insert_iterator<
2020-10-13 12:44:25 +00:00
std::list< C_Data> > out, lbit *dummy=0 ) = 0;
virtual std::back_insert_iterator< std::vector< C_Data> >
enclosing_query( C_Window const &win, std::back_insert_iterator<
2020-10-13 12:44:25 +00:00
std::vector< C_Data> > out,vbit *dummy=0 ) = 0;
#ifdef carray
2020-10-13 12:44:25 +00:00
virtual C_Data * enclosing_query( C_Window const &win,
C_Data *out) = 0;
#endif
#ifdef ostreamiterator
2020-10-13 12:44:25 +00:00
virtual std::ostream_iterator< C_Data> enclosing_query( C_Window const &win,
std::ostream_iterator< C_Data> out,
oit *dummy=0) = 0;
#endif
virtual bool is_inside( C_Window const &win,
2020-10-13 12:44:25 +00:00
C_Data const& object) const =0;
virtual bool is_anchor()const =0;
virtual bool is_valid()const =0;
};
// -------------------------------------------------------------------
// Tree Anchor: this class is used as a recursion anchor.
// The derived tree classes can be nested. Use this class as the
// most inner class. This class is doing nothin exept stopping the recursion
template <class C_Data, class C_Window>
class Tree_anchor: public Tree_base< C_Data, C_Window>
{
public:
// Construct a factory with the given factory as sublayer
Tree_anchor() {}
virtual ~Tree_anchor(){}
Tree_base<C_Data, C_Window> *clone() const { return new Tree_anchor(); }
typedef Tree_base<C_Data, C_Window> tbt;
// Tree_base_type *clone() const { return new Tree_anchor(); }
2020-10-13 12:44:25 +00:00
bool make_tree(const typename std::list< C_Data>::iterator& /*beg*/,
const typename std::list< C_Data>::iterator& /*end*/,
typename tbt::lit * =0)
{
return true;
}
#ifdef stlvector
2020-10-13 12:44:25 +00:00
bool make_tree(const typename std::vector< C_Data>::iterator& /*beg*/,
const typename std::vector< C_Data>::iterator& /*end*/,
typename tbt::vit * =0)
{
return true;
}
#endif
#ifdef carray
2020-10-13 12:44:25 +00:00
bool make_tree(const C_Data * /*beg*/,
const C_Data * /*end*/)
{
return true;
}
#endif
2020-10-13 12:44:25 +00:00
std::back_insert_iterator< std::list< C_Data> >
window_query(
C_Window const &,
std::back_insert_iterator< std::list< C_Data> > out,
typename tbt::lbit * =0){
return out;
}
2020-10-13 12:44:25 +00:00
std::back_insert_iterator< std::vector< C_Data> >
window_query( C_Window const &,
std::back_insert_iterator< std::vector< C_Data> > out,
typename tbt::vbit * =0){
return out;
}
#ifdef carray
2020-10-13 12:44:25 +00:00
C_Data * window_query( C_Window const &,
C_Data * out){
return out;
}
#endif
#ifdef ostreamiterator
std::ostream_iterator< C_Data> window_query( C_Window const &,
2020-10-13 12:44:25 +00:00
std::ostream_iterator< C_Data> out,
typename tbt::oit *dummy=0){
return out;
}
#endif
std::back_insert_iterator< std::list< C_Data> > enclosing_query( C_Window const &,
std::back_insert_iterator< std::list< C_Data> > out,
2020-10-13 12:44:25 +00:00
typename tbt::lbit * =0){
return out;
}
std::back_insert_iterator< std::vector< C_Data> > enclosing_query( C_Window const &,
std::back_insert_iterator< std::vector< C_Data> > out,
2020-10-13 12:44:25 +00:00
typename tbt::vbit * =0){
return out;
}
#ifdef carray
2020-10-13 12:44:25 +00:00
C_Data * enclosing_query( C_Window const &,
C_Data * out){
return out;
}
#endif
#ifdef ostreamiterator
2020-10-13 12:44:25 +00:00
std::ostream_iterator< C_Data> enclosing_query( C_Window const &,
std::ostream_iterator< C_Data> out,
typename tbt::oit *dummy=0){
return out;
}
#endif
bool is_valid()const{ return true;}
protected:
2020-10-13 12:44:25 +00:00
bool is_inside( C_Window const &,
C_Data const&) const
{
return true;
}
bool is_anchor()const {return true;}
};
} //namespace CGAL
#endif