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