⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valarray.cc

📁 Keil for ARM.rar
💻 CC
📖 第 1 页 / 共 5 页
字号:
#ifndef __STD_RW_VALARRAY_CC__
#define __STD_RW_VALARRAY_CC__


/***************************************************************************
 *
 * valaray.cc - Declarations for the Standard Library valarray
 *
 ***************************************************************************
 *
 * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
 * ALL RIGHTS RESERVED
 *
 * The software and information contained herein are proprietary to, and
 * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
 * intends to preserve as trade secrets such software and information.
 * This software is furnished pursuant to a written license agreement and
 * may be used, copied, transmitted, and stored only in accordance with
 * the terms of such license and with the inclusion of the above copyright
 * notice.  This software and information or any other copies thereof may
 * not be provided or otherwise made available to any other person.
 *
 * Notwithstanding any other lease or license that may pertain to, or
 * accompany the delivery of, this computer software and information, the
 * rights of the Government regarding its use, reproduction and disclosure
 * are as set forth in Section 52.227-19 of the FARS Computer
 * Software-Restricted Rights clause.
 * 
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
 * Technical Data and Computer Software clause at DFARS 252.227-7013.
 * Contractor/Manufacturer is Rogue Wave Software, Inc.,
 * P.O. Box 2328, Corvallis, Oregon 97339.
 *
 * This computer software and information is distributed with "restricted
 * rights."  Use, duplication or disclosure is subject to restrictions as
 * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
 * Computer Software-Restricted Rights (April 1985)."  If the Clause at
 * 18-52.227-74 "Rights in Data General" is specified in the contract,
 * then the "Alternate III" clause applies.
 *
 **************************************************************************/

#ifndef _RWSTD_NO_NAMESPACE
namespace std {
#endif


/*****************************************************************
 *                                                                *
 *                 VALARRAY MEMBER FUNCTIONS                      *
 *                                                                *
 ******************************************************************/


// unary operators

  template<class T>
  valarray<T> valarray<T>::operator+() const
  {
    valarray<T> tmp_array(size());
      
    for(size_t ind=0; ind< size(); ind++ )
      tmp_array[ind] = +memory_array[ind];

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  }

  template <class T>
  valarray<T> valarray<T>::operator-() const
  {
    valarray<T> tmp_array(size());
      
    for(size_t ind=0; ind< size(); ind++ )
      tmp_array[ind] = -memory_array[ind];

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  }


#ifndef _RWSTD_NO_ONLY_NEEDED_INSTANTIATION
  template <class T>
  valarray<T> valarray<T>::operator~() const
  {
    valarray<T> tmp_array(size());

    for(size_t ind=0; ind< size(); ind++ )
      tmp_array[ind] = ~memory_array[ind];

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  }

  template <class T>
  valarray<bool> valarray<T>::operator!() const
  {
    valarray<bool> tmp_array(size());

    for(size_t ind=0; ind< size(); ind++ )
      tmp_array[ind] = !memory_array[ind];

    _RW_IMP_SPACE(_RW_temporary<bool>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<bool>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  }
#endif

// computed assignment

  template <class T>
  valarray<T>& valarray<T>::operator*= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]*= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator/= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]/= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator+= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]+= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator-= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]-= array[ind];

    return *this;
  }

#ifndef _RWSTD_NO_ONLY_NEEDED_INSTANTIATION
  template <class T>
  valarray<T>& valarray<T>::operator%= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]%= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator^= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]^= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator&= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]&= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator|= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]|= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator<<= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]<<= array[ind];

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator>>= (const valarray<T>& array)
  {
    size_t upper_l = ( size() < array.size() ) ? size() : array.size();

    for(size_t ind=0; ind < upper_l; ind++)
      memory_array[ind]>>= array[ind];

    return *this;
  }
#endif

  template <class T>
  valarray<T>& valarray<T>::operator*= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]*= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator/= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]/= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator+= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]+= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator-= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]-= val;

    return *this;
  }

#ifndef _RWSTD_NO_ONLY_NEEDED_INSTANTIATION
  template <class T>
  valarray<T>& valarray<T>::operator%= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]%= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator^= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]^= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator&= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]&= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator|= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]|= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator<<= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]<<= val;

    return *this;
  }

  template <class T>
  valarray<T>& valarray<T>::operator>>= (const T& val)
  {
    for(size_t ind=0; ind < size(); ind++)
      memory_array[ind]>>= val;

    return *this;
  }
#endif

// other valarray member functions

  template <class T>
  T valarray<T>::sum() const
  {
    T tmp;
    if ( size() > 0 )
    {
      tmp = memory_array[0];
      for(size_t ind=1; ind<size(); ind++)
        tmp+= memory_array[ind];
    }
    else
      tmp = T(); // std allows undefined

    return tmp;
  }

  template <class T>
  valarray<T> valarray<T>::shift(int sh) const
  {
    valarray<T> tmp_array(T(),size());
      
    int right=0;
    int left=0;

    if ( sh < 0 ) right = -sh;
    else left = sh;

    for(size_t ind=left; ind< (size()-right); ind++ )
      tmp_array[ind+right-left] = memory_array[ind];

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  } 

  template <class T>
  valarray<T> valarray<T>::cshift(int sh) const
  {
    valarray<T> tmp_array(T(),size());
      
    if ( sh >= 0 )
    {
      for(size_t ind=0; ind< size(); ind++ )
        tmp_array[ind] = memory_array[(ind+sh)%size()];
    }
    else
    {
      for(size_t ind=size()+sh; ind< (2*size()+sh); ind++ )
        tmp_array[ind-size()-sh] = memory_array[ind%size()];
    }

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  } 

  template <class T>
  valarray<T> valarray<T>::apply(T func(T)) const
  {
    valarray<T> tmp_array(size());
      
    for(size_t ind=0; ind< size(); ind++ )
      tmp_array[ind] = func(memory_array[ind]);

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  } 

  template <class T>
  valarray<T> valarray<T>::apply(T func(const T&)) const
  {
    valarray<T> tmp_array(size());
      
    for(size_t ind=0; ind< size(); ind++ )
      tmp_array[ind] = func(memory_array[ind]);

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;
  } 

// operator[] for slice

  template <class T> 
  valarray<T> valarray<T>::operator[](slice sl) const
  {
    valarray<T> tmp_array(sl.size());
      
    size_t ind = sl.start();
    size_t cpt = 0; 

    while( cpt < sl.size() )
    {
      tmp_array[cpt] = memory_array[ind];
      ind+= sl.stride();
      cpt++;
    }

    _RW_IMP_SPACE(_RW_temporary<T>)* _tmp_ret = new _RW_IMP_SPACE(_RW_temporary<T>);

    _tmp_ret->store_adr = tmp_array._RW_get_memory_array()._RW_get_storage();
    _tmp_ret->length = sl.size();

    tmp_array._RW_get_memory_array_adr()->_RW_invalidate();

    return _tmp_ret;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -