Commit 1c649817 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: avoid IStringStream when parsing primitives

parent 41f59b07
......@@ -143,7 +143,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
const word subWord = w.substr(start, i-start);
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
{
push(token(readScalar(IStringStream(subWord)())));
push(token(readScalar(subWord)));
}
else
{
......@@ -154,7 +154,9 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
{
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
{
......@@ -169,7 +171,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
const word subWord = w.substr(start);
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
{
push(token(readScalar(IStringStream(subWord)())));
push(token(readScalar(subWord)));
}
else
{
......@@ -539,7 +541,7 @@ Foam::Istream& Foam::dimensionSet::read
{
const word symbol = symbolPow.substr(0, index);
const word exp = symbolPow.substr(index+1);
scalar exponent = readScalar(IStringStream(exp)());
scalar exponent = readScalar(exp);
dimensionedScalar s;
s.read(readSet[symbol], readSet);
......
......@@ -71,7 +71,7 @@ namespace Foam
<< exit(FatalError);
}
return readScalar(IStringStream(splitted[componentColumns_[0]])());
return readScalar(splitted[componentColumns_[0]]);
}
......@@ -80,7 +80,7 @@ namespace Foam
{
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())
{
......@@ -90,10 +90,7 @@ namespace Foam
<< exit(FatalError);
}
result[i] = readScalar
(
IStringStream(splitted[componentColumns_[i]])()
);
result[i] = readScalar(splitted[componentColumns_[i]]);
}
return result;
......@@ -150,7 +147,7 @@ void Foam::csvTableReader<Type>::operator()
break;
}
scalar time = readScalar(IStringStream(splitted[timeColumn_])());
scalar time = readScalar(splitted[timeColumn_]);
Type value = readValue(splitted);
values.append(Tuple2<scalar,Type>(time, value));
......
......@@ -43,7 +43,7 @@ Foam::label Foam::Function1Types::CSV<Foam::label>::readValue
<< 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);
}
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;
for (label i = 0; i < pTraits<Type>::nComponents; i++)
for (label i = 0; i < pTraits<Type>::nComponents; ++i)
{
if (componentColumns_[i] >= splitted.size())
{
FatalErrorInFunction
<< "No column " << componentColumns_[i] << " in "
<< "No column " << componentColumns_[i] << " in "
<< splitted << endl
<< exit(FatalError);
}
result[i] =
readScalar(IStringStream(splitted[componentColumns_[i]])());
result[i] = readScalar(splitted[componentColumns_[i]]);
}
return result;
......@@ -189,7 +188,7 @@ void Foam::Function1Types::CSV<Type>::read()
break;
}
scalar x = readScalar(IStringStream(splitted[refColumn_])());
scalar x = readScalar(splitted[refColumn_]);
Type value = readValue(splitted);
values.append(Tuple2<scalar,Type>(x, value));
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -103,9 +103,9 @@ bool Foam::fileFormats::NASedgeFormat::read
{
edge e;
// label groupId = readLabel(IStringStream(line.substr(16,8))());
e[0] = readLabel(IStringStream(line.substr(24,8))());
e[1] = readLabel(IStringStream(line.substr(32,8))());
// label groupId = readLabel(line.substr(16,8));
e[0] = readLabel(line.substr(24,8));
e[1] = readLabel(line.substr(32,8));
// discard groupID
dynEdges.append(e);
......@@ -114,19 +114,19 @@ bool Foam::fileFormats::NASedgeFormat::read
{
edge e;
// label groupId = readLabel(IStringStream(line.substr(16,8))());
e[0] = readLabel(IStringStream(line.substr(16,8))());
e[1] = readLabel(IStringStream(line.substr(24,8))());
// label groupId = readLabel(line.substr(16,8));
e[0] = readLabel(line.substr(16,8));
e[1] = readLabel(line.substr(24,8));
// discard groupID
dynEdges.append(e);
}
else if (cmd == "GRID")
{
label index = readLabel(IStringStream(line.substr(8,8))());
scalar x = parseNASCoord(line.substr(24, 8));
scalar y = parseNASCoord(line.substr(32, 8));
scalar z = parseNASCoord(line.substr(40, 8));
label index = readLabel(line.substr(8,8));
scalar x = readNasScalar(line.substr(24, 8));
scalar y = readNasScalar(line.substr(32, 8));
scalar z = readNasScalar(line.substr(40, 8));
pointId.append(index);
dynPoints.append(point(x, y, z));
......@@ -139,9 +139,9 @@ bool Foam::fileFormats::NASedgeFormat::read
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02
label index = readLabel(IStringStream(line.substr(8,16))());
scalar x = parseNASCoord(line.substr(40, 16));
scalar y = parseNASCoord(line.substr(56, 16));
label index = readLabel(line.substr(8,16));
scalar x = readNasScalar(line.substr(40, 16));
scalar y = readNasScalar(line.substr(56, 16));
is.getLine(line);
if (line[0] != '*')
......@@ -153,7 +153,7 @@ bool Foam::fileFormats::NASedgeFormat::read
<< "File:" << is.name() << " line:" << is.lineNumber()
<< exit(FatalError);
}
scalar z = parseNASCoord(line.substr(8, 16));
scalar z = readNasScalar(line.substr(8, 16));
pointId.append(index);
dynPoints.append(point(x, y, z));
......
......@@ -92,9 +92,9 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// ANSA extension
if (line.startsWith("$ANSA_NAME"))
{
string::size_type sem0 = line.find(';', 0);
string::size_type sem1 = line.find(';', sem0+1);
string::size_type sem2 = line.find(';', sem1+1);
const auto sem0 = line.find(';', 0);
const auto sem1 = line.find(';', sem0+1);
const auto sem2 = line.find(';', sem1+1);
if
(
......@@ -103,10 +103,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
&& sem2 != string::npos
)
{
ansaId = readLabel
(
IStringStream(line.substr(sem0+1, sem1-sem0-1))()
);
ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
ansaType = line.substr(sem1+1, sem2-sem1-1);
string rawName;
......@@ -125,11 +122,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// $HMNAME COMP 1"partName"
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
{
label groupId = readLabel
(
IStringStream(line.substr(16, 16))()
);
label groupId = readLabel(line.substr(16, 16));
IStringStream lineStream(line.substr(32));
string rawName;
......@@ -177,10 +170,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
if (cmd == "CTRIA3")
{
label groupId = readLabel(IStringStream(line.substr(16,8))());
label a = readLabel(IStringStream(line.substr(24,8))());
label b = readLabel(IStringStream(line.substr(32,8))());
label c = readLabel(IStringStream(line.substr(40,8))());
label groupId = readLabel(line.substr(16,8));
label a = readLabel(line.substr(24,8));
label b = readLabel(line.substr(32,8));
label c = readLabel(line.substr(40,8));
// Convert groupID into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId);
......@@ -207,11 +200,11 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
}
else if (cmd == "CQUAD4")
{
label groupId = readLabel(IStringStream(line.substr(16,8))());
label a = readLabel(IStringStream(line.substr(24,8))());
label b = readLabel(IStringStream(line.substr(32,8))());
label c = readLabel(IStringStream(line.substr(40,8))());
label d = readLabel(IStringStream(line.substr(48,8))());
label groupId = readLabel(line.substr(16,8));
label a = readLabel(line.substr(24,8));
label b = readLabel(line.substr(32,8));
label c = readLabel(line.substr(40,8));
label d = readLabel(line.substr(48,8));
// Convert groupID into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId);
......@@ -249,10 +242,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
}
else if (cmd == "GRID")
{
label index = readLabel(IStringStream(line.substr(8,8))());
scalar x = parseNASCoord(line.substr(24, 8));
scalar y = parseNASCoord(line.substr(32, 8));
scalar z = parseNASCoord(line.substr(40, 8));
label index = readLabel(line.substr(8,8));
scalar x = readNasScalar(line.substr(24, 8));
scalar y = readNasScalar(line.substr(32, 8));
scalar z = readNasScalar(line.substr(40, 8));
pointId.append(index);
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
// * 2.14897901E+02
label index = readLabel(IStringStream(line.substr(8,16))());
scalar x = parseNASCoord(line.substr(40, 16));
scalar y = parseNASCoord(line.substr(56, 16));
label index = readLabel(line.substr(8,16));
scalar x = readNasScalar(line.substr(40, 16));
scalar y = readNasScalar(line.substr(56, 16));
is.getLine(line);
if (line[0] != '*')
......@@ -279,7 +272,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
<< "File:" << is.name() << " line:" << is.lineNumber()
<< exit(FatalError);
}
scalar z = parseNASCoord(line.substr(8, 16));
scalar z = readNasScalar(line.substr(8, 16));
pointId.append(index);
dynPoints.append(point(x, y, z));
......@@ -287,7 +280,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
else if (cmd == "PSHELL")
{
// 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")
{
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -47,9 +47,9 @@ namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// 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
if (line.startsWith("$ANSA_NAME"))
{
string::size_type sem0 = line.find(';', 0);
string::size_type sem1 = line.find(';', sem0+1);
string::size_type sem2 = line.find(';', sem1+1);
const auto sem0 = line.find(';', 0);
const auto sem1 = line.find(';', sem0+1);
const auto sem2 = line.find(';', sem1+1);
if
(
......@@ -129,10 +129,7 @@ bool triSurface::readNAS(const fileName& fName)
&& sem2 != string::npos
)
{
ansaId = readLabel
(
IStringStream(line.substr(sem0+1, sem1-sem0-1))()
);
ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
ansaType = line.substr(sem1+1, sem2-sem1-1);
string nameString;
......@@ -152,11 +149,7 @@ bool triSurface::readNAS(const fileName& fName)
// $HMNAME COMP 1"partName"
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
{
label groupId = readLabel
(
IStringStream(line.substr(16, 16))()
);
label groupId = readLabel(line.substr(16, 16));
IStringStream lineStream(line.substr(32));
string rawName;
......@@ -202,11 +195,10 @@ bool triSurface::readNAS(const fileName& fName)
if (cmd == "CTRIA3")
{
readNASToken(line, 8, linei);
label groupId =
readLabel(IStringStream(readNASToken(line, 8, linei))());
label a = readLabel(IStringStream(readNASToken(line, 8, linei))());
label b = readLabel(IStringStream(readNASToken(line, 8, linei))());
label c = readLabel(IStringStream(readNASToken(line, 8, linei))());
label groupId = readLabel(readNASToken(line, 8, linei));
label a = readLabel(readNASToken(line, 8, linei));
label b = readLabel(readNASToken(line, 8, linei));
label c = readLabel(readNASToken(line, 8, linei));
// Convert group into patch
Map<label>::const_iterator iter = groupToPatch.find(groupId);
......@@ -228,12 +220,11 @@ bool triSurface::readNAS(const fileName& fName)
else if (cmd == "CQUAD4")
{
readNASToken(line, 8, linei);
label groupId =
readLabel(IStringStream(readNASToken(line, 8, linei))());
label a = readLabel(IStringStream(readNASToken(line, 8, linei))());
label b = readLabel(IStringStream(readNASToken(line, 8, linei))());
label c = readLabel(IStringStream(readNASToken(line, 8, linei))());
label d = readLabel(IStringStream(readNASToken(line, 8, linei))());
label groupId = readLabel(readNASToken(line, 8, linei));
label a = readLabel(readNASToken(line, 8, linei));
label b = readLabel(readNASToken(line, 8, linei));
label c = readLabel(readNASToken(line, 8, linei));
label d = readLabel(readNASToken(line, 8, linei));
// Convert group into patch
Map<label>::const_iterator iter = groupToPatch.find(groupId);
......@@ -256,8 +247,7 @@ bool triSurface::readNAS(const fileName& fName)
else if (cmd == "PSHELL")
{
// Read shell type since group gives patchnames
label groupId =
readLabel(IStringStream(readNASToken(line, 8, linei))());
label groupId = readLabel(readNASToken(line, 8, linei));
if (groupId == ansaId && ansaType == "PSHELL")
{
const word groupName = word::validate(ansaName);
......@@ -267,12 +257,11 @@ bool triSurface::readNAS(const fileName& fName)
}
else if (cmd == "GRID")
{
label index =
readLabel(IStringStream(readNASToken(line, 8, linei))());
label index = readLabel(readNASToken(line, 8, linei));
readNASToken(line, 8, linei);
scalar x = parseNASCoord(readNASToken(line, 8, linei));
scalar y = parseNASCoord(readNASToken(line, 8, linei));
scalar z = parseNASCoord(readNASToken(line, 8, linei));
scalar x = readNasScalar(readNASToken(line, 8, linei));
scalar y = readNasScalar(readNASToken(line, 8, linei));
scalar z = readNasScalar(readNASToken(line, 8, linei));
indices.append(index);
points.append(point(x, y, z));
......@@ -284,11 +273,10 @@ bool triSurface::readNAS(const fileName& fName)
// Typical line (spaces compacted)
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02
label index =
readLabel(IStringStream(readNASToken(line, 16, linei))());
label index = readLabel(readNASToken(line, 16, linei));
readNASToken(line, 16, linei);
scalar x = parseNASCoord(readNASToken(line, 16, linei));
scalar y = parseNASCoord(readNASToken(line, 16, linei));
scalar x = readNasScalar(readNASToken(line, 16, linei));
scalar y = readNasScalar(readNASToken(line, 16, linei));
linei = 0;
is.getLine(line);
......@@ -303,7 +291,7 @@ bool triSurface::readNAS(const fileName& fName)
<< exit(FatalError);
}
readNASToken(line, 8, linei);
scalar z = parseNASCoord(readNASToken(line, 16, linei));
scalar z = readNasScalar(readNASToken(line, 16, linei));
indices.append(index);
points.append(point(x, y, z));
......
......@@ -531,11 +531,11 @@ void Foam::radiation::fvDOM::setRayIdLambdaId
) const
{
// assuming name is in the form: CHARS_rayId_lambdaId
const size_type i1 = name.find('_');
const size_type i2 = name.rfind('_');
const auto i1 = name.find('_');
const auto i2 = name.rfind('_');
rayId = readLabel(IStringStream(name.substr(i1+1, i2-1))());
lambdaId = readLabel(IStringStream(name.substr(i2+1))());
rayId = readLabel(name.substr(i1+1, i2-1));
lambdaId = readLabel(name.substr(i2+1));
}
......
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