Whole document tree
    

Whole document tree

slice_array.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

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

Generated on Mon Apr 8 03:11:31 2002 for libstdc++-v3 Source by doxygen1.2.15