|
shards
Version of the Day
|
00001 /* 00002 //@HEADER 00003 // ************************************************************************ 00004 // 00005 // Shards : Shared Discretization Tools 00006 // Copyright 2008 Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Carter Edwards (hcedwar@sandia.gov), 00039 // Pavel Bochev (pbboche@sandia.gov), or 00040 // Denis Ridzal (dridzal@sandia.gov). 00041 // 00042 // ************************************************************************ 00043 //@HEADER 00044 */ 00045 00046 #ifndef Shards_ArrayVector_hpp 00047 #define Shards_ArrayVector_hpp 00048 00049 //---------------------------------------------------------------------- 00050 00051 #include <Shards_Array.hpp> 00052 00053 //---------------------------------------------------------------------- 00054 00055 namespace shards { 00056 00061 template< typename Scalar , ArrayOrder Order , 00062 class Tag1 = void , class Tag2 = void , 00063 class Tag3 = void , class Tag4 = void , 00064 class Tag5 = void , class Tag6 = void , 00065 class Tag7 = void , class Tag8 = void > 00066 class ArrayVector ; 00067 00068 //---------------------------------------------------------------------- 00069 00070 template< typename Scalar , ArrayOrder Order > 00071 class ArrayVector<Scalar,Order,void,void,void,void, void,void,void,void> 00072 : public Array<Scalar,Order,void,void,void,void, void,void,void,void> 00073 { 00074 private: 00075 std::vector<Scalar> m_storage ; 00076 00077 typedef 00078 Array<Scalar,Order,void,void,void,void, void,void,void,void> 00079 BaseType ; 00080 00081 ArrayVector( const ArrayVector & ); 00082 ArrayVector & operator = ( const ArrayVector & ); 00083 00084 Scalar * get_ptr() { return m_storage.empty() ? NULL : & m_storage[0] ; } 00085 00086 public: 00087 00088 typedef array_traits::int_t size_type ; 00089 00090 ArrayVector() 00091 : BaseType() , m_storage() {} 00092 00093 ~ArrayVector() {} 00094 00095 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 , 00096 class Tag5 , class Tag6 , class Tag7 , class Tag8 > 00097 void resize( const size_type n1 , const size_type n2 , 00098 const size_type n3 , const size_type n4 , 00099 const size_type n5 , const size_type n6 , 00100 const size_type n7 , const size_type n8 ) 00101 { 00102 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 * n8 ); 00103 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8> 00104 ( get_ptr() ,n1,n2,n3,n4,n5,n6,n7,n8); 00105 } 00106 00107 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 , 00108 class Tag5 , class Tag6 , class Tag7 > 00109 void resize( const size_type n1 , const size_type n2 , 00110 const size_type n3 , const size_type n4 , 00111 const size_type n5 , const size_type n6 , 00112 const size_type n7 ) 00113 { 00114 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 ); 00115 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> 00116 ( get_ptr() ,n1,n2,n3,n4,n5,n6,n7); 00117 } 00118 00119 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 , 00120 class Tag5 , class Tag6 > 00121 void resize( const size_type n1 , const size_type n2 , 00122 const size_type n3 , const size_type n4 , 00123 const size_type n5 , const size_type n6 ) 00124 { 00125 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 ); 00126 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5,Tag6> 00127 ( get_ptr() ,n1,n2,n3,n4,n5,n6); 00128 } 00129 00130 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 , 00131 class Tag5 > 00132 void resize( const size_type n1 , const size_type n2 , 00133 const size_type n3 , const size_type n4 , 00134 const size_type n5 ) 00135 { 00136 m_storage.resize( n1 * n2 * n3 * n4 * n5 ); 00137 BaseType::template assign<Tag1,Tag2,Tag3,Tag4,Tag5> 00138 ( get_ptr(),n1,n2,n3,n4,n5); 00139 } 00140 00141 template< class Tag1 , class Tag2 , class Tag3 , class Tag4 > 00142 void resize( const size_type n1 , const size_type n2 , 00143 const size_type n3 , const size_type n4 ) 00144 { 00145 m_storage.resize( n1 * n2 * n3 * n4 ); 00146 BaseType::template assign<Tag1,Tag2,Tag3,Tag4> 00147 ( get_ptr(),n1,n2,n3,n4); 00148 } 00149 00150 template< class Tag1 , class Tag2 , class Tag3 > 00151 void resize( const size_type n1 , const size_type n2 , 00152 const size_type n3 ) 00153 { 00154 m_storage.resize( n1 * n2 * n3 ); 00155 BaseType::template assign<Tag1,Tag2,Tag3> 00156 ( get_ptr(),n1,n2,n3); 00157 } 00158 00159 template< class Tag1 , class Tag2 > 00160 void resize( const size_type n1 , const size_type n2 ) 00161 { 00162 m_storage.resize( n1 * n2 ); 00163 BaseType::template assign<Tag1,Tag2>( get_ptr(),n1,n2); 00164 } 00165 00166 template< class Tag1 > 00167 void resize( const size_type n1 ) 00168 { 00169 m_storage.resize( n1 ); 00170 BaseType::template assign<Tag1>( get_ptr(),n1); 00171 } 00172 }; 00173 00174 //---------------------------------------------------------------------- 00175 00176 template< typename Scalar , ArrayOrder Order , 00177 class Tag1 , class Tag2 , class Tag3 , class Tag4 , 00178 class Tag5 , class Tag6 , class Tag7 , class Tag8 > 00179 class ArrayVector 00180 : public Array<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8> 00181 { 00182 private: 00183 std::vector<Scalar> m_storage ; 00184 00185 typedef 00186 array_traits::Helper<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8> 00187 help_type ; 00188 00189 typedef 00190 Array<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8> 00191 BaseType ; 00192 00193 ArrayVector( const ArrayVector & ); 00194 ArrayVector & operator = ( const ArrayVector & ); 00195 00196 Scalar * get_ptr() { return m_storage.empty() ? NULL : & m_storage[0] ; } 00197 00198 public: 00199 00200 typedef array_traits::int_t size_type ; 00201 00202 ArrayVector() 00203 : BaseType() , m_storage() {} 00204 00205 ~ArrayVector() {} 00206 00207 void resize( const size_type * const dims ) 00208 { 00209 help_type::assign( BaseType::m_stride , dims ); 00210 const typename BaseType::size_type n = BaseType::size(); 00211 m_storage.resize( n ); 00212 BaseType::m_ptr = get_ptr(); 00213 } 00214 00215 void resize( const size_type n1 , const size_type n2 , 00216 const size_type n3 , const size_type n4 , 00217 const size_type n5 , const size_type n6 , 00218 const size_type n7 , const size_type n8 ) 00219 { 00220 array_traits::CheckRank<8,BaseType::Rank>::ok(); 00221 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 * n8 ); 00222 BaseType::assign( get_ptr() ,n1,n2,n3,n4,n5,n6,n7,n8); 00223 } 00224 00225 void resize( const size_type n1 , const size_type n2 , 00226 const size_type n3 , const size_type n4 , 00227 const size_type n5 , const size_type n6 , 00228 const size_type n7 ) 00229 { 00230 array_traits::CheckRank<7,BaseType::Rank>::ok(); 00231 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 * n7 ); 00232 BaseType::assign( get_ptr(),n1,n2,n3,n4,n5,n6,n7); 00233 } 00234 00235 void resize( const size_type n1 , const size_type n2 , 00236 const size_type n3 , const size_type n4 , 00237 const size_type n5 , const size_type n6 ) 00238 { 00239 array_traits::CheckRank<6,BaseType::Rank>::ok(); 00240 m_storage.resize( n1 * n2 * n3 * n4 * n5 * n6 ); 00241 BaseType::assign( get_ptr(),n1,n2,n3,n4,n5,n6); 00242 } 00243 00244 void resize( const size_type n1 , const size_type n2 , 00245 const size_type n3 , const size_type n4 , 00246 const size_type n5 ) 00247 { 00248 array_traits::CheckRank<5,BaseType::Rank>::ok(); 00249 m_storage.resize( n1 * n2 * n3 * n4 * n5 ); 00250 BaseType::assign( get_ptr(),n1,n2,n3,n4,n5); 00251 } 00252 00253 void resize( const size_type n1 , const size_type n2 , 00254 const size_type n3 , const size_type n4 ) 00255 { 00256 array_traits::CheckRank<4,BaseType::Rank>::ok(); 00257 m_storage.resize( n1 * n2 * n3 * n4 ); 00258 BaseType::assign( get_ptr(),n1,n2,n3,n4); 00259 } 00260 00261 void resize( const size_type n1 , const size_type n2 , 00262 const size_type n3 ) 00263 { 00264 array_traits::CheckRank<3,BaseType::Rank>::ok(); 00265 m_storage.resize( n1 * n2 * n3 ); 00266 BaseType::assign( get_ptr(),n1,n2,n3); 00267 } 00268 00269 void resize( const size_type n1 , const size_type n2 ) 00270 { 00271 array_traits::CheckRank<2,BaseType::Rank>::ok(); 00272 m_storage.resize( n1 * n2 ); 00273 BaseType::assign( get_ptr(),n1,n2); 00274 } 00275 00276 void resize( const size_type n1 ) 00277 { 00278 array_traits::CheckRank<1,BaseType::Rank>::ok(); 00279 m_storage.resize( n1 ); 00280 BaseType::assign( get_ptr(),n1); 00281 } 00282 00283 00284 ArrayVector( const size_type * const dims ) 00285 : BaseType(), m_storage() { resize( dims ); } 00286 00287 ArrayVector( const size_type n1 , const size_type n2 , 00288 const size_type n3 , const size_type n4 , 00289 const size_type n5 , const size_type n6 , 00290 const size_type n7 , const size_type n8 ) 00291 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5,n6,n7,n8); } 00292 00293 ArrayVector( const size_type n1 , const size_type n2 , 00294 const size_type n3 , const size_type n4 , 00295 const size_type n5 , const size_type n6 , 00296 const size_type n7 ) 00297 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5,n6,n7); } 00298 00299 ArrayVector( const size_type n1 , const size_type n2 , 00300 const size_type n3 , const size_type n4 , 00301 const size_type n5 , const size_type n6 ) 00302 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5,n6); } 00303 00304 ArrayVector( const size_type n1 , const size_type n2 , 00305 const size_type n3 , const size_type n4 , 00306 const size_type n5 ) 00307 : BaseType(), m_storage() { resize(n1,n2,n3,n4,n5); } 00308 00309 ArrayVector( const size_type n1 , const size_type n2 , 00310 const size_type n3 , const size_type n4 ) 00311 : BaseType(), m_storage() { resize(n1,n2,n3,n4); } 00312 00313 ArrayVector( const size_type n1 , const size_type n2 , 00314 const size_type n3 ) 00315 : BaseType(), m_storage() { resize(n1,n2,n3); } 00316 00317 ArrayVector( const size_type n1 , const size_type n2 ) 00318 : BaseType(), m_storage() { resize(n1,n2); } 00319 00320 ArrayVector( const size_type n1 ) 00321 : BaseType(), m_storage() { resize(n1); } 00322 00323 }; 00324 00327 } 00328 00329 #endif /* Shards_ArrayVector_hpp */ 00330