shards Version of the Day
Loading...
Searching...
No Matches
Shards_ArrayVector.hpp
1/*
2//@HEADER
3// ************************************************************************
4//
5// Shards : Shared Discretization Tools
6// Copyright 2008 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Carter Edwards (hcedwar@sandia.gov),
39// Pavel Bochev (pbboche@sandia.gov), or
40// Denis Ridzal (dridzal@sandia.gov).
41//
42// ************************************************************************
43//@HEADER
44*/
45
46#ifndef Shards_ArrayVector_hpp
47#define Shards_ArrayVector_hpp
48
49//----------------------------------------------------------------------
50
51#include <Shards_Array.hpp>
52
53//----------------------------------------------------------------------
54
55namespace shards {
56
61template< typename Scalar , ArrayOrder Order ,
62 class Tag1 = void , class Tag2 = void ,
63 class Tag3 = void , class Tag4 = void ,
64 class Tag5 = void , class Tag6 = void ,
65 class Tag7 = void , class Tag8 = void >
66class ArrayVector ;
67
68//----------------------------------------------------------------------
69
70template< typename Scalar , ArrayOrder Order >
71class ArrayVector<Scalar,Order,void,void,void,void, void,void,void,void>
72 : public Array<Scalar,Order,void,void,void,void, void,void,void,void>
73{
74private:
75 std::vector<Scalar> m_storage ;
76
77 typedef
78 Array<Scalar,Order,void,void,void,void, void,void,void,void>
79 BaseType ;
80
81 ArrayVector( const ArrayVector & );
82 ArrayVector & operator = ( const ArrayVector & );
83
84 Scalar * get_ptr() { return m_storage.empty() ? NULL : & m_storage[0] ; }
85
86public:
87
88 typedef array_traits::int_t size_type ;
89
90 ArrayVector()
91 : BaseType() , m_storage() {}
92
93 ~ArrayVector() {}
94
95 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
96 class Tag5 , class Tag6 , class Tag7 , class Tag8 >
97 void resize( const size_type n1 , const size_type n2 ,
98 const size_type n3 , const size_type n4 ,
99 const size_type n5 , const size_type n6 ,
100 const size_type n7 , const size_type n8 )
101 {
102 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 * n8 );
103 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8>
104 ( get_ptr() ,n1,n2,n3,n4,n5,n6,n7,n8);
105 }
106
107 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
108 class Tag5 , class Tag6 , class Tag7 >
109 void resize( const size_type n1 , const size_type n2 ,
110 const size_type n3 , const size_type n4 ,
111 const size_type n5 , const size_type n6 ,
112 const size_type n7 )
113 {
114 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 );
115 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
116 ( get_ptr() ,n1,n2,n3,n4,n5,n6,n7);
117 }
118
119 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
120 class Tag5 , class Tag6 >
121 void resize( const size_type n1 , const size_type n2 ,
122 const size_type n3 , const size_type n4 ,
123 const size_type n5 , const size_type n6 )
124 {
125 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 );
126 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5,Tag6>
127 ( get_ptr() ,n1,n2,n3,n4,n5,n6);
128 }
129
130 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
131 class Tag5 >
132 void resize( const size_type n1 , const size_type n2 ,
133 const size_type n3 , const size_type n4 ,
134 const size_type n5 )
135 {
136 m_storage.resize( n1 * n2 * n3 * n4 * n5 );
137 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5>
138 ( get_ptr(),n1,n2,n3,n4,n5);
139 }
140
141 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 >
142 void resize( const size_type n1 , const size_type n2 ,
143 const size_type n3 , const size_type n4 )
144 {
145 m_storage.resize( n1 * n2 * n3 * n4 );
146 BaseType::template assign<Tag1,Tag2,Tag3,Tag4>
147 ( get_ptr(),n1,n2,n3,n4);
148 }
149
150 template< class Tag1 , class Tag2 , class Tag3 >
151 void resize( const size_type n1 , const size_type n2 ,
152 const size_type n3 )
153 {
154 m_storage.resize( n1 * n2 * n3 );
155 BaseType::template assign<Tag1,Tag2,Tag3>
156 ( get_ptr(),n1,n2,n3);
157 }
158
159 template< class Tag1 , class Tag2 >
160 void resize( const size_type n1 , const size_type n2 )
161 {
162 m_storage.resize( n1 * n2 );
163 BaseType::template assign<Tag1,Tag2>( get_ptr(),n1,n2);
164 }
165
166 template< class Tag1 >
167 void resize( const size_type n1 )
168 {
169 m_storage.resize( n1 );
170 BaseType::template assign<Tag1>( get_ptr(),n1);
171 }
172};
173
174//----------------------------------------------------------------------
175
176template< typename Scalar , ArrayOrder Order ,
177 class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
178 class Tag5 , class Tag6 , class Tag7 , class Tag8 >
179class ArrayVector
180 : public Array<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8>
181{
182private:
183 std::vector<Scalar> m_storage ;
184
185 typedef
186 array_traits::Helper<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8>
187 help_type ;
188
189 typedef
190 Array<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8>
191 BaseType ;
192
193 ArrayVector( const ArrayVector & );
194 ArrayVector & operator = ( const ArrayVector & );
195
196 Scalar * get_ptr() { return m_storage.empty() ? NULL : & m_storage[0] ; }
197
198public:
199
200 typedef array_traits::int_t size_type ;
201
202 ArrayVector()
203 : BaseType() , m_storage() {}
204
205 ~ArrayVector() {}
206
207 void resize( const size_type * const dims )
208 {
209 help_type::assign( BaseType::m_stride , dims );
210 const typename BaseType::size_type n = BaseType::size();
211 m_storage.resize( n );
212 BaseType::m_ptr = get_ptr();
213 }
214
215 void resize( const size_type n1 , const size_type n2 ,
216 const size_type n3 , const size_type n4 ,
217 const size_type n5 , const size_type n6 ,
218 const size_type n7 , const size_type n8 )
219 {
220 array_traits::CheckRank<8,BaseType::Rank>::ok();
221 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 * n8 );
222 BaseType::assign( get_ptr() ,n1,n2,n3,n4,n5,n6,n7,n8);
223 }
224
225 void resize( const size_type n1 , const size_type n2 ,
226 const size_type n3 , const size_type n4 ,
227 const size_type n5 , const size_type n6 ,
228 const size_type n7 )
229 {
230 array_traits::CheckRank<7,BaseType::Rank>::ok();
231 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 );
232 BaseType::assign( get_ptr(),n1,n2,n3,n4,n5,n6,n7);
233 }
234
235 void resize( const size_type n1 , const size_type n2 ,
236 const size_type n3 , const size_type n4 ,
237 const size_type n5 , const size_type n6 )
238 {
239 array_traits::CheckRank<6,BaseType::Rank>::ok();
240 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 );
241 BaseType::assign( get_ptr(),n1,n2,n3,n4,n5,n6);
242 }
243
244 void resize( const size_type n1 , const size_type n2 ,
245 const size_type n3 , const size_type n4 ,
246 const size_type n5 )
247 {
248 array_traits::CheckRank<5,BaseType::Rank>::ok();
249 m_storage.resize( n1 * n2 * n3 * n4 * n5 );
250 BaseType::assign( get_ptr(),n1,n2,n3,n4,n5);
251 }
252
253 void resize( const size_type n1 , const size_type n2 ,
254 const size_type n3 , const size_type n4 )
255 {
256 array_traits::CheckRank<4,BaseType::Rank>::ok();
257 m_storage.resize( n1 * n2 * n3 * n4 );
258 BaseType::assign( get_ptr(),n1,n2,n3,n4);
259 }
260
261 void resize( const size_type n1 , const size_type n2 ,
262 const size_type n3 )
263 {
264 array_traits::CheckRank<3,BaseType::Rank>::ok();
265 m_storage.resize( n1 * n2 * n3 );
266 BaseType::assign( get_ptr(),n1,n2,n3);
267 }
268
269 void resize( const size_type n1 , const size_type n2 )
270 {
271 array_traits::CheckRank<2,BaseType::Rank>::ok();
272 m_storage.resize( n1 * n2 );
273 BaseType::assign( get_ptr(),n1,n2);
274 }
275
276 void resize( const size_type n1 )
277 {
278 array_traits::CheckRank<1,BaseType::Rank>::ok();
279 m_storage.resize( n1 );
280 BaseType::assign( get_ptr(),n1);
281 }
282
283
284 ArrayVector( const size_type * const dims )
285 : BaseType(), m_storage() { resize( dims ); }
286
287 ArrayVector( const size_type n1 , const size_type n2 ,
288 const size_type n3 , const size_type n4 ,
289 const size_type n5 , const size_type n6 ,
290 const size_type n7 , const size_type n8 )
291 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5,n6,n7,n8); }
292
293 ArrayVector( const size_type n1 , const size_type n2 ,
294 const size_type n3 , const size_type n4 ,
295 const size_type n5 , const size_type n6 ,
296 const size_type n7 )
297 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5,n6,n7); }
298
299 ArrayVector( const size_type n1 , const size_type n2 ,
300 const size_type n3 , const size_type n4 ,
301 const size_type n5 , const size_type n6 )
302 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5,n6); }
303
304 ArrayVector( const size_type n1 , const size_type n2 ,
305 const size_type n3 , const size_type n4 ,
306 const size_type n5 )
307 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5); }
308
309 ArrayVector( const size_type n1 , const size_type n2 ,
310 const size_type n3 , const size_type n4 )
311 : BaseType(), m_storage() { resize(n1,n2,n3,n4); }
312
313 ArrayVector( const size_type n1 , const size_type n2 ,
314 const size_type n3 )
315 : BaseType(), m_storage() { resize(n1,n2,n3); }
316
317 ArrayVector( const size_type n1 , const size_type n2 )
318 : BaseType(), m_storage() { resize(n1,n2); }
319
320 ArrayVector( const size_type n1 )
321 : BaseType(), m_storage() { resize(n1); }
322
323};
324
327}
328
329#endif /* Shards_ArrayVector_hpp */
330
Array & assign(value_type *arg_ptr, const size_type *const dims)
Assign pointer and dimensions.
ArrayOrder
Define Natural (C-language) or Fortran ordering of array dimensions. A RankZero array does not ha...