STYLE: update applications/tests to use SpanStream/CharStream

This commit is contained in:
Mark Olesen 2023-10-04 18:29:16 +02:00 committed by Andrew Heather
parent 3693d61e6c
commit 0fb2c8eb1c
28 changed files with 99 additions and 93 deletions

View File

@ -34,7 +34,6 @@ Description
#include "argList.H"
#include "ListOps.H"
#include "CircularBuffer.H"
#include "StringStream.H"
#include "FlatOutput.H"
using namespace Foam;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
Copyright (C) 2022-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,7 +35,7 @@ Description
#include "CompactListList.H"
#include "IndirectList.H"
#include "IOstreams.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "faceList.H"
using namespace Foam;
@ -126,20 +126,20 @@ int main(int argc, char *argv[])
{
// IO
OStringStream ostr;
OCharStream ostr;
ostr << cll4;
IStringStream istr(ostr.str());
ISpanStream istr(ostr.view());
CompactListList<label> cll5(istr);
Info<< "cll5 = " << cll5 << endl;
}
{
// IO
cll4.clear();
OStringStream ostr;
OCharStream ostr;
ostr << cll4;
IStringStream istr(ostr.str());
ISpanStream istr(ostr.view());
CompactListList<label> cll5(istr);
Info<< "cll5 = " << cll5 << endl;
}

View File

