00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _SLICE_ARRAY_H
00034 #define _SLICE_ARRAY_H 1
00035
00036 #pragma GCC system_header
00037
00038 namespace std _GLIBCXX_VISIBILITY(default)
00039 {
00040 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 class slice
00061 {
00062 public:
00063
00064 slice();
00065
00066
00067
00068
00069
00070
00071
00072
00073 slice(size_t, size_t, size_t);
00074
00075
00076 size_t start() const;
00077
00078 size_t size() const;
00079
00080 size_t stride() const;
00081
00082 private:
00083 size_t _M_off;
00084 size_t _M_sz;
00085 size_t _M_st;
00086 };
00087
00088
00089
00090 inline
00091 slice::slice()
00092 : _M_off(0), _M_sz(0), _M_st(0) {}
00093
00094 inline
00095 slice::slice(size_t __o, size_t __d, size_t __s)
00096 : _M_off(__o), _M_sz(__d), _M_st(__s) {}
00097
00098 inline size_t
00099 slice::start() const
00100 { return _M_off; }
00101
00102 inline size_t
00103 slice::size() const
00104 { return _M_sz; }
00105
00106 inline size_t
00107 slice::stride() const
00108 { return _M_st; }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 template<typename _Tp>
00124 class slice_array
00125 {
00126 public:
00127 typedef _Tp value_type;
00128
00129
00130
00131
00132
00133 slice_array(const slice_array&);
00134
00135
00136
00137 slice_array& operator=(const slice_array&);
00138
00139
00140 void operator=(const valarray<_Tp>&) const;
00141
00142 void operator*=(const valarray<_Tp>&) const;
00143
00144 void operator/=(const valarray<_Tp>&) const;
00145
00146 void operator%=(const valarray<_Tp>&) const;
00147
00148 void operator+=(const valarray<_Tp>&) const;
00149
00150 void operator-=(const valarray<_Tp>&) const;
00151
00152 void operator^=(const valarray<_Tp>&) const;
00153
00154 void operator&=(const valarray<_Tp>&) const;
00155
00156 void operator|=(const valarray<_Tp>&) const;
00157
00158 void operator<<=(const valarray<_Tp>&) const;
00159
00160 void operator>>=(const valarray<_Tp>&) const;
00161
00162 void operator=(const _Tp &) const;
00163
00164
00165 template<class _Dom>
00166 void operator=(const _Expr<_Dom, _Tp>&) const;
00167 template<class _Dom>
00168 void operator*=(const _Expr<_Dom, _Tp>&) const;
00169 template<class _Dom>
00170 void operator/=(const _Expr<_Dom, _Tp>&) const;
00171 template<class _Dom>
00172 void operator%=(const _Expr<_Dom, _Tp>&) const;
00173 template<class _Dom>
00174 void operator+=(const _Expr<_Dom, _Tp>&) const;
00175 template<class _Dom>
00176 void operator-=(const _Expr<_Dom, _Tp>&) const;
00177 template<class _Dom>
00178 void operator^=(const _Expr<_Dom, _Tp>&) const;
00179 template<class _Dom>
00180 void operator&=(const _Expr<_Dom, _Tp>&) const;
00181 template<class _Dom>
00182 void operator|=(const _Expr<_Dom, _Tp>&) const;
00183 template<class _Dom>
00184 void operator<<=(const _Expr<_Dom, _Tp>&) const;
00185 template<class _Dom>
00186 void operator>>=(const _Expr<_Dom, _Tp>&) const;
00187
00188 private:
00189 friend class valarray<_Tp>;
00190 slice_array(_Array<_Tp>, const slice&);
00191
00192 const size_t _M_sz;
00193 const size_t _M_stride;
00194 const _Array<_Tp> _M_array;
00195
00196
00197 slice_array();
00198 };
00199
00200 template<typename _Tp>
00201 inline
00202 slice_array<_Tp>::slice_array(_Array<_Tp> __a, const slice& __s)
00203 : _M_sz(__s.size()), _M_stride(__s.stride()),
00204 _M_array(__a.begin() + __s.start()) {}
00205
00206 template<typename _Tp>
00207 inline
00208 slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
00209 : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
00210
00211
00212
00213
00214 template<typename _Tp>
00215 inline slice_array<_Tp>&
00216 slice_array<_Tp>::operator=(const slice_array<_Tp>& __a)
00217 {
00218 std::__valarray_copy(__a._M_array, __a._M_sz, __a._M_stride,
00219 _M_array, _M_stride);
00220 return *this;
00221 }
00222
00223 template<typename _Tp>
00224 inline void
00225 slice_array<_Tp>::operator=(const _Tp& __t) const
00226 { std::__valarray_fill(_M_array, _M_sz, _M_stride, __t); }
00227
00228 template<typename _Tp>
00229 inline void
00230 slice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00231 { std::__valarray_copy(_Array<_Tp>(__v), _M_array, _M_sz, _M_stride); }
00232
00233 template<typename _Tp>
00234 template<class _Dom>
00235 inline void
00236 slice_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
00237 { std::__valarray_copy(__e, _M_sz, _M_array, _M_stride); }
00238
00239 #undef _DEFINE_VALARRAY_OPERATOR
00240 #define _DEFINE_VALARRAY_OPERATOR(_Op,_Name) \
00241 template<typename _Tp> \
00242 inline void \
00243 slice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \
00244 { \
00245 _Array_augmented_##_Name(_M_array, _M_sz, _M_stride, _Array<_Tp>(__v));\
00246 } \
00247 \
00248 template<typename _Tp> \
00249 template<class _Dom> \
00250 inline void \
00251 slice_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
00252 { \
00253 _Array_augmented_##_Name(_M_array, _M_stride, __e, _M_sz); \
00254 }
00255
00256
00257 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00258 _DEFINE_VALARRAY_OPERATOR(/, __divides)
00259 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00260 _DEFINE_VALARRAY_OPERATOR(+, __plus)
00261 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00262 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00263 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00264 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00265 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00266 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00267
00268 #undef _DEFINE_VALARRAY_OPERATOR
00269
00270
00271
00272 _GLIBCXX_END_NAMESPACE_VERSION
00273 }
00274
00275 #endif