DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_STKMeshEntityIterator.cpp
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 #include "DTK_STKMeshEntityIterator.hpp"
42 #include "DTK_DBC.hpp"
43 #include <DTK_STKMeshEntity.hpp>
44 
45 namespace DataTransferKit
46 {
47 //---------------------------------------------------------------------------//
48 // Default constructor.
50 
51 //---------------------------------------------------------------------------//
52 // Constructor.
54  const Teuchos::RCP<STKMeshEntityIteratorRange> &entity_range,
55  const Teuchos::Ptr<stk::mesh::BulkData> &bulk_data,
56  const PredicateFunction &predicate )
57  : d_entity_range( entity_range )
58  , d_stk_entity_it( d_entity_range->d_stk_entities.begin() )
59  , d_bulk_data( bulk_data )
60 {
61  this->b_predicate = predicate;
62 }
63 
64 //---------------------------------------------------------------------------//
65 // Copy constructor.
67  : d_entity_range( rhs.d_entity_range )
68  , d_stk_entity_it( rhs.d_stk_entity_it )
69  , d_bulk_data( rhs.d_bulk_data )
70 {
71  this->b_predicate = rhs.b_predicate;
72 }
73 
74 //---------------------------------------------------------------------------//
75 // Assignment operator.
78 {
79  this->b_predicate = rhs.b_predicate;
80  if ( &rhs == this )
81  {
82  return *this;
83  }
84  d_entity_range = rhs.d_entity_range;
85  d_stk_entity_it = rhs.d_stk_entity_it;
86  d_bulk_data = rhs.d_bulk_data;
87  return *this;
88 }
89 
90 //---------------------------------------------------------------------------//
91 // Pre-increment operator.
92 EntityIterator &STKMeshEntityIterator::operator++()
93 {
94  ++d_stk_entity_it;
95  return *this;
96 }
97 
98 //---------------------------------------------------------------------------//
99 // Dereference operator.
100 Entity &STKMeshEntityIterator::operator*( void )
101 {
102  this->operator->();
103  return d_current_entity;
104 }
105 
106 //---------------------------------------------------------------------------//
107 // Dereference operator.
108 Entity *STKMeshEntityIterator::operator->( void )
109 {
110  d_current_entity = STKMeshEntity( *d_stk_entity_it, d_bulk_data );
111  return &d_current_entity;
112 }
113 
114 //---------------------------------------------------------------------------//
115 // Equal comparison operator.
116 bool STKMeshEntityIterator::operator==( const EntityIterator &rhs ) const
117 {
118  const STKMeshEntityIterator *rhs_it =
119  static_cast<const STKMeshEntityIterator *>( &rhs );
120  const STKMeshEntityIterator *rhs_it_impl =
121  static_cast<const STKMeshEntityIterator *>(
122  rhs_it->b_iterator_impl.get() );
123  return ( rhs_it_impl->d_stk_entity_it == d_stk_entity_it );
124 }
125 
126 //---------------------------------------------------------------------------//
127 // Not equal comparison operator.
128 bool STKMeshEntityIterator::operator!=( const EntityIterator &rhs ) const
129 {
130  const STKMeshEntityIterator *rhs_it =
131  static_cast<const STKMeshEntityIterator *>( &rhs );
132  const STKMeshEntityIterator *rhs_it_impl =
133  static_cast<const STKMeshEntityIterator *>(
134  rhs_it->b_iterator_impl.get() );
135  return ( rhs_it_impl->d_stk_entity_it != d_stk_entity_it );
136 }
137 
138 //---------------------------------------------------------------------------//
139 // An iterator assigned to the beginning.
140 EntityIterator STKMeshEntityIterator::begin() const
141 {
142  return STKMeshEntityIterator( d_entity_range, d_bulk_data,
143  this->b_predicate );
144 }
145 
146 //---------------------------------------------------------------------------//
147 // An iterator assigned to the end.
148 EntityIterator STKMeshEntityIterator::end() const
149 {
150  STKMeshEntityIterator end_it( d_entity_range, d_bulk_data,
151  this->b_predicate );
152  end_it.d_stk_entity_it = d_entity_range->d_stk_entities.end();
153  return end_it;
154 }
155 
156 //---------------------------------------------------------------------------//
157 // Create a clone of the iterator. We need this for the copy constructor
158 // and assignment operator to pass along the underlying implementation.
159 std::unique_ptr<EntityIterator> STKMeshEntityIterator::clone() const
160 {
161  return std::unique_ptr<EntityIterator>(
162  new STKMeshEntityIterator( *this ) );
163 }
164 
165 //---------------------------------------------------------------------------//
166 
167 } // end namespace DataTransferKit
168 
169 //---------------------------------------------------------------------------//
170 // end DTK_STKMeshEntityIterator.cpp
171 //---------------------------------------------------------------------------//
Geometric entity interface definition.
Definition: DTK_Entity.hpp:61
STKMesh entity interface definition.
Entity iterator interface.
STK mesh entity iterator implementation.
Assertions and Design-by-Contract for error handling.
std::function< bool(Entity)> PredicateFunction
Predicate function typedef.
Definition: DTK_Types.hpp:64
DTK_BasicEntitySet.cpp.
STKMeshEntityIterator & operator=(const STKMeshEntityIterator &rhs)
Assignment operator.