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 
00032 /** @file slice_array.h
00033  *  This is an internal header file, included by other library headers.
00034  *  You should not attempt to use it directly.
00035  */
00036 
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(__a._M_array, __a._M_sz, __a._M_stride,
00161                       _M_array, _M_stride);
00162       return *this;
00163     }
00164 
00165   template<typename _Tp>
00166     inline void
00167     slice_array<_Tp>::operator=(const _Tp& __t) const
00168     { __valarray_fill(_M_array, _M_sz, _M_stride, __t); }
00169     
00170   template<typename _Tp>
00171     inline void
00172     slice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00173     { __valarray_copy(_Array<_Tp>(__v), _M_array, _M_sz, _M_stride); }
00174     
00175   template<typename _Tp>
00176   template<class _Dom>
00177     inline void
00178     slice_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
00179     { __valarray_copy(__e, _M_sz, _M_array, _M_stride); }
00180 
00181 #undef _DEFINE_VALARRAY_OPERATOR
00182 #define _DEFINE_VALARRAY_OPERATOR(_Op,_Name)                \
00183   template<typename _Tp>                        \
00184     inline void                             \
00185     slice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const   \
00186     {                                   \
00187       _Array_augmented_##_Name(_M_array, _M_sz, _M_stride, _Array<_Tp>(__v));\
00188     }                                   \
00189                                     \
00190   template<typename _Tp>                                                \
00191     template<class _Dom>                                \
00192       inline void                           \
00193       slice_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
00194       {                                 \
00195       _Array_augmented_##_Name(_M_array, _M_stride, __e, _M_sz);    \
00196       }
00197         
00198 
00199 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00200 _DEFINE_VALARRAY_OPERATOR(/, __divides)
00201 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00202 _DEFINE_VALARRAY_OPERATOR(+, __plus)
00203 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00204 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00205 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00206 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00207 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00208 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00209 
00210 #undef _DEFINE_VALARRAY_OPERATOR
00211 
00212 } // std::
00213 
00214 #endif /* _CPP_BITS_SLICE_ARRAY_H */
00215 
00216 // Local Variables:
00217 // mode:c++
00218 // End:

Generated on Thu Feb 10 23:22:56 2005 for libstdc++-v3 Source by  doxygen 1.4.0