Commit 817a2d90 authored by Laurent Belcour's avatar Laurent Belcour

Correction of the shared pointer affectation issue.

parent 21a54898
......@@ -81,7 +81,7 @@ template<class T> class ptr
~ptr()
{
_counter->decrement();
if(_counter->value() == 0)
if(_counter->value() < 1 || _ptr == NULL)
{
if(_ptr != NULL) { delete _ptr; }
delete _counter;
......@@ -95,6 +95,27 @@ template<class T> class ptr
return _ptr;
}
//! Assignment operator. If a valid pointer is already present, its
//! counter is decremented and the pointer and counter might be
//! deleted in case the counter reach zero. Then, the elements of
//! a, both counter and pointer, are copied to this and the counter
//! is incremented.
ptr<T>& operator=(const ptr<T>& a)
{
_counter->decrement();
if(_counter->value() < 1)
{
if(_ptr != NULL) { delete _ptr; }
delete _counter;
}
_counter = a._counter;
_ptr = a._ptr;
_counter->increment();
return *this;
}
//! Raw acces to the pointer. It is sometimes needed to
inline T* get() const
{
......
......@@ -278,7 +278,7 @@ vec vertical_segment::get(int i) const
//! is not already present.
void vertical_segment::set(vec x)
{
assert(x.size() == dimX() + dimY());
// assert(x.size() == dimX() + dimY() || x.size() == dimX() + 3*dimY());
_data.push_back(x);
}
......
......@@ -48,14 +48,18 @@ bool rational_fitter_parallel::fit_data(const ptr<data> dat, function* fit, cons
std::cerr << "<<WARNING>> we advise you to perform convertion with a separate command." << std::endl;
ptr<vertical_segment> vs(new vertical_segment());
vs->setDimX(dat->dimX());
vs->setDimY(dat->dimY());
vs->setMin(dat->min()) ;
vs->setMax(dat->max()) ;
for(int i=0; i<dat->size(); ++i)
{
const vec x = dat->get(i);
vec y(dat->dimX() + 3*dat->dimY());
for(int k=0; k<x.size() ; ++k) { y[k] = x[k]; }
for(int k=0; k<dat->dimY(); ++k) { y[k + x.size() + dat->dimY()] = (1.0 - args.get_float("dt", 0.1)) * x[k + dat->dimX()]; }
for(int k=0; k<dat->dimY(); ++k) { y[k + x.size() + 2*dat->dimY()] = (1.0 + args.get_float("dt", 0.1)) * x[k + dat->dimX()]; }
for(int k=0; k<x.size() ; ++k) { y[k] = x[k]; }
for(int k=0; k<dat->dimY(); ++k) { y[k + dat->dimX() + dat->dimY()] = (1.0 - args.get_float("dt", 0.1)) * x[k + dat->dimX()]; }
for(int k=0; k<dat->dimY(); ++k) { y[k + dat->dimX() + 2*dat->dimY()] = (1.0 + args.get_float("dt", 0.1)) * x[k + dat->dimX()]; }
vs->set(y);
}
......
......@@ -7,7 +7,7 @@
* or to perform interpolation of sample values (i.e. to fill gaps).
*
* <h3>Usage</h3>
* \verbatim
* \verbatim
data2data --input data.file --output data.file --out-data exporter.so --in-data importer.so
\endverbatim
*
......@@ -96,14 +96,14 @@ int main(int argc, char** argv)
return 1 ;
}
*/
// Import data
ptr<data> d_in = plugins_manager::get_data(args["in-data"]) ;
d_in->load(args["input"], args);
ptr<data> d_out = plugins_manager::get_data(args["out-data"]) ;
if(!d_in && !d_out)
{
std::cerr << "<<ERROR>> cannot import or export data" << std::endl ;
......@@ -136,7 +136,7 @@ int main(int argc, char** argv)
// Copy the input vector
vec x = d_in->get(i);
params::convert(&x[0], d_in->parametrization(), d_out->parametrization(), &temp[0]);
for(int j=0; j<d_in->dimY(); ++j)
{
temp[d_out->dimX() + j] = x[d_in->dimX() + j];
......@@ -144,7 +144,7 @@ int main(int argc, char** argv)
d_out->set(temp);
}
}
}
else
{
......@@ -168,8 +168,8 @@ int main(int argc, char** argv)
}
d_out->set(x);
}
}
}
}
d_out->save(args["output"]);
return 0 ;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment