Menu

[r151]: / trunk / include / zrovector- / zrovector-misc.hpp  Maximize  Restore  History

Download this file

111 lines (96 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
//=============================================================================
/*! clear vector */
inline void zrovector::clear()
{CPPL_VERBOSE_REPORT;
l =0;
delete [] array;
array =NULL;
}
//=============================================================================
/*! make vector into zero vector */
inline zrovector& zrovector::zero()
{CPPL_VERBOSE_REPORT;
for(long i=0; i<l; i++){ array[i] =comple(0.0,0.0); }
return *this;
}
//=============================================================================
/*! change sign(+/-) of the vector */
inline void zrovector::chsign()
{CPPL_VERBOSE_REPORT;
for(long i=0; i<l; i++){ array[i] =-array[i]; }
}
//=============================================================================
/*! make a deep copy of the zrovector */
inline void zrovector::copy(const zrovector& vec)
{CPPL_VERBOSE_REPORT;
delete [] array;
l =vec.l;
array =new comple[vec.l];
zcopy_(vec.l, vec.array, 1, array, 1);
}
//=============================================================================
/*! make a shallow copy of the vector\n
This function is not desinged to be used in project codes. */
inline void zrovector::shallow_copy(const _zrovector& vec)
{CPPL_VERBOSE_REPORT;
l =vec.l;
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 zrovector::alias(const zrovector& vec)
{CPPL_VERBOSE_REPORT;
l =vec.l;
//cap =vec.cap;
delete [] array;
array =vec.array;
}
//=============================================================================
/*! unalias the vector */
inline void zrovector::unalias()
{CPPL_VERBOSE_REPORT;
l =0;
//cap =0;
array =NULL;
}
//=============================================================================
/*! resize vector */
inline void zrovector::resize(const long& _l)
{CPPL_VERBOSE_REPORT;
#ifdef CPPL_DEBUG
if( _l<0 ){
ERROR_REPORT;
std::cerr << "Vector size must be positive integers." << std::endl
<< "Your input was (" << _l << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
l =_l;
delete [] array;
array =new comple[_l];
}
//=============================================================================
/*! swap two vectors */
inline void swap(zrovector& u, zrovector& v)
{CPPL_VERBOSE_REPORT;
long u_L(u.l);
comple* u_Array(u.array);
u.l=v.l; u.array=v.array;
v.l=u_L; v.array=u_Array;
}
//=============================================================================
/*! convert user object to smart-temporary object */
inline _zrovector _(zrovector& vec)
{CPPL_VERBOSE_REPORT;
_zrovector newvec;
//////// shallow copy ////////
newvec.l =vec.l;
newvec.array =vec.array;
//////// nullify ////////
vec.l =0;
vec.array =NULL;
return newvec;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.