1 // The template and inlines for the -*- C++ -*- gslice_array class. 2 3 // Copyright (C) 1997-1999 Cygnus Solutions 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 2, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // You should have received a copy of the GNU General Public License along 17 // with this library; see the file COPYING. If not, write to the Free 18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 19 // USA. 20 21 // As a special exception, you may use this file as part of a free software 22 // library without restriction. Specifically, if other files instantiate 23 // templates or use macros or inline functions from this file, or you compile 24 // this file and link it with other files to produce an executable, this 25 // file does not by itself cause the resulting executable to be covered by 26 // the GNU General Public License. This exception does not however 27 // invalidate any other reasons why the executable file might be covered by 28 // the GNU General Public License. 29 30 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> 31 32 #ifndef __GSLICE_ARRAY__ 33 #define __GSLICE_ARRAY__ 34 35 extern "C++" { 36 37 template<typename _Tp> class gslice_array 38 { 39 public: 40 typedef _Tp value_type; 41 42 void operator= (const valarray<_Tp>&) const; 43 void operator*= (const valarray<_Tp>&) const; 44 void operator/= (const valarray<_Tp>&) const; 45 void operator%= (const valarray<_Tp>&) const; 46 void operator+= (const valarray<_Tp>&) const; 47 void operator-= (const valarray<_Tp>&) const; 48 void operator^= (const valarray<_Tp>&) const; 49 void operator&= (const valarray<_Tp>&) const; 50 void operator|= (const valarray<_Tp>&) const; 51 void operator<<=(const valarray<_Tp>&) const; 52 void operator>>=(const valarray<_Tp>&) const; 53 void operator=(const _Tp&); 54 55 template<class _Dom> 56 void operator= (const _Expr<_Dom,_Tp>&) const; 57 template<class _Dom> 58 void operator*= (const _Expr<_Dom,_Tp>&) const; 59 template<class _Dom> 60 void operator/= (const _Expr<_Dom,_Tp>&) const; 61 template<class _Dom> 62 void operator%= (const _Expr<_Dom,_Tp>&) const; 63 template<class _Dom> 64 void operator+= (const _Expr<_Dom,_Tp>&) const; 65 template<class _Dom> 66 void operator-= (const _Expr<_Dom,_Tp>&) const; 67 template<class _Dom> 68 void operator^= (const _Expr<_Dom,_Tp>&) const; 69 template<class _Dom> 70 void operator&= (const _Expr<_Dom,_Tp>&) const; 71 template<class _Dom> 72 void operator|= (const _Expr<_Dom,_Tp>&) const; 73 template<class _Dom> 74 void operator<<= (const _Expr<_Dom,_Tp>&) const; 75 template<class _Dom> 76 void operator>>= (const _Expr<_Dom,_Tp>&) const; 77 78 private: 79 _Array<_Tp> _M_array; 80 const valarray<size_t>& _M_index; 81 82 friend class valarray<_Tp>; 83 84 gslice_array (_Array<_Tp>, const valarray<size_t>&); 85 86 // this constructor needs to be implemented. 87 gslice_array (const gslice_array&); 88 89 // not implemented 90 gslice_array(); 91 gslice_array& operator= (const gslice_array&); 92 }; 93 94 template<typename _Tp> 95 inline 96 gslice_array<_Tp>::gslice_array (_Array<_Tp> __a, 97 const valarray<size_t>& __i) 98 : _M_array (__a), _M_index (__i) {} 99 100 101 template<typename _Tp> 102 inline 103 gslice_array<_Tp>::gslice_array (const gslice_array<_Tp>& __a) 104 : _M_array (__a._M_array), _M_index (__a._M_index) {} 105 106 107 template<typename _Tp> 108 inline void 109 gslice_array<_Tp>::operator= (const _Tp& __t) 110 { 111 __valarray_fill (_M_array, _Array<size_t>(_M_index), 112 _M_index.size(), __t); 113 } 114 115 template<typename _Tp> 116 inline void 117 gslice_array<_Tp>::operator= (const valarray<_Tp>& __v) const 118 { 119 __valarray_copy (_Array<_Tp> (__v), __v.size (), 120 _M_array, _Array<size_t>(_M_index)); 121 } 122 123 template<typename _Tp> 124 template<class E> 125 inline void 126 gslice_array<_Tp>::operator= (const _Expr<E, _Tp>& __e) const 127 { 128 __valarray_copy (__e, _M_index.size(), _M_array, 129 _Array<size_t>(_M_index)); 130 } 131 132 #undef _DEFINE_VALARRAY_OPERATOR 133 #define _DEFINE_VALARRAY_OPERATOR(op, name) \ 134 template<typename _Tp> \ 135 inline void \ 136 gslice_array<_Tp>::operator##op##= (const valarray<_Tp>& __v) const \ 137 { \ 138 _Array_augmented_##name (_M_array, _Array<size_t>(_M_index), \ 139 _Array<_Tp> (__v), __v.size ()); \ 140 } \ 141 \ 142 template<typename _Tp> template<class E> \ 143 inline void \ 144 gslice_array<_Tp>::operator##op##= (const _Expr<E, _Tp>& __e) const \ 145 { \ 146 _Array_augmented_##name (_M_array, _Array<size_t>(_M_index), __e, \ 147 _M_index.size()); \ 148 } 149 150 _DEFINE_VALARRAY_OPERATOR(*, multiplies) 151 _DEFINE_VALARRAY_OPERATOR(/, divides) 152 _DEFINE_VALARRAY_OPERATOR(%, modulus) 153 _DEFINE_VALARRAY_OPERATOR(+, plus) 154 _DEFINE_VALARRAY_OPERATOR(-, minus) 155 _DEFINE_VALARRAY_OPERATOR(^, xor) 156 _DEFINE_VALARRAY_OPERATOR(&, and) 157 _DEFINE_VALARRAY_OPERATOR(|, or) 158 _DEFINE_VALARRAY_OPERATOR(<<, shift_left) 159 _DEFINE_VALARRAY_OPERATOR(>>, shift_right) 160 161 #undef _DEFINE_VALARRAY_OPERATOR 162 163 } // extern "C++" 164 165 166 #endif // __GSLICE_ARRAY__ 167 168 // Local Variables: 169 // mode:c++ 170 // End: 171