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 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     
00045     template<typename _Tp>
00046     class slice_array
00047     {
00048     public:
00049         typedef _Tp value_type;
00050 
00051       // This constructor is implemented since we need to return a value.
00052       slice_array (const slice_array&);
00053 
00054       // This operator must be public.  See DR-253.
00055       slice_array& operator= (const slice_array&);
00056 
00057         void operator=   (const valarray<_Tp>&) const;
00058         void operator*=  (const valarray<_Tp>&) const;
00059         void operator/=  (const valarray<_Tp>&) const;
00060         void operator%=  (const valarray<_Tp>&) const;
00061         void operator+=  (const valarray<_Tp>&) const;
00062         void operator-=  (const valarray<_Tp>&) const;
00063         void operator^=  (const valarray<_Tp>&) const;
00064         void operator&=  (const valarray<_Tp>&) const;
00065         void operator|=  (const valarray<_Tp>&) const;
00066         void operator<<= (const valarray<_Tp>&) const;
00067         void operator>>= (const valarray<_Tp>&) const;
00068         void operator= (const _Tp &);
00069         //        ~slice_array ();
00070         
00071         template<class _Dom>
00072         void operator=   (const _Expr<_Dom,_Tp>&) const;
00073         template<class _Dom>
00074         void operator*=  (const _Expr<_Dom,_Tp>&) const;
00075         template<class _Dom>
00076         void operator/=  (const _Expr<_Dom,_Tp>&) const;
00077         template<class _Dom>
00078         void operator%=  (const _Expr<_Dom,_Tp>&) const;
00079         template<class _Dom>
00080         void operator+=  (const _Expr<_Dom,_Tp>&) const;
00081         template<class _Dom>
00082         void operator-=  (const _Expr<_Dom,_Tp>&) const;
00083         template<class _Dom>
00084         void operator^=  (const _Expr<_Dom,_Tp>&) const;
00085         template<class _Dom>
00086         void operator&=  (const _Expr<_Dom,_Tp>&) const;
00087         template<class _Dom>
00088         void operator|=  (const _Expr<_Dom,_Tp>&) const;
00089         template<class _Dom>
00090         void operator<<= (const _Expr<_Dom,_Tp>&) const;
00091         template<class _Dom>
00092         void operator>>= (const _Expr<_Dom,_Tp>&) const;
00093         
00094     private:
00095         friend class valarray<_Tp>;
00096         slice_array(_Array<_Tp>, const slice&);
00097         
00098         const size_t     _M_sz;
00099         const size_t     _M_stride;
00100         const _Array<_Tp> _M_array;
00101 
00102         // not implemented
00103         slice_array ();
00104     };
00105 
00106     template<typename _Tp>
00107     inline slice_array<_Tp>::slice_array (_Array<_Tp> __a, const slice& __s)
00108             : _M_sz (__s.size ()), _M_stride (__s.stride ()),
00109               _M_array (__a.begin () + __s.start ()) {}
00110 
00111     
00112     template<typename _Tp>
00113     inline slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
00114             : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
00115     
00116     //    template<typename _Tp>
00117     //    inline slice_array<_Tp>::~slice_array () {}
00118 
00119   template<typename _Tp>
00120   inline slice_array<_Tp>&
00121   slice_array<_Tp>::operator=(const slice_array<_Tp>& __a)
00122   {
00123     __valarray_copy(_M_array, _M_sz, _M_stride, __a._M_array, __a._M_stride);
00124     return *this;
00125   }
00126 
00127 
00128     template<typename _Tp>
00129     inline void
00130     slice_array<_Tp>::operator= (const _Tp& __t) 
00131     { __valarray_fill (_M_array, _M_sz, _M_stride, __t); }
00132     
00133     template<typename _Tp>
00134     inline void
00135     slice_array<_Tp>::operator= (const valarray<_Tp>& __v) const
00136     { __valarray_copy (_Array<_Tp> (__v), _M_array, _M_sz, _M_stride); }
00137     
00138     template<typename _Tp>
00139     template<class _Dom>
00140     inline void
00141     slice_array<_Tp>::operator= (const _Expr<_Dom,_Tp>& __e) const
00142     { __valarray_copy (__e, _M_sz, _M_array, _M_stride); }
00143 
00144 #undef _DEFINE_VALARRAY_OPERATOR
00145 #define _DEFINE_VALARRAY_OPERATOR(op, name)             \
00146 template<typename _Tp>                          \
00147 inline void                             \
00148 slice_array<_Tp>::operator op##= (const valarray<_Tp>& __v) const   \
00149 {                                   \
00150   _Array_augmented_##name (_M_array, _M_sz, _M_stride, _Array<_Tp> (__v));\
00151 }                                   \
00152                                     \
00153 template<typename _Tp> template<class _Dom>             \
00154 inline void                             \
00155 slice_array<_Tp>::operator op##= (const _Expr<_Dom,_Tp>& __e) const \
00156 {                                   \
00157     _Array_augmented_##name (_M_array, _M_stride, __e, _M_sz);      \
00158 }
00159         
00160 
00161 _DEFINE_VALARRAY_OPERATOR(*, multiplies)
00162 _DEFINE_VALARRAY_OPERATOR(/, divides)
00163 _DEFINE_VALARRAY_OPERATOR(%, modulus)
00164 _DEFINE_VALARRAY_OPERATOR(+, plus)
00165 _DEFINE_VALARRAY_OPERATOR(-, minus)
00166 _DEFINE_VALARRAY_OPERATOR(^, xor)
00167 _DEFINE_VALARRAY_OPERATOR(&, and)
00168 _DEFINE_VALARRAY_OPERATOR(|, or)
00169 _DEFINE_VALARRAY_OPERATOR(<<, shift_left)
00170 _DEFINE_VALARRAY_OPERATOR(>>, shift_right)
00171 
00172 #undef _DEFINE_VALARRAY_OPERATOR
00173 
00174 } // std::
00175 
00176 #endif /* _CPP_BITS_SLICE_ARRAY_H */
00177 
00178 // Local Variables:
00179 // mode:c++
00180 // End:

Generated on Wed May 1 19:19:34 2002 for libstdc++-v3 Source by doxygen1.2.15