STYLE: avoid IStringStream when parsing primitives

This commit is contained in:
Mark Olesen
2017-09-21 16:10:33 +02:00
parent accebc74ee
commit a4e63e2bfb
7 changed files with 84 additions and 105 deletions

View File

@ -143,7 +143,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
const word subWord = w.substr(start, i-start); const word subWord = w.substr(start, i-start);
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT) if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
{ {
push(token(readScalar(IStringStream(subWord)()))); push(token(readScalar(subWord)));
} }
else else
{ {
@ -154,7 +154,9 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
{ {
if (isdigit(w[i])) if (isdigit(w[i]))
{ {
push(token(readScalar(IStringStream(w[i])()))); // Single digit: as scalar value
const scalar val = (w[i] - '0');
push(token(val));
} }
else else
{ {
@ -169,7 +171,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
const word subWord = w.substr(start); const word subWord = w.substr(start);
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT) if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
{ {
push(token(readScalar(IStringStream(subWord)()))); push(token(readScalar(subWord)));
} }
else else
{ {
@ -539,7 +541,7 @@ Foam::Istream& Foam::dimensionSet::read
{ {
const word symbol = symbolPow.substr(0, index); const word symbol = symbolPow.substr(0, index);
const word exp = symbolPow.substr(index+1); const word exp = symbolPow.substr(index+1);
scalar exponent = readScalar(IStringStream(exp)()); scalar exponent = readScalar(exp);
dimensionedScalar s; dimensionedScalar s;
s.read(readSet[symbol], readSet); s.read(readSet[symbol], readSet);

View File

@ -71,7 +71,7 @@ namespace Foam
<< exit(FatalError); << exit(FatalError);
} }
return readScalar(IStringStream(splitted[componentColumns_[0]])()); return readScalar(splitted[componentColumns_[0]]);
} }
@ -80,7 +80,7 @@ namespace Foam
{ {
Type result; Type result;
for(label i = 0;i < pTraits<Type>::nComponents; i++) for (label i = 0; i < pTraits<Type>::nComponents; ++i)
{ {
if (componentColumns_[i] >= splitted.size()) if (componentColumns_[i] >= splitted.size())
{ {
@ -90,10 +90,7 @@ namespace Foam
<< exit(FatalError); << exit(FatalError);
} }
result[i] = readScalar result[i] = readScalar(splitted[componentColumns_[i]]);
(
IStringStream(splitted[componentColumns_[i]])()
);
} }
return result; return result;
@ -150,7 +147,7 @@ void Foam::csvTableReader<Type>::operator()
break; break;
} }
scalar time = readScalar(IStringStream(splitted[timeColumn_])()); scalar time = readScalar(splitted[timeColumn_]);
Type value = readValue(splitted); Type value = readValue(splitted);
values.append(Tuple2<scalar,Type>(time, value)); values.append(Tuple2<scalar,Type>(time, value));

View File

@ -43,7 +43,7 @@ Foam::label Foam::Function1Types::CSV<Foam::label>::readValue
<< exit(FatalError); << exit(FatalError);
} }
return readLabel(IStringStream(splitted[componentColumns_[0]])()); return readLabel(splitted[componentColumns_[0]]);
} }
@ -61,7 +61,7 @@ Foam::scalar Foam::Function1Types::CSV<Foam::scalar>::readValue
<< exit(FatalError); << exit(FatalError);
} }
return readScalar(IStringStream(splitted[componentColumns_[0]])()); return readScalar(splitted[componentColumns_[0]]);
} }
@ -70,18 +70,17 @@ Type Foam::Function1Types::CSV<Type>::readValue(const List<string>& splitted)
{ {
Type result; Type result;
for (label i = 0; i < pTraits<Type>::nComponents; i++) for (label i = 0; i < pTraits<Type>::nComponents; ++i)
{ {
if (componentColumns_[i] >= splitted.size()) if (componentColumns_[i] >= splitted.size())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "No column " << componentColumns_[i] << " in " << "No column " << componentColumns_[i] << " in "
<< splitted << endl << splitted << endl
<< exit(FatalError); << exit(FatalError);
} }
result[i] = result[i] = readScalar(splitted[componentColumns_[i]]);
readScalar(IStringStream(splitted[componentColumns_[i]])());
} }
return result; return result;
@ -189,7 +188,7 @@ void Foam::Function1Types::CSV<Type>::read()
break; break;
} }
scalar x = readScalar(IStringStream(splitted[refColumn_])()); scalar x = readScalar(splitted[refColumn_]);
Type value = readValue(splitted); Type value = readValue(splitted);
values.append(Tuple2<scalar,Type>(x, value)); values.append(Tuple2<scalar,Type>(x, value));

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -103,9 +103,9 @@ bool Foam::fileFormats::NASedgeFormat::read
{ {
edge e; edge e;
// label groupId = readLabel(IStringStream(line.substr(16,8))()); // label groupId = readLabel(line.substr(16,8));
e[0] = readLabel(IStringStream(line.substr(24,8))()); e[0] = readLabel(line.substr(24,8));
e[1] = readLabel(IStringStream(line.substr(32,8))()); e[1] = readLabel(line.substr(32,8));
// discard groupID // discard groupID
dynEdges.append(e); dynEdges.append(e);
@ -114,19 +114,19 @@ bool Foam::fileFormats::NASedgeFormat::read
{ {
edge e; edge e;
// label groupId = readLabel(IStringStream(line.substr(16,8))()); // label groupId = readLabel(line.substr(16,8));
e[0] = readLabel(IStringStream(line.substr(16,8))()); e[0] = readLabel(line.substr(16,8));
e[1] = readLabel(IStringStream(line.substr(24,8))()); e[1] = readLabel(line.substr(24,8));
// discard groupID // discard groupID
dynEdges.append(e); dynEdges.append(e);
} }
else if (cmd == "GRID") else if (cmd == "GRID")
{ {
label index = readLabel(IStringStream(line.substr(8,8))()); label index = readLabel(line.substr(8,8));
scalar x = parseNASCoord(line.substr(24, 8)); scalar x = readNasScalar(line.substr(24, 8));
scalar y = parseNASCoord(line.substr(32, 8)); scalar y = readNasScalar(line.substr(32, 8));
scalar z = parseNASCoord(line.substr(40, 8)); scalar z = readNasScalar(line.substr(40, 8));
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));
@ -139,9 +139,9 @@ bool Foam::fileFormats::NASedgeFormat::read
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02 // * 2.14897901E+02
label index = readLabel(IStringStream(line.substr(8,16))()); label index = readLabel(line.substr(8,16));
scalar x = parseNASCoord(line.substr(40, 16)); scalar x = readNasScalar(line.substr(40, 16));
scalar y = parseNASCoord(line.substr(56, 16)); scalar y = readNasScalar(line.substr(56, 16));
is.getLine(line); is.getLine(line);
if (line[0] != '*') if (line[0] != '*')
@ -153,7 +153,7 @@ bool Foam::fileFormats::NASedgeFormat::read
<< "File:" << is.name() << " line:" << is.lineNumber() << "File:" << is.name() << " line:" << is.lineNumber()
<< exit(FatalError); << exit(FatalError);
} }
scalar z = parseNASCoord(line.substr(8, 16)); scalar z = readNasScalar(line.substr(8, 16));
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));

