/* $Id: CoinDenseVector.cpp 1373 2011-01-03 23:57:44Z lou $ */ // Copyright (C) 2003, International Business Machines // Corporation and others. All Rights Resized. // This code is licensed under the terms of the Eclipse Public License (EPL). #if defined(_MSC_VER) // Turn off compiler warning about long names # pragma warning(disable:4786) #endif #include #include "CoinDenseVector.hpp" #include "CoinHelperFunctions.hpp" //############################################################################# template void CoinDenseVector::clear() { memset(elements_, 0, nElements_*sizeof(T)); } //############################################################################# template CoinDenseVector & CoinDenseVector::operator=(const CoinDenseVector & rhs) { if (this != &rhs) { setVector(rhs.getNumElements(), rhs.getElements()); } return *this; } //############################################################################# template void CoinDenseVector::setVector(int size, const T * elems) { resize(size); CoinMemcpyN( elems,size,elements_); } //############################################################################# template void CoinDenseVector::setConstant(int size, T value) { resize(size); for(int i=0; i void CoinDenseVector::resize(int newsize, T value) { if (newsize != nElements_){ assert(newsize > 0); T *newarray = new T[newsize]; int cpysize = CoinMin(newsize, nElements_); CoinMemcpyN( elements_,cpysize,newarray); delete[] elements_; elements_ = newarray; nElements_ = newsize; for(int i=cpysize; i void CoinDenseVector::setElement(int index, T element) { assert(index >= 0 && index < nElements_); elements_[index] = element; } //############################################################################# template void CoinDenseVector::append(const CoinDenseVector & caboose) { const int s = nElements_; const int cs = caboose.getNumElements(); int newsize = s + cs; resize(newsize); const T * celem = caboose.getElements(); CoinDisjointCopyN(celem, cs, elements_ + s); } //############################################################################# template void CoinDenseVector::operator+=(T value) { for(int i=0; i void CoinDenseVector::operator-=(T value) { for(int i=0; i void CoinDenseVector::operator*=(T value) { for(int i=0; i void CoinDenseVector::operator/=(T value) { for(int i=0; i CoinDenseVector::CoinDenseVector(): nElements_(0), elements_(NULL) {} //############################################################################# template CoinDenseVector::CoinDenseVector(int size, const T * elems): nElements_(0), elements_(NULL) { gutsOfSetVector(size, elems); } //----------------------------------------------------------------------------- template CoinDenseVector::CoinDenseVector(int size, T value): nElements_(0), elements_(NULL) { gutsOfSetConstant(size, value); } //----------------------------------------------------------------------------- template CoinDenseVector::CoinDenseVector(const CoinDenseVector & rhs): nElements_(0), elements_(NULL) { setVector(rhs.getNumElements(), rhs.getElements()); } //----------------------------------------------------------------------------- template CoinDenseVector::~CoinDenseVector () { delete [] elements_; } //############################################################################# template void CoinDenseVector::gutsOfSetVector(int size, const T * elems) { if ( size != 0 ) { resize(size); nElements_ = size; CoinDisjointCopyN(elems, size, elements_); } } //----------------------------------------------------------------------------- template void CoinDenseVector::gutsOfSetConstant(int size, T value) { if ( size != 0 ) { resize(size); nElements_ = size; CoinFillN(elements_, size, value); } } //############################################################################# /** Access the i'th element of the dense vector. */ template T & CoinDenseVector::operator[](int index) const { assert(index >= 0 && index < nElements_); T *where = elements_ + index; return *where; } //############################################################################# // template class CoinDenseVector; This works but causes warning messages template class CoinDenseVector; template class CoinDenseVector;