slice_array.h

Go to the documentation of this file.
00001 // The template and inlines for the -*- C++ -*- slice_array class.
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
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;                      // offset
00082     size_t _M_sz;           // size
00083     size_t _M_st;           // stride unit
00084   };
00085 
00086   // The default constructor constructor is not required to initialize
00087   // data members with any meaningful values, so we choose to do nothing.
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       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00127       // 253. valarray helper functions are almost entirely useless
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       //        ~slice_array ();
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       // not implemented
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   //    template<typename _Tp>
00209   //    inline slice_array<_Tp>::~slice_array () {}
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 } // std::
00268 
00269 #endif /* _SLICE_ARRAY_H */
00270 
00271 // Local Variables:
00272 // mode:c++
00273 // End:

Generated on Tue Jan 30 17:31:53 2007 for GNU C++ STL by doxygen 1.3.6