Fix for bug 10498. Support old storage format of NumberOfSegments hypothesis

This commit is contained in:
jfa 2005-11-25 15:58:28 +00:00
parent 5bbfd7c156
commit b90943f064

View File

@ -474,8 +474,18 @@ istream & StdMeshers_NumberOfSegments::LoadFrom(istream & load)
else else
load.clear(ios::badbit | load.rdstate()); load.clear(ios::badbit | load.rdstate());
// read ditribution type // read second stored value. It can be two variants here:
isOK = (load >> a); // 1. If the hypothesis is stored in old format (nb.segments and scale factor),
// we wait here the scale factor, which is double.
// 2. If the hypothesis is stored in new format
// (nb.segments, distr.type, some other params.),
// we wait here the ditribution type, which is integer
double scale_factor;
isOK = (load >> scale_factor);
a = (int)scale_factor;
// try to interprete ditribution type,
// supposing that this hypothesis was written in the new format
if (isOK) if (isOK)
{ {
if (a < DT_Regular || a > DT_ExprFunc) if (a < DT_Regular || a > DT_ExprFunc)
@ -496,24 +506,36 @@ istream & StdMeshers_NumberOfSegments::LoadFrom(istream & load)
if (isOK) if (isOK)
_scaleFactor = b; _scaleFactor = b;
else else
{
load.clear(ios::badbit | load.rdstate()); load.clear(ios::badbit | load.rdstate());
// this can mean, that the hypothesis is stored in old format
_distrType = DT_Regular;
_scaleFactor = scale_factor;
}
} }
break; break;
case DT_TabFunc: case DT_TabFunc:
{ {
isOK = (load >> a); isOK = (load >> a);
if (isOK) if (isOK)
_table.resize(a, 0.);
else
load.clear(ios::badbit | load.rdstate());
int i;
for (i=0; i < _table.size(); i++)
{ {
isOK = (load >> b); _table.resize(a, 0.);
if (isOK) int i;
_table[i] = b; for (i=0; i < _table.size(); i++)
else {
load.clear(ios::badbit | load.rdstate()); isOK = (load >> b);
if (isOK)
_table[i] = b;
else
load.clear(ios::badbit | load.rdstate());
}
}
else
{
load.clear(ios::badbit | load.rdstate());
// this can mean, that the hypothesis is stored in old format
_distrType = DT_Regular;
_scaleFactor = scale_factor;
} }
} }
break; break;
@ -524,7 +546,12 @@ istream & StdMeshers_NumberOfSegments::LoadFrom(istream & load)
if (isOK) if (isOK)
_func = str; _func = str;
else else
{
load.clear(ios::badbit | load.rdstate()); load.clear(ios::badbit | load.rdstate());
// this can mean, that the hypothesis is stored in old format
_distrType = DT_Regular;
_scaleFactor = scale_factor;
}
} }
break; break;
case DT_Regular: case DT_Regular: