dune-fem  2.4.1-rc
stlarray.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_STLARRAY_HH
2 #define DUNE_FEM_STLARRAY_HH
3 
4 #include <vector>
5 
7 
8 namespace Dune
9 {
10  namespace Fem
11  {
12 
13  template< class ElementImp, class RealImp >
15  {
16  public:
17  typedef ElementImp ElementType;
18 
19  private:
21 
22  protected:
23  RealImp realIterator_;
24 
25  public:
26  inline explicit STLArrayIterator ( RealImp realIterator )
27  : realIterator_( realIterator )
28  {
29  }
30 
31  inline STLArrayIterator( const ThisType &other )
32  : realIterator_( other.realIterator )
33  {
34  }
35 
36  inline ThisType &operator= ( const ThisType &other )
37  {
38  realIterator_ = other.realIterator_;
39  }
40 
41  inline ElementType &operator* ()
42  {
43  return *realIterator_;
44  }
45 
46  inline ThisType &operator++ ()
47  {
48  ++realIterator_;
49  return *this;
50  }
51 
52  inline bool operator== ( const ThisType &other ) const
53  {
54  return realIterator_ == other.realIterator_;
55  }
56 
57  inline bool operator!= ( const ThisType &other ) const
58  {
59  return realIterator_ != other.realIterator_;
60  }
61  };
62 
63 
64  template< class ElementImp >
65  class STLArray;
66 
67 
68  template< class ElementImp >
70  {
71  typedef ElementImp ElementType;
72 
74 
75  typedef std :: vector< ElementType > stdVectorType;
76 
81  };
82 
83 
84 
85  template< class ElementImp >
86  class STLArray
87  : public ArrayInterface< STLArrayTraits< ElementImp > >
88  {
89  public:
90  typedef ElementImp ElementType;
91 
93 
94  private:
97 
98  typedef typename Traits :: stdVectorType stdVectorType;
99 
100  public:
103 
104  protected:
105  stdVectorType vector_;
106 
107  public:
108  inline explicit STLArray ( unsigned int size = 0 )
109  : vector_( size )
110  {
111  }
112 
113  inline STLArray ( unsigned int size,
114  const ElementType &element )
115  : vector_( size, element )
116  {
117  }
118 
119  inline STLArray ( const ThisType &other )
120  : vector_( other.vector_ )
121  {
122  }
123 
124  inline const ElementType &operator[] ( unsigned int index ) const
125  {
126  return vector_[ index ];
127  }
128 
129  inline ElementType &operator[] ( unsigned int index )
130  {
131  return vector_[ index ];
132  }
133 
135  inline ThisType &assign ( const ElementType &element )
136  {
137  vector_.assign( size(), element );
138  return *this;
139  }
140 
142  template< class T >
143  inline ThisType &assign( const ArrayInterface< T > &other )
144  {
145  const unsigned int size = other.size();
146  resize( size );
147  for( unsigned int i = 0; i < size; ++i )
148  vector_[ i ] = other[ i ];
149  return *this;
150  }
151 
152  inline void append ( const ElementType &element )
153  {
154  vector_.push_back( element );
155  }
156 
157  template< class T >
158  inline void append ( const ArrayInterface< T > &array )
159  {
160  const unsigned int arraySize = array.size();
161  for( unsigned int i = 0; i < arraySize; ++i )
162  append( array[ i ] );
163  }
164 
165  inline void resize ( unsigned int newSize )
166  {
167  vector_.resize( newSize );
168  }
169 
171  inline ConstIteratorType begin () const
172  {
173  return ConstIteratorType( vector_.begin() );
174  }
175 
177  inline IteratorType begin ()
178  {
179  return IteratorType( vector_.begin() );
180  }
181 
183  inline ConstIteratorType end () const
184  {
185  return ConstIteratorType( vector_.end() );
186  }
187 
189  inline IteratorType end ()
190  {
191  return IteratorType( vector_.end() );
192  }
193 
194  inline unsigned int size () const
195  {
196  return vector_.size();
197  }
198  };
199 
200  } // namespace Fem
201 
202 } // namespace Dune
203 
204 #endif // #ifndef DUNE_FEM_STLARRAY_HH
STLArrayTraits< ElementType > Traits
Definition: stlarray.hh:92
ConstIteratorType end() const
obtain end iterator
Definition: stlarray.hh:183
void append(const ElementType &element)
Definition: stlarray.hh:152
STLArrayIterator< ElementType, typename stdVectorType::iterator > IteratorType
Definition: stlarray.hh:78
ElementType & operator*()
Definition: stlarray.hh:41
ElementImp ElementType
Definition: stlarray.hh:71
ThisType & operator=(const ThisType &other)
Definition: stlarray.hh:36
Traits::IteratorType IteratorType
Definition: stlarray.hh:101
STLArray< ElementType > ArrayType
Definition: stlarray.hh:73
STLArrayIterator< const ElementType, typename stdVectorType::const_iterator > ConstIteratorType
Definition: stlarray.hh:80
bool operator==(const ThisType &other) const
Definition: stlarray.hh:52
RealImp realIterator_
Definition: stlarray.hh:23
STLArray(unsigned int size, const ElementType &element)
Definition: stlarray.hh:113
bool operator!=(const ThisType &other) const
Definition: stlarray.hh:57
ThisType & assign(const ArrayInterface< T > &other)
copy another array to this one
Definition: stlarray.hh:143
Definition: stlarray.hh:69
ElementImp ElementType
Definition: stlarray.hh:17
ConstIteratorType begin() const
obtain begin iterator
Definition: stlarray.hh:171
Traits::ConstIteratorType ConstIteratorType
Definition: stlarray.hh:102
ThisType & assign(const ElementType &element)
fill the array with copies of an element
Definition: stlarray.hh:135
Definition: coordinate.hh:4
STLArray(const ThisType &other)
Definition: stlarray.hh:119
STLArrayIterator(RealImp realIterator)
Definition: stlarray.hh:26
IteratorType end()
obtain end iterator
Definition: stlarray.hh:189
unsigned int size() const
Definition: stlarray.hh:194
Definition: stlarray.hh:14
ThisType & operator++()
Definition: stlarray.hh:46
STLArrayIterator(const ThisType &other)
Definition: stlarray.hh:31
void resize(unsigned int newSize)
Definition: stlarray.hh:165
unsigned int size() const
Definition: array.hh:155
STLArray(unsigned int size=0)
Definition: stlarray.hh:108
std::vector< ElementType > stdVectorType
Definition: stlarray.hh:75
abstract array interface
Definition: array.hh:23
ElementImp ElementType
Definition: stlarray.hh:90
stdVectorType vector_
Definition: stlarray.hh:105
IteratorType begin()
obtain begin iterator
Definition: stlarray.hh:177
Definition: stlarray.hh:65
void append(const ArrayInterface< T > &array)
Definition: stlarray.hh:158