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 _GLIBCXX_BEGIN_NAMESPACE(std)
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 class slice
00059 {
00060 public:
00061
00062 slice();
00063
00064
00065
00066
00067
00068
00069
00070
00071 slice(size_t, size_t, size_t);
00072
00073
00074 size_t start() const;
00075
00076 size_t size() const;
00077
00078 size_t stride() const;
00079
00080 private:
00081 size_t _M_off;
00082 size_t _M_sz;
00083 size_t _M_st;
00084 };
00085
00086
00087
00088 inline
00089 slice::slice()
00090 : _M_off(0), _M_sz(0), _M_st(0) {}
00091
00092 inline
00093 slice::slice(size_t __o, size_t __d, size_t __s)
00094 : _M_off(__o), _M_sz(__d), _M_st(__s) {}
00095
00096 inline size_t
00097 slice::start() const
00098 { return _M_off; }
00099
00100 inline size_t
00101 slice::size() const
00102 { return _M_sz; }
00103
00104 inline size_t
00105 slice::stride() const
00106 { return _M_st; }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 template<typename _Tp>
00122 class slice_array
00123 {
00124 public:
00125 typedef _Tp value_type;
00126
00127
00128
00129
00130
00131 slice_array(const slice_array&);
00132
00133
00134
00135 slice_array& operator=(const slice_array&);
00136
00137
00138 void operator=(const valarray<_Tp>&) const;
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 _Tp &) const;
00161
00162
00163 template<class _Dom>
00164 void operator=(const _Expr<_Dom, _Tp>&) const;
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
00186 private:
00187 friend class valarray<_Tp>;
00188 slice_array(_Array<_Tp>, const slice&);
00189
00190 const size_t _M_sz;
00191 const size_t _M_stride;
00192 const _Array<_Tp> _M_array;
00193
00194
00195 slice_array();
00196 };
00197
00198 template<typename _Tp>
00199 inline
00200 slice_array<_Tp>::slice_array(_Array<_Tp> __a, const slice& __s)
00201 : _M_sz(__s.size()), _M_stride(__s.stride()),
00202 _M_array(__a.begin() + __s.start()) {}
00203
00204 template<typename _Tp>
00205 inline
00206 slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
00207 : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
00208
00209
00210
00211
00212 template<typename _Tp>
00213 inline slice_array<_Tp>&
00214 slice_array<_Tp>::operator=(const slice_array<_Tp>& __a)
00215 {
00216 std::__valarray_copy(__a._M_array, __a._M_sz, __a._M_stride,
00217 _M_array, _M_stride);
00218 return *this;
00219 }
00220
00221 template<typename _Tp>
00222 inline void
00223 slice_array<_Tp>::operator=(const _Tp& __t) const
00224 { std::__valarray_fill(_M_array, _M_sz, _M_stride, __t); }
00225
00226 template<typename _Tp>
00227 inline void
00228 slice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00229 { std::__valarray_copy(_Array<_Tp>(__v), _M_array, _M_sz, _M_stride); }
00230
00231 template<typename _Tp>
00232 template<class _Dom>
00233 inline void
00234 slice_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
00235 { std::__valarray_copy(__e, _M_sz, _M_array, _M_stride); }
00236
00237 #undef _DEFINE_VALARRAY_OPERATOR
00238 #define _DEFINE_VALARRAY_OPERATOR(_Op,_Name) \
00239 template<typename _Tp> \
00240 inline void \
00241 slice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \
00242 { \
00243 _Array_augmented_##_Name(_M_array, _M_sz, _M_stride, _Array<_Tp>(__v));\
00244 } \
00245 \
00246 template<typename _Tp> \
00247 template<class _Dom> \
00248 inline void \
00249 slice_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
00250 { \
00251 _Array_augmented_##_Name(_M_array, _M_stride, __e, _M_sz); \
00252 }
00253
00254
00255 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00256 _DEFINE_VALARRAY_OPERATOR(/, __divides)
00257 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00258 _DEFINE_VALARRAY_OPERATOR(+, __plus)
00259 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00260 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00261 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00262 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00263 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00264 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00265
00266 #undef _DEFINE_VALARRAY_OPERATOR
00267
00268
00269
00270 _GLIBCXX_END_NAMESPACE
00271
00272 #endif