xref: /haiku/headers/cpp/std/mask_array.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 // The template and inlines for the -*- C++ -*- mask_array 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 __MASK_ARRAY__
33 #define __MASK_ARRAY__
34 
35 extern "C++" {
36 
37 template <class _T> class mask_array
38 {
39 public:
40     typedef _T value_type;
41 
42     void operator=  (const valarray<_T>&) const;
43     void operator*= (const valarray<_T>&) const;
44     void operator/= (const valarray<_T>&) const;
45     void operator%= (const valarray<_T>&) const;
46     void operator+= (const valarray<_T>&) const;
47     void operator-= (const valarray<_T>&) const;
48     void operator^= (const valarray<_T>&) const;
49     void operator&= (const valarray<_T>&) const;
50     void operator|= (const valarray<_T>&) const;
51     void operator<<=(const valarray<_T>&) const;
52     void operator>>=(const valarray<_T>&) const;
53     void operator= (const _T&);
54 
55     template<class _Dom>
56     void operator=  (const _Expr<_Dom,_T>&) const;
57     template<class _Dom>
58     void operator*= (const _Expr<_Dom,_T>&) const;
59     template<class _Dom>
60     void operator/= (const _Expr<_Dom,_T>&) const;
61     template<class _Dom>
62     void operator%= (const _Expr<_Dom,_T>&) const;
63     template<class _Dom>
64     void operator+= (const _Expr<_Dom,_T>&) const;
65     template<class _Dom>
66     void operator-= (const _Expr<_Dom,_T>&) const;
67     template<class _Dom>
68     void operator^= (const _Expr<_Dom,_T>&) const;
69     template<class _Dom>
70     void operator&= (const _Expr<_Dom,_T>&) const;
71     template<class _Dom>
72     void operator|= (const _Expr<_Dom,_T>&) const;
73     template<class _Dom>
74     void operator<<=(const _Expr<_Dom,_T>&) const;
75     template<class _Dom>
76     void operator>>=(const _Expr<_Dom,_T>&) const;
77 
78 private:
79     mask_array (_Array<_T>, size_t, _Array<bool>);
80     friend class valarray<_T>;
81 
82     const size_t       _M_sz;
83     const _Array<bool> _M_mask;
84     const _Array<_T>   _M_array;
85 
86     mask_array (const mask_array&);
87 
88     // not implemented
89     mask_array ();
90     mask_array& operator= (const mask_array&);
91 };
92 
93 template<typename _Tp>
94 inline mask_array<_Tp>::mask_array (const mask_array<_Tp>& a)
95         : _M_sz (a._M_sz), _M_mask (a._M_mask), _M_array (a._M_array) {}
96 
97 template<typename _T>
98 inline
99 mask_array<_T>::mask_array (_Array<_T> __a, size_t __s, _Array<bool> __m)
100         : _M_sz (__s), _M_mask (__m), _M_array (__a) {}
101 
102 template<typename _T>
103 inline void
104 mask_array<_T>::operator= (const _T& __t)
105 { __valarray_fill (_M_array, _M_sz, _M_mask, __t); }
106 
107 template<typename _T>
108 inline void
109 mask_array<_T>::operator= (const valarray<_T>& __v) const
110 { __valarray_copy (_Array<_T> (__v), __v.size (), _M_array, _M_mask); }
111 
112 template<typename _T>
113 template<class E>
114 inline void
115 mask_array<_T>::operator= (const _Expr<E, _T>& __e) const
116 { __valarray_copy (__e, __e.size (), _M_array, _M_mask); }
117 
118 #undef _DEFINE_VALARRAY_OPERATOR
119 #define _DEFINE_VALARRAY_OPERATOR(op, name)				\
120 template<typename _T>							\
121 inline void								\
122 mask_array<_T>::operator##op##= (const valarray<_T>& __v) const		\
123 {									\
124   _Array_augmented_##name (_M_array, _M_mask, 				\
125                            _Array<_T> (__v), __v.size ());		\
126 }									\
127 									\
128 template<typename _T> template<class E>					\
129 inline void								\
130 mask_array<_T>::operator##op##= (const _Expr<E, _T>& __e) const		\
131 {									\
132   _Array_augmented_##name (_M_array, _M_mask, __e, __e.size ());	\
133 }
134 
135 _DEFINE_VALARRAY_OPERATOR(*, multiplies)
136 _DEFINE_VALARRAY_OPERATOR(/, divides)
137 _DEFINE_VALARRAY_OPERATOR(%, modulus)
138 _DEFINE_VALARRAY_OPERATOR(+, plus)
139 _DEFINE_VALARRAY_OPERATOR(-, minus)
140 _DEFINE_VALARRAY_OPERATOR(^, xor)
141 _DEFINE_VALARRAY_OPERATOR(&, and)
142 _DEFINE_VALARRAY_OPERATOR(|, or)
143 _DEFINE_VALARRAY_OPERATOR(<<, shift_left)
144 _DEFINE_VALARRAY_OPERATOR(>>, shift_right)
145 
146 #undef _DEFINE_VALARRAY_OPERATOR
147 
148 } // extern "C++"
149 
150 #endif // __MASK_ARRAY__
151 
152 // Local Variables:
153 // mode:c++
154 // End:
155