Skip to content

Commit

Permalink
MMVII: Fix GetV() : parse has failed only if failbit or badbit is set
Browse files Browse the repository at this point in the history
Also fix API to report the true origin (file,line) of the error
  • Loading branch information
meynardc committed May 16, 2024
1 parent 8edc558 commit 5e319be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 48 deletions.
9 changes: 3 additions & 6 deletions MMVII/include/MMVII_Stringifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,13 @@ class cCmpSerializer
};
*/

static std::string CurFile; /// global var to get context, not proud of that
static int CurLine; /// global var to get context, not proud of that

template<class Type> inline Type GetV(std::istringstream & iss)
template<class Type> inline Type GetV(std::istringstream & iss, const std::string& aSrcFile, int aSrcLine)
{
Type aNum;
iss >> aNum;
if ( iss.rdstate())
if ( ! iss)
{
MMVII_UnclasseUsEr("Bad reading at line " + ToStr(CurLine) + " of file [" + CurFile + "] , rdstate=" + ToStr((size_t)iss.rdstate()));
MMVII_UnclasseUsEr("Bad reading at line " + aSrcFile + " of file [" + std::to_string(aSrcLine+1) + "] , rdstate=" + ToStr((size_t)iss.rdstate()));
}
return aNum;
}
Expand Down
9 changes: 4 additions & 5 deletions MMVII/src/ConvertFormat/ImportClino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,23 @@ void cAppli_CERN_ImportClino::MakeOneDir(const std::string & aDir,cMMVII_Ofs & a
StdOut() << "DDD " << aDir << " " << aVFileIm << "\n";

std::string line;
// mNbLineRead = 0;
// int aNumL = 0;
int aNumL = 0;
cCarLookUpTable aLUT;
aLUT.InitIdGlob();
aLUT.Init("[],",' ');
while (std::getline(infile, line))
{
line = aLUT.Translate(line);
// StdOut() << "DDD=" << aDir << " [" << line << "]\n";
std::istringstream iss(line);

for (const auto & aNameClino : mNamesClino)
{
tREAL8 aAvg = GetV<tREAL8>(iss);
tREAL8 aStdDev = GetV<tREAL8>(iss);
tREAL8 aAvg = GetV<tREAL8>(iss,aNameF,aNumL);
tREAL8 aStdDev = GetV<tREAL8>(iss,aNameF,aNumL);
StdOut() << " * " << aNameClino << " " << aAvg << " " << aStdDev << "\n";
anOFS.Ofs() << " " << aNameClino << " " << aAvg << " " << aStdDev ;
}
aNumL++;
}
anOFS.Ofs() << std::endl;
}
Expand Down
62 changes: 25 additions & 37 deletions MMVII/src/Utils/uti_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ void cReadFilesStruct::SetMemoLinesInit()

