DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_EntityIterator.hpp
1 //---------------------------------------------------------------------------//
2 /*
3  Copyright (c) 2012, Stuart R. Slattery
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are
8  met:
9 
10  *: Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12 
13  *: Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16 
17  *: Neither the name of the University of Wisconsin - Madison nor the
18  names of its contributors may be used to endorse or promote products
19  derived from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 //---------------------------------------------------------------------------//
39 //---------------------------------------------------------------------------//
40 
41 #ifndef DTK_ENTITYITERATOR_HPP
42 #define DTK_ENTITYITERATOR_HPP
43 
44 #include <functional>
45 #include <iterator>
46 #include <memory>
47 
48 #include <DTK_Entity.hpp>
49 #include <DTK_Types.hpp>
50 
51 namespace DataTransferKit
52 {
53 //---------------------------------------------------------------------------//
63 //---------------------------------------------------------------------------//
64 class EntityIterator : public std::iterator<std::forward_iterator_tag, Entity>
65 {
66  public:
71 
75  EntityIterator( const EntityIterator &rhs );
76 
81 
85  virtual ~EntityIterator();
86 
87  // Pre-increment operator.
88  virtual EntityIterator &operator++();
89 
90  // Post-increment operator.
91  virtual EntityIterator operator++( int );
92 
93  // Dereference operator.
94  virtual Entity &operator*( void );
95 
96  // Dereference operator.
97  virtual Entity *operator->( void );
98 
99  // Equal comparison operator.
100  virtual bool operator==( const EntityIterator &rhs ) const;
101 
102  // Not equal comparison operator.
103  virtual bool operator!=( const EntityIterator &rhs ) const;
104 
105  // Number of elements in the iterator that meet the predicate criteria.
106  std::size_t size() const;
107 
108  // An iterator assigned to the first valid element in the iterator.
109  virtual EntityIterator begin() const;
110 
111  // An iterator assigned to the end of all elements under the iterator.
112  virtual EntityIterator end() const;
113 
114  protected:
115  // Implementation.
116  std::unique_ptr<EntityIterator> b_iterator_impl;
117 
118  // Predicate.
119  PredicateFunction b_predicate;
120 
121  protected:
122  // Create a clone of the iterator. We need this for the copy constructor
123  // and assignment operator to pass along the underlying implementation
124  // without pointing to the same implementation in every instance of the
125  // iterator.
126  virtual std::unique_ptr<EntityIterator> clone() const;
127 
128  private:
129  // Advance the iterator to the first valid element that satisfies the
130  // predicate or the end of the iterator.
131  void advanceToFirstValidElement();
132 
133  // Increment the iterator implementation forward until either a valid
134  // increment is found or we have reached the end.
135  void increment();
136 };
137 
138 //---------------------------------------------------------------------------//
139 
140 } // end namespace DataTransferKit
141 
142 #endif // end DTK_ENTITYITERATOR_HPP
143 
144 //---------------------------------------------------------------------------//
145 // end DTK_EntityIterator.hpp
146 //---------------------------------------------------------------------------//
Geometric entity interface definition.
Definition: DTK_Entity.hpp:61
Entity iterator interface.
EntityIterator & operator=(const EntityIterator &rhs)
Assignment operator.
std::function< bool(Entity)> PredicateFunction
Predicate function typedef.
Definition: DTK_Types.hpp:64
virtual ~EntityIterator()
Destructor.
DTK_BasicEntitySet.cpp.