1 #ifndef DUNE_FEM_ARRAY_HH 2 #define DUNE_FEM_ARRAY_HH 6 #include <dune/common/iteratorfacades.hh> 9 #include <dune/fem/misc/metaprogramming.hh> 70 const ElementType &
operator[] (
unsigned int index )
const 72 CHECK_INTERFACE_IMPLEMENTATION(
asImp()[ index ] );
73 return asImp()[ index ];
84 CHECK_INTERFACE_IMPLEMENTATION(
asImp()[ index ] );
85 return asImp()[ index ];
93 void assign (
const ElementType &element )
95 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
asImp().
assign( element ) );
108 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
asImp().
assign( other ) );
117 CHECK_INTERFACE_IMPLEMENTATION(
asImp().
begin() );
118 return asImp().begin();
127 CHECK_INTERFACE_IMPLEMENTATION(
asImp().
begin() );
128 return asImp().begin();
135 ConstIteratorType
end ()
const 137 CHECK_INTERFACE_IMPLEMENTATION(
asImp().
end() );
138 return asImp().end();
147 CHECK_INTERFACE_IMPLEMENTATION(
asImp().
end() );
148 return asImp().end();
157 CHECK_INTERFACE_IMPLEMENTATION(
asImp().
size() );
158 return asImp().size();
163 template<
class Array >
167 static const bool v = Conversion< Array, ArrayInterfaceType >::exists;
171 template<
class Element,
class Array >
173 :
public ForwardIteratorFacade< ArrayDefaultIterator< Element, Array >, Element >
191 assert( index <= array.size() );
195 : array_( other.array_ ),
196 index_( other.index_ )
199 ThisType &operator= (
const ThisType &other )
201 assert( &(other.
array_) == &array_ );
207 assert( index_ < array_.size() );
208 return array_[ index_ ];
213 assert( index_ < array_.size() );
217 bool equals(
const ThisType &other )
const 219 assert( &(other.
array_) == &array_ );
220 return index_ == other.
index_;
230 template<
class ElementImp,
class ArrayImp >
247 template<
class ElementImp,
class ArrayImp >
249 :
public ArrayInterface< ArrayDefaultTraits< ElementImp, ArrayImp > >
266 using BaseType :: size;
280 inline void assign (
const ElementType &element )
282 ArrayType &imp =
asImp();
283 const unsigned int size = imp.size();
284 for(
unsigned int i = 0; i <
size; ++i )
292 ArrayType &imp =
asImp();
293 const unsigned int size = imp.size();
294 assert( size == other.
size() );
295 for(
unsigned int i = 0; i <
size; ++i )
296 imp[ i ] = other[ i ];
300 inline ConstIteratorType
begin ()
const 312 inline ConstIteratorType
end ()
const 318 inline IteratorType
end ()
330 template<
class ElementImp >
332 :
public ArrayDefault< ElementImp, ArrayWrapper< ElementImp > >
343 const unsigned int size_;
344 ElementType *elements_;
350 elements_( elements )
352 assert( elements_ != NULL );
356 inline const ElementType &
operator[] (
unsigned int index )
const 358 assert( index < size_ );
359 return elements_[ index ];
365 assert( index < size_ );
366 return elements_[ index ];
370 inline unsigned int size ()
const 397 template<
class Element,
unsigned int Size >
399 :
public ArrayDefault< Element, FixedSizeArray< Element, Size > >
409 static const unsigned int fixedSize = Size;
412 ElementType elements_[ fixedSize ];
443 inline const ElementType &
operator[] (
unsigned int index )
const 445 assert( index < fixedSize );
446 return elements_[ index ];
452 assert( index < fixedSize );
453 return elements_[ index ];
457 inline unsigned int size ()
const 464 template<
class Element,
467 :
public ArrayDefault< Element, DynamicArray< Element, ArrayAllocator > >
489 using BaseType :: assign;
496 allocator_.
allocate( size_, elements_ );
499 inline explicit DynamicArray (
const ArrayAllocatorType &arrayAllocator,
500 unsigned int size = 0 )
501 : allocator_( arrayAllocator )
504 allocator_.
allocate( size_, elements_ );
508 const ElementType &element )
512 allocator_.
allocate( size_, elements_ );
518 const ElementType defaultElement )
519 : allocator_( arrayAllocator )
522 allocator_.
allocate( size_, elements_ );
527 : allocator_( other.allocator_ )
530 allocator_.
allocate( size_, elements_ );
536 allocator_.
free( elements_ );
539 inline const ElementType&
operator[] (
unsigned int index )
const 541 assert( index < size_ );
542 return elements_[ index ];
547 assert( index < size_ );
548 return elements_[ index ];
551 inline void append (
const ElementType &element )
553 const unsigned int oldSize = size_;
554 resize( oldSize + 1 );
555 elements_[ oldSize ] = element;
561 const unsigned int arraySize = array.
size();
563 const unsigned int oldSize = size_;
564 resize( oldSize + arraySize );
566 for(
unsigned int i = 0; i < arraySize; ++i )
567 elements_[ oldSize + i ] = array[ i ];
574 resize( other.
size() );
575 for(
unsigned int i = 0; i < size_; ++i )
576 elements_[ i ] = other[ i ];
581 return (ElementType *)elements_;
586 return (
const ElementType *)elements_;
591 allocator_.
reserve( newSize, elements_ );
594 inline void resize (
unsigned int newSize )
596 const unsigned int oldSize = size_;
597 if( newSize == oldSize )
600 allocator_.
reallocate( oldSize, newSize, elements_ );
604 inline void resize (
unsigned int newSize,
605 const ElementType &defaultElement )
607 const unsigned int oldSize = size_;
608 if( newSize == oldSize )
611 allocator_.
reallocate( oldSize, newSize, elements_ );
613 for(
unsigned int i = oldSize; i < newSize; ++i )
614 elements_[ i ] = defaultElement;
617 inline unsigned int size ()
const 626 namespace Capabilities
629 template<
class Array >
631 :
public Fem::MetaBool< false >
634 template<
class Element,
template<
class >
class ArrayAllocator >
636 :
public Fem::MetaBool< true >
647 #endif // #ifndef DUNE_FEM_ARRAY_HH ElementPtrType elements_
Definition: array.hh:486
ConstIteratorType end() const
obtain end iterator
Definition: array.hh:135
const ElementType * leakPointer() const
Definition: array.hh:584
ArrayAllocator< ElementType > ArrayAllocatorType
Definition: array.hh:478
Traits::ConstIteratorType ConstIteratorType
type of constant iterator
Definition: array.hh:273
Traits::ElementType ElementType
type of the array elements
Definition: array.hh:40
void assign(const ArrayInterface< T > &other)
copy another array to this one
Definition: array.hh:106
ElementType value_type
Definition: array.hh:475
unsigned int size() const
Definition: array.hh:617
FixedSizeArray(const ThisType &other)
copy constructor
Definition: array.hh:437
Array ArrayType
Definition: array.hh:180
unsigned int index_
Definition: array.hh:184
AT Traits
type of the traits
Definition: array.hh:31
ConstIteratorType end() const
obtain end iterator
Definition: array.hh:312
unsigned int size() const
Definition: array.hh:457
IteratorType begin()
obtain begin iterator
Definition: array.hh:125
ElementType * leakPointer()
Definition: array.hh:579
void assign(const ElementType &element)
fill the array with copies of an element
Definition: array.hh:280
default implementation of the ArrayInterface
Definition: array.hh:248
void reallocate(unsigned int oldSize, unsigned int newSize, ElementPtrType &array) const
Definition: arrayallocator.hh:80
IteratorType iterator
type of (non-constant) iterator
Definition: array.hh:55
ConstIteratorType const_iterator
type of constant iterator
Definition: array.hh:52
IteratorType end()
obtain end iterator
Definition: array.hh:145
const Implementation & asImp() const
Definition: bartonnackmaninterface.hh:37
void reserve(unsigned int newSize)
Definition: array.hh:589
Element ElementType
Definition: array.hh:178
IteratorType end()
obtain end iterator
Definition: array.hh:318
~DynamicArray()
Definition: array.hh:534
ArrayAllocatorType allocator_
Definition: array.hh:483
DynamicArray(const ArrayAllocatorType &arrayAllocator, unsigned int size, const ElementType defaultElement)
Definition: array.hh:516
void append(const ArrayInterface< T > &array)
Definition: array.hh:559
ThisType ArrayInterfaceType
type of this interface
Definition: array.hh:37
ArrayDefaultIterator< ElementType, ArrayType > IteratorType
Definition: array.hh:237
DynamicArray(unsigned int size, const ElementType &element)
Definition: array.hh:507
ArrayInterface< typename Array::Traits > ArrayInterfaceType
Definition: array.hh:166
ElementType FieldType
Definition: array.hh:474
void append(const ElementType &element)
Definition: array.hh:551
standard array with fixed size
Definition: array.hh:398
ArrayDefaultTraits< ElementType, ArrayType > Traits
type of the traits
Definition: array.hh:259
FixedSizeArray(const ElementType &element)
initializing constructor
Definition: array.hh:428
ElementImp ElementType
type of the array elements
Definition: array.hh:336
unsigned int index() const
Definition: array.hh:223
Definition: coordinate.hh:4
IteratorType begin()
obtain begin iterator
Definition: array.hh:306
DynamicArray(unsigned int size=0)
Definition: array.hh:492
Element ElementType
Definition: array.hh:473
ArrayType & array_
Definition: array.hh:183
ElementType & dereference() const
Definition: array.hh:205
ArrayAllocatorType::ElementPtrType ElementPtrType
Definition: array.hh:480
Traits::ConstIteratorType ConstIteratorType
type of constant iterator
Definition: array.hh:46
const ElementType & operator[](unsigned int index) const
access an array element
Definition: array.hh:70
implementation of the ArrayInterface wrapping a pointer to an array of elements
Definition: array.hh:331
ArrayImp ArrayType
type of the implementation (Barton-Nackman)
Definition: array.hh:256
Traits::ArrayType ArrayType
type of the implementation (Barton-Nackman)
Definition: array.hh:34
ElementImp ElementType
type of the array elements
Definition: array.hh:253
bool equals(const ThisType &other) const
Definition: array.hh:217
ArrayDefaultIterator(const ThisType &other)
Definition: array.hh:194
ConstIteratorType begin() const
obtain begin iterator
Definition: array.hh:300
ElementType value_type
make consistent with std::vector
Definition: array.hh:43
ElementImp ElementType
Definition: array.hh:233
unsigned int size_
Definition: array.hh:485
ArrayImp ArrayType
Definition: array.hh:235
unsigned int size() const
Definition: array.hh:155
ArrayDefaultIterator(ArrayType &array, unsigned int index)
Definition: array.hh:187
void reserve(unsigned int newSize, ElementPtrType &array) const
Definition: arrayallocator.hh:96
void free(ElementPtrType &array) const
Definition: arrayallocator.hh:158
void assign(const ArrayInterface< T > &other)
copy another array to this one
Definition: array.hh:572
void assign(const ElementType &element)
fill the array with copies of an element
Definition: array.hh:93
ConstIteratorType begin() const
obtain begin iterator
Definition: array.hh:115
void allocate(unsigned int size, ElementPtrType &array) const
Definition: arrayallocator.hh:146
Traits::IteratorType IteratorType
type of (non-constant) iterator
Definition: array.hh:49
ArrayDefaultIterator< const ElementType, const ArrayType > ConstIteratorType
Definition: array.hh:239
unsigned int size_type
type of unsigned integral type of indexing
Definition: array.hh:58
ArrayWrapper(unsigned int size, ElementType *elements)
create an ArrayWrapper from a size and a pointer
Definition: array.hh:348
abstract array interface
Definition: array.hh:23
void resize(unsigned int newSize, const ElementType &defaultElement)
Definition: array.hh:604
void resize(unsigned int newSize)
Definition: array.hh:594
Traits::IteratorType IteratorType
type of (non-constant) iterator
Definition: array.hh:276
FixedSizeArray()
default constructor
Definition: array.hh:419
unsigned int size() const
Definition: array.hh:370
DynamicArray(const ThisType &other)
Definition: array.hh:526
void assign(const ArrayInterface< T > &other)
copy another array to this one
Definition: array.hh:290
Definition: bartonnackmaninterface.hh:15
void increment()
Definition: array.hh:211
Element ElementType
type of the array elements
Definition: array.hh:406
DynamicArray(const ArrayAllocatorType &arrayAllocator, unsigned int size=0)
Definition: array.hh:499
Definition: arrayallocator.hh:112