1// The template and inlines for the -*- C++ -*- internal _Array helper class.
2
3// Copyright (C) 1997-1999 Cygnus Solutions
4//
5// This file is part of the GNU ISO C++ Library.  This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING.  If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// As a special exception, you may use this file as part of a free software
22// library without restriction.  Specifically, if other files instantiate
23// templates or use macros or inline functions from this file, or you compile
24// this file and link it with other files to produce an executable, this
25// file does not by itself cause the resulting executable to be covered by
26// the GNU General Public License.  This exception does not however
27// invalidate any other reasons why the executable file might be covered by
28// the GNU General Public License.
29
30// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
31
32#ifndef __VALARRAY_ARRAY_TCC__
33#define __VALARRAY_ARRAY_TCC__
34
35extern "C++" {
36
37export template<typename _Tp>
38void
39__valarray_fill (_Array<_Tp> __a, size_t __n, _Array<bool> __m, const _Tp& __t)
40{
41    _Tp* __p = __a._M_data;
42    bool* __ok (__m._M_data);
43    for (size_t __i=0; __i<__n; ++__i, ++__ok, ++__p) {
44        while (! *__ok) {
45            ++__ok;
46            ++__p;
47        }
48        *__p = __t;
49    }
50}
51
52export template<typename _Tp>
53void
54__valarray_copy (_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b, size_t __n)
55{
56    _Tp* __p (__a._M_data);
57    bool* __ok (__m._M_data);
58    for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++__ok, ++__p) {
59        while (! *__ok) {
60            ++__ok;
61            ++__p;
62        }
63        *__q = *__p;
64    }
65}
66
67export template<typename _Tp>
68void
69__valarray_copy (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, _Array<bool> __m)
70{
71    _Tp* __q (__b._M_data);
72    bool* __ok (__m._M_data);
73    for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, ++__ok, ++__q) {
74        while (! *__ok) {
75            ++__ok;
76            ++__q;
77        }
78        *__q = *__p;
79    }
80}
81
82export template<typename _Tp, class _Dom>
83void
84__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
85{
86    _Tp* __p (__a._M_data);
87    for (size_t __i=0; __i<__n; ++__i, ++__p) *__p = __e[__i];
88}
89
90export template<typename _Tp, class _Dom>
91void
92__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, 
93                 _Array<_Tp> __a, size_t __s)
94{
95    _Tp* __p (__a._M_data);
96    for (size_t __i=0; __i<__n; ++__i, __p+=__s) *__p = __e[__i];
97}
98
99export template<typename _Tp, class _Dom>
100void
101__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, 
102                 _Array<_Tp> __a, _Array<size_t> __i)
103{
104    size_t* __j (__i._M_data);
105    for (size_t __k=0; __k<__n; ++__k, ++__j) __a._M_data[*__j] = __e[__k];
106}
107
108export template<typename _Tp, class _Dom>
109void
110__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, 
111                 _Array<_Tp> __a, _Array<bool> __m)
112{
113    bool* __ok (__m._M_data);
114    _Tp* __p (__a._M_data);
115    for (size_t __i=0; __i<__n; ++__i, ++__ok, ++__p) {
116        while (! *__ok) {
117            ++__ok;
118            ++__p;
119        }
120        *__p = __e[__i];
121    }
122}
123
124} // extern "C++"
125
126#endif // __VALARRAY_ARRAY_TCC__
127
128// Local Variables:
129// mode:c++
130// End:
131