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 
00038 #ifndef _SLICE_ARRAY_H
00039 #define _SLICE_ARRAY_H 1
00040 
00041 #pragma GCC system_header
00042 
00043 namespace std
00044 {
00058   class slice
00059   {
00060   public:
00062     slice();
00063 
00071     slice(size_t, size_t, size_t);
00072 
00074     size_t start() const;
00076     size_t size() const;
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 
00091   inline
00092   slice::slice(size_t __o, size_t __d, size_t __s)
00093   : _M_off(__o), _M_sz(__d), _M_st(__s) {}
00094 
00095   inline size_t
00096   slice::start() const
00097   { return _M_off; }
00098 
00099   inline size_t
00100   slice::size() const
00101   { return _M_sz; }
00102 
00103   inline size_t
00104   slice::stride() const
00105   { return _M_st; }
00106 
00120   template<typename _Tp>
00121     class slice_array
00122     {
00123     public:
00124       typedef _Tp value_type;
00125 
00126       
00127       
00128 
00130       slice_array(const slice_array&);
00131 
00134       slice_array& operator=(const slice_array&);
00135 
00137       void operator=(const valarray<_Tp>&) const;
00139       void operator*=(const valarray<_Tp>&) const;
00141       void operator/=(const valarray<_Tp>&) const;
00143       void operator%=(const valarray<_Tp>&) const;
00145       void operator+=(const valarray<_Tp>&) const;
00147       void operator-=(const valarray<_Tp>&) const;
00149       void operator^=(const valarray<_Tp>&) const;
00151       void operator&=(const valarray<_Tp>&) const;
00153       void operator|=(const valarray<_Tp>&) const;
00155       void operator<<=(const valarray<_Tp>&) const;
00157       void operator>>=(const valarray<_Tp>&) const;
00159       void operator=(const _Tp &) const;
00160       
00161 
00162       template<class _Dom>
00163         void operator=(const _Expr<_Dom, _Tp>&) const;
00164       template<class _Dom>
00165     void operator*=(const _Expr<_Dom, _Tp>&) const;
00166       template<class _Dom>
00167     void operator/=(const _Expr<_Dom, _Tp>&) const;
00168       template<class _Dom>
00169     void operator%=(const _Expr<_Dom, _Tp>&) const;
00170       template<class _Dom>
00171     void operator+=(const _Expr<_Dom, _Tp>&) const;
00172       template<class _Dom>
00173     void operator-=(const _Expr<_Dom, _Tp>&) const;
00174       template<class _Dom>
00175     void operator^=(const _Expr<_Dom, _Tp>&) const;
00176       template<class _Dom>
00177     void operator&=(const _Expr<_Dom, _Tp>&) const;
00178       template<class _Dom>
00179     void operator|=(const _Expr<_Dom, _Tp>&) const;
00180       template<class _Dom>
00181     void operator<<=(const _Expr<_Dom, _Tp>&) const;
00182       template<class _Dom>
00183     void operator>>=(const _Expr<_Dom, _Tp>&) const;
00184 
00185     private:
00186       friend class valarray<_Tp>;
00187       slice_array(_Array<_Tp>, const slice&);
00188 
00189       const size_t      _M_sz;
00190       const size_t      _M_stride;
00191       const _Array<_Tp> _M_array;
00192 
00193       
00194       slice_array();
00195     };
00196 
00197   template<typename _Tp>
00198     inline
00199     slice_array<_Tp>::slice_array(_Array<_Tp> __a, const slice& __s)
00200     : _M_sz(__s.size()), _M_stride(__s.stride()),
00201       _M_array(__a.begin() + __s.start()) {}
00202 
00203   template<typename _Tp>
00204     inline
00205     slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
00206     : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
00207 
00208   
00209   
00210 
00211   template<typename _Tp>
00212     inline slice_array<_Tp>&
00213     slice_array<_Tp>::operator=(const slice_array<_Tp>& __a)
00214     {
00215       std::__valarray_copy(__a._M_array, __a._M_sz, __a._M_stride,
00216                _M_array, _M_stride);
00217       return *this;
00218     }
00219 
00220   template<typename _Tp>
00221     inline void
00222     slice_array<_Tp>::operator=(const _Tp& __t) const
00223     { std::__valarray_fill(_M_array, _M_sz, _M_stride, __t); }
00224 
00225   template<typename _Tp>
00226     inline void
00227     slice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00228     { std::__valarray_copy(_Array<_Tp>(__v), _M_array, _M_sz, _M_stride); }
00229 
00230   template<typename _Tp>
00231   template<class _Dom>
00232     inline void
00233     slice_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
00234     { std::__valarray_copy(__e, _M_sz, _M_array, _M_stride); }
00235 
00236 #undef _DEFINE_VALARRAY_OPERATOR
00237 #define _DEFINE_VALARRAY_OPERATOR(_Op,_Name)                \
00238   template<typename _Tp>                        \
00239     inline void                             \
00240     slice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const   \
00241     {                                   \
00242       _Array_augmented_##_Name(_M_array, _M_sz, _M_stride, _Array<_Tp>(__v));\
00243     }                                   \
00244                                     \
00245   template<typename _Tp>                                                \
00246     template<class _Dom>                                \
00247       inline void                           \
00248       slice_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
00249       {                                 \
00250       _Array_augmented_##_Name(_M_array, _M_stride, __e, _M_sz);    \
00251       }
00252 
00253 
00254 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00255 _DEFINE_VALARRAY_OPERATOR(/, __divides)
00256 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00257 _DEFINE_VALARRAY_OPERATOR(+, __plus)
00258 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00259 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00260 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00261 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00262 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00263 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00264 
00265 #undef _DEFINE_VALARRAY_OPERATOR
00266 
00267 } 
00268 
00269 #endif 
00270 
00271 
00272 
00273