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

Generated on Tue Jan 30 17:31:49 2007 for GNU C++ STL by doxygen 1.3.6