1*f2ced752SOliver Tappe // The template and inlines for the -*- C++ -*- mask_array class.
2*f2ced752SOliver Tappe
3*f2ced752SOliver Tappe // Copyright (C) 1997-1999 Cygnus Solutions
4*f2ced752SOliver Tappe //
5*f2ced752SOliver Tappe // This file is part of the GNU ISO C++ Library. This library is free
6*f2ced752SOliver Tappe // software; you can redistribute it and/or modify it under the
7*f2ced752SOliver Tappe // terms of the GNU General Public License as published by the
8*f2ced752SOliver Tappe // Free Software Foundation; either version 2, or (at your option)
9*f2ced752SOliver Tappe // any later version.
10*f2ced752SOliver Tappe
11*f2ced752SOliver Tappe // This library is distributed in the hope that it will be useful,
12*f2ced752SOliver Tappe // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*f2ced752SOliver Tappe // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*f2ced752SOliver Tappe // GNU General Public License for more details.
15*f2ced752SOliver Tappe
16*f2ced752SOliver Tappe // You should have received a copy of the GNU General Public License along
17*f2ced752SOliver Tappe // with this library; see the file COPYING. If not, write to the Free
18*f2ced752SOliver Tappe // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19*f2ced752SOliver Tappe // USA.
20*f2ced752SOliver Tappe
21*f2ced752SOliver Tappe // As a special exception, you may use this file as part of a free software
22*f2ced752SOliver Tappe // library without restriction. Specifically, if other files instantiate
23*f2ced752SOliver Tappe // templates or use macros or inline functions from this file, or you compile
24*f2ced752SOliver Tappe // this file and link it with other files to produce an executable, this
25*f2ced752SOliver Tappe // file does not by itself cause the resulting executable to be covered by
26*f2ced752SOliver Tappe // the GNU General Public License. This exception does not however
27*f2ced752SOliver Tappe // invalidate any other reasons why the executable file might be covered by
28*f2ced752SOliver Tappe // the GNU General Public License.
29*f2ced752SOliver Tappe
30*f2ced752SOliver Tappe // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
31*f2ced752SOliver Tappe
32*f2ced752SOliver Tappe #ifndef __MASK_ARRAY__
33*f2ced752SOliver Tappe #define __MASK_ARRAY__
34*f2ced752SOliver Tappe
35*f2ced752SOliver Tappe extern "C++" {
36*f2ced752SOliver Tappe
37*f2ced752SOliver Tappe template <class _T> class mask_array
38*f2ced752SOliver Tappe {
39*f2ced752SOliver Tappe public:
40*f2ced752SOliver Tappe typedef _T value_type;
41*f2ced752SOliver Tappe
42*f2ced752SOliver Tappe void operator= (const valarray<_T>&) const;
43*f2ced752SOliver Tappe void operator*= (const valarray<_T>&) const;
44*f2ced752SOliver Tappe void operator/= (const valarray<_T>&) const;
45*f2ced752SOliver Tappe void operator%= (const valarray<_T>&) const;
46*f2ced752SOliver Tappe void operator+= (const valarray<_T>&) const;
47*f2ced752SOliver Tappe void operator-= (const valarray<_T>&) const;
48*f2ced752SOliver Tappe void operator^= (const valarray<_T>&) const;
49*f2ced752SOliver Tappe void operator&= (const valarray<_T>&) const;
50*f2ced752SOliver Tappe void operator|= (const valarray<_T>&) const;
51*f2ced752SOliver Tappe void operator<<=(const valarray<_T>&) const;
52*f2ced752SOliver Tappe void operator>>=(const valarray<_T>&) const;
53*f2ced752SOliver Tappe void operator= (const _T&);
54*f2ced752SOliver Tappe
55*f2ced752SOliver Tappe template<class _Dom>
56*f2ced752SOliver Tappe void operator= (const _Expr<_Dom,_T>&) const;
57*f2ced752SOliver Tappe template<class _Dom>
58*f2ced752SOliver Tappe void operator*= (const _Expr<_Dom,_T>&) const;
59*f2ced752SOliver Tappe template<class _Dom>
60*f2ced752SOliver Tappe void operator/= (const _Expr<_Dom,_T>&) const;
61*f2ced752SOliver Tappe template<class _Dom>
62*f2ced752SOliver Tappe void operator%= (const _Expr<_Dom,_T>&) const;
63*f2ced752SOliver Tappe template<class _Dom>
64*f2ced752SOliver Tappe void operator+= (const _Expr<_Dom,_T>&) const;
65*f2ced752SOliver Tappe template<class _Dom>
66*f2ced752SOliver Tappe void operator-= (const _Expr<_Dom,_T>&) const;
67*f2ced752SOliver Tappe template<class _Dom>
68*f2ced752SOliver Tappe void operator^= (const _Expr<_Dom,_T>&) const;
69*f2ced752SOliver Tappe template<class _Dom>
70*f2ced752SOliver Tappe void operator&= (const _Expr<_Dom,_T>&) const;
71*f2ced752SOliver Tappe template<class _Dom>
72*f2ced752SOliver Tappe void operator|= (const _Expr<_Dom,_T>&) const;
73*f2ced752SOliver Tappe template<class _Dom>
74*f2ced752SOliver Tappe void operator<<=(const _Expr<_Dom,_T>&) const;
75*f2ced752SOliver Tappe template<class _Dom>
76*f2ced752SOliver Tappe void operator>>=(const _Expr<_Dom,_T>&) const;
77*f2ced752SOliver Tappe
78*f2ced752SOliver Tappe private:
79*f2ced752SOliver Tappe mask_array (_Array<_T>, size_t, _Array<bool>);
80*f2ced752SOliver Tappe friend class valarray<_T>;
81*f2ced752SOliver Tappe
82*f2ced752SOliver Tappe const size_t _M_sz;
83*f2ced752SOliver Tappe const _Array<bool> _M_mask;
84*f2ced752SOliver Tappe const _Array<_T> _M_array;
85*f2ced752SOliver Tappe
86*f2ced752SOliver Tappe mask_array (const mask_array&);
87*f2ced752SOliver Tappe
88*f2ced752SOliver Tappe // not implemented
89*f2ced752SOliver Tappe mask_array ();
90*f2ced752SOliver Tappe mask_array& operator= (const mask_array&);
91*f2ced752SOliver Tappe };
92*f2ced752SOliver Tappe
93*f2ced752SOliver Tappe template<typename _Tp>
mask_array(const mask_array<_Tp> & a)94*f2ced752SOliver Tappe inline mask_array<_Tp>::mask_array (const mask_array<_Tp>& a)
95*f2ced752SOliver Tappe : _M_sz (a._M_sz), _M_mask (a._M_mask), _M_array (a._M_array) {}
96*f2ced752SOliver Tappe
97*f2ced752SOliver Tappe template<typename _T>
98*f2ced752SOliver Tappe inline
mask_array(_Array<_T> __a,size_t __s,_Array<bool> __m)99*f2ced752SOliver Tappe mask_array<_T>::mask_array (_Array<_T> __a, size_t __s, _Array<bool> __m)
100*f2ced752SOliver Tappe : _M_sz (__s), _M_mask (__m), _M_array (__a) {}
101*f2ced752SOliver Tappe
102*f2ced752SOliver Tappe template<typename _T>
103*f2ced752SOliver Tappe inline void
104*f2ced752SOliver Tappe mask_array<_T>::operator= (const _T& __t)
105*f2ced752SOliver Tappe { __valarray_fill (_M_array, _M_sz, _M_mask, __t); }
106*f2ced752SOliver Tappe
107*f2ced752SOliver Tappe template<typename _T>
108*f2ced752SOliver Tappe inline void
109*f2ced752SOliver Tappe mask_array<_T>::operator= (const valarray<_T>& __v) const
110*f2ced752SOliver Tappe { __valarray_copy (_Array<_T> (__v), __v.size (), _M_array, _M_mask); }
111*f2ced752SOliver Tappe
112*f2ced752SOliver Tappe template<typename _T>
113*f2ced752SOliver Tappe template<class E>
114*f2ced752SOliver Tappe inline void
115*f2ced752SOliver Tappe mask_array<_T>::operator= (const _Expr<E, _T>& __e) const
116*f2ced752SOliver Tappe { __valarray_copy (__e, __e.size (), _M_array, _M_mask); }
117*f2ced752SOliver Tappe
118*f2ced752SOliver Tappe #undef _DEFINE_VALARRAY_OPERATOR
119*f2ced752SOliver Tappe #define _DEFINE_VALARRAY_OPERATOR(op, name) \
120*f2ced752SOliver Tappe template<typename _T> \
121*f2ced752SOliver Tappe inline void \
122*f2ced752SOliver Tappe mask_array<_T>::operator##op##= (const valarray<_T>& __v) const \
123*f2ced752SOliver Tappe { \
124*f2ced752SOliver Tappe _Array_augmented_##name (_M_array, _M_mask, \
125*f2ced752SOliver Tappe _Array<_T> (__v), __v.size ()); \
126*f2ced752SOliver Tappe } \
127*f2ced752SOliver Tappe \
128*f2ced752SOliver Tappe template<typename _T> template<class E> \
129*f2ced752SOliver Tappe inline void \
130*f2ced752SOliver Tappe mask_array<_T>::operator##op##= (const _Expr<E, _T>& __e) const \
131*f2ced752SOliver Tappe { \
132*f2ced752SOliver Tappe _Array_augmented_##name (_M_array, _M_mask, __e, __e.size ()); \
133*f2ced752SOliver Tappe }
134*f2ced752SOliver Tappe
135*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(*, multiplies)
136*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(/, divides)
137*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(%, modulus)
138*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(+, plus)
139*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(-, minus)
140*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(^, xor)
141*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(&, and)
142*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(|, or)
143*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(<<, shift_left)
144*f2ced752SOliver Tappe _DEFINE_VALARRAY_OPERATOR(>>, shift_right)
145*f2ced752SOliver Tappe
146*f2ced752SOliver Tappe #undef _DEFINE_VALARRAY_OPERATOR
147*f2ced752SOliver Tappe
148*f2ced752SOliver Tappe } // extern "C++"
149*f2ced752SOliver Tappe
150*f2ced752SOliver Tappe #endif // __MASK_ARRAY__
151*f2ced752SOliver Tappe
152*f2ced752SOliver Tappe // Local Variables:
153*f2ced752SOliver Tappe // mode:c++
154*f2ced752SOliver Tappe // End:
155