qspline: Replace alloc_mem, free_mem by C++ new, delete

Remove unneeded assignments and a wrong comment in the destructor.
Fix wrong data type for local variable xstarts.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-06-25 14:55:36 +02:00
parent 52218c3d99
commit 556a1c1e28

View File

@ -18,7 +18,6 @@
**********************************************************************/
#include "allheaders.h"
#include "memry.h"
#include "quadlsq.h"
#include "quspline.h"
@ -43,8 +42,8 @@ QSPLINE::QSPLINE( //constructor
int32_t index; //segment index
//get memory
xcoords = (int32_t *) alloc_mem ((count + 1) * sizeof (int32_t));
quadratics = (QUAD_COEFFS *) alloc_mem (count * sizeof (QUAD_COEFFS));
xcoords = new int32_t[count + 1];
quadratics = new QUAD_COEFFS[count];
segments = count;
for (index = 0; index < segments; index++) {
//copy them
@ -77,9 +76,9 @@ int degree //fit required
QLSQ qlsq; /*accumulator */
segments = segcount;
xcoords = (int32_t *) alloc_mem ((segcount + 1) * sizeof (int32_t));
ptcounts = (int32_t *) alloc_mem ((segcount + 1) * sizeof (int32_t));
quadratics = (QUAD_COEFFS *) alloc_mem (segcount * sizeof (QUAD_COEFFS));
xcoords = new int32_t[segcount + 1];
ptcounts = new int32_t[segcount + 1];
quadratics = new QUAD_COEFFS[segcount];
memmove (xcoords, xstarts, (segcount + 1) * sizeof (int32_t));
ptcounts[0] = 0; /*none in any yet */
for (segment = 0, pointindex = 0; pointindex < pointcount; pointindex++) {
@ -123,7 +122,7 @@ int degree //fit required
quadratics[segment].b = qlsq.get_b ();
quadratics[segment].c = qlsq.get_c ();
}
free_mem(ptcounts);
delete[] ptcounts;
}
@ -148,16 +147,9 @@ QSPLINE::QSPLINE( //constructor
* Destroy a QSPLINE.
**********************************************************************/
QSPLINE::~QSPLINE ( //constructor
) {
if (xcoords != nullptr) {
free_mem(xcoords);
xcoords = nullptr;
}
if (quadratics != nullptr) {
free_mem(quadratics);
quadratics = nullptr;
}
QSPLINE::~QSPLINE () {
delete[] xcoords;
delete[] quadratics;
}
@ -169,14 +161,12 @@ QSPLINE::~QSPLINE ( //constructor
QSPLINE & QSPLINE::operator= ( //assignment
const QSPLINE & source) {
if (xcoords != nullptr)
free_mem(xcoords);
if (quadratics != nullptr)
free_mem(quadratics);
delete[] xcoords;
delete[] quadratics;
segments = source.segments;
xcoords = (int32_t *) alloc_mem ((segments + 1) * sizeof (int32_t));
quadratics = (QUAD_COEFFS *) alloc_mem (segments * sizeof (QUAD_COEFFS));
xcoords = new int32_t[segments + 1];
quadratics = new QUAD_COEFFS[segments];
memmove (xcoords, source.xcoords, (segments + 1) * sizeof (int32_t));
memmove (quadratics, source.quadratics, segments * sizeof (QUAD_COEFFS));
return *this;
@ -303,7 +293,7 @@ void QSPLINE::extrapolate( //linear extrapolation
) {
int segment; /*current segment of spline */
int dest_segment; //dest index
int *xstarts; //new boundaries
int32_t* xstarts; //new boundaries
QUAD_COEFFS *quads; //new ones
int increment; //in size
@ -312,9 +302,8 @@ void QSPLINE::extrapolate( //linear extrapolation
increment++;
if (increment == 0)
return;
xstarts = (int *) alloc_mem ((segments + 1 + increment) * sizeof (int));
quads =
(QUAD_COEFFS *) alloc_mem ((segments + increment) * sizeof (QUAD_COEFFS));
xstarts = new int32_t[segments + 1 + increment];
quads = new QUAD_COEFFS[segments + increment];
if (xmin < xcoords[0]) {
xstarts[0] = xmin;
quads[0].a = 0;
@ -339,9 +328,9 @@ void QSPLINE::extrapolate( //linear extrapolation
xstarts[dest_segment] = xmax + 1;
}
segments = dest_segment;
free_mem(xcoords);
free_mem(quadratics);
xcoords = (int32_t *) xstarts;
delete[] xcoords;
delete[] quadratics;
xcoords = xstarts;
quadratics = quads;
}