# 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 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    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 /** @file valarray_array.tcc
    00031  *  This is an internal header file, included by other library headers.
    00032  *  You should not attempt to use it directly.
    00033  */
    00034
    00035 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
    00036
    00037 #ifndef _VALARRAY_ARRAY_TCC
    00038 #define _VALARRAY_ARRAY_TCC 1
    00039
    00040 _GLIBCXX_BEGIN_NAMESPACE(std)
    00041
    00042   template<typename _Tp>
    00043     void
    00044     __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m,
    00045             const _Tp& __t)
    00046     {
    00047       _Tp* __p = __a._M_data;
    00048       bool* __ok (__m._M_data);
    00049       for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p)
    00050     {
    00051       while (!*__ok)
    00052       {
    00053         ++__ok;
    00054         ++__p;
    00055       }
    00056       *__p = __t;
    00057     }
    00058     }
    00059
    00060   // Copy n elements of a into consecutive elements of b.  When m is
    00061   // false, the corresponding element of a is skipped.  m must contain
    00062   // at least n true elements.  a must contain at least n elements and
    00063   // enough elements to match up with m through the nth true element
    00064   // of m.  I.e.  if n is 10, m has 15 elements with 5 false followed
    00065   // by 10 true, a must have 15 elements.
    00066   template<typename _Tp>
    00067     void
    00068     __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b,
    00069             size_t __n)
    00070     {
    00071       _Tp* __p (__a._M_data);
    00072       bool* __ok (__m._M_data);
    00073       for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;
    00074        ++__q, ++__ok, ++__p)
    00075     {
    00076       while (! *__ok)
    00077         {
    00078           ++__ok;
    00079           ++__p;
    00080         }
    00081       *__q = *__p;
    00082     }
    00083     }
    00084
    00085   // Copy n consecutive elements from a into elements of b.  Elements
    00086   // of b are skipped if the corresponding element of m is false.  m
    00087   // must contain at least n true elements.  b must have at least as
    00088   // many elements as the index of the nth true element of m.  I.e. if
    00089   // m has 15 elements with 5 false followed by 10 true, b must have
    00090   // at least 15 elements.
    00091   template<typename _Tp>
    00092     void
    00093     __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
    00094             _Array<bool> __m)
    00095     {
    00096       _Tp* __q (__b._M_data);
    00097       bool* __ok (__m._M_data);
    00098       for (_Tp* __p = __a._M_data; __p < __a._M_data+__n;
    00099        ++__p, ++__ok, ++__q)
    00100     {
    00101       while (! *__ok)
    00102         {
    00103           ++__ok;
    00104           ++__q;
    00105         }
    00106       *__q = *__p;
    00107     }
    00108     }
    00109
    00110   // Copy n elements from a into elements of b.  Elements of a are
    00111   // skipped if the corresponding element of m is false.  Elements of
    00112   // b are skipped if the corresponding element of k is false.  m and
    00113   // k must contain at least n true elements.  a and b must have at
    00114   // least as many elements as the index of the nth true element of m.
    00115   template<typename _Tp>
    00116     void
    00117     __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n,
    00118             _Array<_Tp> __b, _Array<bool> __k)
    00119     {
    00120       _Tp* __p (__a._M_data);
    00121       _Tp* __q (__b._M_data);
    00122       bool* __srcok (__m._M_data);
    00123       bool* __dstok (__k._M_data);
    00124       for (size_t __i = 0; __i < __n;
    00125        ++__srcok, ++__p, ++__dstok, ++__q, ++__i)
    00126     {
    00127       while (! *__srcok)
    00128         {
    00129           ++__srcok;
    00130           ++__p;
    00131         }
    00132       while (! *__dstok)
    00133         {
    00134           ++__dstok;
    00135           ++__q;
    00136         }
    00137       *__q = *__p;
    00138     }
    00139     }
    00140
    00141   // Copy n consecutive elements of e into consecutive elements of a.
    00142   // I.e. a[i] = e[i].
    00143   template<typename _Tp, class _Dom>
    00144     void
    00145     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
    00146     {
    00147       _Tp* __p (__a._M_data);
    00148       for (size_t __i = 0; __i < __n; ++__i, ++__p)
    00149     *__p = __e[__i];
    00150     }
    00151
    00152   // Copy n consecutive elements of e into elements of a using stride
    00153   // s.  I.e., a[0] = e[0], a[s] = e[1], a[2*s] = e[2].
    00154   template<typename _Tp, class _Dom>
    00155     void
    00156     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
    00157              _Array<_Tp> __a, size_t __s)
    00158     {
    00159       _Tp* __p (__a._M_data);
    00160       for (size_t __i = 0; __i < __n; ++__i, __p += __s)
    00161     *__p = __e[__i];
    00162     }
    00163
    00164   // Copy n consecutive elements of e into elements of a indexed by
    00165   // contents of i.  I.e., a[i[0]] = e[0].
    00166   template<typename _Tp, class _Dom>
    00167     void
    00168     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
    00169             _Array<_Tp> __a, _Array<size_t> __i)
    00170     {
    00171       size_t* __j (__i._M_data);
    00172       for (size_t __k = 0; __k < __n; ++__k, ++__j)
    00173     __a._M_data[*__j] = __e[__k];
    00174     }
    00175
    00176   // Copy n elements of e indexed by contents of f into elements of a
    00177   // indexed by contents of i.  I.e., a[i[0]] = e[f[0]].
    00178   template<typename _Tp>
    00179     void
    00180     __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f,
    00181             size_t __n,
    00182             _Array<_Tp> __a, _Array<size_t> __i)
    00183     {
    00184       size_t* __g (__f._M_data);
    00185       size_t* __j (__i._M_data);
    00186       for (size_t __k = 0; __k < __n; ++__k, ++__j, ++__g)
    00187     __a._M_data[*__j] = __e._M_data[*__g];
    00188     }
    00189
    00190   // Copy n consecutive elements of e into elements of a.  Elements of
    00191   // a are skipped if the corresponding element of m is false.  m must
    00192   // have at least n true elements and a must have at least as many
    00193   // elements as the index of the nth true element of m.  I.e. if m
    00194   // has 5 false followed by 10 true elements and n == 10, a must have
    00195   // at least 15 elements.
    00196   template<typename _Tp, class _Dom>
    00197     void
    00198     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
    00199             _Array<_Tp> __a, _Array<bool> __m)
    00200     {
    00201       bool* __ok (__m._M_data);
    00202       _Tp* __p (__a._M_data);
    00203       for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)
    00204     {
    00205       while (! *__ok)
    00206         {
    00207           ++__ok;
    00208           ++__p;
    00209         }
    00210       *__p = __e[__i];
    00211     }
    00212     }
    00213
    00214
    00215   template<typename _Tp, class _Dom>
    00216     void
    00217     __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n,
    00218                   _Array<_Tp> __a)
    00219     {
    00220       _Tp* __p (__a._M_data);
    00221       for (size_t __i = 0; __i < __n; ++__i, ++__p)
    00222     new (__p) _Tp(__e[__i]);
    00223     }
    00224
    00225
    00226   template<typename _Tp>
    00227     void
    00228     __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m,
    00229                   _Array<_Tp> __b, size_t __n)
    00230     {
    00231       _Tp* __p (__a._M_data);
    00232       bool* __ok (__m._M_data);
    00233       for (_Tp* __q = __b._M_data; __q < __b._M_data+__n; ++__q, ++__ok, ++__p)
    00234     {
    00235       while (! *__ok)
    00236         {
    00237           ++__ok;
    00238           ++__p;
    00239         }
    00240       new (__q) _Tp(*__p);
    00241     }
    00242     }
    00243
    00244 _GLIBCXX_END_NAMESPACE
    00245
    00246 #endif /* _VALARRAY_ARRAY_TCC */