# 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 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 2, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
    00031
    00037 #ifndef _CPP_BITS_SLICE_ARRAY_H
    00038 #define _CPP_BITS_SLICE_ARRAY_H 1
    00039
    00040 #pragma GCC system_header
    00041
    00042 namespace std
    00043 {
    00044   class slice
    00045   {
    00046   public:
    00047     slice();
    00048     slice(size_t, size_t, size_t);
    00049
    00050     size_t start() const;
    00051     size_t size() const;
    00052     size_t stride() const;
    00053
    00054   private:
    00055     size_t _M_off;                      // offset
    00056     size_t _M_sz;           // size
    00057     size_t _M_st;           // stride unit
    00058   };
    00059
    00060   // The default constructor constructor is not required to initialize
    00061   // data members with any meaningful values, so we choose to do nothing.
    00062   inline
    00063   slice::slice() {}
    00064
    00065   inline
    00066   slice::slice(size_t __o, size_t __d, size_t __s)
    00067     : _M_off(__o), _M_sz(__d), _M_st(__s) {}
    00068
    00069   inline size_t
    00070   slice::start() const
    00071   { return _M_off; }
    00072
    00073   inline size_t
    00074   slice::size() const
    00075   { return _M_sz; }
    00076
    00077   inline size_t
    00078   slice::stride() const
    00079   { return _M_st; }
    00080
    00081   template<typename _Tp>
    00082     class slice_array
    00083     {
    00084     public:
    00085       typedef _Tp value_type;
    00086
    00087       // This constructor is implemented since we need to return a value.
    00088       slice_array(const slice_array&);
    00089
    00090       // This operator must be public.  See DR-253.
    00091       slice_array& operator=(const slice_array&);
    00092
    00093       void operator=(const valarray<_Tp>&) const;
    00094       void operator*=(const valarray<_Tp>&) const;
    00095       void operator/=(const valarray<_Tp>&) const;
    00096       void operator%=(const valarray<_Tp>&) const;
    00097       void operator+=(const valarray<_Tp>&) const;
    00098       void operator-=(const valarray<_Tp>&) const;
    00099       void operator^=(const valarray<_Tp>&) const;
    00100       void operator&=(const valarray<_Tp>&) const;
    00101       void operator|=(const valarray<_Tp>&) const;
    00102       void operator<<=(const valarray<_Tp>&) const;
    00103       void operator>>=(const valarray<_Tp>&) const;
    00104       void operator=(const _Tp &) const;
    00105       //        ~slice_array ();
    00106
    00107       template<class _Dom>
    00108     void operator=(const _Expr<_Dom,_Tp>&) const;
    00109       template<class _Dom>
    00110     void operator*=(const _Expr<_Dom,_Tp>&) const;
    00111       template<class _Dom>
    00112     void operator/=(const _Expr<_Dom,_Tp>&) const;
    00113       template<class _Dom>
    00114     void operator%=(const _Expr<_Dom,_Tp>&) const;
    00115       template<class _Dom>
    00116     void operator+=(const _Expr<_Dom,_Tp>&) const;
    00117       template<class _Dom>
    00118     void operator-=(const _Expr<_Dom,_Tp>&) const;
    00119       template<class _Dom>
    00120     void operator^=(const _Expr<_Dom,_Tp>&) const;
    00121       template<class _Dom>
    00122     void operator&=(const _Expr<_Dom,_Tp>&) const;
    00123       template<class _Dom>
    00124     void operator|=(const _Expr<_Dom,_Tp>&) const;
    00125       template<class _Dom>
    00126     void operator<<=(const _Expr<_Dom,_Tp>&) const;
    00127       template<class _Dom>
    00128     void operator>>=(const _Expr<_Dom,_Tp>&) const;
    00129
    00130     private:
    00131       friend class valarray<_Tp>;
    00132       slice_array(_Array<_Tp>, const slice&);
    00133
    00134       const size_t     _M_sz;
    00135       const size_t     _M_stride;
    00136       const _Array<_Tp> _M_array;
    00137
    00138       // not implemented
    00139       slice_array();
    00140     };
    00141
    00142   template<typename _Tp>
    00143     inline
    00144     slice_array<_Tp>::slice_array(_Array<_Tp> __a, const slice& __s)
    00145       : _M_sz(__s.size()), _M_stride(__s.stride()),
    00146     _M_array(__a.begin() + __s.start()) {}
    00147
    00148   template<typename _Tp>
    00149     inline
    00150     slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
    00151       : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
    00152
    00153   //    template<typename _Tp>
    00154   //    inline slice_array<_Tp>::~slice_array () {}
    00155
    00156   template<typename _Tp>
    00157     inline slice_array<_Tp>&
    00158     slice_array<_Tp>::operator=(const slice_array<_Tp>& __a)
    00159     {
    00160       __valarray_copy(_M_array, _M_sz, _M_stride, __a._M_array, __a._M_stride);
    00161       return *this;
    00162     }
    00163
    00164   template<typename _Tp>
    00165     inline void
    00166     slice_array<_Tp>::operator=(const _Tp& __t) const
    00167     { __valarray_fill(_M_array, _M_sz, _M_stride, __t); }
    00168
    00169   template<typename _Tp>
    00170     inline void
    00171     slice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
    00172     { __valarray_copy(_Array<_Tp>(__v), _M_array, _M_sz, _M_stride); }
    00173
    00174   template<typename _Tp>
    00175   template<class _Dom>
    00176     inline void
    00177     slice_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
    00178     { __valarray_copy(__e, _M_sz, _M_array, _M_stride); }
    00179
    00180 #undef _DEFINE_VALARRAY_OPERATOR
    00181 #define _DEFINE_VALARRAY_OPERATOR(_Op,_Name)                \
    00182   template<typename _Tp>                        \
    00183     inline void                             \
    00184     slice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const   \
    00185     {                                   \
    00186       _Array_augmented_##_Name(_M_array, _M_sz, _M_stride, _Array<_Tp>(__v));\
    00187     }                                   \
    00188                                     \
    00189   template<typename _Tp>                                                \
    00190     template<class _Dom>                                \
    00191       inline void                           \
    00192       slice_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
    00193       {                                 \
    00194       _Array_augmented_##_Name(_M_array, _M_stride, __e, _M_sz);    \
    00195       }
    00196
    00197
    00198 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
    00199 _DEFINE_VALARRAY_OPERATOR(/, __divides)
    00200 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
    00201 _DEFINE_VALARRAY_OPERATOR(+, __plus)
    00202 _DEFINE_VALARRAY_OPERATOR(-, __minus)
    00203 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
    00204 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
    00205 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
    00206 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
    00207 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
    00208
    00209 #undef _DEFINE_VALARRAY_OPERATOR
    00210
    00211 } // std::
    00212
    00213 #endif /* _CPP_BITS_SLICE_ARRAY_H */
    00214
    00215 // Local Variables:
    00216 // mode:c++
    00217 // End: