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