void cReadFilesStruct::Read()
{
CurFile = mNameFile;


/*
char aLut[256];
Expand Down Expand Up @@ -307,11 +305,6 @@ void cReadFilesStruct::Read()
int aNumL = 0;
while (std::getline(infile, line))
{
// StdOut() << "LllllInnneee=" << aNumL << "\n";
// JOE
MMVII_DEV_WARNING("Dont understand why must add \" \" at end of line ReadFilesStruct");
line += " ";
CurLine = aNumL+1; // editor begin at line 1, non 0
/*
for (size_t aK=0 ; aK<line.size() ; aK++)
line[aK] = aLut[line[aK]];
Expand Down Expand Up @@ -354,23 +347,23 @@ void cReadFilesStruct::Read()
{
switch (aCar)
{
case 'F' : aLNum.push_back(GetV<tREAL8>(iss)); initF++; break;
case 'E' : aLInt.push_back(GetV<int>(iss)); initI++; break;
case 'X' : aXYZ.x() = GetV<tREAL8>(iss); initXYZ++; break;
case 'Y' : aXYZ.y() = GetV<tREAL8>(iss); initXYZ++; break;
case 'Z' : aXYZ.z() = GetV<tREAL8>(iss); initXYZ++; break;
case 'F' : aLNum.push_back(GetV<tREAL8>(iss,mNameFile,mNbLineRead)); initF++; break;
case 'E' : aLInt.push_back(GetV<int>(iss,mNameFile,mNbLineRead)); initI++; break;
case 'X' : aXYZ.x() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initXYZ++; break;
case 'Y' : aXYZ.y() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initXYZ++; break;
case 'Z' : aXYZ.z() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initXYZ++; break;

case 'W' : aWPK.x() = GetV<tREAL8>(iss); initWPK++; break;
case 'P' : aWPK.y() = GetV<tREAL8>(iss); initWPK++; break;
case 'K' : aWPK.z() = GetV<tREAL8>(iss); initWPK++; break;
case 'W' : aWPK.x() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initWPK++; break;
case 'P' : aWPK.y() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initWPK++; break;
case 'K' : aWPK.z() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initWPK++; break;

case 'i' : aij.x() = GetV<tREAL8>(iss); initij++; break;
case 'j' : aij.y() = GetV<tREAL8>(iss); initij++; break;
case 'i' : aij.x() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initij++; break;
case 'j' : aij.y() = GetV<tREAL8>(iss,mNameFile,mNbLineRead); initij++; break;

case 'N' : aNamePt = GetV<std::string>(iss); initPt++; break;
case 'I' : aNameIm = GetV<std::string>(iss); initIm++; break;
case 'S' : aLString.push_back(GetV<std::string>(iss)); initString++; break;
case '#' : GetV<std::string>(iss); break;
case 'N' : aNamePt = GetV<std::string>(iss,mNameFile,mNbLineRead); initPt++; break;
case 'I' : aNameIm = GetV<std::string>(iss,mNameFile,mNbLineRead); initIm++; break;
case 'S' : aLString.push_back(GetV<std::string>(iss,mNameFile,mNbLineRead)); initString++; break;
case '#' : GetV<std::string>(iss,mNameFile,mNbLineRead); break;

default :
MMVII_INTERNAL_ERROR(std::string(("Unhandled car in cReadFilesStruct::Read=") + aCar)+"]");
Expand Down Expand Up @@ -409,7 +402,6 @@ void ReadFilesStruct
bool CheckFormat
)
{
CurFile = aNameFile;
if (CheckFormat)
{
CptSameOccur(aFormat,"NXYZ");
Expand All @@ -434,10 +426,6 @@ void ReadFilesStruct
int aNumL = 0;
while (std::getline(infile, line))
{
// JOE
MMVII_DEV_WARNING("Dont understand why must add \" \" at end of line ReadFilesStruct");
line += " ";
CurLine = aNumL+1; // editor begin at line 1, non 0
if ((aNumL>=aL0) && (aNumL<aLastL))
{
std::istringstream iss(line);
Expand All @@ -454,22 +442,22 @@ line += " ";
{
switch (aCar)
{
case 'F' : aLNum.push_back(GetV<tREAL8>(iss)); break;
case 'X' : aXYZ.x() = GetV<tREAL8>(iss); break;
case 'Y' : aXYZ.y() = GetV<tREAL8>(iss); break;
case 'Z' : aXYZ.z() = GetV<tREAL8>(iss); break;
case 'F' : aLNum.push_back(GetV<tREAL8>(iss,aNameFile,aNumL)); break;
case 'X' : aXYZ.x() = GetV<tREAL8>(iss,aNameFile,aNumL); break;
case 'Y' : aXYZ.y() = GetV<tREAL8>(iss,aNameFile,aNumL); break;
case 'Z' : aXYZ.z() = GetV<tREAL8>(iss,aNameFile,aNumL); break;

case 'W' : aWKP.x() = GetV<tREAL8>(iss); break;
case 'P' : aWKP.y() = GetV<tREAL8>(iss); break;
case 'K' : aWKP.z() = GetV<tREAL8>(iss); break;
case 'W' : aWKP.x() = GetV<tREAL8>(iss,aNameFile,aNumL); break;
case 'P' : aWKP.y() = GetV<tREAL8>(iss,aNameFile,aNumL); break;
case 'K' : aWKP.z() = GetV<tREAL8>(iss,aNameFile,aNumL); break;

// case 'i' : aWKP.x() = GetV<tREAL8>(iss); break;
// case 'j' : aWKP.y() = GetV<tREAL8>(iss); break;

case 'N' : aLNames.push_back(GetV<std::string>(iss)); break;
case 'I' : aLNames.push_back(GetV<std::string>(iss)); break;
case 'A' : aLNames.push_back(GetV<std::string>(iss)); break;
case 'S' : GetV<std::string>(iss); break;
case 'N' : aLNames.push_back(GetV<std::string>(iss,aNameFile,aNumL)); break;
case 'I' : aLNames.push_back(GetV<std::string>(iss,aNameFile,aNumL)); break;
case 'A' : aLNames.push_back(GetV<std::string>(iss,aNameFile,aNumL)); break;
case 'S' : GetV<std::string>(iss,aNameFile,aNumL); break;

default :
break;
Expand Down

0 comments on commit 5e319be

Please sign in to comment.