1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_valarray.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,196 @@
1.4 +/*
1.5 + *
1.6 + *
1.7 + * Copyright (c) 1994
1.8 + * Hewlett-Packard Company
1.9 + *
1.10 + * Copyright (c) 1996,1997
1.11 + * Silicon Graphics Computer Systems, Inc.
1.12 + *
1.13 + * Copyright (c) 1997
1.14 + * Moscow Center for SPARC Technology
1.15 + *
1.16 + * Copyright (c) 1999
1.17 + * Boris Fomitchev
1.18 + *
1.19 + * This material is provided "as is", with absolutely no warranty expressed
1.20 + * or implied. Any use is at your own risk.
1.21 + *
1.22 + * Permission to use or copy this software for any purpose is hereby granted
1.23 + * without fee, provided the above notices are retained on all copies.
1.24 + * Permission to modify the code and to distribute modified code is granted,
1.25 + * provided the above notices are retained, and a notice that the code was
1.26 + * modified is included with the above copyright notice.
1.27 + *
1.28 + */
1.29 +#ifndef _STLP_VALARRAY_C
1.30 +#define _STLP_VALARRAY_C
1.31 +
1.32 +#ifndef _STLP_VALARRAY_H
1.33 +# include <stl/_valarray.h>
1.34 +#endif
1.35 +
1.36 +_STLP_BEGIN_NAMESPACE
1.37 +
1.38 +template <class _Tp>
1.39 +_Valarray_bool valarray<_Tp>:: operator!() const {
1.40 + _Valarray_bool __tmp(this->size(), _Valarray_bool::_NoInit());
1.41 + for (size_t __i = 0; __i < this->size(); ++__i)
1.42 + __tmp[__i] = !(*this)[__i];
1.43 + return __tmp;
1.44 +}
1.45 +
1.46 +// Behavior is undefined if __x and *this have different sizes
1.47 +template <class _Tp>
1.48 +valarray<_Tp>& valarray<_Tp>::operator=(const slice_array<_Tp>& __x)
1.49 +{
1.50 + size_t __index = __x._M_slice.start();
1.51 + for (size_t __i = 0;
1.52 + __i < __x._M_slice.size();
1.53 + ++__i, __index += __x._M_slice.stride())
1.54 + (*this)[__i] = __x._M_array[__index];
1.55 + return *this;
1.56 +}
1.57 +
1.58 +template <class _Tp>
1.59 +valarray<_Tp> valarray<_Tp>::operator[](slice __slice) const {
1.60 + valarray<_Tp> __tmp(__slice.size(), _NoInit());
1.61 + size_t __index = __slice.start();
1.62 + for (size_t __i = 0;
1.63 + __i < __slice.size();
1.64 + ++__i, __index += __slice.stride())
1.65 + __tmp[__i] = (*this)[__index];
1.66 + return __tmp;
1.67 +}
1.68 +
1.69 +template <class _Size>
1.70 +bool _Gslice_Iter_tmpl<_Size>::_M_incr() {
1.71 + size_t __dim = _M_indices.size() - 1;
1.72 + ++_M_step;
1.73 + for (;;) {
1.74 + _M_1d_idx += _M_gslice._M_strides[__dim];
1.75 + if (++_M_indices[__dim] != _M_gslice._M_lengths[__dim])
1.76 + return true;
1.77 + else if (__dim != 0) {
1.78 + _M_1d_idx -= _M_gslice._M_strides[__dim] * _M_gslice._M_lengths[__dim];
1.79 + _M_indices[__dim] = 0;
1.80 + --__dim;
1.81 + }
1.82 + else
1.83 + return false;
1.84 + }
1.85 +}
1.86 +
1.87 +// Behavior is undefined if __x and *this have different sizes, or if
1.88 +// __x was constructed from a degenerate gslice.
1.89 +template <class _Tp>
1.90 +valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array<_Tp>& __x)
1.91 +{
1.92 + if (this->size() != 0) {
1.93 + _Gslice_Iter __i(__x._M_gslice);
1.94 + do
1.95 + (*this)[__i._M_step] = __x._M_array[__i._M_1d_idx];
1.96 + while(__i._M_incr());
1.97 + }
1.98 + return *this;
1.99 +}
1.100 +
1.101 +template <class _Tp>
1.102 +valarray<_Tp> valarray<_Tp>::operator[](const gslice& __slice) const
1.103 +{
1.104 + valarray<_Tp> __tmp(__slice._M_size(), _NoInit());
1.105 + if (__tmp.size() != 0) {
1.106 + _Gslice_Iter __i(__slice);
1.107 + do __tmp[__i._M_step] = (*this)[__i._M_1d_idx]; while(__i._M_incr());
1.108 + }
1.109 + return __tmp;
1.110 +}
1.111 +
1.112 +template <class _Tp>
1.113 +valarray<_Tp> valarray<_Tp>::operator[](const _Valarray_bool& __mask) const
1.114 +{
1.115 + size_t _p_size = 0;
1.116 + {
1.117 + for (size_t __i = 0; __i < __mask.size(); ++__i)
1.118 + if (__mask[__i]) ++_p_size;
1.119 + }
1.120 +
1.121 + valarray<_Tp> __tmp(_p_size, _NoInit());
1.122 + size_t __idx = 0;
1.123 + {
1.124 + for (size_t __i = 0; __i < __mask.size(); ++__i)
1.125 + if (__mask[__i]) __tmp[__idx++] = (*this)[__i];
1.126 + }
1.127 +
1.128 + return __tmp;
1.129 +}
1.130 +
1.131 +template <class _Tp>
1.132 +valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<_Tp>& __x) {
1.133 + for (size_t __i = 0; __i < __x._M_addr.size(); ++__i)
1.134 + (*this)[__i] = __x._M_array[__x._M_addr[__i]];
1.135 + return *this;
1.136 +}
1.137 +
1.138 +template <class _Tp>
1.139 +valarray<_Tp>
1.140 +valarray<_Tp>::operator[](const _Valarray_size_t& __addr) const
1.141 +{
1.142 + valarray<_Tp> __tmp(__addr.size(), _NoInit());
1.143 + for (size_t __i = 0; __i < __addr.size(); ++__i)
1.144 + __tmp[__i] = (*this)[__addr[__i]];
1.145 + return __tmp;
1.146 +}
1.147 +
1.148 +//----------------------------------------------------------------------
1.149 +// Other valarray noninline member functions
1.150 +
1.151 +// Shift and cshift
1.152 +
1.153 +template <class _Tp>
1.154 +valarray<_Tp> valarray<_Tp>::shift(int __n) const
1.155 +{
1.156 + valarray<_Tp> __tmp(this->size());
1.157 +
1.158 + if (__n >= 0) {
1.159 + if (__n < this->size())
1.160 + copy(this->_M_first + __n, this->_M_first + this->size(),
1.161 + __tmp._M_first);
1.162 + }
1.163 + else {
1.164 + if (-__n < this->size())
1.165 + copy(this->_M_first, this->_M_first + this->size() + __n,
1.166 + __tmp._M_first - __n);
1.167 + }
1.168 + return __tmp;
1.169 +}
1.170 +
1.171 +template <class _Tp>
1.172 +valarray<_Tp> valarray<_Tp>::cshift(int __m) const
1.173 +{
1.174 + valarray<_Tp> __tmp(this->size());
1.175 +
1.176 + // Reduce __m to an equivalent number in the range [0, size()). We
1.177 + // have to be careful with negative numbers, since the sign of a % b
1.178 + // is unspecified when a < 0.
1.179 + long __n = __m;
1.180 + if (this->size() < (numeric_limits<long>::max)())
1.181 + __n %= long(this->size());
1.182 + if (__n < 0)
1.183 + __n += this->size();
1.184 +
1.185 + copy(this->_M_first, this->_M_first + __n,
1.186 + __tmp._M_first + (this->size() - __n));
1.187 + copy(this->_M_first + __n, this->_M_first + this->size(),
1.188 + __tmp._M_first);
1.189 +
1.190 + return __tmp;
1.191 +}
1.192 +
1.193 +_STLP_END_NAMESPACE
1.194 +
1.195 +#endif /* _STLP_VALARRAY_C */
1.196 +
1.197 +// Local Variables:
1.198 +// mode:C++
1.199 +// End: