Browse Source

Removed copy constructor from BaseData to prevent unnecessary copying of data

interpolate
Michael Uleysky 1 year ago
parent
commit
c85dc28858
  1. 6
      include/actiondep.h
  2. 10
      include/basedata.h
  3. 11
      sources/AVISOLOCAL.cpp
  4. 11
      sources/BINFILE.cpp
  5. 4
      sources/MODISBINLOCAL.cpp
  6. 46
      src/layereddata.cpp

6
include/actiondep.h

@ -133,11 +133,11 @@ template<class D> ReadType<D> Read(const D& data, const MString& vname, const Ba
else if constexpr(ReadSupported<D>)
dat = data.Read(vname, ind);
if(dat)
out.Add(dat);
out.Add(std::move(dat));
else
ok = false;
}
if(ok) return out.Div();
if(ok) return std::move(out.Div());
}
return RT();
}
@ -191,7 +191,7 @@ template<class D> UVData<ReadType<D>> ReadUV(const D& data, const BaseParameters
}
UV dat(u, v);
if(dat)
out.Add(dat);
out.Add(std::move(dat));
else
ok = false;
}

10
include/basedata.h

@ -25,7 +25,11 @@ class BaseData
BaseData(size_t n, MString&& unit_ = ""): data(n), unit(std::move(unit_)) {}
public:
BaseData() = default;
BaseData() = default;
BaseData(const BaseData&) = delete;
BaseData(BaseData&&) = default;
BaseData& operator=(BaseData&&) = default;
const real& V(size_t i) const { return data[i]; }
real& V(size_t i) { return data[i]; }
@ -86,12 +90,12 @@ template<class Data> class DefaultAverager: public Data
}
public:
void Add(const Data& d)
void Add(Data&& d)
{
if(!d) return;
if(!*this)
{
*static_cast<Data*>(this) = d;
*static_cast<Data*>(this) = std::move(d);
count.resize(Data::N());
for(size_t i = 0; i < Data::N(); i++) count[i] = DataOk(this, i) ? 1 : 0;
return;

11
sources/AVISOLOCAL.cpp

@ -122,16 +122,15 @@ AVISOLOCALData::Data AVISOLOCALData::Read(const MString& vname, const BaseParame
auto u = Read("u", ip, i);
auto v = Read("v", ip, i);
if(!(u && v)) return Data();
auto out = u;
out.SetUnit(square ? ("(" + u.Unit() + ")2") : u.Unit());
for(size_t ind = 0; ind < out.N(); ind++)
if(square && u.Unit().Exist()) u.SetUnit("(" + u.Unit() + ")2");
for(size_t ind = 0; ind < u.N(); ind++)
{
if(u.IsFill(ind) || v.IsFill(ind))
out.V(ind) = out.Fillval();
u.V(ind) = u.Fillval();
else
out.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
u.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
}
return out;
return u;
}
return Data();
}

11
sources/BINFILE.cpp

@ -69,16 +69,15 @@ BINFILEData::Data BINFILEData::Read(const MString& vname, size_t i) const
auto u = Read("u", i);
auto v = Read("v", i);
if(!(u && v)) return Data();
auto out = u;
out.SetUnit(square ? ("(" + u.Unit() + ")2") : u.Unit());
for(size_t ind = 0; ind < out.N(); ind++)
if(square && u.Unit().Exist()) u.SetUnit("(" + u.Unit() + ")2");
for(size_t ind = 0; ind < u.N(); ind++)
{
if(u.IsFill(ind) || v.IsFill(ind))
out.V(ind) = out.Fillval();
u.V(ind) = u.Fillval();
else
out.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
u.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
}
return out;
return u;
}
if(vname == "u" || vname == "v")

4
sources/MODISBINLOCAL.cpp

@ -92,9 +92,9 @@ MODISBINLOCALData::Data MODISBINLOCALData::Read(const MString& var, const BasePa
for(const auto& suf: dataset)
{
Data dat = ReadFile(suf, p, tind);
if(dat) out.Add(dat);
if(dat) out.Add(std::move(dat));
}
return out.Div();
return std::move(out.Div());
}
MODISBINLOCALData::Data MODISBINLOCALData::ReadFile(const MString& suf, const struct MODISBINLOCALData::Parameters* p, size_t tind) const

46
src/layereddata.cpp

@ -193,16 +193,15 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto temp = Read("temp", ip, i);
auto sal = Read("sal", ip, i);
if(!(temp && sal)) return Data();
auto out = temp;
out.SetUnit("degrees_C");
for(size_t ind = 0; ind < out.N(); ind++)
temp.SetUnit("degrees_C");
for(size_t ind = 0; ind < temp.N(); ind++)
{
if(temp.IsFill(ind) || sal.IsFill(ind))
out.V(ind) = out.Fillval();
temp.V(ind) = temp.Fillval();
else
out.V(ind) = Temp2PTemp(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind));
temp.V(ind) = Temp2PTemp(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind));
}
return out;
return temp;
}
// temp from ptemp and sal
if(vname == "temp")
@ -210,16 +209,15 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto temp = Read("ptemp", ip, i);
auto sal = Read("sal", ip, i);
if(!(temp && sal)) return Data();
auto out = temp;
out.SetUnit("degrees_C");
for(size_t ind = 0; ind < out.N(); ind++)
temp.SetUnit("degrees_C");
for(size_t ind = 0; ind < temp.N(); ind++)
{
if(temp.IsFill(ind) || sal.IsFill(ind))
out.V(ind) = out.Fillval();
temp.V(ind) = temp.Fillval();
else
out.V(ind) = PTemp2Temp(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind));
temp.V(ind) = PTemp2Temp(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind));
}
return out;
return temp;
}
// pdens from temp and sal
if(vname == "pdens")
@ -228,17 +226,16 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto temp = Read(tempispot ? "ptemp" : "temp", ip, i);
auto sal = Read("sal", ip, i);
if(!(temp && sal)) return Data();
auto out = temp;
out.SetUnit("kg m-3");
for(size_t ind = 0; ind < out.N(); ind++)
temp.SetUnit("kg m-3");
for(size_t ind = 0; ind < temp.N(); ind++)
{
if(temp.IsFill(ind) || sal.IsFill(ind))
out.V(ind) = out.Fillval();
temp.V(ind) = temp.Fillval();
else
out.V(ind) = tempispot ? PTemp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind))
: Temp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind));
temp.V(ind) = tempispot ? PTemp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind))
: Temp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind));
}
return out;
return temp;
}
// U and U2 from u and v
if(vname == "U" || vname == "U2")
@ -247,16 +244,15 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto u = Read("u", ip, i);
auto v = Read("v", ip, i);
if(!(u && v)) return Data();
auto out = u;
out.SetUnit(square ? ("(" + u.Unit() + ")2") : u.Unit());
for(size_t ind = 0; ind < out.N(); ind++)
if(square && u.Unit().Exist()) u.SetUnit("(" + u.Unit() + ")2");
for(size_t ind = 0; ind < u.N(); ind++)
{
if(u.IsFill(ind) || v.IsFill(ind))
out.V(ind) = out.Fillval();
u.V(ind) = u.Fillval();
else
out.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
u.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
}
return out;
return u;
}
return Data();
}

Loading…
Cancel
Save