/home/ntakagi/work/STLport-5.1.5/stlport/stl/_valarray.cGo to the documentation of this file.00001 /* 00002 * 00003 * 00004 * Copyright (c) 1994 00005 * Hewlett-Packard Company 00006 * 00007 * Copyright (c) 1996,1997 00008 * Silicon Graphics Computer Systems, Inc. 00009 * 00010 * Copyright (c) 1997 00011 * Moscow Center for SPARC Technology 00012 * 00013 * Copyright (c) 1999 00014 * Boris Fomitchev 00015 * 00016 * This material is provided "as is", with absolutely no warranty expressed 00017 * or implied. Any use is at your own risk. 00018 * 00019 * Permission to use or copy this software for any purpose is hereby granted 00020 * without fee, provided the above notices are retained on all copies. 00021 * Permission to modify the code and to distribute modified code is granted, 00022 * provided the above notices are retained, and a notice that the code was 00023 * modified is included with the above copyright notice. 00024 * 00025 */ 00026 #ifndef _STLP_VALARRAY_C 00027 #define _STLP_VALARRAY_C 00028 00029 #ifndef _STLP_VALARRAY_H 00030 # include <stl/_valarray.h> 00031 #endif 00032 00033 _STLP_BEGIN_NAMESPACE 00034 00035 template <class _Tp> 00036 _Valarray_bool valarray<_Tp>:: operator!() const { 00037 _Valarray_bool __tmp(this->size(), _Valarray_bool::_NoInit()); 00038 for (size_t __i = 0; __i < this->size(); ++__i) 00039 __tmp[__i] = !(*this)[__i]; 00040 return __tmp; 00041 } 00042 00043 // Behavior is undefined if __x and *this have different sizes 00044 template <class _Tp> 00045 valarray<_Tp>& valarray<_Tp>::operator=(const slice_array<_Tp>& __x) 00046 { 00047 size_t __index = __x._M_slice.start(); 00048 for (size_t __i = 0; 00049 __i < __x._M_slice.size(); 00050 ++__i, __index += __x._M_slice.stride()) 00051 (*this)[__i] = __x._M_array[__index]; 00052 return *this; 00053 } 00054 00055 template <class _Tp> 00056 valarray<_Tp> valarray<_Tp>::operator[](slice __slice) const { 00057 valarray<_Tp> __tmp(__slice.size(), _NoInit()); 00058 size_t __index = __slice.start(); 00059 for (size_t __i = 0; 00060 __i < __slice.size(); 00061 ++__i, __index += __slice.stride()) 00062 __tmp[__i] = (*this)[__index]; 00063 return __tmp; 00064 } 00065 00066 template <class _Size> 00067 bool _Gslice_Iter_tmpl<_Size>::_M_incr() { 00068 size_t __dim = _M_indices.size() - 1; 00069 ++_M_step; 00070 for (;;) { 00071 _M_1d_idx += _M_gslice._M_strides[__dim]; 00072 if (++_M_indices[__dim] != _M_gslice._M_lengths[__dim]) 00073 return true; 00074 else if (__dim != 0) { 00075 _M_1d_idx -= _M_gslice._M_strides[__dim] * _M_gslice._M_lengths[__dim]; 00076 _M_indices[__dim] = 0; 00077 --__dim; 00078 } 00079 else 00080 return false; 00081 } 00082 } 00083 00084 // Behavior is undefined if __x and *this have different sizes, or if 00085 // __x was constructed from a degenerate gslice. 00086 template <class _Tp> 00087 valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array<_Tp>& __x) 00088 { 00089 if (this->size() != 0) { 00090 _Gslice_Iter __i(__x._M_gslice); 00091 do 00092 (*this)[__i._M_step] = __x._M_array[__i._M_1d_idx]; 00093 while(__i._M_incr()); 00094 } 00095 return *this; 00096 } 00097 00098 template <class _Tp> 00099 valarray<_Tp> valarray<_Tp>::operator[](const gslice& __slice) const 00100 { 00101 valarray<_Tp> __tmp(__slice._M_size(), _NoInit()); 00102 if (__tmp.size() != 0) { 00103 _Gslice_Iter __i(__slice); 00104 do __tmp[__i._M_step] = (*this)[__i._M_1d_idx]; while(__i._M_incr()); 00105 } 00106 return __tmp; 00107 } 00108 00109 template <class _Tp> 00110 valarray<_Tp> valarray<_Tp>::operator[](const _Valarray_bool& __mask) const 00111 { 00112 size_t _p_size = 0; 00113 { 00114 for (size_t __i = 0; __i < __mask.size(); ++__i) 00115 if (__mask[__i]) ++_p_size; 00116 } 00117 00118 valarray<_Tp> __tmp(_p_size, _NoInit()); 00119 size_t __idx = 0; 00120 { 00121 for (size_t __i = 0; __i < __mask.size(); ++__i) 00122 if (__mask[__i]) __tmp[__idx++] = (*this)[__i]; 00123 } 00124 00125 return __tmp; 00126 } 00127 00128 template <class _Tp> 00129 valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<_Tp>& __x) { 00130 for (size_t __i = 0; __i < __x._M_addr.size(); ++__i) 00131 (*this)[__i] = __x._M_array[__x._M_addr[__i]]; 00132 return *this; 00133 } 00134 00135 template <class _Tp> 00136 valarray<_Tp> 00137 valarray<_Tp>::operator[](const _Valarray_size_t& __addr) const 00138 { 00139 valarray<_Tp> __tmp(__addr.size(), _NoInit()); 00140 for (size_t __i = 0; __i < __addr.size(); ++__i) 00141 __tmp[__i] = (*this)[__addr[__i]]; 00142 return __tmp; 00143 } 00144 00145 //---------------------------------------------------------------------- 00146 // Other valarray noninline member functions 00147 00148 // Shift and cshift 00149 00150 template <class _Tp> 00151 valarray<_Tp> valarray<_Tp>::shift(int __n) const 00152 { 00153 valarray<_Tp> __tmp(this->size()); 00154 00155 if (__n >= 0) { 00156 if (__n < this->size()) 00157 copy(this->_M_first + __n, this->_M_first + this->size(), 00158 __tmp._M_first); 00159 } 00160 else { 00161 if (-__n < this->size()) 00162 copy(this->_M_first, this->_M_first + this->size() + __n, 00163 __tmp._M_first - __n); 00164 } 00165 return __tmp; 00166 } 00167 00168 template <class _Tp> 00169 valarray<_Tp> valarray<_Tp>::cshift(int __m) const 00170 { 00171 valarray<_Tp> __tmp(this->size()); 00172 00173 // Reduce __m to an equivalent number in the range [0, size()). We 00174 // have to be careful with negative numbers, since the sign of a % b 00175 // is unspecified when a < 0. 00176 long __n = __m; 00177 if (this->size() < (numeric_limits<long>::max)()) 00178 __n %= long(this->size()); 00179 if (__n < 0) 00180 __n += this->size(); 00181 00182 copy(this->_M_first, this->_M_first + __n, 00183 __tmp._M_first + (this->size() - __n)); 00184 copy(this->_M_first + __n, this->_M_first + this->size(), 00185 __tmp._M_first); 00186 00187 return __tmp; 00188 } 00189 00190 _STLP_END_NAMESPACE 00191 00192 #endif /* _STLP_VALARRAY_C */ 00193 00194 // Local Variables: 00195 // mode:C++ 00196 // End:
Generated on Mon Mar 10 15:32:44 2008 by ![]() |