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 
00033 /** @file gslice_array.h
00034  *  This is an internal header file, included by other library headers.
00035  *  You should not attempt to use it directly.
00036  */
00037 
00038 #ifndef _CPP_BITS_GSLICE_ARRAY
00039 #define _CPP_BITS_GSLICE_ARRAY 1
00040 
00041 #pragma GCC system_header
00042 
00043 namespace std {
00044 
00045   template<typename _Tp>
00046     class gslice_array
00047     {
00048     public:
00049       typedef _Tp value_type;
00050 
00051       gslice_array(const gslice_array&);
00052       gslice_array& operator=(const gslice_array&);
00053       
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 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 _Tp&) const;
00066 
00067       template<class _Dom>
00068         void operator=(const _Expr<_Dom,_Tp>&) const;
00069       template<class _Dom>
00070         void operator*=(const _Expr<_Dom,_Tp>&) const;
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         
00090     private:
00091       _Array<_Tp>    _M_array;
00092       const valarray<size_t>& _M_index;
00093         
00094       friend class valarray<_Tp>;
00095       
00096       gslice_array(_Array<_Tp>, const valarray<size_t>&);
00097 
00098       // not implemented
00099       gslice_array();
00100     };
00101 
00102   template<typename _Tp>
00103     inline
00104     gslice_array<_Tp>::gslice_array(_Array<_Tp> __a,
00105                     const valarray<size_t>& __i)
00106       : _M_array(__a), _M_index(__i) {}
00107 
00108 
00109   template<typename _Tp>
00110     inline
00111     gslice_array<_Tp>::gslice_array(const gslice_array<_Tp>& __a)
00112       : _M_array(__a._M_array), _M_index(__a._M_index) {}
00113 
00114   template<typename _Tp>
00115     inline gslice_array<_Tp>&
00116     gslice_array<_Tp>::operator=(const gslice_array<_Tp>& __a)
00117     {
00118       __valarray_copy(_Array<_Tp>(__a._M_array),
00119               _Array<size_t>(__a._M_index), _M_index.size(),
00120               _M_array, _Array<size_t>(_M_index));
00121       return *this;
00122     }
00123 
00124   template<typename _Tp>
00125     inline void
00126     gslice_array<_Tp>::operator=(const _Tp& __t) const
00127     { 
00128       __valarray_fill(_M_array, _Array<size_t>(_M_index),
00129               _M_index.size(), __t); 
00130     }
00131 
00132   template<typename _Tp>
00133     inline void
00134     gslice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00135     {
00136       __valarray_copy(_Array<_Tp>(__v), __v.size(),
00137               _M_array, _Array<size_t>(_M_index));
00138     }
00139 
00140   template<typename _Tp>
00141     template<class _Dom>
00142       inline void
00143       gslice_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const
00144       {
00145     __valarray_copy (__e, _M_index.size(), _M_array,
00146              _Array<size_t>(_M_index));
00147       }
00148 
00149 #undef _DEFINE_VALARRAY_OPERATOR
00150 #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name)               \
00151   template<typename _Tp>                        \
00152     inline void                             \
00153     gslice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const  \
00154     {                                   \
00155       _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index),  \
00156                   _Array<_Tp>(__v), __v.size());        \
00157     }                                   \
00158                                     \
00159   template<typename _Tp>                                                \
00160     template<class _Dom>                                    \
00161       inline void                           \
00162       gslice_array<_Tp>::operator _Op##= (const _Expr<_Dom, _Tp>& __e) const\
00163       {                                 \
00164     _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), __e,\
00165                  _M_index.size());          \
00166       }
00167 
00168 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00169 _DEFINE_VALARRAY_OPERATOR(/, __divides)    
00170 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00171 _DEFINE_VALARRAY_OPERATOR(+, __plus)    
00172 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00173 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00174 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00175 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00176 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00177 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00178 
00179 #undef _DEFINE_VALARRAY_OPERATOR
00180 
00181 } // std::
00182 
00183 #endif /* _CPP_BITS_GSLICE_ARRAY */
00184 
00185 // Local Variables:
00186 // mode:c++
00187 // End:

Generated on Sat Mar 19 18:32:15 2005 for libstdc++-v3 Source by  doxygen 1.4.1