epoc32/include/stdapis/stlportv5/stl/_valarray.c
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_valarray.c@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /*
     2  *
     3  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     4  *
     5  * Copyright (c) 1994
     6  * Hewlett-Packard Company
     7  *
     8  * Copyright (c) 1996,1997
     9  * Silicon Graphics Computer Systems, Inc.
    10  *
    11  * Copyright (c) 1997
    12  * Moscow Center for SPARC Technology
    13  *
    14  * Copyright (c) 1999 
    15  * Boris Fomitchev
    16  *
    17  * This material is provided "as is", with absolutely no warranty expressed
    18  * or implied. Any use is at your own risk.
    19  *
    20  * Permission to use or copy this software for any purpose is hereby granted 
    21  * without fee, provided the above notices are retained on all copies.
    22  * Permission to modify the code and to distribute modified code is granted,
    23  * provided the above notices are retained, and a notice that the code was
    24  * modified is included with the above copyright notice.
    25  *
    26  */
    27 #ifndef _STLP_VALARRAY_C
    28 #define _STLP_VALARRAY_C
    29 
    30 #ifndef _STLP_VALARRAY_H
    31 # include <stl/_valarray.h>
    32 #endif
    33 
    34 _STLP_BEGIN_NAMESPACE
    35 
    36 template <class _Tp>
    37 _Valarray_bool valarray<_Tp>:: operator!() const {
    38   _Valarray_bool __tmp(this->size(), _Valarray_bool::_NoInit());
    39   for (size_t __i = 0; __i < this->size(); ++__i)
    40     __tmp[__i] = !(*this)[__i];
    41   return __tmp;
    42 }
    43 
    44 // Behavior is undefined if __x and *this have different sizes
    45 template <class _Tp>
    46 valarray<_Tp>& valarray<_Tp>::operator=(const slice_array<_Tp>& __x)
    47 {
    48   size_t __index = __x._M_slice.start();
    49   for (size_t __i = 0;
    50        __i < __x._M_slice.size();
    51        ++__i, __index += __x._M_slice.stride())
    52     (*this)[__i] = (*(__x._M_array))[__index];
    53   return *this;
    54 }
    55 
    56 template <class _Tp>
    57 valarray<_Tp> valarray<_Tp>::operator[](slice __slice) const {
    58   valarray<_Tp> __tmp(__slice.size(), _NoInit());
    59   size_t __index = __slice.start();
    60   for (size_t __i = 0;
    61        __i < __slice.size();
    62        ++__i, __index += __slice.stride())
    63     __tmp[__i] = (*this)[__index];
    64   return __tmp;
    65 }
    66 
    67 template <class _Size>
    68 bool _Gslice_Iter_tmpl<_Size>::_M_incr() {
    69   size_t __dim = _M_indices.size() - 1;
    70   ++_M_step;
    71   while (true) {
    72     _M_1d_idx += _M_gslice._M_strides[__dim];
    73     if (++_M_indices[__dim] != _M_gslice._M_lengths[__dim])
    74       return true;
    75     else if (__dim != 0) {
    76       _M_1d_idx -=
    77 	_M_gslice._M_strides[__dim] * _M_gslice._M_lengths[__dim];
    78       _M_indices[__dim] = 0;
    79       --__dim;
    80     }
    81     else
    82       return false;
    83   }
    84 }
    85 
    86 // Behavior is undefined if __x and *this have different sizes, or if
    87 // __x was constructed from a degenerate gslice.
    88 template <class _Tp>
    89 valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array<_Tp>& __x)
    90 {
    91   if (this->size() != 0) {
    92     _Gslice_Iter __i(__x._M_gslice);
    93     do
    94       (*this)[__i._M_step] = __x._M_array[__i._M_1d_idx];
    95     while(__i._M_incr());
    96   }
    97   return *this;
    98 }
    99 
   100 template <class _Tp>
   101 valarray<_Tp> valarray<_Tp>::operator[](gslice __slice) const
   102 {
   103   valarray<_Tp> __tmp(__slice._M_size(), _NoInit());
   104   if (__tmp.size() != 0) {
   105     _Gslice_Iter __i(__slice);
   106     do __tmp[__i._M_step] = (*this)[__i._M_1d_idx]; while(__i._M_incr());
   107   }
   108   return __tmp;
   109 }
   110 
   111 template <class _Tp>
   112 valarray<_Tp> valarray<_Tp>::operator[](const _Valarray_bool& __mask) const
   113 {
   114   size_t _p_size = 0;
   115   {
   116     for (size_t __i = 0; __i < __mask.size(); ++__i)
   117       if (__mask[__i]) ++_p_size;
   118   }
   119 
   120   valarray<_Tp> __tmp(_p_size, _NoInit());
   121   size_t __idx = 0;
   122   {
   123     for (size_t __i = 0; __i < __mask.size(); ++__i)
   124       if (__mask[__i]) __tmp[__idx++] = (*this)[__i];
   125   }
   126 
   127   return __tmp;
   128 }
   129 
   130 template <class _Tp>
   131 valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<_Tp>& __x) {
   132   for (size_t __i = 0; __i < __x._M_addr.size(); ++__i)
   133     (*this)[__i] = __x._M_array[__x._M_addr[__i]];
   134   return *this;
   135 }
   136 
   137 template <class _Tp>
   138 valarray<_Tp>
   139 valarray<_Tp>::operator[](const _Valarray_size_t& __addr) const
   140 {
   141   valarray<_Tp> __tmp(__addr.size(), _NoInit());
   142   for (size_t __i = 0; __i < __addr.size(); ++__i)
   143     __tmp[__i] = (*this)[__addr[__i]];
   144   return __tmp;
   145 }
   146 
   147 //----------------------------------------------------------------------
   148 // Other valarray noninline member functions
   149 
   150 // Shift and cshift
   151 
   152 template <class _Tp>
   153 valarray<_Tp> valarray<_Tp>::shift(int __n) const
   154 {
   155   valarray<_Tp> __tmp(this->size());
   156 
   157   if (__n >= 0) {
   158     if (__n < this->size())
   159       copy(this->_M_first + __n, this->_M_first + this->size(),
   160            __tmp._M_first);
   161   }
   162   else {
   163     if (-__n < this->size())
   164       copy(this->_M_first, this->_M_first + this->size() + __n,
   165            __tmp._M_first - __n);
   166   }
   167   return __tmp;
   168 }
   169 
   170 template <class _Tp>
   171 valarray<_Tp> valarray<_Tp>::cshift(int __m) const
   172 {
   173   valarray<_Tp> __tmp(this->size());
   174   
   175 #ifdef __SYMBIAN32__
   176 	if (!this->size())
   177 		return __tmp;
   178 #endif	
   179 	
   180   // Reduce __m to an equivalent number in the range [0, size()).  We
   181   // have to be careful with negative numbers, since the sign of a % b
   182   // is unspecified when a < 0.
   183   long __n = __m;
   184   if (this->size() < (numeric_limits<long>::max)())
   185     __n %= long(this->size());
   186   if (__n < 0)
   187     __n += this->size();
   188 
   189   copy(this->_M_first,       this->_M_first + __n,
   190        __tmp._M_first + (this->size() - __n));
   191   copy(this->_M_first + __n, this->_M_first + this->size(),
   192        __tmp._M_first);
   193 
   194   return __tmp;
   195 }
   196 
   197 _STLP_END_NAMESPACE
   198 
   199 #endif /*  _STLP_VALARRAY_C */
   200 
   201 // Local Variables:
   202 // mode:C++
   203 // End: