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