]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // The template and inlines for the -*- C++ -*- indirect_array class. |
2 | ||
3 | // Copyright (C) 1997-1999, 2000 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 | #ifndef _CPP_BITS_INDIRECT_ARRAY_H | |
33 | #define _CPP_BITS_INDIRECT_ARRAY_H | |
34 | ||
35 | namespace std { | |
36 | ||
37 | template <class _Tp> class indirect_array | |
38 | { | |
39 | public: | |
40 | typedef _Tp value_type; | |
41 | ||
42 | void operator= (const valarray<_Tp>&) const; | |
43 | void operator*= (const valarray<_Tp>&) const; | |
44 | void operator/= (const valarray<_Tp>&) const; | |
45 | void operator%= (const valarray<_Tp>&) const; | |
46 | void operator+= (const valarray<_Tp>&) const; | |
47 | void operator-= (const valarray<_Tp>&) const; | |
48 | void operator^= (const valarray<_Tp>&) const; | |
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 _Tp&); | |
54 | // ~indirect_array(); | |
55 | ||
56 | template<class _Dom> | |
57 | void operator= (const _Expr<_Dom, _Tp>&) const; | |
58 | template<class _Dom> | |
59 | void operator*= (const _Expr<_Dom, _Tp>&) const; | |
60 | template<class _Dom> | |
61 | void operator/= (const _Expr<_Dom, _Tp>&) const; | |
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 | ||
79 | private: | |
80 | indirect_array (const indirect_array&); | |
81 | indirect_array (_Array<_Tp>, size_t, _Array<size_t>); | |
82 | ||
83 | friend class valarray<_Tp>; | |
84 | friend class gslice_array<_Tp>; | |
85 | ||
86 | const size_t _M_sz; | |
87 | const _Array<size_t> _M_index; | |
88 | const _Array<_Tp> _M_array; | |
89 | ||
90 | // not implemented | |
91 | indirect_array (); | |
92 | indirect_array& operator= (const indirect_array&); | |
93 | }; | |
94 | ||
95 | template<typename _Tp> | |
96 | inline indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a) | |
97 | : _M_sz (__a._M_sz), _M_index (__a._M_index), | |
98 | _M_array (__a._M_array) {} | |
99 | ||
100 | template<typename _Tp> | |
101 | inline | |
102 | indirect_array<_Tp>::indirect_array (_Array<_Tp> __a, size_t __s, | |
103 | _Array<size_t> __i) | |
104 | : _M_sz (__s), _M_index (__i), _M_array (__a) {} | |
105 | ||
106 | // template<typename _Tp> | |
107 | // inline indirect_array<_Tp>::~indirect_array() {} | |
108 | ||
109 | template<typename _Tp> | |
110 | inline void | |
111 | indirect_array<_Tp>::operator= (const _Tp& __t) | |
112 | { __valarray_fill(_M_array, _M_index, _M_sz, __t); } | |
113 | ||
114 | template<typename _Tp> | |
115 | inline void | |
116 | indirect_array<_Tp>::operator= (const valarray<_Tp>& __v) const | |
117 | { __valarray_copy (_Array<_Tp> (__v), _M_sz, _M_array, _M_index); } | |
118 | ||
119 | template<typename _Tp> | |
120 | template<class _Dom> | |
121 | inline void | |
122 | indirect_array<_Tp>::operator= (const _Expr<_Dom,_Tp>& __e) const | |
123 | { __valarray_copy (__e, _M_sz, _M_array, _M_index); } | |
124 | ||
125 | #undef _DEFINE_VALARRAY_OPERATOR | |
126 | #define _DEFINE_VALARRAY_OPERATOR(op, name) \ | |
127 | template<typename _Tp> \ | |
128 | inline void \ | |
129 | indirect_array<_Tp>::operator op##= (const valarray<_Tp>& __v) const \ | |
130 | { \ | |
131 | _Array_augmented_##name (_M_array, _M_index, _Array<_Tp> (__v), _M_sz); \ | |
132 | } \ | |
133 | \ | |
134 | template<typename _Tp> template<class _Dom> \ | |
135 | inline void \ | |
136 | indirect_array<_Tp>::operator op##= (const _Expr<_Dom,_Tp>& __e) const \ | |
137 | { \ | |
138 | _Array_augmented_##name (_M_array, _M_index, __e, _M_sz); \ | |
139 | } | |
140 | ||
141 | _DEFINE_VALARRAY_OPERATOR(*, multiplies) | |
142 | _DEFINE_VALARRAY_OPERATOR(/, divides) | |
143 | _DEFINE_VALARRAY_OPERATOR(%, modulus) | |
144 | _DEFINE_VALARRAY_OPERATOR(+, plus) | |
145 | _DEFINE_VALARRAY_OPERATOR(-, minus) | |
146 | _DEFINE_VALARRAY_OPERATOR(^, xor) | |
147 | _DEFINE_VALARRAY_OPERATOR(&, and) | |
148 | _DEFINE_VALARRAY_OPERATOR(|, or) | |
149 | _DEFINE_VALARRAY_OPERATOR(<<, shift_left) | |
150 | _DEFINE_VALARRAY_OPERATOR(>>, shift_right) | |
151 | ||
152 | #undef _DEFINE_VALARRAY_OPERATOR | |
153 | ||
154 | } // std:: | |
155 | ||
156 | #endif /* _CPP_BITS_INDIRECT_ARRAY_H */ | |
157 | ||
158 | // Local Variables: | |
159 | // mode:c++ | |
160 | // End: |