1// The template and inlines for the -*- C++ -*- slice_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 __SLICE_ARRAY__ 33#define __SLICE_ARRAY__ 34 35extern "C++" { 36 37template<typename _T> 38class slice_array 39{ 40public: 41 typedef _T value_type; 42 43 void operator= (const valarray<_T>&) const; 44 void operator*= (const valarray<_T>&) const; 45 void operator/= (const valarray<_T>&) const; 46 void operator%= (const valarray<_T>&) const; 47 void operator+= (const valarray<_T>&) const; 48 void operator-= (const valarray<_T>&) const; 49 void operator^= (const valarray<_T>&) const; 50 void operator&= (const valarray<_T>&) const; 51 void operator|= (const valarray<_T>&) const; 52 void operator<<= (const valarray<_T>&) const; 53 void operator>>= (const valarray<_T>&) const; 54 void operator= (const _T &); 55 56 template<class _Dom> 57 void operator= (const _Expr<_Dom,_T>&) const; 58 template<class _Dom> 59 void operator*= (const _Expr<_Dom,_T>&) const; 60 template<class _Dom> 61 void operator/= (const _Expr<_Dom,_T>&) const; 62 template<class _Dom> 63 void operator%= (const _Expr<_Dom,_T>&) const; 64 template<class _Dom> 65 void operator+= (const _Expr<_Dom,_T>&) const; 66 template<class _Dom> 67 void operator-= (const _Expr<_Dom,_T>&) const; 68 template<class _Dom> 69 void operator^= (const _Expr<_Dom,_T>&) const; 70 template<class _Dom> 71 void operator&= (const _Expr<_Dom,_T>&) const; 72 template<class _Dom> 73 void operator|= (const _Expr<_Dom,_T>&) const; 74 template<class _Dom> 75 void operator<<= (const _Expr<_Dom,_T>&) const; 76 template<class _Dom> 77 void operator>>= (const _Expr<_Dom,_T>&) const; 78 79private: 80 friend class valarray<_T>; 81 slice_array(_Array<_T>, const slice&); 82 83 const size_t _M_sz; 84 const size_t _M_stride; 85 const _Array<_T> _M_array; 86 87 // this constructor is implemented since we need to return a value. 88 slice_array (const slice_array&); 89 90 // not implemented 91 slice_array (); 92 slice_array& operator= (const slice_array&); 93}; 94 95template<typename _T> 96inline slice_array<_T>::slice_array (_Array<_T> __a, const slice& __s) 97 : _M_sz (__s.size ()), _M_stride (__s.stride ()), 98 _M_array (__a.begin () + __s.start ()) {} 99 100template<typename _Tp> 101inline slice_array<_Tp>::slice_array(const slice_array<_Tp>& a) 102 : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {} 103 104template<typename _T> 105inline void 106slice_array<_T>::operator= (const _T& __t) 107{ __valarray_fill (_M_array, _M_sz, _M_stride, __t); } 108 109template<typename _T> 110inline void 111slice_array<_T>::operator= (const valarray<_T>& __v) const 112{ __valarray_copy (_Array<_T> (__v), _M_array, _M_sz, _M_stride); } 113 114template<typename _T> 115template<class _Dom> 116inline void 117slice_array<_T>::operator= (const _Expr<_Dom,_T>& __e) const 118{ __valarray_copy (__e, _M_sz, _M_array, _M_stride); } 119 120#undef _DEFINE_VALARRAY_OPERATOR 121#define _DEFINE_VALARRAY_OPERATOR(op, name) \ 122template<typename _T> \ 123inline void \ 124slice_array<_T>::operator##op##= (const valarray<_T>& __v) const \ 125{ \ 126 _Array_augmented_##name (_M_array, _M_sz, _M_stride, _Array<_T> (__v));\ 127} \ 128 \ 129template<typename _T> template<class _Dom> \ 130inline void \ 131slice_array<_T>::operator##op##= (const _Expr<_Dom,_T>& __e) const \ 132{ \ 133 _Array_augmented_##name (_M_array, _M_stride, __e, _M_sz); \ 134} 135 136 137_DEFINE_VALARRAY_OPERATOR(*, multiplies) 138_DEFINE_VALARRAY_OPERATOR(/, divides) 139_DEFINE_VALARRAY_OPERATOR(%, modulus) 140_DEFINE_VALARRAY_OPERATOR(+, plus) 141_DEFINE_VALARRAY_OPERATOR(-, minus) 142_DEFINE_VALARRAY_OPERATOR(^, xor) 143_DEFINE_VALARRAY_OPERATOR(&, and) 144_DEFINE_VALARRAY_OPERATOR(|, or) 145_DEFINE_VALARRAY_OPERATOR(<<, shift_left) 146_DEFINE_VALARRAY_OPERATOR(>>, shift_right) 147 148#undef _DEFINE_VALARRAY_OPERATOR 149 150} // extern "C++" 151 152#endif // __SLICE_ARRAY__ 153 154// Local Variables: 155// mode:c++ 156// End: 157