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