# gslice_array.h

Go to the documentation of this file.

    00001 // The template and inlines for the -*- C++ -*- gslice_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_GSLICE_ARRAY
    00038 #define _CPP_BITS_GSLICE_ARRAY 1
    00039
    00040 #pragma GCC system_header
    00041
    00042 namespace std {
    00043
    00044     template<typename _Tp> class gslice_array
    00045     {
    00046     public:
    00047         typedef _Tp value_type;
    00048
    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 valarray<_Tp>&) const;
    00058         void operator<<=(const valarray<_Tp>&) const;
    00059         void operator>>=(const valarray<_Tp>&) const;
    00060         void operator=(const _Tp&);
    00061
    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         template<class _Dom>
    00083         void operator>>= (const _Expr<_Dom,_Tp>&) const;
    00084
    00085     private:
    00086         _Array<_Tp>    _M_array;
    00087         const valarray<size_t>& _M_index;
    00088
    00089         friend class valarray<_Tp>;
    00090
    00091         gslice_array (_Array<_Tp>, const valarray<size_t>&);
    00092
    00093         // this constructor needs to be implemented.
    00094         gslice_array (const gslice_array&);
    00095
    00096         // not implemented
    00097         gslice_array();
    00098         gslice_array& operator= (const gslice_array&);
    00099     };
    00100
    00101     template<typename _Tp>
    00102     inline
    00103     gslice_array<_Tp>::gslice_array (_Array<_Tp> __a,
    00104                                      const valarray<size_t>& __i)
    00105             : _M_array (__a), _M_index (__i) {}
    00106
    00107
    00108     template<typename _Tp>
    00109     inline
    00110     gslice_array<_Tp>::gslice_array (const gslice_array<_Tp>& __a)
    00111             : _M_array (__a._M_array), _M_index (__a._M_index) {}
    00112
    00113
    00114     template<typename _Tp>
    00115     inline void
    00116     gslice_array<_Tp>::operator= (const _Tp& __t)
    00117     {
    00118         __valarray_fill (_M_array, _Array<size_t>(_M_index),
    00119                          _M_index.size(), __t);
    00120     }
    00121
    00122     template<typename _Tp>
    00123     inline void
    00124     gslice_array<_Tp>::operator= (const valarray<_Tp>& __v) const
    00125     {
    00126         __valarray_copy (_Array<_Tp> (__v), __v.size (),
    00127                          _M_array, _Array<size_t>(_M_index));
    00128     }
    00129
    00130     template<typename _Tp>
    00131     template<class E>
    00132     inline void
    00133     gslice_array<_Tp>::operator= (const _Expr<E, _Tp>& __e) const
    00134     {
    00135         __valarray_copy (__e, _M_index.size(), _M_array,
    00136                          _Array<size_t>(_M_index));
    00137     }
    00138
    00139 #undef _DEFINE_VALARRAY_OPERATOR
    00140 #define _DEFINE_VALARRAY_OPERATOR(op, name)             \
    00141 template<typename _Tp>                          \
    00142 inline void                             \
    00143 gslice_array<_Tp>::operator op##= (const valarray<_Tp>& __v) const  \
    00144 {                                   \
    00145     _Array_augmented_##name (_M_array, _Array<size_t>(_M_index),    \
    00146                               _Array<_Tp> (__v), __v.size ());      \
    00147 }                                   \
    00148                                     \
    00149 template<typename _Tp> template<class E>                    \
    00150 inline void                                 \
    00151 gslice_array<_Tp>::operator op##= (const _Expr<E, _Tp>& __e) const  \
    00152 {                                   \
    00153     _Array_augmented_##name (_M_array, _Array<size_t>(_M_index), __e,   \
    00154                               _M_index.size());             \
    00155 }
    00156
    00157 _DEFINE_VALARRAY_OPERATOR(*, multiplies)
    00158 _DEFINE_VALARRAY_OPERATOR(/, divides)
    00159 _DEFINE_VALARRAY_OPERATOR(%, modulus)
    00160 _DEFINE_VALARRAY_OPERATOR(+, plus)
    00161 _DEFINE_VALARRAY_OPERATOR(-, minus)
    00162 _DEFINE_VALARRAY_OPERATOR(^, xor)
    00163 _DEFINE_VALARRAY_OPERATOR(&, and)
    00164 _DEFINE_VALARRAY_OPERATOR(|, or)
    00165 _DEFINE_VALARRAY_OPERATOR(<<, shift_left)
    00166 _DEFINE_VALARRAY_OPERATOR(>>, shift_right)
    00167
    00168 #undef _DEFINE_VALARRAY_OPERATOR
    00169
    00170 } // std::
    00171
    00172 #endif /* _CPP_BITS_GSLICE_ARRAY */
    00173
    00174 // Local Variables:
    00175 // mode:c++
    00176 // End: