indirect_array.h

Go to the documentation of this file.
00001 // The template and inlines for the -*- C++ -*- indirect_array class.
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 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 _INDIRECT_ARRAY_H
00039 #define _INDIRECT_ARRAY_H 1
00040 
00041 #pragma GCC system_header
00042 
00043 namespace std
00044 {
00060   template <class _Tp>
00061     class indirect_array
00062     {
00063     public:
00064       typedef _Tp value_type;
00065 
00066       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00067       // 253. valarray helper functions are almost entirely useless
00068 
00070       indirect_array(const indirect_array&);
00071 
00074       indirect_array& operator=(const indirect_array&);
00075 
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 valarray<_Tp>&) const;
00099       void operator= (const _Tp&) const;
00100       //    ~indirect_array();
00101 
00102       template<class _Dom>
00103       void operator=(const _Expr<_Dom, _Tp>&) const;
00104       template<class _Dom>
00105       void operator*=(const _Expr<_Dom, _Tp>&) const;
00106       template<class _Dom>
00107       void operator/=(const _Expr<_Dom, _Tp>&) const;
00108       template<class _Dom>
00109       void operator%=(const _Expr<_Dom, _Tp>&) const;
00110       template<class _Dom>
00111       void operator+=(const _Expr<_Dom, _Tp>&) const;
00112       template<class _Dom>
00113       void operator-=(const _Expr<_Dom, _Tp>&) const;
00114       template<class _Dom>
00115       void operator^=(const _Expr<_Dom, _Tp>&) const;
00116       template<class _Dom>
00117       void operator&=(const _Expr<_Dom, _Tp>&) const;
00118       template<class _Dom>
00119       void operator|=(const _Expr<_Dom, _Tp>&) const;
00120       template<class _Dom>
00121       void operator<<=(const _Expr<_Dom, _Tp>&) const;
00122       template<class _Dom>
00123       void operator>>=(const _Expr<_Dom, _Tp>&) const;
00124 
00125     private:
00127       indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
00128 
00129       friend class valarray<_Tp>;
00130       friend class gslice_array<_Tp>;
00131 
00132       const size_t   _M_sz;
00133       const _Array<size_t> _M_index;
00134       const _Array<_Tp>  _M_array;
00135 
00136       // not implemented
00137       indirect_array();
00138     };
00139 
00140   template<typename _Tp>
00141     inline
00142     indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
00143     : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {}
00144 
00145   template<typename _Tp>
00146      inline
00147      indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s,
00148                      _Array<size_t> __i)
00149      : _M_sz(__s), _M_index(__i), _M_array(__a) {}
00150 
00151   template<typename _Tp>
00152      inline indirect_array<_Tp>&
00153      indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a)
00154      {
00155        std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array, _M_index);
00156        return *this;
00157      }
00158 
00159 
00160   template<typename _Tp>
00161      inline void
00162      indirect_array<_Tp>::operator=(const _Tp& __t) const
00163      { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); }
00164 
00165   template<typename _Tp>
00166      inline void
00167      indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00168      { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); }
00169 
00170   template<typename _Tp>
00171      template<class _Dom>
00172        inline void
00173        indirect_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
00174        { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); }
00175 
00176 #undef _DEFINE_VALARRAY_OPERATOR
00177 #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name)               \
00178   template<typename _Tp>                        \
00179     inline void                             \
00180     indirect_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const\
00181     {                                   \
00182       _Array_augmented_##_Name(_M_array, _M_index, _Array<_Tp>(__v), _M_sz); \
00183     }                                   \
00184                                     \
00185   template<typename _Tp>                                                \
00186     template<class _Dom>                                \
00187       inline void                           \
00188       indirect_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
00189       {                                 \
00190     _Array_augmented_##_Name(_M_array, _M_index, __e, _M_sz);   \
00191       }
00192 
00193 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00194 _DEFINE_VALARRAY_OPERATOR(/, __divides)
00195 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00196 _DEFINE_VALARRAY_OPERATOR(+, __plus)
00197 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00198 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00199 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00200 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00201 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00202 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00203 
00204 #undef _DEFINE_VALARRAY_OPERATOR
00205 
00206 } // std::
00207 
00208 #endif /* _INDIRECT_ARRAY_H */
00209 
00210 // Local Variables:
00211 // mode:c++
00212 // End:

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