xref: /openbsd-src/gnu/lib/libstdc++/libstdc++/include/bits/indirect_array.h (revision 03a78d155d6fff5698289342b62759a75b20d130)
1*03a78d15Sespie // The template and inlines for the -*- C++ -*- indirect_array class.
2*03a78d15Sespie 
3*03a78d15Sespie // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4*03a78d15Sespie //  Free Software Foundation, Inc.
5*03a78d15Sespie //
6*03a78d15Sespie // This file is part of the GNU ISO C++ Library.  This library is free
7*03a78d15Sespie // software; you can redistribute it and/or modify it under the
8*03a78d15Sespie // terms of the GNU General Public License as published by the
9*03a78d15Sespie // Free Software Foundation; either version 2, or (at your option)
10*03a78d15Sespie // any later version.
11*03a78d15Sespie 
12*03a78d15Sespie // This library is distributed in the hope that it will be useful,
13*03a78d15Sespie // but WITHOUT ANY WARRANTY; without even the implied warranty of
14*03a78d15Sespie // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*03a78d15Sespie // GNU General Public License for more details.
16*03a78d15Sespie 
17*03a78d15Sespie // You should have received a copy of the GNU General Public License along
18*03a78d15Sespie // with this library; see the file COPYING.  If not, write to the Free
19*03a78d15Sespie // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20*03a78d15Sespie // USA.
21*03a78d15Sespie 
22*03a78d15Sespie // As a special exception, you may use this file as part of a free software
23*03a78d15Sespie // library without restriction.  Specifically, if other files instantiate
24*03a78d15Sespie // templates or use macros or inline functions from this file, or you compile
25*03a78d15Sespie // this file and link it with other files to produce an executable, this
26*03a78d15Sespie // file does not by itself cause the resulting executable to be covered by
27*03a78d15Sespie // the GNU General Public License.  This exception does not however
28*03a78d15Sespie // invalidate any other reasons why the executable file might be covered by
29*03a78d15Sespie // the GNU General Public License.
30*03a78d15Sespie 
31*03a78d15Sespie // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
32*03a78d15Sespie 
33*03a78d15Sespie /** @file indirect_array.h
34*03a78d15Sespie  *  This is an internal header file, included by other library headers.
35*03a78d15Sespie  *  You should not attempt to use it directly.
36*03a78d15Sespie  */
37*03a78d15Sespie 
38*03a78d15Sespie #ifndef _CPP_BITS_INDIRECT_ARRAY_H
39*03a78d15Sespie #define _CPP_BITS_INDIRECT_ARRAY_H 1
40*03a78d15Sespie 
41*03a78d15Sespie #pragma GCC system_header
42*03a78d15Sespie 
43*03a78d15Sespie namespace std
44*03a78d15Sespie {
45*03a78d15Sespie   template <class _Tp>
46*03a78d15Sespie      class indirect_array
47*03a78d15Sespie      {
48*03a78d15Sespie      public:
49*03a78d15Sespie        typedef _Tp value_type;
50*03a78d15Sespie 
51*03a78d15Sespie        // XXX: This is a proposed resolution for DR-253.
52*03a78d15Sespie        indirect_array& operator=(const indirect_array&);
53*03a78d15Sespie 
54*03a78d15Sespie        void operator=(const valarray<_Tp>&) const;
55*03a78d15Sespie        void operator*=(const valarray<_Tp>&) const;
56*03a78d15Sespie        void operator/=(const valarray<_Tp>&) const;
57*03a78d15Sespie        void operator%=(const valarray<_Tp>&) const;
58*03a78d15Sespie        void operator+=(const valarray<_Tp>&) const;
59*03a78d15Sespie        void operator-=(const valarray<_Tp>&) const;
60*03a78d15Sespie        void operator^=(const valarray<_Tp>&) const;
61*03a78d15Sespie        void operator&=(const valarray<_Tp>&) const;
62*03a78d15Sespie        void operator|=(const valarray<_Tp>&) const;
63*03a78d15Sespie        void operator<<=(const valarray<_Tp>&) const;
64*03a78d15Sespie        void operator>>=(const valarray<_Tp>&) const;
65*03a78d15Sespie        void operator= (const _Tp&) const;
66*03a78d15Sespie        //    ~indirect_array();
67*03a78d15Sespie 
68*03a78d15Sespie        template<class _Dom>
69*03a78d15Sespie          void operator=(const _Expr<_Dom, _Tp>&) const;
70*03a78d15Sespie        template<class _Dom>
71*03a78d15Sespie          void operator*=(const _Expr<_Dom, _Tp>&) const;
72*03a78d15Sespie        template<class _Dom>
73*03a78d15Sespie          void operator/=(const _Expr<_Dom, _Tp>&) const;
74*03a78d15Sespie        template<class _Dom>
75*03a78d15Sespie          void operator%=(const _Expr<_Dom, _Tp>&) const;
76*03a78d15Sespie        template<class _Dom>
77*03a78d15Sespie          void operator+=(const _Expr<_Dom, _Tp>&) const;
78*03a78d15Sespie        template<class _Dom>
79*03a78d15Sespie          void operator-=(const _Expr<_Dom, _Tp>&) const;
80*03a78d15Sespie        template<class _Dom>
81*03a78d15Sespie          void operator^=(const _Expr<_Dom, _Tp>&) const;
82*03a78d15Sespie        template<class _Dom>
83*03a78d15Sespie          void operator&=(const _Expr<_Dom, _Tp>&) const;
84*03a78d15Sespie        template<class _Dom>
85*03a78d15Sespie          void operator|=(const _Expr<_Dom, _Tp>&) const;
86*03a78d15Sespie        template<class _Dom>
87*03a78d15Sespie          void operator<<=(const _Expr<_Dom, _Tp>&) const;
88*03a78d15Sespie        template<class _Dom>
89*03a78d15Sespie          void operator>>=(const _Expr<_Dom, _Tp>&) const;
90*03a78d15Sespie 
91*03a78d15Sespie      private:
92*03a78d15Sespie        indirect_array(const indirect_array&);
93*03a78d15Sespie        indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
94*03a78d15Sespie 
95*03a78d15Sespie        friend class valarray<_Tp>;
96*03a78d15Sespie        friend class gslice_array<_Tp>;
97*03a78d15Sespie 
98*03a78d15Sespie        const size_t 	 _M_sz;
99*03a78d15Sespie        const _Array<size_t> _M_index;
100*03a78d15Sespie        const _Array<_Tp> 	 _M_array;
101*03a78d15Sespie 
102*03a78d15Sespie        // not implemented
103*03a78d15Sespie        indirect_array();
104*03a78d15Sespie      };
105*03a78d15Sespie 
106*03a78d15Sespie   template<typename _Tp>
107*03a78d15Sespie     inline
indirect_array(const indirect_array<_Tp> & __a)108*03a78d15Sespie     indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
109*03a78d15Sespie       : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {}
110*03a78d15Sespie 
111*03a78d15Sespie   template<typename _Tp>
112*03a78d15Sespie      inline
indirect_array(_Array<_Tp> __a,size_t __s,_Array<size_t> __i)113*03a78d15Sespie      indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s,
114*03a78d15Sespie 					 _Array<size_t> __i)
115*03a78d15Sespie        : _M_sz(__s), _M_index(__i), _M_array(__a) {}
116*03a78d15Sespie 
117*03a78d15Sespie   template<typename _Tp>
118*03a78d15Sespie      inline indirect_array<_Tp>&
119*03a78d15Sespie      indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a)
120*03a78d15Sespie      {
121*03a78d15Sespie        __valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array, _M_index);
122*03a78d15Sespie        return *this;
123*03a78d15Sespie      }
124*03a78d15Sespie 
125*03a78d15Sespie 
126*03a78d15Sespie   template<typename _Tp>
127*03a78d15Sespie      inline void
128*03a78d15Sespie      indirect_array<_Tp>::operator=(const _Tp& __t) const
129*03a78d15Sespie      { __valarray_fill(_M_array, _M_index, _M_sz, __t); }
130*03a78d15Sespie 
131*03a78d15Sespie   template<typename _Tp>
132*03a78d15Sespie      inline void
133*03a78d15Sespie      indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const
134*03a78d15Sespie      { __valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); }
135*03a78d15Sespie 
136*03a78d15Sespie   template<typename _Tp>
137*03a78d15Sespie      template<class _Dom>
138*03a78d15Sespie        inline void
139*03a78d15Sespie        indirect_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
140*03a78d15Sespie        { __valarray_copy(__e, _M_sz, _M_array, _M_index); }
141*03a78d15Sespie 
142*03a78d15Sespie #undef _DEFINE_VALARRAY_OPERATOR
143*03a78d15Sespie #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name)				\
144*03a78d15Sespie   template<typename _Tp>						\
145*03a78d15Sespie     inline void								\
146*03a78d15Sespie     indirect_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const\
147*03a78d15Sespie     {									\
148*03a78d15Sespie       _Array_augmented_##_Name(_M_array, _M_index, _Array<_Tp>(__v), _M_sz); \
149*03a78d15Sespie     }									\
150*03a78d15Sespie 									\
151*03a78d15Sespie   template<typename _Tp>                                                \
152*03a78d15Sespie     template<class _Dom>				                \
153*03a78d15Sespie       inline void							\
154*03a78d15Sespie       indirect_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
155*03a78d15Sespie       {									\
156*03a78d15Sespie 	_Array_augmented_##_Name(_M_array, _M_index, __e, _M_sz);	\
157*03a78d15Sespie       }
158*03a78d15Sespie 
159*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
160*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(/, __divides)
161*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(%, __modulus)
162*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(+, __plus)
163*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(-, __minus)
164*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
165*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
166*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
167*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
168*03a78d15Sespie _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
169*03a78d15Sespie 
170*03a78d15Sespie #undef _DEFINE_VALARRAY_OPERATOR
171*03a78d15Sespie 
172*03a78d15Sespie } // std::
173*03a78d15Sespie 
174*03a78d15Sespie #endif /* _CPP_BITS_INDIRECT_ARRAY_H */
175*03a78d15Sespie 
176*03a78d15Sespie // Local Variables:
177*03a78d15Sespie // mode:c++
178*03a78d15Sespie // End:
179