gslice_array.h revision 97403
1// The template and inlines for the -*- C++ -*- gslice_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 <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
31
32/** @file gslice_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_GSLICE_ARRAY
38#define _CPP_BITS_GSLICE_ARRAY 1
39
40#pragma GCC system_header
41
42namespace std {
43
44    template<typename _Tp> class gslice_array
45    {
46    public:
47        typedef _Tp value_type;
48
49        void operator=  (const valarray<_Tp>&) const;
50        void operator*= (const valarray<_Tp>&) const;
51        void operator/= (const valarray<_Tp>&) const;
52        void operator%= (const valarray<_Tp>&) const;
53        void operator+= (const valarray<_Tp>&) const;
54        void operator-= (const valarray<_Tp>&) const;
55        void operator^= (const valarray<_Tp>&) const;
56        void operator&= (const valarray<_Tp>&) const;
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 _Tp&);
61
62        template<class _Dom>
63        void operator= (const _Expr<_Dom,_Tp>&) const;
64        template<class _Dom>
65        void operator*= (const _Expr<_Dom,_Tp>&) const;
66        template<class _Dom>
67        void operator/= (const _Expr<_Dom,_Tp>&) const;
68        template<class _Dom>
69        void operator%= (const _Expr<_Dom,_Tp>&) const;
70        template<class _Dom>
71        void operator+= (const _Expr<_Dom,_Tp>&) const;
72        template<class _Dom>
73        void operator-= (const _Expr<_Dom,_Tp>&) const;
74        template<class _Dom>
75        void operator^= (const _Expr<_Dom,_Tp>&) const;
76        template<class _Dom>
77        void operator&= (const _Expr<_Dom,_Tp>&) const;
78        template<class _Dom>
79        void operator|= (const _Expr<_Dom,_Tp>&) const;
80        template<class _Dom>
81        void operator<<= (const _Expr<_Dom,_Tp>&) const;
82        template<class _Dom>
83        void operator>>= (const _Expr<_Dom,_Tp>&) const;
84
85    private:
86        _Array<_Tp>    _M_array;
87        const valarray<size_t>& _M_index;
88
89        friend class valarray<_Tp>;
90
91        gslice_array (_Array<_Tp>, const valarray<size_t>&);
92
93        // this constructor needs to be implemented.
94        gslice_array (const gslice_array&);
95
96        // not implemented
97        gslice_array();
98        gslice_array& operator= (const gslice_array&);
99    };
100
101    template<typename _Tp>
102    inline
103    gslice_array<_Tp>::gslice_array (_Array<_Tp> __a,
104                                     const valarray<size_t>& __i)
105            : _M_array (__a), _M_index (__i) {}
106
107
108    template<typename _Tp>
109    inline
110    gslice_array<_Tp>::gslice_array (const gslice_array<_Tp>& __a)
111            : _M_array (__a._M_array), _M_index (__a._M_index) {}
112
113
114    template<typename _Tp>
115    inline void
116    gslice_array<_Tp>::operator= (const _Tp& __t)
117    {
118        __valarray_fill (_M_array, _Array<size_t>(_M_index),
119                         _M_index.size(), __t);
120    }
121
122    template<typename _Tp>
123    inline void
124    gslice_array<_Tp>::operator= (const valarray<_Tp>& __v) const
125    {
126        __valarray_copy (_Array<_Tp> (__v), __v.size (),
127                         _M_array, _Array<size_t>(_M_index));
128    }
129
130    template<typename _Tp>
131    template<class E>
132    inline void
133    gslice_array<_Tp>::operator= (const _Expr<E, _Tp>& __e) const
134    {
135        __valarray_copy (__e, _M_index.size(), _M_array,
136                         _Array<size_t>(_M_index));
137    }
138
139#undef _DEFINE_VALARRAY_OPERATOR
140#define _DEFINE_VALARRAY_OPERATOR(op, name)				\
141template<typename _Tp>							\
142inline void								\
143gslice_array<_Tp>::operator op##= (const valarray<_Tp>& __v) const	\
144{									\
145    _Array_augmented_##name (_M_array, _Array<size_t>(_M_index),	\
146                              _Array<_Tp> (__v), __v.size ());		\
147}									\
148									\
149template<typename _Tp> template<class E>        			\
150inline void 								\
151gslice_array<_Tp>::operator op##= (const _Expr<E, _Tp>& __e) const	\
152{									\
153    _Array_augmented_##name (_M_array, _Array<size_t>(_M_index), __e,	\
154                              _M_index.size());				\
155}
156
157_DEFINE_VALARRAY_OPERATOR(*, multiplies)
158_DEFINE_VALARRAY_OPERATOR(/, divides)
159_DEFINE_VALARRAY_OPERATOR(%, modulus)
160_DEFINE_VALARRAY_OPERATOR(+, plus)
161_DEFINE_VALARRAY_OPERATOR(-, minus)
162_DEFINE_VALARRAY_OPERATOR(^, xor)
163_DEFINE_VALARRAY_OPERATOR(&, and)
164_DEFINE_VALARRAY_OPERATOR(|, or)
165_DEFINE_VALARRAY_OPERATOR(<<, shift_left)
166_DEFINE_VALARRAY_OPERATOR(>>, shift_right)
167
168#undef _DEFINE_VALARRAY_OPERATOR
169
170} // std::
171
172#endif /* _CPP_BITS_GSLICE_ARRAY */
173
174// Local Variables:
175// mode:c++
176// End:
177