View File

@ -92,9 +92,9 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// ANSA extension // ANSA extension
if (line.startsWith("$ANSA_NAME")) if (line.startsWith("$ANSA_NAME"))
{ {
string::size_type sem0 = line.find(';', 0); const auto sem0 = line.find(';', 0);
string::size_type sem1 = line.find(';', sem0+1); const auto sem1 = line.find(';', sem0+1);
string::size_type sem2 = line.find(';', sem1+1); const auto sem2 = line.find(';', sem1+1);
if if
( (
@ -103,10 +103,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
&& sem2 != string::npos && sem2 != string::npos
) )
{ {
ansaId = readLabel ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
(
IStringStream(line.substr(sem0+1, sem1-sem0-1))()
);
ansaType = line.substr(sem1+1, sem2-sem1-1); ansaType = line.substr(sem1+1, sem2-sem1-1);
string rawName; string rawName;
@ -125,11 +122,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// $HMNAME COMP 1"partName" // $HMNAME COMP 1"partName"
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos) if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
{ {
label groupId = readLabel label groupId = readLabel(line.substr(16, 16));
(
IStringStream(line.substr(16, 16))()
);
IStringStream lineStream(line.substr(32)); IStringStream lineStream(line.substr(32));
string rawName; string rawName;
@ -177,10 +170,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
if (cmd == "CTRIA3") if (cmd == "CTRIA3")
{ {
label groupId = readLabel(IStringStream(line.substr(16,8))()); label groupId = readLabel(line.substr(16,8));
label a = readLabel(IStringStream(line.substr(24,8))()); label a = readLabel(line.substr(24,8));
label b = readLabel(IStringStream(line.substr(32,8))()); label b = readLabel(line.substr(32,8));
label c = readLabel(IStringStream(line.substr(40,8))()); label c = readLabel(line.substr(40,8));
// Convert groupID into zoneId // Convert groupID into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId); Map<label>::const_iterator fnd = lookup.find(groupId);
@ -207,11 +200,11 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
else if (cmd == "CQUAD4") else if (cmd == "CQUAD4")
{ {
label groupId = readLabel(IStringStream(line.substr(16,8))()); label groupId = readLabel(line.substr(16,8));
label a = readLabel(IStringStream(line.substr(24,8))()); label a = readLabel(line.substr(24,8));
label b = readLabel(IStringStream(line.substr(32,8))()); label b = readLabel(line.substr(32,8));
label c = readLabel(IStringStream(line.substr(40,8))()); label c = readLabel(line.substr(40,8));
label d = readLabel(IStringStream(line.substr(48,8))()); label d = readLabel(line.substr(48,8));
// Convert groupID into zoneId // Convert groupID into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId); Map<label>::const_iterator fnd = lookup.find(groupId);
@ -249,10 +242,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
else if (cmd == "GRID") else if (cmd == "GRID")
{ {
label index = readLabel(IStringStream(line.substr(8,8))()); label index = readLabel(line.substr(8,8));
scalar x = parseNASCoord(line.substr(24, 8)); scalar x = readNasScalar(line.substr(24, 8));
scalar y = parseNASCoord(line.substr(32, 8)); scalar y = readNasScalar(line.substr(32, 8));
scalar z = parseNASCoord(line.substr(40, 8)); scalar z = readNasScalar(line.substr(40, 8));
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));
@ -265,9 +258,9 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02 // * 2.14897901E+02
label index = readLabel(IStringStream(line.substr(8,16))()); label index = readLabel(line.substr(8,16));
scalar x = parseNASCoord(line.substr(40, 16)); scalar x = readNasScalar(line.substr(40, 16));
scalar y = parseNASCoord(line.substr(56, 16)); scalar y = readNasScalar(line.substr(56, 16));
is.getLine(line); is.getLine(line);
if (line[0] != '*') if (line[0] != '*')
@ -279,7 +272,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
<< "File:" << is.name() << " line:" << is.lineNumber() << "File:" << is.name() << " line:" << is.lineNumber()
<< exit(FatalError); << exit(FatalError);
} }
scalar z = parseNASCoord(line.substr(8, 16)); scalar z = readNasScalar(line.substr(8, 16));
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));
@ -287,7 +280,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
else if (cmd == "PSHELL") else if (cmd == "PSHELL")
{ {
// pshell type for zone names with the Ansa extension // pshell type for zone names with the Ansa extension
label groupId = readLabel(IStringStream(line.substr(8,8))()); label groupId = readLabel(line.substr(8,8));
if (groupId == ansaId && ansaType == "PSHELL") if (groupId == ansaId && ansaType == "PSHELL")
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,9 +47,9 @@ namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Do weird things to extract number // Do weird things to extract number
static inline scalar parseNASCoord(const string& s) static inline scalar readNasScalar(const string& s)
{ {
return fileFormats::NASCore::parseNASCoord(s); return Foam::fileFormats::NASCore::readNasScalar(s);
} }
@ -118,9 +118,9 @@ bool triSurface::readNAS(const fileName& fName)
// ANSA extension // ANSA extension
if (line.startsWith("$ANSA_NAME")) if (line.startsWith("$ANSA_NAME"))
{ {
string::size_type sem0 = line.find(';', 0); const auto sem0 = line.find(';', 0);
string::size_type sem1 = line.find(';', sem0+1); const auto sem1 = line.find(';', sem0+1);
string::size_type sem2 = line.find(';', sem1+1); const auto sem2 = line.find(';', sem1+1);
if if
( (
@ -129,10 +129,7 @@ bool triSurface::readNAS(const fileName& fName)
&& sem2 != string::npos && sem2 != string::npos
) )
{ {
ansaId = readLabel ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
(
IStringStream(line.substr(sem0+1, sem1-sem0-1))()
);
ansaType = line.substr(sem1+1, sem2-sem1-1); ansaType = line.substr(sem1+1, sem2-sem1-1);
string nameString; string nameString;
@ -152,11 +149,7 @@ bool triSurface::readNAS(const fileName& fName)
// $HMNAME COMP 1"partName" // $HMNAME COMP 1"partName"
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos) if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
{ {
label groupId = readLabel label groupId = readLabel(line.substr(16, 16));
(
IStringStream(line.substr(16, 16))()
);
IStringStream lineStream(line.substr(32)); IStringStream lineStream(line.substr(32));
string rawName; string rawName;
@ -202,11 +195,10 @@ bool triSurface::readNAS(const fileName& fName)
if (cmd == "CTRIA3") if (cmd == "CTRIA3")
{ {
readNASToken(line, 8, linei); readNASToken(line, 8, linei);
label groupId = label groupId = readLabel(readNASToken(line, 8, linei));
readLabel(IStringStream(readNASToken(line, 8, linei))()); label a = readLabel(readNASToken(line, 8, linei));
label a = readLabel(IStringStream(readNASToken(line, 8, linei))()); label b = readLabel(readNASToken(line, 8, linei));
label b = readLabel(IStringStream(readNASToken(line, 8, linei))()); label c = readLabel(readNASToken(line, 8, linei));
label c = readLabel(IStringStream(readNASToken(line, 8, linei))());
// Convert group into patch // Convert group into patch
Map<label>::const_iterator iter = groupToPatch.find(groupId); Map<label>::const_iterator iter = groupToPatch.find(groupId);
@ -228,12 +220,11 @@ bool triSurface::readNAS(const fileName& fName)
else if (cmd == "CQUAD4") else if (cmd == "CQUAD4")
{ {
readNASToken(line, 8, linei); readNASToken(line, 8, linei);
label groupId = label groupId = readLabel(readNASToken(line, 8, linei));
readLabel(IStringStream(readNASToken(line, 8, linei))()); label a = readLabel(readNASToken(line, 8, linei));
label a = readLabel(IStringStream(readNASToken(line, 8, linei))()); label b = readLabel(readNASToken(line, 8, linei));
label b = readLabel(IStringStream(readNASToken(line, 8, linei))()); label c = readLabel(readNASToken(line, 8, linei));
label c = readLabel(IStringStream(readNASToken(line, 8, linei))()); label d = readLabel(readNASToken(line, 8, linei));
label d = readLabel(IStringStream(readNASToken(line, 8, linei))());
// Convert group into patch // Convert group into patch
Map<label>::const_iterator iter = groupToPatch.find(groupId); Map<label>::const_iterator iter = groupToPatch.find(groupId);
@ -256,8 +247,7 @@ bool triSurface::readNAS(const fileName& fName)
else if (cmd == "PSHELL") else if (cmd == "PSHELL")
{ {
// Read shell type since group gives patchnames // Read shell type since group gives patchnames
label groupId = label groupId = readLabel(readNASToken(line, 8, linei));
readLabel(IStringStream(readNASToken(line, 8, linei))());
if (groupId == ansaId && ansaType == "PSHELL") if (groupId == ansaId && ansaType == "PSHELL")
{ {
const word groupName = word::validate(ansaName); const word groupName = word::validate(ansaName);
@ -267,12 +257,11 @@ bool triSurface::readNAS(const fileName& fName)
} }
else if (cmd == "GRID") else if (cmd == "GRID")
{ {
label index = label index = readLabel(readNASToken(line, 8, linei));
readLabel(IStringStream(readNASToken(line, 8, linei))());
readNASToken(line, 8, linei); readNASToken(line, 8, linei);
scalar x = parseNASCoord(readNASToken(line, 8, linei)); scalar x = readNasScalar(readNASToken(line, 8, linei));
scalar y = parseNASCoord(readNASToken(line, 8, linei)); scalar y = readNasScalar(readNASToken(line, 8, linei));
scalar z = parseNASCoord(readNASToken(line, 8, linei)); scalar z = readNasScalar(readNASToken(line, 8, linei));
indices.append(index); indices.append(index);
points.append(point(x, y, z)); points.append(point(x, y, z));
@ -284,11 +273,10 @@ bool triSurface::readNAS(const fileName& fName)
// Typical line (spaces compacted) // Typical line (spaces compacted)
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02 // * 2.14897901E+02
label index = label index = readLabel(readNASToken(line, 16, linei));
readLabel(IStringStream(readNASToken(line, 16, linei))());
readNASToken(line, 16, linei); readNASToken(line, 16, linei);
scalar x = parseNASCoord(readNASToken(line, 16, linei)); scalar x = readNasScalar(readNASToken(line, 16, linei));
scalar y = parseNASCoord(readNASToken(line, 16, linei)); scalar y = readNasScalar(readNASToken(line, 16, linei));
linei = 0; linei = 0;
is.getLine(line); is.getLine(line);
@ -303,7 +291,7 @@ bool triSurface::readNAS(const fileName& fName)
<< exit(FatalError); << exit(FatalError);
} }
readNASToken(line, 8, linei); readNASToken(line, 8, linei);
scalar z = parseNASCoord(readNASToken(line, 16, linei)); scalar z = readNasScalar(readNASToken(line, 16, linei));
indices.append(index); indices.append(index);
points.append(point(x, y, z)); points.append(point(x, y, z));

View File

@ -531,11 +531,11 @@ void Foam::radiation::fvDOM::setRayIdLambdaId
) const ) const
{ {
// assuming name is in the form: CHARS_rayId_lambdaId // assuming name is in the form: CHARS_rayId_lambdaId
const size_type i1 = name.find('_'); const auto i1 = name.find('_');
const size_type i2 = name.rfind('_'); const auto i2 = name.rfind('_');
rayId = readLabel(IStringStream(name.substr(i1+1, i2-1))()); rayId = readLabel(name.substr(i1+1, i2-1));
lambdaId = readLabel(IStringStream(name.substr(i2+1))()); lambdaId = readLabel(name.substr(i2+1));
} }