@ -33,7 +33,6 @@ Description
#include "IOstreams.H"
#include "ITstream.H"
#include "OTstream.H"
#include "StringStream.H"
#include "FlatOutput.H"
#include "ListOps.H"
#include "labelRange.H"

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,7 +31,7 @@ License
#include "DynamicList.H"
#include "FlatOutput.H"
#include "IOstreams.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "ListOps.H"
#include "stringListOps.H"
@ -119,9 +119,9 @@ int main()
<< table1["aaa"] << nl;
{
OStringStream os;
OCharStream os;
os << table1;
HashTable<scalar> readTable(IStringStream(os.str())());
HashTable<scalar> readTable(ISpanStream(os.view())());
Info<< "Istream constructor:" << readTable << endl;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -20,7 +20,7 @@ Description
#include "argList.H"
#include "labelPair.H"
#include "IntRange.H"
#include "StringStream.H"
#include "SpanStream.H"
using namespace Foam;
@ -75,9 +75,8 @@ int main(int argc, char *argv[])
// Read from stream
{
IStringStream is("(10 100)");
ICharStream is("(10 100)");
intRange range;
is >> range;
Info<< "From stream int32_t: " << range << nl;

View File

@ -40,7 +40,7 @@ See also
#include "wordRes.H"
#include "IOstreams.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "scalar.H"
#include "vector.H"
@ -183,17 +183,17 @@ int main(int argc, char *argv[])
if (false)
{
labelList intlist(IStringStream("(0 1 2)")());
labelList intlist(ICharStream("(0 1 2)")());
Info<<"construct from Istream: " << intlist << endl;
IStringStream("(3 4 5)")() >> static_cast<labelUList&>(intlist);
ICharStream("(3 4 5)")() >> static_cast<labelUList&>(intlist);
Info<<"is >>: " << intlist << endl;
IStringStream("(6 7 8)")() >> intlist;
ICharStream("(6 7 8)")() >> intlist;
Info<<"is >>: " << intlist << endl;
}
List<vector> list1(IStringStream("1 ((0 1 2))")());
List<vector> list1(ICharStream("1 ((0 1 2))")());
Info<< "list1: " << list1 << endl;
List<vector> list2

View File

@ -37,7 +37,6 @@ Description
#include "IOstreams.H"
#include "Fstream.H"
#include "StringStream.H"
#include "scalar.H"
#include "vector.H"

View File

@ -290,8 +290,8 @@ int main(int argc, char *argv[])
Info<< "address: " << Foam::name(os2.list().cdata()) << nl;
List<char> chars(os2.release());
Info<< "chars: " << chars.size() << nl;
DynamicList<char> chars(os2.release());
Info<< "chars: " << chars.size() << '/' << chars.capacity() << nl;
Info<< "address: " << Foam::name(chars.cdata()) << nl;
Info<< "release" << nl;
printInfo(os2);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,6 +29,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "OCountStream.H"
#include "SpanStream.H"
#include "StringStream.H"
#include "Fstream.H"
#include "IOstreams.H"
@ -63,9 +64,11 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
OCountStream cnt;
OCharStream cstr;
OStringStream str;
ocountstream plain;
generateOutput(cstr);
generateOutput(str);
generateOutput(cnt);
generateOutput(plain);
@ -73,6 +76,7 @@ int main(int argc, char *argv[])
cnt.print(Info);
Info<< "counter state: " << (cnt.stdStream().rdstate()) << nl
<< "via char-stream: " << label(cstr.view().size()) << " chars" << nl
<< "via string-stream: " << str.str().size() << " chars" << nl
<< "via ocountstream: " << plain.count() << " chars" << endl;

View File

@ -28,18 +28,15 @@ Description
\*---------------------------------------------------------------------------*/
#include "IOstreams.H"
#include "SpanStream.H"
#include "StringStream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
template<class OStreamType>
void doTest()
{
Info<< "Begin test OStringStream" << endl;
OStringStream os;
OStreamType os;
os << "output with some values " << 1 << " entry" << endl;
Info<< "contains:" << nl
@ -59,8 +56,20 @@ int main(int argc, char *argv[])
Info<< "after reset:" << nl
<< os.str() << endl;
}
Info<< "End\n" << endl;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
Info<< "Begin test OStringStream" << endl;
doTest<OStringStream>();
// No reset() method: doTest<OCharStream>();
Info<< "\nEnd\n" << endl;
return 0;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,7 +36,7 @@ See also
#include "OSspecific.H"
#include "IOstreams.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "labelList.H"
#include "ListOps.H"
@ -95,7 +95,7 @@ int main(int argc, char *argv[])
{
Info<<"Read from " << inputSLList << nl;
IStringStream is(inputSLList);
ISpanStream is(inputSLList);
is >> ulist;
// Info<<"source: "; print(source);
@ -107,7 +107,7 @@ int main(int argc, char *argv[])
{
Info<<"Read from " << inputCompound << nl;
IStringStream is(inputCompound);
ISpanStream is(inputCompound);
is >> ulist;
// Info<<"source: "; print(source);

View File

@ -31,7 +31,6 @@ Description
#include "IOstreams.H"
#include "MinMax.H"
#include "Switch.H"
#include "StringStream.H"
using namespace Foam;

View File

@ -37,7 +37,7 @@ Description
#include "HashSet.H"
#include "ListOps.H"
#include "cpuTime.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "FlatOutput.H"
#include <vector>
#include <unordered_set>
@ -124,7 +124,7 @@ int main(int argc, char *argv[])
Info<< "Test read/write (ASCII)" << nl;
OStringStream ostr;
OCharStream ostr;
undecorated(ostr, set3a); // like flatOutput
ostr << bitSet();
@ -132,7 +132,7 @@ int main(int argc, char *argv[])
undecorated(ostr, set3a); // like flatOutput
{
IStringStream istr(ostr.str());
ISpanStream istr(ostr.view());
Info<< "parse: " << istr.str() << nl;
bitSet bset1(istr);

View File

@ -36,7 +36,7 @@ Description
#include "DynamicList.H"
#include "IOstreams.H"
#include "ITstream.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "bitSet.H"
#include "FlatOutput.H"
@ -415,7 +415,7 @@ int main(int argc, char *argv[])
Info<< "\nassign from indices\n";
list4.readList
(
IStringStream
ICharStream
(
"{0 1 2 3 12 13 14 19 20 21}"
)()

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,7 +38,7 @@ Description
#include "charList.H"
#include "labelList.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "ListOps.H"
#include "SubList.H"
#include "FlatOutput.H"
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
// Info<< "Known compound tokens: "
// << token::compound::emptyConstructorTablePtr_->sortedToc() << nl;
OStringStream ostr;
OCharStream ostr;
{
List<char> alphabet(64);
@ -75,7 +75,8 @@ int main(int argc, char *argv[])
}
{
IStringStream istr(ostr.str());
// ICharStream istr(ostr.release());
ISpanStream istr(ostr.view());
List<char> alphabet(istr);
Info<< "re-read: " << alphabet << nl;
@ -88,6 +89,8 @@ int main(int argc, char *argv[])
Info<< "blanked: " << alphabet << nl;
}
Info<< "\nEnd\n" << nl;
return 0;
}

View File

@ -31,7 +31,6 @@ Description
#include "IOobject.H"
#include "IOstreams.H"
#include "IFstream.H"
#include "StringStream.H"
#include "cpuTime.H"
#include "labelList.H"
#include "DynamicList.H"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,6 +36,7 @@ Description
#include "IOobject.H"
#include "IFstream.H"
#include "dictionary.H"
#include "SpanStream.H"
#include "ops.H"
#include "scalarRange.H"
#include "stringOps.H"
@ -348,7 +349,7 @@ int main(int argc, char *argv[])
Info<< nl << "Test reading good/bad/empty scalar entries" << nl;
dictionary dict2
(
IStringStream
ICharStream
(
"good 3.14159;\n"
"negative -3.14159;\n"
@ -418,7 +419,7 @@ int main(int argc, char *argv[])
dictionary mydict
(
IStringStream
ICharStream
(
"scalar 3.14159;\n"
"label 10;\n"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,7 +35,7 @@ Description
#include "IOstreams.H"
#include "dictionary.H"
#include "vector.H"
#include "StringStream.H"
#include "SpanStream.H"
using namespace Foam;
@ -47,7 +47,7 @@ int main(int argc, char *argv[])
argList::noParallel();
{
IStringStream is
ICharStream is
(
"value 10;"
"scalar1 $value;"

View File

@ -29,6 +29,7 @@ License
#include "dictionary.H"
#include "primitiveEntry.H"
#include "dimensionedTypes.H"
#include "SpanStream.H"
using namespace Foam;
@ -53,7 +54,7 @@ int main(int argc, char *argv[])
{
string dimString("[Pa m^2 s^-2]");
IStringStream is("[Pa m^2 s^-2]");
ICharStream is("[Pa m^2 s^-2]");
Pout<< nl;
Pout<< "dimensionSet construct from (is) with contents "
@ -70,23 +71,23 @@ int main(int argc, char *argv[])
{
Pout<< nl
<< "construct from (is) = "
<< dimensionedScalar(IStringStream("bla [Pa mm^2 s^-2] 3.0")())
<< dimensionedScalar(ICharStream("bla [Pa mm^2 s^-2] 3.0")())
<< endl;
Pout<< "construct from (name,is) = "
<< dimensionedScalar
(
"ABC",
IStringStream("[Pa mm^2 s^-2] 3.0")()
ICharStream("[Pa mm^2 s^-2] 3.0")()
) << endl;
Pout<< "construct from (name,dims,is) = "
<< dimensionedScalar
(
"ABC",
dimLength,
IStringStream("bla [mm] 3.0")()
ICharStream("bla [mm] 3.0")()
) << endl;
{
IStringStream is("bla [mm] 3.0");
ICharStream is("bla [mm] 3.0");
dimensionedScalar ds;
is >> ds;
Pout<< "read:" << ds << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,6 +30,7 @@ License
#include "fvMesh.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "SpanStream.H"
using namespace Foam;
@ -76,9 +77,9 @@ int main(int argc, char *argv[])
PtrList<dictionary> boundaryDicts(pbm.size());
forAll(pbm, patchi)
{
OStringStream os;
OCharStream os;
os << pbm[patchi];
IStringStream is(os.str());
ISpanStream is(os.view());
boundaryDicts.set(patchi, new dictionary(is));
}

View File

@ -34,7 +34,6 @@ Description
#include "scalar.H"
#include "FlatOutput.H"
#include "SpanStream.H"
#include "StringStream.H"
#include "NASCore.H"
#include "parsing.H"
#include "Tuple2.H"
@ -443,6 +442,7 @@ int main(int argc, char *argv[])
<< " read " << sizeof(scalar) << nl;
List<otherType> srcList(15);
List<scalar> dstList; // Read back
forAll(srcList, i)
{
@ -452,13 +452,8 @@ int main(int argc, char *argv[])
OCharStream os(IOstreamOption::BINARY);
os << srcList;
DynamicList<char> buf;
os.swap(buf); // Recover written contents
// Read back
List<scalar> dstList;
ISpanStream is(buf, IOstreamOption::BINARY);
// Recover written contents
ICharStream is(os.release(), IOstreamOption::BINARY);
is.setScalarByteSize(sizeof(otherType));
Info<< "Stream scalar-size ("

View File

@ -37,7 +37,7 @@ Description
#include "scalarPredicates.H"
#include "FlatOutput.H"
#include "Tuple2.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "ops.H"
#include "bitSet.H"
@ -164,7 +164,7 @@ int main(int argc, char *argv[])
Info<< nl << "Construct from Istream" << nl;
{
IStringStream is("((less 10) (greater 100) (less -8) (le -9))");
ICharStream is("((less 10) (greater 100) (less -8) (le -9))");
predicates::scalars accept(is);
doTest(values, accept);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,6 +32,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "OSHA1stream.H"
#include "SpanStream.H"
#include "StringStream.H"
#include "dictionary.H"
@ -118,7 +119,7 @@ int main(int argc, char * argv[])
{
dictionary dict
(
IStringStream
ICharStream
(
"parent { Default_Boundary_Region { type zeroGradient; } }"
"inlet_1 { value inlet_1; }"

View File

@ -34,7 +34,6 @@ Description
#include "argList.H"
#include "IOstreams.H"
#include "StringStream.H"
#include "scalar.H"
#include "vector.H"
#include "labelRange.H"

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,7 +32,7 @@ Description
#include "ListOps.H"
#include "FlatOutput.H"
#include "IOstreams.H"
#include "StringStream.H"
#include "SpanStream.H"
using namespace Foam;
@ -55,7 +55,7 @@ int main(int argc, char *argv[])
};
labelList matches;
wordRes matcher1(IStringStream("( okey \"[hy]e+.*\" )")());
wordRes matcher1(ICharStream("( okey \"[hy]e+.*\" )")());
Info<< "stringList " << strings << nl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -66,8 +66,7 @@ Note
#include "MeshedSurfaces.H"
#include "ModifiableMeshedSurface.H"
#include "UnsortedMeshedSurfaces.H"
#include "StringStream.H"
#include "SpanStream.H"
using namespace Foam;
@ -180,9 +179,9 @@ int main(int argc, char *argv[])
// check: output to ostream, construct from istream
{
OStringStream os;
OCharStream os;
os << surf;
IStringStream is(os.str());
ISpanStream is(os.view());
// both work:
triSurface surf2(is);
@ -245,9 +244,9 @@ int main(int argc, char *argv[])
// check: output to ostream, construct from istream
{
OStringStream os;
OCharStream os;
os << surf;
IStringStream is(os.str());
ISpanStream is(os.view());
// both work:
UnsortedMeshedSurface<face> surf2(is);
@ -309,9 +308,9 @@ int main(int argc, char *argv[])
// check: output to ostream, construct from istream
{
OStringStream os;
OCharStream os;
os << surf;
IStringStream is(os.str());
ISpanStream is(os.view());
// both work:
MeshedSurface<face> surf2(is);
@ -373,9 +372,9 @@ int main(int argc, char *argv[])
// check: output to ostream, construct from istream
{
OStringStream os;
OCharStream os;
os << surf;
IStringStream is(os.str());
ISpanStream is(os.view());
// both work:
MeshedSurface<face> surf2(is);

View File

@ -31,7 +31,6 @@ Description
#include "IOobject.H"
#include "IOstreams.H"
#include "IFstream.H"
#include "StringStream.H"
#include "cpuTime.H"
#include "labelList.H"
#include "scalarList.H"

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,7 +34,7 @@ Description
#include "IOobject.H"
#include "IOstreams.H"
#include "IFstream.H"
#include "StringStream.H"
#include "SpanStream.H"
#include "cpuTime.H"
#include "DynamicList.H"
@ -69,7 +69,7 @@ int main(int argc, char *argv[])
Info<< "input string: " << rawArg << nl;
}
IStringStream is(rawArg);
ISpanStream is(rawArg);
DynamicList<token> tokens;