mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
Add assignment operators to some classes (#3937)
The implicitly defined assignment operator for classes having custom defined copy constructor is deprecated. This patch adds explicit assignment operators. XDataSeries assignment operator now deletes XDataPoints pointed by datapoints array in the target and creates new ones for the source, this required a change in the way XDataSeries is used in JSON parser, which was based on default assignment operator semantics.
This commit is contained in:
@@ -41,11 +41,15 @@ public:
|
||||
for (int i = 0; i<MAX_MEASURES; i++) values[i] = 0.0;
|
||||
}
|
||||
Measure(const Measure &other) {
|
||||
*this = other;
|
||||
}
|
||||
Measure& operator=(const Measure &other) {
|
||||
this->when = other.when;
|
||||
this->comment = other.comment;
|
||||
this->source = other.source;
|
||||
this->originalSource = other.originalSource;
|
||||
for (int i = 0; i<MAX_MEASURES; i++) this->values[i] = other.values[i];
|
||||
return *this;
|
||||
}
|
||||
~Measure() {}
|
||||
|
||||
|
||||
@@ -262,11 +262,7 @@ xdata_list: xdata_series
|
||||
| xdata_list ',' xdata_series
|
||||
;
|
||||
|
||||
xdata_series: '{' xdata_items '}' { XDataSeries *add = new XDataSeries;
|
||||
add->name=jc->xdataseries.name;
|
||||
add->datapoints=jc->xdataseries.datapoints;
|
||||
add->valuename=jc->xdataseries.valuename;
|
||||
add->unitname=jc->xdataseries.unitname;
|
||||
xdata_series: '{' xdata_items '}' { XDataSeries *add = new XDataSeries(jc->xdataseries);
|
||||
jc->JsonRide->addXData(add->name, add);
|
||||
|
||||
// clear for next one
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
v3(double a, double b, double c) : m_t(a, b, c) {};
|
||||
|
||||
v3(const v3& o) : m_t(o.m_t) {}
|
||||
v3& operator=(const v3& o) { m_t = o.m_t; return *this; }
|
||||
|
||||
double x() const { return std::get<0>(m_t); }
|
||||
double y() const { return std::get<1>(m_t); }
|
||||
|
||||
@@ -572,13 +572,17 @@ public:
|
||||
string[i]="";
|
||||
}
|
||||
}
|
||||
XDataPoint (const XDataPoint &other) {
|
||||
XDataPoint(const XDataPoint &other) {
|
||||
*this = other;
|
||||
}
|
||||
XDataPoint& operator=(const XDataPoint &other) {
|
||||
this->secs=other.secs;
|
||||
this->km=other.km;
|
||||
for(int i=0; i<XDATA_MAXVALUES; i++) {
|
||||
this->number[i]= other.number[i];
|
||||
this->string[i]= other.string[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
double secs, km;
|
||||
@@ -589,16 +593,21 @@ public:
|
||||
class XDataSeries {
|
||||
public:
|
||||
XDataSeries() {}
|
||||
XDataSeries(XDataSeries &other) {
|
||||
XDataSeries(const XDataSeries& other) { *this = other; }
|
||||
XDataSeries& operator=(const XDataSeries &other) {
|
||||
name = other.name;
|
||||
valuename = other.valuename;
|
||||
unitname = other.unitname;
|
||||
valuetype = other.valuetype;
|
||||
// we need to delete objects pointed by the assignment target
|
||||
foreach(XDataPoint *p, datapoints) delete p;
|
||||
datapoints.clear();
|
||||
// we need to create new objects since we are holding pointers to objects
|
||||
// otherwise we would end up w/ multiple frees or dangling ptrs!
|
||||
foreach (XDataPoint *p, other.datapoints) {
|
||||
datapoints.push_back(new XDataPoint(*p));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~XDataSeries() { foreach(XDataPoint *p, datapoints) delete p; }
|
||||
|
||||
Reference in New Issue
Block a user