ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_valarray.c
Go 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   _STLP_ASSERT(__x._M_slice.size() == this->size())
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   if (this->size() != 0) {
00089     _Gslice_Iter __i(__x._M_gslice);
00090     do
00091       (*this)[__i._M_step] = __x._M_array[__i._M_1d_idx];
00092     while(__i._M_incr());
00093   }
00094   return *this;
00095 }
00096 
00097 template <class _Tp>
00098 valarray<_Tp> valarray<_Tp>::operator[](const gslice& __slice) const {
00099   valarray<_Tp> __tmp(__slice._M_size(), _NoInit());
00100   if (__tmp.size() != 0) {
00101     _Gslice_Iter __i(__slice);
00102     do __tmp[__i._M_step] = (*this)[__i._M_1d_idx]; while(__i._M_incr());
00103   }
00104   return __tmp;
00105 }
00106 
00107 template <class _Tp>
00108 valarray<_Tp> valarray<_Tp>::operator[](const _Valarray_bool& __mask) const {
00109   size_t _p_size = 0;
00110   {
00111     for (size_t __i = 0; __i < __mask.size(); ++__i)
00112       if (__mask[__i]) ++_p_size;
00113   }
00114 
00115   valarray<_Tp> __tmp(_p_size, _NoInit());
00116   size_t __idx = 0;
00117   {
00118     for (size_t __i = 0; __i < __mask.size(); ++__i)
00119       if (__mask[__i]) __tmp[__idx++] = (*this)[__i];
00120   }
00121 
00122   return __tmp;
00123 }
00124 
00125 template <class _Tp>
00126 valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<_Tp>& __x) {
00127   _STLP_ASSERT(__x._M_addr.size() == this->size())
00128   for (size_t __i = 0; __i < __x._M_addr.size(); ++__i)
00129     (*this)[__i] = __x._M_array[__x._M_addr[__i]];
00130   return *this;
00131 }
00132 
00133 template <class _Tp>
00134 valarray<_Tp>
00135 valarray<_Tp>::operator[](const _Valarray_size_t& __addr) const {
00136   valarray<_Tp> __tmp(__addr.size(), _NoInit());
00137   for (size_t __i = 0; __i < __addr.size(); ++__i)
00138     __tmp[__i] = (*this)[__addr[__i]];
00139   return __tmp;
00140 }
00141 
00142 //----------------------------------------------------------------------
00143 // Other valarray noninline member functions
00144 
00145 // Shift and cshift
00146 
00147 template <class _Tp>
00148 valarray<_Tp> valarray<_Tp>::shift(int __n) const {
00149   valarray<_Tp> __tmp(this->size());
00150 
00151   if (__n >= 0) {
00152     if (__n < this->size())
00153       copy(this->_M_first + __n, this->_M_first + this->size(),
00154            __tmp._M_first);
00155   }
00156   else {
00157     if (-__n < this->size())
00158       copy(this->_M_first, this->_M_first + this->size() + __n,
00159            __tmp._M_first - __n);
00160   }
00161   return __tmp;
00162 }
00163 
00164 template <class _Tp>
00165 valarray<_Tp> valarray<_Tp>::cshift(int __m) const {
00166   valarray<_Tp> __tmp(this->size());
00167 
00168   // Reduce __m to an equivalent number in the range [0, size()).  We
00169   // have to be careful with negative numbers, since the sign of a % b
00170   // is unspecified when a < 0.
00171   long __n = __m;
00172   if (this->size() < (numeric_limits<long>::max)())
00173     __n %= long(this->size());
00174   if (__n < 0)
00175     __n += this->size();
00176 
00177   copy(this->_M_first,       this->_M_first + __n,
00178        __tmp._M_first + (this->size() - __n));
00179   copy(this->_M_first + __n, this->_M_first + this->size(),
00180        __tmp._M_first);
00181 
00182   return __tmp;
00183 }
00184 
00185 _STLP_END_NAMESPACE
00186 
00187 #endif /*  _STLP_VALARRAY_C */
00188 
00189 // Local Variables:
00190 // mode:C++
00191 // End:

Generated on Fri May 25 2012 04:28:17 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.