valarray_array.tcc

00001 // The template and inlines for the -*- C++ -*- internal _Array helper class. 00002 00003 // Copyright (C) 1997, 1998, 1999, 2003 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> 00031 00032 #ifndef _VALARRAY_ARRAY_TCC 00033 #define _VALARRAY_ARRAY_TCC 1 00034 00035 namespace std 00036 { 00037 template<typename _Tp> 00038 void 00039 __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m, 00040 const _Tp& __t) 00041 { 00042 _Tp* __p = __a._M_data; 00043 bool* __ok (__m._M_data); 00044 for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p) 00045 { 00046 while (!*__ok) 00047 { 00048 ++__ok; 00049 ++__p; 00050 } 00051 *__p = __t; 00052 } 00053 } 00054 00055 // Copy n elements of a into consecutive elements of b. When m is 00056 // false, the corresponding element of a is skipped. m must contain 00057 // at least n true elements. a must contain at least n elements and 00058 // enough elements to match up with m through the nth true element 00059 // of m. I.e. if n is 10, m has 15 elements with 5 false followed 00060 // by 10 true, a must have 15 elements. 00061 template<typename _Tp> 00062 void 00063 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b, 00064 size_t __n) 00065 { 00066 _Tp* __p (__a._M_data); 00067 bool* __ok (__m._M_data); 00068 for (_Tp* __q = __b._M_data; __q < __b._M_data + __n; 00069 ++__q, ++__ok, ++__p) 00070 { 00071 while (! *__ok) 00072 { 00073 ++__ok; 00074 ++__p; 00075 } 00076 *__q = *__p; 00077 } 00078 } 00079 00080 // Copy n consecutive elements from a into elements of b. Elements 00081 // of b are skipped if the corresponding element of m is false. m 00082 // must contain at least n true elements. b must have at least as 00083 // many elements as the index of the nth true element of m. I.e. if 00084 // m has 15 elements with 5 false followed by 10 true, b must have 00085 // at least 15 elements. 00086 template<typename _Tp> 00087 void 00088 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, 00089 _Array<bool> __m) 00090 { 00091 _Tp* __q (__b._M_data); 00092 bool* __ok (__m._M_data); 00093 for (_Tp* __p = __a._M_data; __p < __a._M_data+__n; 00094 ++__p, ++__ok, ++__q) 00095 { 00096 while (! *__ok) 00097 { 00098 ++__ok; 00099 ++__q; 00100 } 00101 *__q = *__p; 00102 } 00103 } 00104 00105 // Copy n elements from a into elements of b. Elements of a are 00106 // skipped if the corresponding element of m is false. Elements of 00107 // b are skipped if the corresponding element of k is false. m and 00108 // k must contain at least n true elements. a and b must have at 00109 // least as many elements as the index of the nth true element of m. 00110 template<typename _Tp> 00111 void 00112 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n, 00113 _Array<_Tp> __b, _Array<bool> __k) 00114 { 00115 _Tp* __p (__a._M_data); 00116 _Tp* __q (__b._M_data); 00117 bool* __srcok (__m._M_data); 00118 bool* __dstok (__k._M_data); 00119 for (size_t __i = 0; __i < __n; 00120 ++__srcok, ++__p, ++__dstok, ++__q, ++__i) 00121 { 00122 while (! *__srcok) 00123 { 00124 ++__srcok; 00125 ++__p; 00126 } 00127 while (! *__dstok) 00128 { 00129 ++__dstok; 00130 ++__q; 00131 } 00132 *__q = *__p; 00133 } 00134 } 00135 00136 // Copy n consecutive elements of e into consecutive elements of a. 00137 // I.e. a[i] = e[i]. 00138 template<typename _Tp, class _Dom> 00139 void 00140 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a) 00141 { 00142 _Tp* __p (__a._M_data); 00143 for (size_t __i = 0; __i < __n; ++__i, ++__p) 00144 *__p = __e[__i]; 00145 } 00146 00147 // Copy n consecutive elements of e into elements of a using stride 00148 // s. I.e., a[0] = e[0], a[s] = e[1], a[2*s] = e[2]. 00149 template<typename _Tp, class _Dom> 00150 void 00151 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, 00152 _Array<_Tp> __a, size_t __s) 00153 { 00154 _Tp* __p (__a._M_data); 00155 for (size_t __i = 0; __i < __n; ++__i, __p += __s) 00156 *__p = __e[__i]; 00157 } 00158 00159 // Copy n consecutive elements of e into elements of a indexed by 00160 // contents of i. I.e., a[i[0]] = e[0]. 00161 template<typename _Tp, class _Dom> 00162 void 00163 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, 00164 _Array<_Tp> __a, _Array<size_t> __i) 00165 { 00166 size_t* __j (__i._M_data); 00167 for (size_t __k = 0; __k < __n; ++__k, ++__j) 00168 __a._M_data[*__j] = __e[__k]; 00169 } 00170 00171 // Copy n elements of e indexed by contents of f into elements of a 00172 // indexed by contents of i. I.e., a[i[0]] = e[f[0]]. 00173 template<typename _Tp> 00174 void 00175 __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f, 00176 size_t __n, 00177 _Array<_Tp> __a, _Array<size_t> __i) 00178 { 00179 size_t* __g (__f._M_data); 00180 size_t* __j (__i._M_data); 00181 for (size_t __k = 0; __k < __n; ++__k, ++__j, ++__g) 00182 __a._M_data[*__j] = __e._M_data[*__g]; 00183 } 00184 00185 // Copy n consecutive elements of e into elements of a. Elements of 00186 // a are skipped if the corresponding element of m is false. m must 00187 // have at least n true elements and a must have at least as many 00188 // elements as the index of the nth true element of m. I.e. if m 00189 // has 5 false followed by 10 true elements and n == 10, a must have 00190 // at least 15 elements. 00191 template<typename _Tp, class _Dom> 00192 void 00193 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, 00194 _Array<_Tp> __a, _Array<bool> __m) 00195 { 00196 bool* __ok (__m._M_data); 00197 _Tp* __p (__a._M_data); 00198 for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p) 00199 { 00200 while (! *__ok) 00201 { 00202 ++__ok; 00203 ++__p; 00204 } 00205 *__p = __e[__i]; 00206 } 00207 } 00208 00209 00210 template<typename _Tp, class _Dom> 00211 void 00212 __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n, 00213 _Array<_Tp> __a) 00214 { 00215 _Tp* __p (__a._M_data); 00216 for (size_t __i = 0; __i < __n; ++__i, ++__p) 00217 new (__p) _Tp(__e[__i]); 00218 } 00219 00220 00221 template<typename _Tp> 00222 void 00223 __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m, 00224 _Array<_Tp> __b, size_t __n) 00225 { 00226 _Tp* __p (__a._M_data); 00227 bool* __ok (__m._M_data); 00228 for (_Tp* __q = __b._M_data; __q < __b._M_data+__n; ++__q, ++__ok, ++__p) 00229 { 00230 while (! *__ok) 00231 { 00232 ++__ok; 00233 ++__p; 00234 } 00235 new (__q) _Tp(*__p); 00236 } 00237 } 00238 } // namespace std 00239 00240 #endif /* _VALARRAY_ARRAY_TCC */

Generated on Tue Sep 7 10:05:24 2004 for libstdc++-v3 Source by doxygen 1.3.8