summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjoye <joye>2014-07-03 20:52:07 (GMT)
committerjoye <joye>2014-07-03 20:52:07 (GMT)
commit551ee12095b9cabfee787bb5ef59cce7d2ecb4df (patch)
tree7fb35d8e781de460945779055c3ac3b02de1bce9 /src
parent4f7a2ece9c889c3e6ac5377f39a8757827e5323c (diff)
downloadblt-551ee12095b9cabfee787bb5ef59cce7d2ecb4df.zip
blt-551ee12095b9cabfee787bb5ef59cce7d2ecb4df.tar.gz
blt-551ee12095b9cabfee787bb5ef59cce7d2ecb4df.tar.bz2
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/bltChain.C2
-rw-r--r--src/bltGrAxis.C83
-rw-r--r--src/bltGrAxis.h4
-rw-r--r--src/bltGrAxisOption.C19
4 files changed, 72 insertions, 36 deletions
diff --git a/src/bltChain.C b/src/bltChain.C
index fb747fe..6443671 100644
--- a/src/bltChain.C
+++ b/src/bltChain.C
@@ -36,7 +36,7 @@ extern "C" {
#ifndef ALIGN
#define ALIGN(a) \
(((size_t)a + (sizeof(double) - 1)) & (~(sizeof(double) - 1)))
-#endif /* ALIGN */
+#endif
typedef int (QSortCompareProc) (const void *, const void *);
diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C
index 5394992..8257027 100644
--- a/src/bltGrAxis.C
+++ b/src/bltGrAxis.C
@@ -298,10 +298,16 @@ Axis::~Axis()
if (ops->minor.gc)
graphPtr_->freePrivateGC(ops->minor.gc);
- if (t1Ptr_)
- free(t1Ptr_);
- if (t2Ptr_)
- free(t2Ptr_);
+ if (t1Ptr_) {
+ if (t1Ptr_->values)
+ delete [] t1Ptr_->values;
+ delete t1Ptr_;
+ }
+ if (t2Ptr_) {
+ if (t2Ptr_->values)
+ delete [] t2Ptr_->values;
+ delete t2Ptr_;
+ }
freeTickLabels();
@@ -439,10 +445,16 @@ void Axis::mapGridlines()
needed += (t1Ptr->nTicks * t2Ptr->nTicks);
if (needed == 0) {
- if (t1Ptr != t1Ptr_)
- free(t1Ptr);
- if (t2Ptr != t2Ptr_)
- free(t2Ptr);
+ if (t1Ptr != t1Ptr_) {
+ if (t1Ptr->values)
+ delete [] t1Ptr->values;
+ delete t1Ptr;
+ }
+ if (t2Ptr != t2Ptr_) {
+ if (t2Ptr->values)
+ delete [] t2Ptr->values;
+ delete t2Ptr;
+ }
return;
}
@@ -484,10 +496,16 @@ void Axis::mapGridlines()
}
}
- if (t1Ptr != t1Ptr_)
- free(t1Ptr);
- if (t2Ptr != t2Ptr_)
- free(t2Ptr);
+ if (t1Ptr != t1Ptr_) {
+ if (t1Ptr->values)
+ delete [] t1Ptr->values;
+ delete t1Ptr;
+ }
+ if (t2Ptr != t2Ptr_) {
+ if (t2Ptr->values)
+ delete [] t2Ptr->values;
+ delete t2Ptr;
+ }
ops->major.nUsed = s1 - ops->major.segments;
ops->minor.nUsed = s2 - ops->minor.segments;
@@ -596,7 +614,7 @@ void Axis::draw(Drawable drawable)
for (Blt_ChainLink link=Blt_Chain_FirstLink(tickLabels_); link;
link = Blt_Chain_NextLink(link)) {
- TickLabel *labelPtr = (TickLabel*)Blt_Chain_GetValue(link);
+ TickLabel* labelPtr = (TickLabel*)Blt_Chain_GetValue(link);
ts.drawText(drawable, labelPtr->string, labelPtr->anchorPos.x,
labelPtr->anchorPos.y);
}
@@ -1002,8 +1020,10 @@ void Axis::freeTickLabels()
Blt_Chain chain = tickLabels_;
for (Blt_ChainLink link=Blt_Chain_FirstLink(chain); link;
link = Blt_Chain_NextLink(link)) {
- TickLabel *labelPtr = (TickLabel*)Blt_Chain_GetValue(link);
- free(labelPtr);
+ TickLabel* labelPtr = (TickLabel*)Blt_Chain_GetValue(link);
+ if (labelPtr->string)
+ delete [] labelPtr->string;
+ delete(labelPtr);
}
Blt_Chain_Reset(chain);
}
@@ -1042,7 +1062,8 @@ TickLabel* Axis::makeLabel(double value)
}
}
- TickLabel* labelPtr = (TickLabel*)malloc(sizeof(TickLabel) + strlen(string));
+ TickLabel* labelPtr = new TickLabel;
+ labelPtr->string = new char[strlen(string)+1];
strcpy(labelPtr->string, string);
labelPtr->anchorPos.x = DBL_MAX;
labelPtr->anchorPos.y = DBL_MAX;
@@ -1587,11 +1608,12 @@ void Axis::makeSegments(AxisInfo *infoPtr)
link = Blt_Chain_NextLink(link);
Segment2d seg;
makeTick(t1, infoPtr->t1, infoPtr->axis, &seg);
- /* Save tick label X-Y position. */
+ // Save tick label X-Y position
if (isHoriz) {
labelPtr->anchorPos.x = seg.p.x;
labelPtr->anchorPos.y = labelPos;
- } else {
+ }
+ else {
labelPtr->anchorPos.x = labelPos;
labelPtr->anchorPos.y = seg.p.y;
}
@@ -1603,14 +1625,14 @@ void Axis::makeSegments(AxisInfo *infoPtr)
Ticks* Axis::generateTicks(TickSweep *sweepPtr)
{
- Ticks* ticksPtr =
- (Ticks*)malloc(sizeof(Ticks) + (sweepPtr->nSteps * sizeof(double)));
+ Ticks* ticksPtr = new Ticks;
+ ticksPtr->values = new double[sweepPtr->nSteps];
ticksPtr->nTicks = 0;
if (sweepPtr->step == 0.0) {
- /* Hack: A zero step indicates to use log values. */
+ // Hack: A zero step indicates to use log values
int i;
- /* Precomputed log10 values [1..10] */
+ // Precomputed log10 values [1..10]
static double logTable[] = {
0.0,
0.301029995663981,
@@ -1635,6 +1657,7 @@ Ticks* Axis::generateTicks(TickSweep *sweepPtr)
}
}
ticksPtr->nTicks = sweepPtr->nSteps;
+
return ticksPtr;
}
@@ -1845,6 +1868,7 @@ void Axis::getGeometry()
{
AxisOptions* ops = (AxisOptions*)ops_;
GraphOptions* gops = (GraphOptions*)graphPtr_->ops_;
+
freeTickLabels();
// Leave room for axis baseline and padding
@@ -1854,11 +1878,18 @@ void Axis::getGeometry()
maxTickHeight_ = maxTickWidth_ = 0;
- if (t1Ptr_)
- free(t1Ptr_);
+ if (t1Ptr_) {
+ if (t1Ptr_->values)
+ delete [] t1Ptr_->values;
+ delete t1Ptr_;
+ }
t1Ptr_ = generateTicks(&majorSweep_);
- if (t2Ptr_)
- free(t2Ptr_);
+
+ if (t2Ptr_) {
+ if (t2Ptr_->values)
+ delete [] t2Ptr_->values;
+ delete t2Ptr_;
+ }
t2Ptr_ = generateTicks(&minorSweep_);
if (ops->showTicks) {
diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h
index 6aac63d..28492e2 100644
--- a/src/bltGrAxis.h
+++ b/src/bltGrAxis.h
@@ -82,12 +82,12 @@ namespace Blt {
Point2d anchorPos;
unsigned int width;
unsigned int height;
- char string[1];
+ char* string;
} TickLabel;
typedef struct {
int nTicks;
- double values[1];
+ double* values;
} Ticks;
typedef struct {
diff --git a/src/bltGrAxisOption.C b/src/bltGrAxisOption.C
index 9009cbd..df5b626 100644
--- a/src/bltGrAxisOption.C
+++ b/src/bltGrAxisOption.C
@@ -170,11 +170,13 @@ static int TicksSetProc(ClientData clientData, Tcl_Interp* interp,
Ticks* ticksPtr = NULL;
if (objc > 0) {
- ticksPtr = (Ticks*)malloc(sizeof(Ticks) + (objc*sizeof(double)));
- for (int ii = 0; ii<objc; ii++) {
+ ticksPtr = new Ticks;
+ ticksPtr->values = new double[objc];
+ for (int ii=0; ii<objc; ii++) {
double value;
if (Tcl_GetDoubleFromObj(interp, objv[ii], &value) != TCL_OK) {
- free(ticksPtr);
+ delete [] ticksPtr->values;
+ delete ticksPtr;
return TCL_ERROR;
}
ticksPtr->values[ii] = value;
@@ -196,12 +198,12 @@ static Tcl_Obj* TicksGetProc(ClientData clientData, Tk_Window tkwin,
return Tcl_NewListObj(0, NULL);
int cnt = ticksPtr->nTicks;
- Tcl_Obj** ll = (Tcl_Obj**)calloc(cnt, sizeof(Tcl_Obj*));
+ Tcl_Obj** ll = new Tcl_Obj*[cnt];
for (int ii = 0; ii<cnt; ii++)
ll[ii] = Tcl_NewDoubleObj(ticksPtr->values[ii]);
Tcl_Obj* listObjPtr = Tcl_NewListObj(cnt, ll);
- free(ll);
+ delete [] ll;
return listObjPtr;
}
@@ -209,8 +211,11 @@ static void TicksFreeProc(ClientData clientData, Tk_Window tkwin,
char *ptr)
{
Ticks* ticksPtr = *(Ticks**)ptr;
- if (ticksPtr)
- free(ticksPtr);
+ if (ticksPtr) {
+ if (ticksPtr->values)
+ delete [] ticksPtr->values;
+ delete ticksPtr;
+ }
}
static Tk_CustomOptionSetProc ObjectSetProc;