]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/slice_array.h
Makefile.am (bits_headers): Remove slice.h
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / slice_array.h
1 // The template and inlines for the -*- C++ -*- slice_array class.
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 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 class slice
45 {
46 public:
47 slice();
48 slice(size_t, size_t, size_t);
49
50 size_t start() const;
51 size_t size() const;
52 size_t stride() const;
53
54 private:
55 size_t _M_off; // offset
56 size_t _M_sz; // size
57 size_t _M_st; // stride unit
58 };
59
60 // The default constructor constructor is not required to initialize
61 // data members with any meaningful values, so we choose to do nothing.
62 inline
63 slice::slice() {}
64
65 inline
66 slice::slice(size_t __o, size_t __d, size_t __s)
67 : _M_off(__o), _M_sz(__d), _M_st(__s) {}
68
69 inline size_t
70 slice::start() const
71 { return _M_off; }
72
73 inline size_t
74 slice::size() const
75 { return _M_sz; }
76
77 inline size_t
78 slice::stride() const
79 { return _M_st; }
80
81 template<typename _Tp>
82 class slice_array
83 {
84 public:
85 typedef _Tp value_type;
86
87 // This constructor is implemented since we need to return a value.
88 slice_array(const slice_array&);
89
90 // This operator must be public. See DR-253.
91 slice_array& operator=(const slice_array&);
92
93 void operator=(const valarray<_Tp>&) const;
94 void operator*=(const valarray<_Tp>&) const;
95 void operator/=(const valarray<_Tp>&) const;
96 void operator%=(const valarray<_Tp>&) const;
97 void operator+=(const valarray<_Tp>&) const;
98 void operator-=(const valarray<_Tp>&) const;
99 void operator^=(const valarray<_Tp>&) const;
100 void operator&=(const valarray<_Tp>&) const;
101 void operator|=(const valarray<_Tp>&) const;
102 void operator<<=(const valarray<_Tp>&) const;
103 void operator>>=(const valarray<_Tp>&) const;
104 void operator=(const _Tp &);
105 // ~slice_array ();
106
107 template<class _Dom>
108 void operator=(const _Expr<_Dom,_Tp>&) const;
109 template<class _Dom>
110 void operator*=(const _Expr<_Dom,_Tp>&) const;
111 template<class _Dom>
112 void operator/=(const _Expr<_Dom,_Tp>&) const;
113 template<class _Dom>
114 void operator%=(const _Expr<_Dom,_Tp>&) const;
115 template<class _Dom>
116 void operator+=(const _Expr<_Dom,_Tp>&) const;
117 template<class _Dom>
118 void operator-=(const _Expr<_Dom,_Tp>&) const;
119 template<class _Dom>
120 void operator^=(const _Expr<_Dom,_Tp>&) const;
121 template<class _Dom>
122 void operator&=(const _Expr<_Dom,_Tp>&) const;
123 template<class _Dom>
124 void operator|=(const _Expr<_Dom,_Tp>&) const;
125 template<class _Dom>
126 void operator<<=(const _Expr<_Dom,_Tp>&) const;
127 template<class _Dom>
128 void operator>>=(const _Expr<_Dom,_Tp>&) const;
129
130 private:
131 friend class valarray<_Tp>;
132 slice_array(_Array<_Tp>, const slice&);
133
134 const size_t _M_sz;
135 const size_t _M_stride;
136 const _Array<_Tp> _M_array;
137
138 // not implemented
139 slice_array();
140 };
141
142 template<typename _Tp>
143 inline
144 slice_array<_Tp>::slice_array(_Array<_Tp> __a, const slice& __s)
145 : _M_sz(__s.size()), _M_stride(__s.stride()),
146 _M_array(__a.begin() + __s.start()) {}
147
148 template<typename _Tp>
149 inline
150 slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
151 : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
152
153 // template<typename _Tp>
154 // inline slice_array<_Tp>::~slice_array () {}
155
156 template<typename _Tp>
157 inline slice_array<_Tp>&
158 slice_array<_Tp>::operator=(const slice_array<_Tp>& __a)
159 {
160 __valarray_copy(_M_array, _M_sz, _M_stride, __a._M_array, __a._M_stride);
161 return *this;
162 }
163
164 template<typename _Tp>
165 inline void
166 slice_array<_Tp>::operator=(const _Tp& __t)
167 { __valarray_fill(_M_array, _M_sz, _M_stride, __t); }
168
169 template<typename _Tp>
170 inline void
171 slice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
172 { __valarray_copy (_Array<_Tp> (__v), _M_array, _M_sz, _M_stride); }
173
174 template<typename _Tp>
175 template<class _Dom>
176 inline void
177 slice_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
178 { __valarray_copy (__e, _M_sz, _M_array, _M_stride); }
179
180 #undef _DEFINE_VALARRAY_OPERATOR
181 #define _DEFINE_VALARRAY_OPERATOR(_Op,_Nname) \
182 template<typename _Tp> \
183 inline void \
184 slice_array<_Tp>::operator _Op##= (const valarray<_Tp>& __v) const \
185 { \
186 _Array_augmented_##_Name (_M_array, _M_sz, _M_stride, _Array<_Tp> (__v));\
187 } \
188 \
189 template<typename _Tp> template<class _Dom> \
190 inline void \
191 slice_array<_Tp>::operator _Op##= (const _Expr<_Dom,_Tp>& __e) const \
192 { \
193 _Array_augmented_##_Name (_M_array, _M_stride, __e, _M_sz); \
194 }
195
196
197 _DEFINE_VALARRAY_OPERATOR(*, multiplies)
198 _DEFINE_VALARRAY_OPERATOR(/, divides)
199 _DEFINE_VALARRAY_OPERATOR(%, modulus)
200 _DEFINE_VALARRAY_OPERATOR(+, plus)
201 _DEFINE_VALARRAY_OPERATOR(-, minus)
202 _DEFINE_VALARRAY_OPERATOR(^, xor)
203 _DEFINE_VALARRAY_OPERATOR(&, and)
204 _DEFINE_VALARRAY_OPERATOR(|, or)
205 _DEFINE_VALARRAY_OPERATOR(<<, shift_left)
206 _DEFINE_VALARRAY_OPERATOR(>>, shift_right)
207
208 #undef _DEFINE_VALARRAY_OPERATOR
209
210 } // std::
211
212 #endif /* _CPP_BITS_SLICE_ARRAY_H */
213
214 // Local Variables:
215 // mode:c++
216 // End: