//=============================================================================
/*! clear vector */
inline void drovector::clear()
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::clear()" << std::endl;
std::cerr << "# [NOTE] drovector::clear()" << " An array at " << Array << " is going to be cleared." << std::endl;
#endif//CPPL_VERBOSE
L =0;
delete [] Array; Array =NULL;
}
//=============================================================================
/*! make vector into zero vector */
inline drovector& drovector::zero()
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::zero()" << std::endl;
#endif//CPPL_VERBOSE
for(long i=0; i<L; i++){ Array[i] =0.0; }
return *this;
}
//=============================================================================
/*! change sign(+/-) of the vector */
inline void drovector::chsign()
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::chsign()" << std::endl;
#endif//CPPL_VERBOSE
for(long i=0; i<L; i++){ Array[i] =-Array[i]; }
}
//=============================================================================
/*! make a deep copy of the drovector */
inline void drovector::copy(const drovector& vec)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::copy(const drovector&)" << std::endl;
std::cerr << "# [NOTE] drovector::copy(const drovector&)" << " A drovector at " << Array << " is going to be deleted. ";
#endif//CPPL_VERBOSE
L =vec.L;
CAP =vec.CAP;
delete [] Array;
Array =new double[vec.CAP];
dcopy_(vec.L, vec.Array, 1, Array, 1);
#ifdef CPPL_VERBOSE
std::cerr << "Then, a COPY of a drovector has been cleated at " << Array << "." << std::endl;
#endif//CPPL_VERBOSE
}
//=============================================================================
/*! make a shallow copy of the vector\n
This function is not desinged to be used in project codes. */
inline void drovector::shallow_copy(const _drovector& vec)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::shallow_copy(const _drovector&)" << std::endl;
std::cerr << "# [NOTE] drovector::shallow_copy(const _drovector&)" << " A drovector at " << Array << " is going to be deleted " << "and point at " << vec.Array << " instead." << std::endl;
#endif//CPPL_VERBOSE
L =vec.L;
CAP =vec.CAP;
delete [] Array;
Array =vec.Array;
vec.nullify();
}
//=============================================================================
/*! make an alias of the vector\n
Be carefull to use this function not to cause double free. */
inline void drovector::alias(const drovector& vec)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::alias(const drovector&)" << std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_VERBOSE
std::cerr << "# [NOTE] drovector::alias(const drovector&) " << "A drovector at " << Array << " is going to be deleted " << "and point at " << vec.Array << " instead." << std::endl;
#endif//CPPL_VERBOSE
L =vec.L;
CAP =vec.CAP;
delete [] Array;
Array =vec.Array;
}
//=============================================================================
/*! unalias the vector */
inline void drovector::unalias()
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::unalias()" << std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_VERBOSE
std::cerr << "# [NOTE] drovector::unalias() " << "A drovector at " << Array << " is going to be out of reference." << std::endl;
#endif//CPPL_VERBOSE
L =0;
CAP =0;
Array =NULL;
}
//=============================================================================
/*! resize vector */
inline void drovector::resize(const long& _l, const long margin)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::resize(const long&, const long=0)" << std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if( _l<0 || margin<0 ){
std::cerr << "[ERROR] drovector::resize(const long&, const long=0)" << std::endl
<< "Vector size must be positive integers." << std::endl
<< "Your input was (" << _l << ", " << margin << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
L =_l;
CAP =L+margin;
delete [] Array;
Array =new double[CAP];
}
//=============================================================================
/*! stretch or shrink vector */
inline void drovector::stretch(const long& dl)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] drovector::stretch(const long&)" << std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if( l+dl<0 ){
std::cerr << "[ERROR] drovector::stretch(const long&)" << std::endl
<< "Vector size must be positive integers." << std::endl
<< "Your input was (" << dl << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
L +=dl;
if(L>CAP){
CAP += dl+CPPL_SECTOR_SIZE;
double* newArray(new double[CAP]);
dcopy_(L-dl, Array, 1, newArray, 1);
delete [] Array;
Array =newArray;
}
}
//=============================================================================
/*! swap two vectors */
inline void swap(drovector& u, drovector& v)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] swap(drovector&, drovector&)" << std::endl;
#endif//CPPL_VERBOSE
long u_cap(u.CAP), u_l(u.L);
double* u_array(u.Array);
u.L=v.L; u.CAP=v.CAP; u.Array=v.Array;
v.L=u_l; v.CAP=u_cap; v.Array=u_array;
}
//=============================================================================
/*! convert user object to smart-temporary object */
inline _drovector _(drovector& vec)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] _(drovector&)" << std::endl;
#endif//CPPL_VERBOSE
_drovector newvec;
newvec.L =vec.L;
newvec.CAP =vec.CAP;
newvec.Array =vec.Array;
vec.L =0;
vec.CAP =0;
vec.Array =NULL;
return newvec;
}