Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Random_access_adaptor.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 1997, 1998, 1999, 2000 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 //
33 // release : CGAL-2.2
34 // release_date : 2000, September 30
35 //
36 // file : include/CGAL/Random_access_adaptor.h
37 // package : STL_Extension (2.21)
38 // chapter : $CGAL_Chapter: STL Extensions for CGAL $
39 // source : stl_extension.fw
40 // revision : $Revision: 1.1.1.1 $
41 // revision_date : $Date: 2001/07/05 22:17:48 $
42 // author(s) : Michael Hoffmann
43 // Lutz Kettner
44 //
45 //
46 // Random Access Adaptor provides random access for sequences.
47 // coordinator : ?
48 // email : contact@cgal.org
49 // www : http://www.cgal.org
50 //
51 // ======================================================================
52 
53 #ifndef CGAL_RANDOM_ACCESS_ADAPTOR_H
54 #define CGAL_RANDOM_ACCESS_ADAPTOR_H 1
55 #include <vector>
56 #include <CGAL/circulator.h>
57 
59 
60 template < class IC>
62 
63  // DEFINITION
64  //
65  // The class Random_access_adaptor<IC> provides a random access
66  // for data structures. Either the data structure supports random access
67  // iterators or circulators where this class maps function calls to the
68  // iterator or circulator, or a STL `vector' is used to provide the random
69  // access. The iterator or circulator of the data structure are of type
70  // `IC'.
71  //
72  // CREATION
73 
74 protected:
75  typedef std::vector< IC> Index;
77  IC start;
78 
79 public:
80  typedef typename Index::size_type size_type;
81 
82  void init_index( IC i, const IC& j, std::forward_iterator_tag);
83  void init_index( const IC& i, const IC& j,
84  std::bidirectional_iterator_tag){
85  init_index( i, j, std::forward_iterator_tag());
86  }
87  void init_index( const IC& i, const IC&,
88  std::random_access_iterator_tag){
89  start = i;
90  }
91  void init_index( const IC& i, const IC& j) {
92 #if !defined(CGAL_CFG_NO_ITERATOR_TRAITS) || \
93  defined(CGAL_LIMITED_ITERATOR_TRAITS_SUPPORT)
94  typedef typename std::iterator_traits<IC>::iterator_category ICC;
95  init_index( i, j, ICC());
96 #else
97  init_index( i, j, std::iterator_category( i));
98 #endif
99  }
100 
101 
102  void reserve( size_type r, std::forward_iterator_tag) {
103  index.reserve( r);
104  }
105  void reserve( size_type r, std::bidirectional_iterator_tag){
106  reserve( r, std::forward_iterator_tag());
107  }
108  void reserve( size_type, std::random_access_iterator_tag){}
109 
110 
111  void push_back( const IC& k, std::forward_iterator_tag) {
112  index.push_back(k);
113  }
114  void push_back( const IC& k, std::bidirectional_iterator_tag){
115  push_back( k, std::forward_iterator_tag());
116  }
117  void push_back( const IC&, std::random_access_iterator_tag){}
118 
119 
120  const IC& find( size_type n, std::forward_iterator_tag) const {
121  // returns inverse index of k.
122  CGAL_assertion( n < index.size());
123  return index[n];
124  }
125  const IC& find( size_type n, std::bidirectional_iterator_tag) const {
126  return find( n, std::forward_iterator_tag());
127  }
128  IC find( size_type n, std::random_access_iterator_tag) const {
129  return start + n;
130  }
131 
132  typedef IC iterator;
133  typedef IC Circulator;
134 
136  // invalid index.
137 
138  Random_access_adaptor( const IC& i) : start(i) {}
139  // empty random access index initialized to start at i.
140 
141  Random_access_adaptor( const IC& i, const IC& j) : start(i) {
142  // random access index initialized with range [i,j).
143  init_index( i, j);
144  }
145 
146  void reserve( size_type r) {
147  // reserve r entries, if a `vector' is used internally.
148 #if !defined(CGAL_CFG_NO_ITERATOR_TRAITS) || \
149  defined(CGAL_LIMITED_ITERATOR_TRAITS_SUPPORT)
150  typedef typename std::iterator_traits<IC>::iterator_category ICC;
151  reserve( r, ICC());
152 #else
153  reserve( r, std::iterator_category( IC()));
154 #endif
155  }
156 
157  // OPERATIONS
158 
159  IC find( size_type n) const {
160  // returns inverse index of k.
161 #if !defined(CGAL_CFG_NO_ITERATOR_TRAITS) || \
162  defined(CGAL_LIMITED_ITERATOR_TRAITS_SUPPORT)
163  typedef typename std::iterator_traits<IC>::iterator_category ICC;
164  return find( n, ICC());
165 #else
166  return find( n, std::iterator_category( IC()));
167 #endif
168  }
169 
170  IC operator[]( size_type n) const { return find(n); }
171 
172  void push_back( const IC& k) {
173  // adds k at the end of the indices.
174 #if !defined(CGAL_CFG_NO_ITERATOR_TRAITS) || \
175  defined(CGAL_LIMITED_ITERATOR_TRAITS_SUPPORT)
176  typedef typename std::iterator_traits<IC>::iterator_category ICC;
177  push_back( k, ICC());
178 #else
179  push_back( k, std::iterator_category( k));
180 #endif
181  }
182 };
183 
184 template < class IC>
185 void
187  std::forward_iterator_tag) {
188  if ( ! is_empty_range( i, j)) {
189  do {
190  index.push_back( i);
191  } while ((++i) != (j));
192  }
193 }
194 
196 #endif // CGAL_RANDOM_ACCESS_ADAPTOR_H //
197 // EOF //
#define CGAL_assertion(EX)
Definition: assertions.h:87
void reserve(size_type r, std::bidirectional_iterator_tag)
j indices k indices k
Definition: Indexing.h:6
void push_back(const IC &, std::random_access_iterator_tag)
const IC & find(size_type n, std::forward_iterator_tag) const
bool is_empty_range(const IC &ic1, const IC &ic2)
Definition: circulator.h:362
void init_index(const IC &i, const IC &j, std::bidirectional_iterator_tag)
void init_index(IC i, const IC &j, std::forward_iterator_tag)
IC find(size_type n) const
void push_back(const IC &k, std::bidirectional_iterator_tag)
void reserve(size_type, std::random_access_iterator_tag)
blockLoc i
Definition: read.cpp:79
void init_index(const IC &i, const IC &, std::random_access_iterator_tag)
const NT & n
IC find(size_type n, std::random_access_iterator_tag) const
Random_access_adaptor(const IC &i, const IC &j)
void reserve(size_type r, std::forward_iterator_tag)
j indices j
Definition: Indexing.h:6
void init_index(const IC &i, const IC &j)
IC operator[](size_type n) const
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
void push_back(const IC &k, std::forward_iterator_tag)
const IC & find(size_type n, std::bidirectional_iterator_tag) const