1 // The template and inlines for the -*- C++ -*- slice_array class.
2 
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
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 <[email protected]>
31 
32 /** @file slice_array.h
33  *  This is an internal header file, included by other library headers.
34  *  You should not attempt to use it directly.
35  */
36 
37 #ifndef _CPP_BITS_SLICE_ARRAY_H
38 #define _CPP_BITS_SLICE_ARRAY_H 1
39 
40 #pragma GCC system_header
41 
42 namespace std
43 {
44 
45     template<typename _Tp>
46     class slice_array
47     {
48     public:
49         typedef _Tp value_type;
50 
51       // This constructor is implemented since we need to return a value.
52       slice_array (const slice_array&);
53 
54       // This operator must be public.  See DR-253.
55       slice_array& operator= (const slice_array&);
56 
57         void operator=   (const valarray<_Tp>&) const;
58         void operator*=  (const valarray<_Tp>&) const;
59         void operator/=  (const valarray<_Tp>&) const;
60         void operator%=  (const valarray<_Tp>&) const;
61         void operator+=  (const valarray<_Tp>&) const;
62         void operator-=  (const valarray<_Tp>&) const;
63         void operator^=  (const valarray<_Tp>&) const;
64         void operator&=  (const valarray<_Tp>&) const;
65         void operator|=  (const valarray<_Tp>&) const;
66         void operator<<= (const valarray<_Tp>&) const;
67         void operator>>= (const valarray<_Tp>&) const;
68         void operator= (const _Tp &);
69         //        ~slice_array ();
70 
71         template<class _Dom>
72         void operator=   (const _Expr<_Dom,_Tp>&) const;
73         template<class _Dom>
74         void operator*=  (const _Expr<_Dom,_Tp>&) const;
75         template<class _Dom>
76         void operator/=  (const _Expr<_Dom,_Tp>&) const;
77         template<class _Dom>
78         void operator%=  (const _Expr<_Dom,_Tp>&) const;
79         template<class _Dom>
80         void operator+=  (const _Expr<_Dom,_Tp>&) const;
81         template<class _Dom>
82         void operator-=  (const _Expr<_Dom,_Tp>&) const;
83         template<class _Dom>
84         void operator^=  (const _Expr<_Dom,_Tp>&) const;
85         template<class _Dom>
86         void operator&=  (const _Expr<_Dom,_Tp>&) const;
87         template<class _Dom>
88         void operator|=  (const _Expr<_Dom,_Tp>&) const;
89         template<class _Dom>
90         void operator<<= (const _Expr<_Dom,_Tp>&) const;
91         template<class _Dom>
92         void operator>>= (const _Expr<_Dom,_Tp>&) const;
93 
94     private:
95         friend class valarray<_Tp>;
96         slice_array(_Array<_Tp>, const slice&);
97 
98         const size_t     _M_sz;
99         const size_t     _M_stride;
100         const _Array<_Tp> _M_array;
101 
102         // not implemented
103         slice_array ();
104     };
105 
106     template<typename _Tp>
107     inline slice_array<_Tp>::slice_array (_Array<_Tp> __a, const slice& __s)
108             : _M_sz (__s.size ()), _M_stride (__s.stride ()),
109               _M_array (__a.begin () + __s.start ()) {}
110 
111 
112     template<typename _Tp>
113     inline slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
114             : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
115 
116     //    template<typename _Tp>
117     //    inline slice_array<_Tp>::~slice_array () {}
118 
119   template<typename _Tp>
120   inline slice_array<_Tp>&
121   slice_array<_Tp>::operator=(const slice_array<_Tp>& __a)
122   {
123     __valarray_copy(__a._M_array, __a._M_sz, __a._M_stride,
124 		    _M_array, _M_stride);
125     return *this;
126   }
127 
128 
129     template<typename _Tp>
130     inline void
131     slice_array<_Tp>::operator= (const _Tp& __t)
132     { __valarray_fill (_M_array, _M_sz, _M_stride, __t); }
133 
134     template<typename _Tp>
135     inline void
136     slice_array<_Tp>::operator= (const valarray<_Tp>& __v) const
137     { __valarray_copy (_Array<_Tp> (__v), _M_array, _M_sz, _M_stride); }
138 
139     template<typename _Tp>
140     template<class _Dom>
141     inline void
142     slice_array<_Tp>::operator= (const _Expr<_Dom,_Tp>& __e) const
143     { __valarray_copy (__e, _M_sz, _M_array, _M_stride); }
144 
145 #undef _DEFINE_VALARRAY_OPERATOR
146 #define _DEFINE_VALARRAY_OPERATOR(op, name)				\
147 template<typename _Tp>							\
148 inline void								\
149 slice_array<_Tp>::operator op##= (const valarray<_Tp>& __v) const	\
150 {									\
151   _Array_augmented_##name (_M_array, _M_sz, _M_stride, _Array<_Tp> (__v));\
152 }									\
153 									\
154 template<typename _Tp> template<class _Dom>				\
155 inline void								\
156 slice_array<_Tp>::operator op##= (const _Expr<_Dom,_Tp>& __e) const	\
157 {									\
158     _Array_augmented_##name (_M_array, _M_stride, __e, _M_sz);		\
159 }
160 
161 
162 _DEFINE_VALARRAY_OPERATOR(*, multiplies)
163 _DEFINE_VALARRAY_OPERATOR(/, divides)
164 _DEFINE_VALARRAY_OPERATOR(%, modulus)
165 _DEFINE_VALARRAY_OPERATOR(+, plus)
166 _DEFINE_VALARRAY_OPERATOR(-, minus)
167 _DEFINE_VALARRAY_OPERATOR(^, xor)
168 _DEFINE_VALARRAY_OPERATOR(&, and)
169 _DEFINE_VALARRAY_OPERATOR(|, or)
170 _DEFINE_VALARRAY_OPERATOR(<<, shift_left)
171 _DEFINE_VALARRAY_OPERATOR(>>, shift_right)
172 
173 #undef _DEFINE_VALARRAY_OPERATOR
174 
175 } // std::
176 
177 #endif /* _CPP_BITS_SLICE_ARRAY_H */
178 
179 // Local Variables:
180 // mode:c++
181 // End:
182