Merge branch 'feature-streams-cleanup' into 'develop'

Feature streams cleanup

See merge request !127
This commit is contained in:
Andrew Heather
2017-07-18 12:48:31 +01:00
113 changed files with 824 additions and 647 deletions

View File

@ -31,8 +31,7 @@ Description
#include "CompactListList.H" #include "CompactListList.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "OStringStream.H" #include "StringStream.H"
#include "IStringStream.H"
#include "faceList.H" #include "faceList.H"
using namespace Foam; using namespace Foam;

View File

@ -29,8 +29,7 @@ License
#include "DynamicList.H" #include "DynamicList.H"
#include "FlatOutput.H" #include "FlatOutput.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OStringStream.H"
using namespace Foam; using namespace Foam;

View File

@ -25,7 +25,7 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "IStringStream.H" #include "StringStream.H"
#include "wordList.H" #include "wordList.H"
#include "IOstreams.H" #include "IOstreams.H"

View File

@ -37,7 +37,7 @@ See also
#include "wordReList.H" #include "wordReList.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H" #include "StringStream.H"
#include "scalar.H" #include "scalar.H"
#include "vector.H" #include "vector.H"

View File

@ -25,8 +25,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OStringStream.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "StringStream.H"
using namespace Foam; using namespace Foam;
@ -35,15 +35,28 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Info<< "khkj" << endl; Info<< "Begin test OStringStream" << endl;
OStringStream testStream; OStringStream os;
testStream << "hello " << 1 << endl; os << "output with some values " << 1 << " entry" << endl;
Info<< testStream.str() << endl;
testStream.rewind(); Info<< "contains:" << nl
Info<< testStream.str() << endl; << os.str() << endl;
testStream << "hello " << 2 << endl; os.rewind();
Info<< testStream.str() << endl;
Info<< "after rewind:" << nl
<< os.str() << endl;
os << "####";
Info<< "overwrite with short string:" << nl
<< os.str() << endl;
os.reset();
os << "%%%% reset";
Info<< "after reset:" << nl
<< os.str() << endl;
Info<< "End\n" << endl; Info<< "End\n" << endl;

View File

@ -30,7 +30,7 @@ Description
#include "uLabel.H" #include "uLabel.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "PackedBoolList.H" #include "PackedBoolList.H"
#include "IStringStream.H" #include "StringStream.H"
using namespace Foam; using namespace Foam;

View File

@ -29,7 +29,7 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "IStringStream.H" #include "StringStream.H"
#include "Polynomial.H" #include "Polynomial.H"
#include "polynomialFunction.H" #include "polynomialFunction.H"
#include "Random.H" #include "Random.H"

View File

@ -25,8 +25,7 @@ License
#include "StaticHashTable.H" #include "StaticHashTable.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OStringStream.H"
using namespace Foam; using namespace Foam;

View File

@ -47,8 +47,24 @@ int main(int argc, char *argv[])
IOWarningInFunction(dict) << "warning 3" << endl; IOWarningInFunction(dict) << "warning 3" << endl;
FatalErrorInFunction << "error 1" << endl; FatalErrorInFunction
FatalErrorInFunction << "error 2" << exit(FatalError); << "This is an error from 1" << nl
<< "Explanation to follow:" << endl;
FatalErrorInFunction
<< "Error 2"
<< exit(FatalError);
}
catch (Foam::error& fErr)
{
Serr<< "Caught Foam error " << fErr << nl << endl;
}
try
{
FatalErrorInFunction
<< "Error# 3"
<< exit(FatalError);
} }
catch (Foam::error& fErr) catch (Foam::error& fErr)
{ {

View File

@ -26,7 +26,6 @@ License
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "IStringStream.H"
#include "indexedOctree.H" #include "indexedOctree.H"
#include "treeDataCell.H" #include "treeDataCell.H"
#include "OFstream.H" #include "OFstream.H"

View File

@ -26,7 +26,6 @@ License
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "IStringStream.H"
#include "indexedOctree.H" #include "indexedOctree.H"
#include "treeDataEdge.H" #include "treeDataEdge.H"
#include "OFstream.H" #include "OFstream.H"

View File

@ -34,8 +34,6 @@ Description
#include "Time.H" #include "Time.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "OStringStream.H"
#include "IStringStream.H"
using namespace Foam; using namespace Foam;

View File

@ -31,7 +31,6 @@ Description
#include "OSspecific.H" #include "OSspecific.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H"
#include "scalar.H" #include "scalar.H"
#include "vector.H" #include "vector.H"
#include "ListOps.H" #include "ListOps.H"
@ -49,31 +48,26 @@ int main(int argc, char *argv[])
//Pout.prefix() = '[' + name(Pstream::myProcNo()) + "] "; //Pout.prefix() = '[' + name(Pstream::myProcNo()) + "] ";
List<vector> list(IStringStream("1 ((0 1 2))")()); List<vector> list{{0, 1, 2}};
Info<< list << endl; Info<< list << endl;
List<vector> list2 List<vector> list2
( {
IStringStream {0, 1, 2},
( {3, 4, 5},
"(\ {3, 4, 5},
(0 1 2)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ {3, 4, 5},
(3 4 5)\ };
(3 4 5)\
(3 4 5)\
)"
)()
);
Pout<< list2 << endl; Pout<< list2 << endl;
Info<< findIndex(list2, vector(3, 4, 5)) << endl; Info<< findIndex(list2, vector(3, 4, 5)) << endl;

View File

@ -28,10 +28,8 @@ Description
#include "argList.H" #include "argList.H"
#include "label.H" #include "label.H"
#include "labelList.H" #include "labelList.H"
#include "OStringStream.H"
#include "IStringStream.H"
#include "OFstream.H"
#include "IFstream.H" #include "IFstream.H"
#include "OFstream.H"
#include "point.H" #include "point.H"
#include "Time.H" #include "Time.H"
#include "fvMesh.H" #include "fvMesh.H"

View File

@ -30,7 +30,7 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OSHA1stream.H" #include "OSHA1stream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "dictionary.H" #include "dictionary.H"
using namespace Foam; using namespace Foam;
@ -96,7 +96,7 @@ int main(int argc, char * argv[])
os << str; os << str;
Info<< os.digest() << endl; Info<< os.digest() << endl;
os.rewind(); os.reset();
os << "The quick brown fox jumps over the lazy dog"; os << "The quick brown fox jumps over the lazy dog";
Info<< os.digest() << endl; Info<< os.digest() << endl;
} }

View File

