1#ifndef DUNE_SPGRID_PARTITIONLIST_HH
2#define DUNE_SPGRID_PARTITIONLIST_HH
6#include <dune/grid/spgrid/partition.hh>
17 typedef SPPartitionList< dim > This;
23 typedef SPPartition< dim > Partition;
25 typedef typename Partition::MultiIndex MultiIndex;
26 typedef typename Partition::Mesh Mesh;
30 SPPartitionList () : head_( nullptr ) {}
32 SPPartitionList (
const This &other ) : head_( other.head_ ? new Node( *other.head_ ) : nullptr ) {}
34 SPPartitionList ( This &&other ) : head_( other.head_ ) { other.head_ =
nullptr; }
36 ~SPPartitionList () {
delete head_; }
38 This &operator= (
const This &other )
41 head_ = (other.head_ ?
new Node( *other.head_ ) : nullptr);
45 This &operator= ( This &&other )
49 other.head_ =
nullptr;
53 This &operator+= (
const Partition &partition );
55 Iterator begin ()
const {
return Iterator( head_ ); }
56 Iterator end ()
const {
return Iterator(
nullptr ); }
58 bool contains (
const MultiIndex &
id,
unsigned int number )
const;
59 const Partition *findPartition (
const MultiIndex &
id )
const;
62 bool empty ()
const {
return !head_; }
63 unsigned int size ()
const;
75 struct SPPartitionList< dim >::Node
77 explicit Node (
const Partition &partition )
78 : partition_( partition ),
82 Node (
const Node &other )
83 : partition_( other.partition_ ),
84 next_( other.next_ ? new Node( *other.next_ ) : nullptr )
88 : partition_( other.partition_ ),
91 other.next_ =
nullptr;
94 ~Node () {
delete next_; }
96 Node &operator= (
const Node & ) =
delete;
97 Node &operator= ( Node && ) =
delete;
99 void append ( Node *other )
102 next_->append( other );
107 const Partition &partition ()
const {
return partition_; }
109 const Node *next ()
const {
return next_; }
112 Partition partition_;
122 struct SPPartitionList< dim >::Iterator
123 :
public std::iterator< std::forward_iterator_tag, const Partition >
125 explicit Iterator (
const Node *node =
nullptr )
129 Iterator &operator++ ()
132 node_ = node_->next();
136 Iterator operator++ (
int ) { Iterator copy( *
this ); ++(*this);
return copy; }
138 operator bool ()
const {
return bool( node_ ); }
140 bool operator== (
const Iterator &other )
const {
return (node_ == other.node_); }
141 bool operator!= (
const Iterator &other )
const {
return (node_ != other.node_); }
143 const Partition &operator* ()
const { assert( *
this );
return node_->partition(); }
144 const Partition *operator-> ()
const { assert( *
this );
return &(node_->partition()); }
156 inline typename SPPartitionList< dim >::This &
157 SPPartitionList< dim >::operator+= (
const Partition &partition )
160 head_->append(
new Node( partition ) );
162 head_ =
new Node( partition );
169 SPPartitionList< dim >
170 ::contains (
const MultiIndex &
id,
unsigned int number )
const
172 const Partition *partition = findPartition(
id );
173 assert( !partition || (partition->number() == number) );
174 return bool( partition );
179 inline const typename SPPartitionList< dim >::Partition *
180 SPPartitionList< dim >::findPartition (
const MultiIndex &
id )
const
182 for(
const Node *it = head_; it; it = it->next() )
184 if( it->partition().contains(
id ) )
185 return &(it->partition());
192 inline int SPPartitionList< dim >::volume ()
const
195 for(
const Node *it = head_; it; it = it->next() )
196 volume += it->partition().volume();
202 inline unsigned int SPPartitionList< dim >::size ()
const
204 unsigned int size = 0;
205 for(
const Node *it = head_; it; it = it->next() )
215 template<
class char_type,
class traits,
int dim >
216 inline std::basic_ostream< char_type, traits > &
217 operator<< ( std::basic_ostream< char_type, traits > &out,
const SPPartitionList< dim > &partition )
219 typedef typename SPPartitionList< dim >::Iterator Iterator;
220 std::string separator =
"";
221 for( Iterator it = partition.begin(); it; ++it )
223 out << separator << *it;
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:237
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:259
Dune namespace.
Definition: alignedallocator.hh:13