@ -32,7 +32,6 @@ Description
#include "dictionary.H" #include "dictionary.H"
#include "nil.H" #include "nil.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H"
namespace Foam namespace Foam
{ {

View File

@ -26,8 +26,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "stringListOps.H" #include "stringListOps.H"
#include "IStringStream.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "StringStream.H"
using namespace Foam; using namespace Foam;
@ -37,22 +37,17 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
stringList strLst stringList strLst
( {
IStringStream "hello",
( "heello",
"(" "heeello",
"\"hello\"" "bye",
"\"heello\"" "bbye",
"\"heeello\"" "bbbye",
"\"bye\"" "okey",
"\"bbye\"" "okkey",
"\"bbbye\"" "okkkey",
"\"okey\"" };
"\"okkey\""
"\"okkkey\""
")"
)()
);
wordReList reLst(IStringStream("( okey \"[hy]e+.*\" )")()); wordReList reLst(IStringStream("( okey \"[hy]e+.*\" )")());

View File

@ -31,7 +31,7 @@ Description
#include "IOobject.H" #include "IOobject.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "cpuTime.H" #include "cpuTime.H"
using namespace Foam; using namespace Foam;
@ -41,22 +41,28 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::noBanner();
argList::noParallel(); argList::noParallel();
argList::validArgs.insert("string .. stringN"); argList::validArgs.insert("string .. stringN");
argList::addOption("file", "name"); argList::addOption("file", "name");
argList::addOption("repeat", "count"); argList::addOption("repeat", "count");
argList::addBoolOption("verbose", "report for each repeat");
argList args(argc, argv, false, true); argList args(argc, argv, false, true);
const label repeat = args.optionLookupOrDefault<label>("repeat", 1); const label repeat = args.optionLookupOrDefault<label>("repeat", 1);
const bool optVerbose = args.optionFound("verbose");
cpuTime timer; cpuTime timer;
for (label count = 0; count < repeat; ++count) for (label count = 0; count < repeat; ++count)
{ {
const bool verbose = (optVerbose || count == 0);
for (label argI=1; argI < args.size(); ++argI) for (label argI=1; argI < args.size(); ++argI)
{ {
const string& rawArg = args[argI]; const string& rawArg = args[argI];
if (count == 0) if (verbose)
{ {
Info<< "input string: " << rawArg << nl; Info<< "input string: " << rawArg << nl;
} }
@ -71,14 +77,15 @@ int main(int argc, char *argv[])
// is.putback(ch); // is.putback(ch);
int lookahead = is.peek(); int lookahead = is.peek();
if (count == 0) if (verbose)
{ {
Info<< "token: " << tok.info(); Info<< "token: " << tok.info()
Info<< " lookahead: '" << char(lookahead) << "'" << endl; << " lookahead: '" << char(lookahead) << "'"
<< endl;
} }
} }
if (count == 0) if (verbose)
{ {
Info<< nl; Info<< nl;
IOobject::writeDivider(Info); IOobject::writeDivider(Info);
@ -89,31 +96,44 @@ int main(int argc, char *argv[])
Info<< "tokenized args " << repeat << " times in " Info<< "tokenized args " << repeat << " times in "
<< timer.cpuTimeIncrement() << " s\n\n"; << timer.cpuTimeIncrement() << " s\n\n";
if (args.optionFound("file")) fileName inputFile;
if (args.optionReadIfPresent("file", inputFile))
{ {
IFstream is(inputFile);
for (label count = 0; count < repeat; ++count) for (label count = 0; count < repeat; ++count)
{ {
IFstream is(args["file"]); const bool verbose = (optVerbose || count == 0);
label nTokens = 0;
if (count == 0) if (count)
{ {
Info<< "tokenizing file: " << args["file"] << nl; is.rewind();
} }
Info<< nl
<< "tokenizing file (pass #" << (count+1) << ") "
<< inputFile << nl
<< "state: " << is.info() << endl;
while (is.good()) while (is.good())
{ {
token tok(is); token tok(is);
if (count == 0) if (verbose)
{ {
Info<< "token: " << tok.info() << endl; Info<< "token: " << tok.info() << endl;
} }
++nTokens;
} }
if (count == 0) if (verbose)
{ {
Info<< nl; Info<< nl;
IOobject::writeDivider(Info); IOobject::writeDivider(Info);
} }
Info<<"pass #" << (count+1)
<< " extracted " << nTokens << " tokens" << endl;
} }
Info<< "tokenized file " << repeat << " times in " Info<< "tokenized file " << repeat << " times in "

View File

@ -30,7 +30,6 @@ Description
#include "OSspecific.H" #include "OSspecific.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H"
#include "labelList.H" #include "labelList.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "face.H" #include "face.H"

View File

@ -46,7 +46,7 @@ Description
#include <cstdio> #include <cstdio>
#include "scalar.H" #include "scalar.H"
#include "IStringStream.H" #include "StringStream.H"
using namespace Foam; using namespace Foam;
@ -271,7 +271,6 @@ elementType ^{space}"TYPE"{cspace}
#include "fileName.H" #include "fileName.H"
#include <fstream> #include <fstream>
using std::ifstream;
label findFace(const polyMesh& mesh, const face& f) label findFace(const polyMesh& mesh, const face& f)
@ -318,8 +317,8 @@ int main(int argc, char *argv[])
#include "createTime.H" #include "createTime.H"
fileName ansysFile(args[1]); const fileName ansysFile(args[1]);
ifstream ansysStream(ansysFile.c_str()); std::ifstream ansysStream(ansysFile);
if (!ansysStream) if (!ansysStream)
{ {

View File

@ -58,7 +58,7 @@ int main(int argc, char *argv[])
#include "createTime.H" #include "createTime.H"
std::ifstream plot3dFile(args[1].c_str()); std::ifstream plot3dFile(args[1]);
string line; string line;
std::getline(plot3dFile, line); std::getline(plot3dFile, line);

View File

@ -43,7 +43,7 @@ Description
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "IStringStream.H" #include "StringStream.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "emptyPolyPatch.H" #include "emptyPolyPatch.H"
#include "wallPolyPatch.H" #include "wallPolyPatch.H"
@ -906,7 +906,7 @@ int main(int argc, char *argv[])
#include "createTime.H" #include "createTime.H"
const fileName fluentFile = args[1]; const fileName fluentFile = args[1];
std::ifstream fluentStream(fluentFile.c_str()); std::ifstream fluentStream(fluentFile);
if (!fluentStream) if (!fluentStream)
{ {

View File

@ -26,7 +26,6 @@ License
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
using std::ofstream;
using std::ios; using std::ios;
#include "Time.H" #include "Time.H"
@ -49,18 +48,16 @@ Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
void Foam::fluentFvMesh::writeFluentMesh() const void Foam::fluentFvMesh::writeFluentMesh() const
{ {
// make a directory called proInterface in the case // Make a directory called fluentInterface in the case
mkDir(time().rootPath()/time().caseName()/"fluentInterface"); mkDir(time().rootPath()/time().caseName()/"fluentInterface");
// open a file for the mesh // Open a file for the mesh
ofstream fluentMeshFile std::ofstream fluentMeshFile
( (
( time().rootPath()
time().rootPath()/ / time().caseName()
time().caseName()/ / "fluentInterface"
"fluentInterface"/ / time().caseName() + ".msh"
time().caseName() + ".msh"
).c_str()
); );
Info<< "Writing Header" << endl; Info<< "Writing Header" << endl;

View File

@ -41,7 +41,7 @@ Description
\* ------------------------------------------------------------------------- */ \* ------------------------------------------------------------------------- */
#include "scalarList.H" #include "scalarList.H"
#include "IStringStream.H" #include "StringStream.H"
// For EOF only // For EOF only
#include <cstdio> #include <cstdio>
@ -622,7 +622,6 @@ mtype {space}"MTYPE:"{space}
#include "fileName.H" #include "fileName.H"
#include <fstream> #include <fstream>
using std::ifstream;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -647,7 +646,7 @@ int main(int argc, char *argv[])
#include "createTime.H" #include "createTime.H"
const fileName gambitFile = args[1]; const fileName gambitFile = args[1];
ifstream gambitStream(gambitFile.c_str()); std::ifstream gambitStream(gambitFile);
if (!gambitStream) if (!gambitStream)
{ {

View File

@ -1,4 +1,4 @@
ifstream kivaFile(kivaFileName.c_str()); std::ifstream kivaFile(kivaFileName);
if (!kivaFile.good()) if (!kivaFile.good())
{ {

View File

@ -27,8 +27,7 @@ License
#include "point.H" #include "point.H"
#include "Istream.H" #include "Istream.H"
#include "Ostream.H" #include "Ostream.H"
#include "OStringStream.H" #include "StringStream.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * // // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //

View File

@ -36,7 +36,6 @@ Description
#include "argList.H" #include "argList.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "pointFields.H" #include "pointFields.H"
#include "IStringStream.H"
#include "volPointInterpolation.H" #include "volPointInterpolation.H"
using namespace Foam; using namespace Foam;

View File

@ -34,16 +34,12 @@ Description
#include "argList.H" #include "argList.H"
#include "OFstream.H" #include "OFstream.H"
#include <fstream> #include "StringStream.H"
#include <sstream>
#include "IStringStream.H"
#include "point.H" #include "point.H"
#include "DynamicList.H" #include "DynamicList.H"
using namespace Foam; using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
string getLine(std::ifstream& is) string getLine(std::ifstream& is)
@ -122,7 +118,7 @@ int main(int argc, char *argv[])
const fileName objName = args[1]; const fileName objName = args[1];
const fileName outName = args[2]; const fileName outName = args[2];
std::ifstream OBJfile(objName.c_str()); std::ifstream OBJfile(objName);
if (!OBJfile.good()) if (!OBJfile.good())
{ {

View File

@ -36,7 +36,7 @@ Description
#include "Time.H" #include "Time.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "globalMeshData.H" #include "globalMeshData.H"
#include "IStringStream.H" #include "StringStream.H"
#include "cellSet.H" #include "cellSet.H"
#include "faceSet.H" #include "faceSet.H"
#include "pointSet.H" #include "pointSet.H"

View File

@ -46,12 +46,9 @@ Description
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "IStringStream.H"
#include "cellSet.H" #include "cellSet.H"
#include "faceSet.H" #include "faceSet.H"
#include "pointSet.H" #include "pointSet.H"
#include "OFstream.H"
#include "IFstream.H"
#include "IOobjectList.H" #include "IOobjectList.H"
#include "SortableList.H" #include "SortableList.H"
#include "timeSelector.H" #include "timeSelector.H"

View File

@ -68,7 +68,7 @@ Usage
#include "pointFields.H" #include "pointFields.H"
#include "transformField.H" #include "transformField.H"
#include "transformGeometricField.H" #include "transformGeometricField.H"
#include "IStringStream.H" #include "StringStream.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
using namespace Foam; using namespace Foam;

View File

@ -31,7 +31,7 @@ License
#include "blockMeshTools.H" #include "blockMeshTools.H"
#include "Time.H" #include "Time.H"
#include "patchZones.H" #include "patchZones.H"
#include "OStringStream.H" #include "StringStream.H"
// VTK includes // VTK includes
#include "vtkDataArraySelection.h" #include "vtkDataArraySelection.h"

View File

@ -26,7 +26,7 @@ License
#include "boundaryTemplates.H" #include "boundaryTemplates.H"
#include "Time.H" #include "Time.H"
#include "IFstream.H" #include "IFstream.H"
#include "OStringStream.H" #include "StringStream.H"
using namespace Foam; using namespace Foam;

View File

@ -71,8 +71,7 @@ Note
#include "ModifiableMeshedSurface.H" #include "ModifiableMeshedSurface.H"
#include "UnsortedMeshedSurfaces.H" #include "UnsortedMeshedSurfaces.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OStringStream.H"
using namespace Foam; using namespace Foam;

View File

@ -36,8 +36,7 @@ Description
#include "argList.H" #include "argList.H"
#include "chemkinReader.H" #include "chemkinReader.H"
#include "OFstream.H" #include "OFstream.H"
#include "OStringStream.H" #include "StringStream.H"
#include "IStringStream.H"
using namespace Foam; using namespace Foam;

View File

@ -724,13 +724,13 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
} }
// Open and check streams. // Open and check streams.
std::ifstream srcStream(src.c_str()); std::ifstream srcStream(src);
if (!srcStream) if (!srcStream)
{ {
return false; return false;
} }
std::ofstream destStream(destFile.c_str()); std::ofstream destStream(destFile);
if (!destStream) if (!destStream)
{ {
return false; return false;

View File

@ -24,9 +24,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
#include "OStringStream.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "IFstream.H" #include "IFstream.H"
#include "StringStream.H"
#include <inttypes.h> #include <inttypes.h>
#include <cxxabi.h> #include <cxxabi.h>
@ -55,7 +55,7 @@ string pOpen(const string &cmd, label line=0)
{ {
size_t linecap = 0; size_t linecap = 0;
ssize_t linelen; ssize_t linelen;
linelen = getline(&buf, &linecap, cmdPipe); linelen = ::getline(&buf, &linecap, cmdPipe);
if (linelen < 0) if (linelen < 0)
{ {

View File

@ -171,7 +171,7 @@ Tstreams = $(Streams)/Tstreams
$(Tstreams)/ITstream.C $(Tstreams)/ITstream.C
StringStreams = $(Streams)/StringStreams StringStreams = $(Streams)/StringStreams
$(StringStreams)/StringStreamsPrint.C $(StringStreams)/StringStream.C
Pstreams = $(Streams)/Pstreams Pstreams = $(Streams)/Pstreams
$(Pstreams)/UIPstream.C $(Pstreams)/UIPstream.C

View File

@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InClass
Foam::Fstream
Description
Input/output from file streams.
\*---------------------------------------------------------------------------*/
#ifndef Fstream_H
#define Fstream_H
#include "IFstream.H"
#include "OFstream.H"
#endif
// ************************************************************************* //

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.
@ -35,11 +35,11 @@ namespace Foam
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
: :
ifPtr_(nullptr), allocatedPtr_(nullptr),
compression_(IOstream::UNCOMPRESSED) compression_(IOstream::UNCOMPRESSED)
{ {
if (pathname.empty()) if (pathname.empty())
@ -50,21 +50,21 @@ Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
} }
} }
ifPtr_ = new ifstream(pathname.c_str()); allocatedPtr_ = new std::ifstream(pathname);
// If the file is compressed, decompress it before reading. // If the file is compressed, decompress it before reading.
if (!ifPtr_->good() && isFile(pathname + ".gz", false)) if (!allocatedPtr_->good() && isFile(pathname + ".gz", false))
{ {
if (IFstream::debug) if (IFstream::debug)
{ {
InfoInFunction << "Decompressing " << pathname + ".gz" << endl; InfoInFunction << "Decompressing " << pathname + ".gz" << endl;
} }
delete ifPtr_; delete allocatedPtr_;
ifPtr_ = new igzstream((pathname + ".gz").c_str()); allocatedPtr_ = new igzstream((pathname + ".gz").c_str());
if (ifPtr_->good()) if (allocatedPtr_->good())
{ {
compression_ = IOstream::COMPRESSED; compression_ = IOstream::COMPRESSED;
} }
@ -72,9 +72,23 @@ Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::IFstreamAllocator::~IFstreamAllocator() Foam::IFstreamAllocator::~IFstreamAllocator()
{ {
delete ifPtr_; deallocate();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::IFstreamAllocator::deallocate()
{
if (allocatedPtr_)
{
delete allocatedPtr_;
allocatedPtr_ = nullptr;
}
} }
@ -90,7 +104,7 @@ Foam::IFstream::IFstream
IFstreamAllocator(pathname), IFstreamAllocator(pathname),
ISstream ISstream
( (
*ifPtr_, *allocatedPtr_,
pathname, pathname,
format, format,
version, version,
@ -99,14 +113,15 @@ Foam::IFstream::IFstream
{ {
setClosed(); setClosed();
setState(ifPtr_->rdstate()); setState(allocatedPtr_->rdstate());
if (!good()) if (!good())
{ {
if (debug) if (debug)
{ {
InfoInFunction InfoInFunction
<< "Could not open file for input" << endl << info() << endl; << "Could not open file " << pathname
<< " for input" << nl << info() << Foam::endl;
} }
setBad(); setBad();
@ -130,29 +145,63 @@ Foam::IFstream::~IFstream()
std::istream& Foam::IFstream::stdStream() std::istream& Foam::IFstream::stdStream()
{ {
if (!ifPtr_) if (!allocatedPtr_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "No stream allocated" << abort(FatalError); << "No stream allocated"
<< abort(FatalError);
} }
return *ifPtr_; return *allocatedPtr_;
} }
const std::istream& Foam::IFstream::stdStream() const const std::istream& Foam::IFstream::stdStream() const
{ {
if (!ifPtr_) if (!allocatedPtr_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "No stream allocated" << abort(FatalError); << "No stream allocated"
<< abort(FatalError);
} }
return *ifPtr_; return *allocatedPtr_;
}
Foam::Istream& Foam::IFstream::rewind()
{
lineNumber_ = 1; // Reset line number
igzstream* gzPtr = nullptr;
try
{
gzPtr = dynamic_cast<igzstream*>(allocatedPtr_);
}
catch (std::bad_cast)
{
gzPtr = nullptr;
}
if (gzPtr)
{
// Need special treatment for gzstream.
gzPtr->close();
gzPtr->clear();
gzPtr->open((this->name() + ".gz").c_str());
setState(gzPtr->rdstate());
}
else
{
ISstream::rewind();
}
return *this;
} }
void Foam::IFstream::print(Ostream& os) const void Foam::IFstream::print(Ostream& os) const
{ {
// Print File data
os << "IFstream: "; os << "IFstream: ";
ISstream::print(os); ISstream::print(os);
} }
@ -164,10 +213,10 @@ Foam::IFstream& Foam::IFstream::operator()() const
{ {
if (!good()) if (!good())
{ {
// also checks .gz file // Also checks .gz file
if (isFile(this->name(), true)) if (isFile(this->name(), true))
{ {
check("IFstream::operator()"); check(FUNCTION_NAME);
FatalIOError.exit(); FatalIOError.exit();
} }
else else

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 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 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.
@ -25,7 +25,7 @@ Class
Foam::IFstream Foam::IFstream
Description Description
Input from file stream. Input from file stream, using a ISstream
SourceFiles SourceFiles
IFstream.C IFstream.C
@ -47,20 +47,21 @@ using std::ifstream;
namespace Foam namespace Foam
{ {
class IFstream;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class IFstreamAllocator Declaration Class IFstreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- A std::istream with ability to handle compressed files //- A std::istream with the ability to handle compressed files
class IFstreamAllocator class IFstreamAllocator
{ {
friend class IFstream; protected:
// Private data // Member Data
istream* ifPtr_; //- The allocated stream pointer (ifstream or igzstream).
std::istream* allocatedPtr_;
//- The requested compression type
IOstream::compressionType compression_; IOstream::compressionType compression_;
@ -72,6 +73,13 @@ class IFstreamAllocator
//- Destructor //- Destructor
~IFstreamAllocator(); ~IFstreamAllocator();
// Protected Member Functions
//- Delete the stream pointer
void deallocate();
}; };
@ -105,27 +113,30 @@ public:
~IFstream(); ~IFstream();
// Member functions // Member Functions
// Access // Access
//- Read/write access to the name of the stream //- Read/write access to the name of the stream
using ISstream::name; using ISstream::name;
// STL stream // STL stream
//- Access to underlying std::istream //- Access to underlying std::istream
virtual istream& stdStream(); virtual std::istream& stdStream();
//- Const access to underlying std::istream //- Const access to underlying std::istream
virtual const istream& stdStream() const; virtual const std::istream& stdStream() const;
//- Rewind the stream so that it may be read again
virtual Istream& rewind();
// Print // Print
//- Print description of IOstream to Ostream //- Print description of IOstream to Ostream
virtual void print(Ostream&) const; virtual void print(Ostream& os) const;
// Member operators // Member operators

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.
@ -43,7 +43,7 @@ Foam::OFstreamAllocator::OFstreamAllocator
IOstream::compressionType compression IOstream::compressionType compression
) )
: :
ofPtr_(nullptr) allocatedPtr_(nullptr)
{ {
if (pathname.empty()) if (pathname.empty())
{ {
@ -55,30 +55,40 @@ Foam::OFstreamAllocator::OFstreamAllocator
if (compression == IOstream::COMPRESSED) if (compression == IOstream::COMPRESSED)
{ {
// get identically named uncompressed version out of the way // Get identically named uncompressed version out of the way
if (isFile(pathname, false)) if (isFile(pathname, false))
{ {
rm(pathname); rm(pathname);
} }
ofPtr_ = new ogzstream((pathname + ".gz").c_str()); allocatedPtr_ = new ogzstream((pathname + ".gz").c_str());
} }
else else
{ {
// get identically named compressed version out of the way // Get identically named compressed version out of the way
if (isFile(pathname + ".gz", false)) if (isFile(pathname + ".gz", false))
{ {
rm(pathname + ".gz"); rm(pathname + ".gz");
} }
ofPtr_ = new ofstream(pathname.c_str()); allocatedPtr_ = new std::ofstream(pathname);
} }
} }
Foam::OFstreamAllocator::~OFstreamAllocator() Foam::OFstreamAllocator::~OFstreamAllocator()
{ {
delete ofPtr_; deallocate();
}
void Foam::OFstreamAllocator::deallocate()
{
if (allocatedPtr_)
{
delete allocatedPtr_;
allocatedPtr_ = nullptr;
}
} }
@ -93,10 +103,10 @@ Foam::OFstream::OFstream
) )
: :
OFstreamAllocator(pathname, compression), OFstreamAllocator(pathname, compression),
OSstream(*ofPtr_, pathname, format, version, compression) OSstream(*allocatedPtr_, pathname, format, version, compression)
{ {
setClosed(); setClosed();
setState(ofPtr_->rdstate()); setState(allocatedPtr_->rdstate());
if (!good()) if (!good())
{ {
@ -104,8 +114,7 @@ Foam::OFstream::OFstream
{ {
InfoInFunction InfoInFunction
<< "Could not open file " << pathname << "Could not open file " << pathname
<< "for input\n" << " for output" << nl << info() << Foam::endl;
"in stream " << info() << Foam::endl;
} }
setBad(); setBad();
@ -129,29 +138,29 @@ Foam::OFstream::~OFstream()
std::ostream& Foam::OFstream::stdStream() std::ostream& Foam::OFstream::stdStream()
{ {
if (!ofPtr_) if (!allocatedPtr_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "No stream allocated." << abort(FatalError); << "No stream allocated." << abort(FatalError);
} }
return *ofPtr_; return *allocatedPtr_;
} }
const std::ostream& Foam::OFstream::stdStream() const const std::ostream& Foam::OFstream::stdStream() const
{ {
if (!ofPtr_) if (!allocatedPtr_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "No stream allocated." << abort(FatalError); << "No stream allocated." << abort(FatalError);
} }
return *ofPtr_; return *allocatedPtr_;
} }
void Foam::OFstream::print(Ostream& os) const void Foam::OFstream::print(Ostream& os) const
{ {
os << " OFstream: "; os << "OFstream: ";
OSstream::print(os); OSstream::print(os);
} }

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 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 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.
@ -25,7 +25,7 @@ Class
Foam::OFstream Foam::OFstream
Description Description
Output to file stream. Output to file stream, using a OSstream
SourceFiles SourceFiles
OFstream.C OFstream.C
@ -47,18 +47,20 @@ using std::ofstream;
namespace Foam namespace Foam
{ {
class OFstream;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OFstreamAllocator Declaration Class OFstreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- A std::ostream with ability to handle compressed files //- A std::ostream with the ability to handle compressed files
class OFstreamAllocator class OFstreamAllocator
{ {
friend class OFstream; protected:
// Member Data
//- The allocated stream pointer (ofstream or ogzstream).
std::ostream* allocatedPtr_;
ostream* ofPtr_;
// Constructors // Constructors
@ -69,9 +71,16 @@ class OFstreamAllocator
IOstream::compressionType compression=IOstream::UNCOMPRESSED IOstream::compressionType compression=IOstream::UNCOMPRESSED
); );
//- Destructor //- Destructor
~OFstreamAllocator(); ~OFstreamAllocator();
// Protected Member Functions
//- Delete the stream pointer
void deallocate();
}; };
@ -81,7 +90,7 @@ class OFstreamAllocator
class OFstream class OFstream
: :
private OFstreamAllocator, public OFstreamAllocator,
public OSstream public OSstream
{ {
public: public:
@ -108,25 +117,25 @@ public:
// Member functions // Member functions
// Access // Access
//- Read/write access to the name of the stream //- Read/write access to the name of the stream
using OSstream::name; using OSstream::name;
// STL stream // STL stream
//- Access to underlying std::ostream //- Access to underlying std::ostream
virtual ostream& stdStream(); virtual std::ostream& stdStream();
//- Const access to underlying std::ostream //- Const access to underlying std::ostream
virtual const ostream& stdStream() const; virtual const std::ostream& stdStream() const;
// Print // Print
//- Print description of IOstream to Ostream //- Print description of IOstream to Ostream
void print(Ostream&) const; void print(Ostream& os) const;
}; };

View File

@ -799,7 +799,13 @@ Foam::Istream& Foam::ISstream::read(char* buf, std::streamsize count)
Foam::Istream& Foam::ISstream::rewind() Foam::Istream& Foam::ISstream::rewind()
{ {
stdStream().rdbuf()->pubseekpos(0); lineNumber_ = 1; // Reset line number
stdStream().clear(); // Clear the iostate error state flags
setGood(); // Sync local copy of iostate
// pubseekpos() rather than seekg() so that it works with gzstream
stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
return *this; return *this;
} }

View File

@ -56,23 +56,23 @@ class ISstream
// Private data // Private data
fileName name_; fileName name_;
istream& is_; std::istream& is_;
// Private Member Functions // Private Member Functions
char nextValid(); char nextValid();
void readWordToken(token&); void readWordToken(token& t);
// Private Member Functions // Private Member Functions
//- Read a verbatim string (excluding block delimiters). //- Read a verbatim string (excluding block delimiters).
Istream& readVerbatim(string&); Istream& readVerbatim(string& str);
//- Read a variable name (includes '{') //- Read a variable name (includes '{')
Istream& readVariable(string&); Istream& readVariable(string& str);
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const ISstream&) = delete; void operator=(const ISstream&) = delete;
@ -85,7 +85,7 @@ public:
//- Construct as wrapper around istream //- Construct as wrapper around istream
inline ISstream inline ISstream
( (
istream& is, std::istream& is,
const string& name, const string& name,
streamFormat format=ASCII, streamFormat format=ASCII,
versionNumber version=currentVersion, versionNumber version=currentVersion,
@ -123,7 +123,7 @@ public:
// Read functions // Read functions
//- Raw, low-level get character function. //- Raw, low-level get character function.
inline ISstream& get(char&); inline ISstream& get(char& c);
//- Raw, low-level peek function. //- Raw, low-level peek function.
// Does not remove the character from the stream. // Does not remove the character from the stream.
@ -132,36 +132,36 @@ public:
inline int peek(); inline int peek();
//- Raw, low-level getline into a string function. //- Raw, low-level getline into a string function.
inline ISstream& getLine(string&); inline ISstream& getLine(string& str);
//- Raw, low-level putback character function. //- Raw, low-level putback character function.
inline ISstream& putback(const char&); inline ISstream& putback(const char c);
//- Return next token from stream //- Return next token from stream
virtual Istream& read(token&); virtual Istream& read(token& t);
//- Read a character //- Read a character
virtual Istream& read(char&); virtual Istream& read(char& c);
//- Read a word //- Read a word
virtual Istream& read(word&); virtual Istream& read(word& str);
//- Read a string (including enclosing double-quotes). //- Read a string (including enclosing double-quotes).
// Backslashes are retained, except when escaping double-quotes // Backslashes are retained, except when escaping double-quotes
// and an embedded newline character. // and an embedded newline character.
virtual Istream& read(string&); virtual Istream& read(string& str);
//- Read a label //- Read a label
virtual Istream& read(label&); virtual Istream& read(label& val);
//- Read a floatScalar //- Read a floatScalar
virtual Istream& read(floatScalar&); virtual Istream& read(floatScalar& val);
//- Read a doubleScalar //- Read a doubleScalar
virtual Istream& read(doubleScalar&); virtual Istream& read(doubleScalar& val);
//- Read binary block //- Read binary block
virtual Istream& read(char*, std::streamsize); virtual Istream& read(char* buf, std::streamsize count);
//- Rewind and return the stream so that it may be read again //- Rewind and return the stream so that it may be read again
virtual Istream& rewind(); virtual Istream& rewind();
@ -169,20 +169,20 @@ public:
// Stream state functions // Stream state functions
//- Set flags of output stream //- Set stream flags
virtual ios_base::fmtflags flags(const ios_base::fmtflags flags); virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
// STL stream // STL stream
//- Access to underlying std::istream //- Access to underlying std::istream
virtual istream& stdStream() virtual std::istream& stdStream()
{ {
return is_; return is_;
} }
//- Const access to underlying std::istream //- Const access to underlying std::istream
virtual const istream& stdStream() const virtual const std::istream& stdStream() const
{ {
return is_; return is_;
} }
@ -191,7 +191,7 @@ public:
// Print // Print
//- Print description of IOstream to Ostream //- Print description of IOstream to Ostream
virtual void print(Ostream&) const; virtual void print(Ostream& os) const;
}; };

View File

@ -23,13 +23,11 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ISstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::ISstream::ISstream inline Foam::ISstream::ISstream
( (
istream& is, std::istream& is,
const string& name, const string& name,
streamFormat format, streamFormat format,
versionNumber version, versionNumber version,
@ -74,9 +72,9 @@ inline int Foam::ISstream::peek()
} }
inline Foam::ISstream& Foam::ISstream::getLine(string& s) inline Foam::ISstream& Foam::ISstream::getLine(string& str)
{ {
getline(is_, s); std::getline(is_, str);
setState(is_.rdstate()); setState(is_.rdstate());
lineNumber_++; lineNumber_++;
@ -84,7 +82,7 @@ inline Foam::ISstream& Foam::ISstream::getLine(string& s)
} }
inline Foam::ISstream& Foam::ISstream::putback(const char& c) inline Foam::ISstream& Foam::ISstream::putback(const char c)
{ {
if (c == '\n') if (c == '\n')
{ {

View File

@ -56,7 +56,7 @@ class OSstream
// Private data // Private data
fileName name_; fileName name_;
ostream& os_; std::ostream& os_;
// Private Member Functions // Private Member Functions
@ -72,7 +72,7 @@ public:
//- Construct and set stream status //- Construct and set stream status
OSstream OSstream
( (
ostream& os, std::ostream& os,
const string& name, const string& name,
streamFormat format=ASCII, streamFormat format=ASCII,
versionNumber version=currentVersion, versionNumber version=currentVersion,
@ -105,45 +105,45 @@ public:
// Write functions // Write functions
//- Write next token to stream //- Write next token to stream
virtual Ostream& write(const token&); virtual Ostream& write(const token& t);
//- Write character //- Write character
virtual Ostream& write(const char); virtual Ostream& write(const char c);
//- Write character string //- Write character string
virtual Ostream& write(const char*); virtual Ostream& write(const char* str);
//- Write word //- Write word
virtual Ostream& write(const word&); virtual Ostream& write(const word& str);
//- Write string //- Write string
// In the rare case that the string contains a final trailing // In the rare case that the string contains a final trailing
// backslash, it will be dropped to the appearance of an escaped // backslash, it will be dropped to the appearance of an escaped
// double-quote. // double-quote.
virtual Ostream& write(const string&); virtual Ostream& write(const string& str);
//- Write std::string surrounded by quotes. //- Write std::string surrounded by quotes.
// Optional write without quotes. // Optional write without quotes.
virtual Ostream& writeQuoted virtual Ostream& writeQuoted
( (
const std::string&, const std::string& str,
const bool quoted=true const bool quoted=true
); );
//- Write int32_t //- Write int32_t
virtual Ostream& write(const int32_t); virtual Ostream& write(const int32_t val);
//- Write int64_t //- Write int64_t
virtual Ostream& write(const int64_t); virtual Ostream& write(const int64_t val);
//- Write floatScalar //- Write floatScalar
virtual Ostream& write(const floatScalar); virtual Ostream& write(const floatScalar val);
//- Write doubleScalar //- Write doubleScalar
virtual Ostream& write(const doubleScalar); virtual Ostream& write(const doubleScalar val);
//- Write binary block //- Write binary block
virtual Ostream& write(const char*, std::streamsize); virtual Ostream& write(const char* buf, std::streamsize count);
//- Add indentation characters //- Add indentation characters
virtual void indent(); virtual void indent();
@ -151,8 +151,8 @@ public:
// Stream state functions // Stream state functions
//- Set flags of output stream //- Set stream flags
virtual ios_base::fmtflags flags(const ios_base::fmtflags flags); virtual ios_base::fmtflags flags(const ios_base::fmtflags f);
//- Flush stream //- Flush stream
virtual void flush(); virtual void flush();
@ -163,26 +163,28 @@ public:
//- Get width of output field //- Get width of output field
virtual int width() const; virtual int width() const;
//- Set width of output field (and return old width) //- Set width of output field
virtual int width(const int); // \return previous width
virtual int width(const int w);
//- Get precision of output field //- Get precision of output field
virtual int precision() const; virtual int precision() const;
//- Set precision of output field (and return old precision) //- Set precision of output field
virtual int precision(const int); // \return old precision
virtual int precision(const int p);
// STL stream // STL stream
//- Access to underlying std::ostream //- Access to underlying std::ostream
virtual ostream& stdStream() virtual std::ostream& stdStream()
{ {
return os_; return os_;
} }
//- Const access to underlying std::ostream //- Const access to underlying std::ostream
virtual const ostream& stdStream() const virtual const std::ostream& stdStream() const
{ {
return os_; return os_;
} }
@ -191,7 +193,7 @@ public:
// Print // Print
//- Print description of IOstream to Ostream //- Print description of IOstream to Ostream
virtual void print(Ostream&) const; virtual void print(Ostream& os) const;
}; };

View File

@ -29,7 +29,7 @@ License
inline Foam::OSstream::OSstream inline Foam::OSstream::OSstream
( (
ostream& os, std::ostream& os,
const string& name, const string& name,
streamFormat format, streamFormat format,
versionNumber version, versionNumber version,

View File

@ -43,7 +43,7 @@ inline void Foam::prefixOSstream::checkWritePrefix()
Foam::prefixOSstream::prefixOSstream Foam::prefixOSstream::prefixOSstream
( (
ostream& os, std::ostream& os,
const string& name, const string& name,
streamFormat format, streamFormat format,
versionNumber version, versionNumber version,
@ -182,4 +182,5 @@ void Foam::prefixOSstream::indent()
OSstream::indent(); OSstream::indent();
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -46,7 +46,7 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class prefixOSstream Declaration Class prefixOSstream Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class prefixOSstream class prefixOSstream
@ -71,7 +71,7 @@ public:
//- Construct and set stream status //- Construct and set stream status
prefixOSstream prefixOSstream
( (
ostream& os, std::ostream& os,
const string& name, const string& name,
streamFormat format=ASCII, streamFormat format=ASCII,
versionNumber version=currentVersion, versionNumber version=currentVersion,
@ -83,13 +83,13 @@ public:
// Enquiry // Enquiry
//- Return the prefix of the stream //- Return the sream prefix
const string& prefix() const const string& prefix() const
{ {
return prefix_; return prefix_;
} }
//- Return non-const access to the prefix of the stream //- Return non-const access to the stream prefix
string& prefix() string& prefix()
{ {
return prefix_; return prefix_;
@ -99,42 +99,42 @@ public:
// Write functions // Write functions
//- Write next token to stream //- Write next token to stream
virtual Ostream& write(const token&); virtual Ostream& write(const token& t);
//- Write character //- Write character
virtual Ostream& write(const char); virtual Ostream& write(const char c);
//- Write character string //- Write character string
virtual Ostream& write(const char*); virtual Ostream& write(const char* str);
//- Write word //- Write word
virtual Ostream& write(const word&); virtual Ostream& write(const word& val);
//- Write string //- Write string
virtual Ostream& write(const string&); virtual Ostream& write(const string& val);
//- Write std::string surrounded by quotes. //- Write std::string surrounded by quotes.
// Optional write without quotes. // Optional write without quotes.
virtual Ostream& writeQuoted virtual Ostream& writeQuoted
( (
const std::string&, const std::string& val,
const bool quoted=true const bool quoted=true
); );
//- Write int32_t //- Write int32_t
virtual Ostream& write(const int32_t); virtual Ostream& write(const int32_t val);
//- Write int64_t //- Write int64_t
virtual Ostream& write(const int64_t); virtual Ostream& write(const int64_t val);
//- Write floatScalar //- Write floatScalar
virtual Ostream& write(const floatScalar); virtual Ostream& write(const floatScalar val);
//- Write doubleScalar //- Write doubleScalar
virtual Ostream& write(const doubleScalar); virtual Ostream& write(const doubleScalar val);
//- Write binary block //- Write binary block
virtual Ostream& write(const char*, std::streamsize); virtual Ostream& write(const char* buf, std::streamsize count);
//- Add indentation characters //- Add indentation characters
virtual void indent(); virtual void indent();
@ -143,7 +143,7 @@ public:
// Print // Print
//- Print description of IOstream to Ostream //- Print description of IOstream to Ostream
virtual void print(Ostream&) const; virtual void print(Ostream& os) const;
}; };

View File

@ -1,141 +1,13 @@
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::IStringStream
Description Description
Input from memory buffer stream. Compatibility include
SourceFiles
StringStreamsPrint.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef IStringStream_H #ifndef IStringStream_H
#define IStringStream_H #define IStringStream_H
#include "ISstream.H" #include "StringStream.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class IStringStream Declaration
\*---------------------------------------------------------------------------*/
class IStringStream
:
public ISstream
{
public:
// Constructors
//- Construct from string
IStringStream
(
const string& buffer,
streamFormat format=ASCII,
versionNumber version=currentVersion
)
:
ISstream
(
*(new std::istringstream(buffer)),
"input",
format,
version
)
{}
//- Construct from char*
IStringStream
(
const char* buffer,
streamFormat format=ASCII,
versionNumber version=currentVersion
)
:
ISstream
(
*(new std::istringstream(buffer)),
"input",
format,
version
)
{}
//- Destructor
~IStringStream()
{
delete &dynamic_cast<std::istringstream&>(stdStream());
}
// Member functions
// Access
//- Return the string
string str() const
{
return dynamic_cast<const std::istringstream&>
(
stdStream()
).str();
}
// Print
//- Print description to Ostream
void print(Ostream&) const;
// Member operators
//- Return a non-const reference to const Istream
// Needed for read-constructors where the stream argument is temporary:
// e.g. thing thisThing(IFstream("thingFileName")());
Istream& operator()() const
{
return const_cast<IStringStream&>(*this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif

View File

@ -1,140 +1,13 @@
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::OStringStream
Description Description
Output to memory buffer stream. Compatibility include
SourceFiles
StringStreamsPrint.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef OStringStream_H #ifndef OStringStream_H
#define OStringStream_H #define OStringStream_H
#include "OSstream.H" #include "StringStream.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class OStringStream Declaration
\*---------------------------------------------------------------------------*/
class OStringStream
:
public OSstream
{
public:
// Constructors
//- Construct and set stream status
OStringStream
(
streamFormat format=ASCII,
versionNumber version=currentVersion
)
:
OSstream
(
*(new std::ostringstream()),
"output",
format,
version
)
{}
//- Construct as copy
OStringStream(const OStringStream& oss)
:
OSstream
(
*(
new std::ostringstream
(
dynamic_cast<const std::ostringstream&>
(
oss.stdStream()
).str()
)
),
oss.name(),
oss.format(),
oss.version()
)
{}
//- Destructor
~OStringStream()
{
delete &dynamic_cast<std::ostringstream&>(stdStream());
}
// Member functions
// Access
//- Return the string
string str() const
{
return dynamic_cast<const std::ostringstream&>
(
stdStream()
).str();
}
// Edit
//- Rewind the OStringStream
void rewind()
{
stdStream().rdbuf()->pubseekpos(0);
}
// Print
//- Print description to Ostream
void print(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif

View File

@ -21,15 +21,11 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Prints out a description of the StringStream
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "IStringStream.H" #include "StringStream.H"
#include "OStringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::IStringStream::print(Ostream& os) const void Foam::IStringStream::print(Ostream& os) const
{ {
@ -40,6 +36,8 @@ void Foam::IStringStream::print(Ostream& os) const
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::OStringStream::print(Ostream& os) const void Foam::OStringStream::print(Ostream& os) const
{ {
os << "OStringStream " << name() << " : " os << "OStringStream " << name() << " : "

View File

@ -0,0 +1,254 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InClass
Foam::StringStream
Description
Input/output from string buffers.
SourceFiles
StringStream.C
\*---------------------------------------------------------------------------*/
#ifndef StringStream_H
#define StringStream_H
#include "ISstream.H"
#include "OSstream.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class StringStreamAllocator Declaration
\*---------------------------------------------------------------------------*/
//- Allocator for variants of a std stringstream
template<class StreamType>
class StringStreamAllocator
{
protected:
// Member Data
//- The allocated stream pointer.
StreamType* allocatedPtr_;
// Constructors
//- Construct null
StringStreamAllocator()
:
allocatedPtr_(new StreamType())
{}
//- Construct from pointer, taking ownership
StringStreamAllocator(StreamType* ptr)
:
allocatedPtr_(ptr)
{}
//- Construct from string
StringStreamAllocator(const std::string& buffer)
:
allocatedPtr_(new StreamType(buffer))
{}
//- Destructor
~StringStreamAllocator()
{
deallocate();
}
// Protected Member Functions
//- Delete the stream pointer
void deallocate()
{
if (allocatedPtr_)
{
delete allocatedPtr_;
allocatedPtr_ = nullptr;
}
}
public:
// Public Member Functions
//- Get the string
Foam::string str() const
{
return allocatedPtr_->str();
}
//- Set the string
void str(const std::string& s)
{
allocatedPtr_->str(s);
}
};
/*---------------------------------------------------------------------------*\
Class IStringStream Declaration
\*---------------------------------------------------------------------------*/
//- Input from string buffer, using a ISstream
class IStringStream
:
public StringStreamAllocator<std::istringstream>,
public ISstream
{
public:
// Constructors
//- Construct from string
IStringStream
(
const Foam::string& buffer,
streamFormat format=ASCII,
versionNumber version=currentVersion
)
:
StringStreamAllocator<std::istringstream>(buffer),
ISstream(*allocatedPtr_, "input", format, version)
{}
//- Construct from char*
IStringStream
(
const char* buffer,
streamFormat format=ASCII,
versionNumber version=currentVersion
)
:
StringStreamAllocator<std::istringstream>(buffer),
ISstream(*allocatedPtr_, "input", format, version)
{}
//- Destructor
~IStringStream()
{}
// Member Functions
//- Print description to Ostream
void print(Ostream& os) const;
// Member operators
//- Return a non-const reference to const Istream
// Needed for read-constructors where the stream argument is temporary:
// e.g. thing thisThing(IFstream("thingFileName")());
Istream& operator()() const
{
return const_cast<IStringStream&>(*this);
}
};
/*---------------------------------------------------------------------------*\
Class OStringStream Declaration
\*---------------------------------------------------------------------------*/
//- Output to string buffer, using a OSstream
class OStringStream
:
public StringStreamAllocator<std::ostringstream>,
public OSstream
{
public:
// Constructors
//- Construct and set stream status
OStringStream
(
streamFormat format=ASCII,
versionNumber version=currentVersion
)
:
StringStreamAllocator<std::ostringstream>(),
OSstream(*allocatedPtr_, "output", format, version)
{}
//- Construct as copy
OStringStream(const OStringStream& oss)
:
StringStreamAllocator<std::ostringstream>(oss.str()),
OSstream(*allocatedPtr_, oss.name(), oss.format(), oss.version())
{}
//- Destructor
~OStringStream()
{}
// Member Functions
//- Reset the output buffer and rewind the stream
void reset()
{
this->str(""); // No other way to reset the end
this->rewind();
}
//- Rewind the output stream
void rewind()
{
// pubseekpos() instead of seekp() for symmetry with other classes
allocatedPtr_->rdbuf()->pubseekpos(0, std::ios_base::out);
}
//- Print description to Ostream
void print(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -126,6 +126,61 @@ public:
}; };
/*---------------------------------------------------------------------------*\
Class OSHA1streamAllocator Declaration
\*---------------------------------------------------------------------------*/
//- Allocator for an osha1stream
class OSHA1streamAllocator
{
protected:
// Member data
//- The allocated stream pointer
osha1stream* allocatedPtr_;
// Constructors
//- Construct null
OSHA1streamAllocator()
:
allocatedPtr_(new osha1stream())
{}
//- Destructor
~OSHA1streamAllocator()
{
deallocate();
}
// Member Functions
//- Delete the stream pointer
void deallocate()
{
if (allocatedPtr_)
{
delete allocatedPtr_;
allocatedPtr_ = nullptr;
}
}
public:
//- Full access to the sha1
SHA1& sha1()
{
return allocatedPtr_->sha1();
}
};
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OSHA1stream Declaration Class OSHA1stream Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -133,6 +188,7 @@ public:
//- The output stream for calculating SHA1 digests //- The output stream for calculating SHA1 digests
class OSHA1stream class OSHA1stream
: :
public OSHA1streamAllocator,
public OSstream public OSstream
{ {
@ -155,35 +211,22 @@ public:
versionNumber version=currentVersion versionNumber version=currentVersion
) )
: :
OSstream OSHA1streamAllocator(),
( OSstream(*allocatedPtr_, "OSHA1stream", format, version)
*(new osha1stream),
"OSHA1stream",
format,
version
)
{} {}
//- Destructor //- Destructor
~OSHA1stream() ~OSHA1stream()
{ {}
delete &dynamic_cast<osha1stream&>(stdStream());
}
// Member functions // Member functions
// Access // Access
//- Full access to the sha1
Foam::SHA1& sha1()
{
return dynamic_cast<osha1stream&>(stdStream()).sha1();
}
//- Return SHA1::Digest for the data processed until now //- Return SHA1::Digest for the data processed until now
Foam::SHA1Digest digest() SHA1Digest digest()
{ {
return sha1().digest(); return sha1().digest();
} }
@ -192,6 +235,13 @@ public:
// Edit // Edit
//- Clear the SHA1 calculation //- Clear the SHA1 calculation
void reset()
{
sha1().clear();
}
//- Clear the SHA1 calculation
// \deprecated use reset instead (deprecated Jul 2017)
void rewind() void rewind()
{ {
sha1().clear(); sha1().clear();

View File

@ -59,8 +59,8 @@ namespace Foam
class token; class token;
Istream& operator>>(Istream&, token&); Istream& operator>>(Istream& is, token& t);
Ostream& operator<<(Ostream&, const token&); Ostream& operator<<(Ostream& os, const token& t);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -418,8 +418,8 @@ public:
// IOstream operators // IOstream operators
friend Istream& operator>>(Istream&, token&); friend Istream& operator>>(Istream& is, token& t);
friend Ostream& operator<<(Ostream&, const token&); friend Ostream& operator<<(Ostream& os, const token& t);
friend Ostream& operator<<(Ostream&, const punctuationToken&); friend Ostream& operator<<(Ostream&, const punctuationToken&);
friend ostream& operator<<(ostream&, const punctuationToken&); friend ostream& operator<<(ostream&, const punctuationToken&);

View File

@ -23,8 +23,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include <iostream>
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline void Foam::token::clear() inline void Foam::token::clear()

View File

@ -39,7 +39,7 @@ Foam::token::token(Istream& is)
} }
// * * * * * * * * * * * * IOstream operators * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, token& t) Foam::Istream& Foam::operator>>(Istream& is, token& t)
{ {

View File

@ -30,7 +30,7 @@ Description
#include "Time.H" #include "Time.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "IStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -27,7 +27,7 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "IStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -25,7 +25,7 @@ License
#include "entry.H" #include "entry.H"
#include "dictionary.H" #include "dictionary.H"
#include "OStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -25,8 +25,7 @@ License
#include "codeStream.H" #include "codeStream.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OStringStream.H"
#include "dynamicCode.H" #include "dynamicCode.H"
#include "dynamicCodeContext.H" #include "dynamicCodeContext.H"
#include "Time.H" #include "Time.H"

View File

@ -26,8 +26,7 @@ License
#include "removeEntry.H" #include "removeEntry.H"
#include "dictionary.H" #include "dictionary.H"
#include "stringListOps.H" #include "stringListOps.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OStringStream.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -25,8 +25,7 @@ License
#include "primitiveEntry.H" #include "primitiveEntry.H"
#include "dictionary.H" #include "dictionary.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OStringStream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
#include "OStringStream.H" #include "StringStream.H"
#include "fileName.H" #include "fileName.H"
#include "dictionary.H" #include "dictionary.H"
#include "JobInfo.H" #include "JobInfo.H"
@ -193,8 +193,8 @@ void Foam::IOerror::exit(const int)
// Make a copy of the error to throw // Make a copy of the error to throw
IOerror errorException(*this); IOerror errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }
@ -238,8 +238,8 @@ void Foam::IOerror::abort()
// Make a copy of the error to throw // Make a copy of the error to throw
IOerror errorException(*this); IOerror errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
#include "OStringStream.H" #include "StringStream.H"
#include "fileName.H" #include "fileName.H"
#include "dictionary.H" #include "dictionary.H"
#include "JobInfo.H" #include "JobInfo.H"
@ -188,8 +188,8 @@ void Foam::error::exit(const int errNo)
// Make a copy of the error to throw // Make a copy of the error to throw
error errorException(*this); error errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }
@ -233,8 +233,8 @@ void Foam::error::abort()
// Make a copy of the error to throw // Make a copy of the error to throw
error errorException(*this); error errorException(*this);
// Rewind the message buffer for the next error message // Reset the message buffer for the next error message
messageStreamPtr_->rewind(); messageStreamPtr_->reset();
throw errorException; throw errorException;
} }

View File

@ -31,17 +31,18 @@ License
int Foam::messageStream::level(Foam::debug::debugSwitch("level", 2)); int Foam::messageStream::level(Foam::debug::debugSwitch("level", 2));
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::messageStream::messageStream Foam::messageStream::messageStream
( (
const string& title, const string& title,
errorSeverity sev, const errorSeverity severity,
const int maxErrors const int maxErrors
) )
: :
title_(title), title_(title),
severity_(sev), severity_(severity),
maxErrors_(maxErrors), maxErrors_(maxErrors),
errorCount_(0) errorCount_(0)
{} {}
@ -56,6 +57,8 @@ Foam::messageStream::messageStream(const dictionary& dict)
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::OSstream& Foam::messageStream::masterStream(const label communicator) Foam::OSstream& Foam::messageStream::masterStream(const label communicator)
{ {
if (UPstream::warnComm != -1 && communicator != UPstream::warnComm) if (UPstream::warnComm != -1 && communicator != UPstream::warnComm)
@ -76,6 +79,8 @@ Foam::OSstream& Foam::messageStream::masterStream(const label communicator)
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
Foam::OSstream& Foam::messageStream::operator() Foam::OSstream& Foam::messageStream::operator()
( (
const char* functionName, const char* functionName,
@ -237,7 +242,7 @@ Foam::messageStream::operator Foam::OSstream&()
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Variables * * * * * * * * * * * * * //
Foam::messageStream Foam::SeriousError Foam::messageStream Foam::SeriousError
( (

View File

@ -28,8 +28,8 @@ Description
Class to handle messaging in a simple, consistent stream-based Class to handle messaging in a simple, consistent stream-based
manner. manner.
The messageStream class is globaly instantiated with a title string a The messageStream class is globaly instantiated with a title string and
given severity, which controls the program termination, and a number of a severity (which controls the program termination) and a number of
errors before termination. Errors, messages and other data are piped to errors before termination. Errors, messages and other data are piped to
the messageStream class in the standard manner. the messageStream class in the standard manner.
@ -104,13 +104,13 @@ public:
messageStream messageStream
( (
const string& title, const string& title,
errorSeverity, const errorSeverity severity,
const int maxErrors = 0 const int maxErrors = 0
); );
//- Construct from dictionary //- Construct as Fatal from dictionary, extracting the 'title'.
messageStream(const dictionary&); messageStream(const dictionary& dict);
// Member functions // Member functions

View File

@ -25,7 +25,7 @@ License
#include "dimensionSet.H" #include "dimensionSet.H"
#include "dimensionedScalar.H" #include "dimensionedScalar.H"
#include "OStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -100,7 +100,7 @@ SourceFiles
#include "word.H" #include "word.H"
#include "fileName.H" #include "fileName.H"
#include "parRun.H" #include "parRun.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OSspecific.H" #include "OSspecific.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -28,7 +28,7 @@ License
#include "boolList.H" #include "boolList.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IOmanip.H" #include "IOmanip.H"
#include "OStringStream.H" #include "StringStream.H"
#include "Pstream.H" #include "Pstream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -25,7 +25,7 @@ License
#include "vectorTensorTransform.H" #include "vectorTensorTransform.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "OStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -28,7 +28,6 @@ License
#include "IOstreams.H" #include "IOstreams.H"
#include <inttypes.h> #include <inttypes.h>
#include <sstream>
#include <cerrno> #include <cerrno>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -28,7 +28,6 @@ License
#include "IOstreams.H" #include "IOstreams.H"
#include <inttypes.h> #include <inttypes.h>
#include <sstream>
#include <cerrno> #include <cerrno>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -27,8 +27,6 @@ License
#include "stringOps.H" #include "stringOps.H"
#include "IOstreams.H" #include "IOstreams.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::word Foam::name(const char* fmt, const uint32_t val) Foam::word Foam::name(const char* fmt, const uint32_t val)

View File

@ -27,8 +27,6 @@ License
#include "stringOps.H" #include "stringOps.H"
#include "IOstreams.H" #include "IOstreams.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::word Foam::name(const char* fmt, const uint64_t val) Foam::word Foam::name(const char* fmt, const uint64_t val)

View File

@ -25,7 +25,7 @@ License
#include "quaternion.H" #include "quaternion.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "OStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -25,7 +25,7 @@ License
#include "septernion.H" #include "septernion.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "OStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -27,7 +27,7 @@ License
#include "typeInfo.H" #include "typeInfo.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "etcFiles.H" #include "etcFiles.H"
#include "OStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -26,7 +26,7 @@ License
#include "ccmWriter.H" #include "ccmWriter.H"
#include "dictionary.H" #include "dictionary.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "ccmInternal.H" // include last to avoid any strange interactions #include "ccmInternal.H" // include last to avoid any strange interactions

View File

@ -45,7 +45,7 @@ void Foam::vtk::writeSurfFields
const bool legacy_(opts.legacy()); const bool legacy_(opts.legacy());
std::ofstream os((baseName + (legacy_ ? ".vtk" : ".vtp")).c_str()); std::ofstream os(baseName + (legacy_ ? ".vtk" : ".vtp"));
autoPtr<vtk::formatter> format = opts.newFormatter(os); autoPtr<vtk::formatter> format = opts.newFormatter(os);
// Same payload size for points and vector fields! // Same payload size for points and vector fields!

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ensightReadFile.H" #include "ensightReadFile.H"
#include <sstream>
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "NASCore.H" #include "NASCore.H"
#include "IStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -27,7 +27,7 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "clock.H" #include "clock.H"
#include "PackedBoolList.H" #include "PackedBoolList.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OSspecific.H" #include "OSspecific.H"

View File

@ -89,9 +89,9 @@ int Foam::fileFormats::STLCore::detectBinaryHeader
) )
{ {
bool compressed = false; bool compressed = false;
autoPtr<istream> streamPtr autoPtr<std::istream> streamPtr
( (
new ifstream(filename.c_str(), std::ios::binary) new std::ifstream(filename, std::ios::binary)
); );
// If the file is compressed, decompress it before further checking. // If the file is compressed, decompress it before further checking.
@ -100,7 +100,7 @@ int Foam::fileFormats::STLCore::detectBinaryHeader
compressed = true; compressed = true;
streamPtr.reset(new igzstream((filename + ".gz").c_str())); streamPtr.reset(new igzstream((filename + ".gz").c_str()));
} }
istream& is = streamPtr(); std::istream& is = streamPtr();
if (!is.good()) if (!is.good())
{ {
@ -165,9 +165,9 @@ Foam::fileFormats::STLCore::readBinaryHeader
bool compressed = false; bool compressed = false;
nTrisEstimated = 0; nTrisEstimated = 0;
autoPtr<istream> streamPtr autoPtr<std::istream> streamPtr
( (
new ifstream(filename.c_str(), std::ios::binary) new std::ifstream(filename, std::ios::binary)
); );
// If the file is compressed, decompress it before reading. // If the file is compressed, decompress it before reading.
@ -176,7 +176,7 @@ Foam::fileFormats::STLCore::readBinaryHeader
compressed = true; compressed = true;
streamPtr.reset(new igzstream((filename + ".gz").c_str())); streamPtr.reset(new igzstream((filename + ".gz").c_str()));
} }
istream& is = streamPtr(); std::istream& is = streamPtr();
if (!is.good()) if (!is.good())
{ {

View File

@ -33,7 +33,7 @@ License
#include "mixedFvPatchFields.H" #include "mixedFvPatchFields.H"
#include "fixedGradientFvPatchFields.H" #include "fixedGradientFvPatchFields.H"
#include "fixedValueFvPatchFields.H" #include "fixedValueFvPatchFields.H"
#include "OStringStream.H" #include "StringStream.H"
#include "globalIndex.H" #include "globalIndex.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -25,7 +25,7 @@ License
#include "NASedgeFormat.H" #include "NASedgeFormat.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "PackedBoolList.H" #include "PackedBoolList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -26,7 +26,7 @@ License
#include "OBJedgeFormat.H" #include "OBJedgeFormat.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "Ostream.H" #include "Ostream.H"
#include "OFstream.H" #include "OFstream.H"
#include "ListOps.H" #include "ListOps.H"

View File

@ -27,7 +27,7 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "clock.H" #include "clock.H"
#include "PackedBoolList.H" #include "PackedBoolList.H"
#include "IStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -45,7 +45,7 @@ void Foam::vtk::writeCellSetFaces
const bool legacy_(opts.legacy()); const bool legacy_(opts.legacy());
std::ofstream os((baseName + (legacy_ ? ".vtk" : ".vtp")).c_str()); std::ofstream os(baseName + (legacy_ ? ".vtk" : ".vtp"));
autoPtr<vtk::formatter> format = opts.newFormatter(os); autoPtr<vtk::formatter> format = opts.newFormatter(os);

View File

@ -45,7 +45,7 @@ void Foam::vtk::writeFaceSet
const bool legacy_(opts.legacy()); const bool legacy_(opts.legacy());
std::ofstream os((baseName + (legacy_ ? ".vtk" : ".vtp")).c_str()); std::ofstream os(baseName + (legacy_ ? ".vtk" : ".vtp"));
autoPtr<vtk::formatter> format = opts.newFormatter(os); autoPtr<vtk::formatter> format = opts.newFormatter(os);

View File

@ -44,7 +44,7 @@ void Foam::vtk::writePointSet
const bool legacy_(opts.legacy()); const bool legacy_(opts.legacy());
std::ofstream os((baseName + (legacy_ ? ".vtk" : ".vtp")).c_str()); std::ofstream os(baseName + (legacy_ ? ".vtk" : ".vtp"));
autoPtr<vtk::formatter> format = opts.newFormatter(os); autoPtr<vtk::formatter> format = opts.newFormatter(os);

View File

@ -37,6 +37,7 @@ SourceFiles
#include "surfaceReader.H" #include "surfaceReader.H"
#include "ensightReadFile.H" #include "ensightReadFile.H"
#include "StringStream.H"
#include "Tuple2.H" #include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -30,7 +30,7 @@ License
#include "ensightPartFaces.H" #include "ensightPartFaces.H"
#include "ensightSerialOutput.H" #include "ensightSerialOutput.H"
#include "ensightPTraits.H" #include "ensightPTraits.H"
#include "OStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "AC3DsurfaceFormat.H" #include "AC3DsurfaceFormat.H"
#include "IStringStream.H" #include "StringStream.H"
#include "PrimitivePatch.H" #include "PrimitivePatch.H"
#include "faceTraits.H" #include "faceTraits.H"

View File

@ -26,7 +26,7 @@ License
#include "AC3DsurfaceFormatCore.H" #include "AC3DsurfaceFormatCore.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "AC3DsurfaceFormatCore.H" #include "AC3DsurfaceFormatCore.H"
#include "IStringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -27,7 +27,7 @@ License
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OFstream.H" #include "OFstream.H"
#include "faceTraits.H" #include "faceTraits.H"

View File

@ -25,7 +25,7 @@ License
#include "NASsurfaceFormat.H" #include "NASsurfaceFormat.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "faceTraits.H" #include "faceTraits.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -26,7 +26,7 @@ License
#include "OBJsurfaceFormat.H" #include "OBJsurfaceFormat.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "StringStream.H"
#include "OFstream.H" #include "OFstream.H"
#include "ListOps.H" #include "ListOps.H"
#include "faceTraits.H" #include "faceTraits.H"

Some files were not shown because too many files have changed in this diff Show More