Commit 86ef9e86 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: make treatment of stream allocators more uniform (issue #532)

- use allocator class to wrap the stream pointers instead of passing
  them into ISstream, OSstream and using a dynamic cast to delete
  then. This is especially important if we will have a bidirectional
  stream (can't delete twice!).

STYLE:

- file stream constructors with std::string (C++11)

- for rewind, explicit about in|out direction. This is not currently
  important, but avoids surprises with any future bidirectional access.

- combined string streams in StringStream.H header.
  Similar to <sstream> include that has both input and output string
  streams.
parent b0db30ba
......@@ -31,8 +31,7 @@ Description
#include "CompactListList.H"
#include "IOstreams.H"
#include "OStringStream.H"
#include "IStringStream.H"
#include "StringStream.H"
#include "faceList.H"
using namespace Foam;
......
......@@ -29,8 +29,7 @@ License
#include "DynamicList.H"
#include "FlatOutput.H"
#include "IOstreams.H"
#include "IStringStream.H"
#include "OStringStream.H"
#include "StringStream.H"
using namespace Foam;
......
......@@ -25,7 +25,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "IStringStream.H"
#include "StringStream.H"
#include "wordList.H"
#include "IOstreams.H"
......
......@@ -37,7 +37,7 @@ See also
#include "wordReList.H"
#include "IOstreams.H"
#include "IStringStream.H"
#include "StringStream.H"
#include "scalar.H"
#include "vector.H"
......
......@@ -25,8 +25,8 @@ Description
\*---------------------------------------------------------------------------*/
#include "OStringStream.H"
#include "IOstreams.H"
#include "StringStream.H"
using namespace Foam;
......@@ -35,15 +35,26 @@ using namespace Foam;
int main(int argc, char *argv[])
{
Info<< "khkj" << endl;
OStringStream testStream;
testStream << "hello " << 1 << endl;
Info<< testStream.str() << endl;
testStream.rewind();
Info<< testStream.str() << endl;
testStream << "hello " << 2 << endl;
Info<< testStream.str() << endl;
Info<< "Begin test OStringStream" << endl;
OStringStream os;
os << "output with some values " << 1 << " entry" << endl;
Info<< "contains:" << nl
<< os.str() << endl;
os.rewind();
Info<< "after rewind:" << nl
<< os.str() << endl;
os << "####";
Info<< "overwrite with short string:" << nl
<< os.str() << endl;
// os.reset();
// Info<< "after reset:" << nl
// << os.str() << endl;
Info<< "End\n" << endl;
......
......@@ -30,7 +30,7 @@ Description
#include "uLabel.H"
#include "IOstreams.H"
#include "PackedBoolList.H"
#include "IStringStream.H"
#include "StringStream.H"
using namespace Foam;
......
......@@ -29,7 +29,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "IStringStream.H"
#include "StringStream.H"
#include "Polynomial.H"
#include "polynomialFunction.H"
#include "Random.H"
......
......@@ -25,8 +25,7 @@ License
#include "StaticHashTable.H"
#include "IOstreams.H"
#include "IStringStream.H"
#include "OStringStream.H"
#include "StringStream.H"
using namespace Foam;
......
......@@ -26,7 +26,6 @@ License
#include "argList.H"
#include "Time.H"
#include "fvMesh.H"
#include "IStringStream.H"
#include "indexedOctree.H"
#include "treeDataCell.H"
#include "OFstream.H"
......
......@@ -26,7 +26,6 @@ License
#include "argList.H"
#include "Time.H"
#include "fvMesh.H"
#include "IStringStream.H"
#include "indexedOctree.H"
#include "treeDataEdge.H"
#include "OFstream.H"
......
......@@ -34,8 +34,6 @@ Description
#include "Time.H"
#include "polyMesh.H"
#include "IOstreams.H"
#include "OStringStream.H"
#include "IStringStream.H"
using namespace Foam;
......
......@@ -31,7 +31,6 @@ Description
#include "OSspecific.H"
#include "IOstreams.H"
#include "IStringStream.H"
#include "scalar.H"
#include "vector.H"
#include "ListOps.H"
......@@ -49,31 +48,26 @@ int main(int argc, char *argv[])
//Pout.prefix() = '[' + name(Pstream::myProcNo()) + "] ";
List<vector> list(IStringStream("1 ((0 1 2))")());
List<vector> list{{0, 1, 2}};
Info<< list << endl;
List<vector> list2
(
IStringStream
(
"(\
(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)\
)"
)()
);
{
{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},
};
Pout<< list2 << endl;
Info<< findIndex(list2, vector(3, 4, 5)) << endl;
......
......@@ -28,10 +28,8 @@ Description
#include "argList.H"
#include "label.H"
#include "labelList.H"
#include "OStringStream.H"
#include "IStringStream.H"
#include "OFstream.H"
#include "IFstream.H"
#include "OFstream.H"
#include "point.H"
#include "Time.H"
#include "fvMesh.H"
......
......@@ -30,7 +30,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "OSHA1stream.H"
#include "IStringStream.H"
#include "StringStream.H"
#include "dictionary.H"
using namespace Foam;
......
......@@ -32,7 +32,6 @@ Description
#include "dictionary.H"
#include "nil.H"
#include "IOstreams.H"
#include "IStringStream.H"
namespace Foam
{
......
......@@ -26,8 +26,8 @@ Description
\*---------------------------------------------------------------------------*/
#include "stringListOps.H"
#include "IStringStream.H"
#include "IOstreams.H"
#include "StringStream.H"
using namespace Foam;
......@@ -37,22 +37,17 @@ using namespace Foam;
int main(int argc, char *argv[])
{
stringList strLst
(
IStringStream
(
"("
"\"hello\""
"\"heello\""
"\"heeello\""
"\"bye\""
"\"bbye\""
"\"bbbye\""
"\"okey\""
"\"okkey\""
"\"okkkey\""
")"
)()
);
{
"hello",
"heello",
"heeello",
"bye",
"bbye",
"bbbye",
"okey",
"okkey",
"okkkey",
};
wordReList reLst(IStringStream("( okey \"[hy]e+.*\" )")());
......
......@@ -31,7 +31,7 @@ Description
#include "IOobject.H"
#include "IOstreams.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "StringStream.H"
#include "cpuTime.H"
using namespace Foam;
......
......@@ -30,7 +30,6 @@ Description
#include "OSspecific.H"
#include "IOstreams.H"
#include "IStringStream.H"
#include "labelList.H"
#include "DynamicList.H"
#include "face.H"
......
......@@ -46,7 +46,7 @@ Description
#include <cstdio>
#include "scalar.H"
#include "IStringStream.H"
#include "StringStream.H"
using namespace Foam;
......@@ -271,7 +271,6 @@ elementType ^{space}"TYPE"{cspace}
#include "fileName.H"
#include <fstream>
using std::ifstream;
label findFace(const polyMesh& mesh, const face& f)
......@@ -318,8 +317,8 @@ int main(int argc, char *argv[])
#include "createTime.H"
fileName ansysFile(args[1]);
ifstream ansysStream(ansysFile.c_str());
const fileName ansysFile(args[1]);
std::ifstream ansysStream(ansysFile);
if (!ansysStream)
{
......
......@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
std::ifstream plot3dFile(args[1].c_str());
std::ifstream plot3dFile(args[1]);
string line;
std::getline(plot3dFile, line);
......
......@@ -43,7 +43,7 @@ Description
#include "argList.H"
#include "Time.H"
#include "IStringStream.H"
#include "StringStream.H"
#include "polyMesh.H"
#include "emptyPolyPatch.H"
#include "wallPolyPatch.H"
......@@ -906,7 +906,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const fileName fluentFile = args[1];
std::ifstream fluentStream(fluentFile.c_str());
std::ifstream fluentStream(fluentFile);
if (!fluentStream)
{
......
......@@ -26,7 +26,6 @@ License
#include <fstream>
#include <iostream>
using std::ofstream;
using std::ios;
#include "Time.H"
......@@ -49,18 +48,16 @@ Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
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");
// open a file for the mesh
ofstream fluentMeshFile
// Open a file for the mesh
std::ofstream fluentMeshFile
(
(
time().rootPath()/
time().caseName()/
"fluentInterface"/
time().caseName() + ".msh"
).c_str()
time().rootPath()
/ time().caseName()
/ "fluentInterface"
/ time().caseName() + ".msh"
);
Info<< "Writing Header" << endl;
......
......@@ -41,7 +41,7 @@ Description
\* ------------------------------------------------------------------------- */
#include "scalarList.H"
#include "IStringStream.H"
#include "StringStream.H"
// For EOF only
#include <cstdio>
......@@ -622,7 +622,6 @@ mtype {space}"MTYPE:"{space}
#include "fileName.H"
#include <fstream>
using std::ifstream;
int main(int argc, char *argv[])
{
......@@ -647,7 +646,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const fileName gambitFile = args[1];
ifstream gambitStream(gambitFile.c_str());
std::ifstream gambitStream(gambitFile);
if (!gambitStream)
{
......
ifstream kivaFile(kivaFileName.c_str());
std::ifstream kivaFile(kivaFileName);
if (!kivaFile.good())
{
......
......@@ -27,8 +27,7 @@ License
#include "point.H"
#include "Istream.H"
#include "Ostream.H"
#include "OStringStream.H"
#include "IStringStream.H"
#include "StringStream.H"
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
......
......@@ -36,7 +36,6 @@ Description
#include "argList.H"
#include "fvMesh.H"
#include "pointFields.H"
#include "IStringStream.H"
#include "volPointInterpolation.H"
using namespace Foam;
......
......@@ -34,16 +34,12 @@ Description
#include "argList.H"
#include "OFstream.H"
#include <fstream>
#include <sstream>
#include "IStringStream.H"
#include "StringStream.H"
#include "point.H"
#include "DynamicList.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
string getLine(std::ifstream& is)
......@@ -122,7 +118,7 @@ int main(int argc, char *argv[])
const fileName objName = args[1];
const fileName outName = args[2];
std::ifstream OBJfile(objName.c_str());
std::ifstream OBJfile(objName);
if (!OBJfile.good())
{
......
......@@ -36,7 +36,7 @@ Description
#include "Time.H"
#include "polyMesh.H"
#include "globalMeshData.H"
#include "IStringStream.H"
#include "StringStream.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
......
......@@ -46,12 +46,9 @@ Description
#include "argList.H"
#include "Time.H"
#include "polyMesh.H"
#include "IStringStream.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "OFstream.H"
#include "IFstream.H"
#include "IOobjectList.H"
#include "SortableList.H"
#include "timeSelector.H"
......
......@@ -68,7 +68,7 @@ Usage
#include "pointFields.H"
#include "transformField.H"
#include "transformGeometricField.H"
#include "IStringStream.H"
#include "StringStream.H"
#include "mathematicalConstants.H"
using namespace Foam;
......
......@@ -31,7 +31,7 @@ License
#include "blockMeshTools.H"
#include "Time.H"
#include "patchZones.H"
#include "OStringStream.H"
#include "StringStream.H"
// VTK includes
#include "vtkDataArraySelection.h"
......
......@@ -26,7 +26,7 @@ License
#include "boundaryTemplates.H"
#include "Time.H"
#include "IFstream.H"
#include "OStringStream.H"
#include "StringStream.H"
using namespace Foam;
......
......@@ -71,8 +71,7 @@ Note
#include "ModifiableMeshedSurface.H"
#include "UnsortedMeshedSurfaces.H"
#include "IStringStream.H"
#include "OStringStream.H"
#include "StringStream.H"
using namespace Foam;
......
......@@ -36,8 +36,7 @@ Description
#include "argList.H"
#include "chemkinReader.H"
#include "OFstream.H"
#include "OStringStream.H"
#include "IStringStream.H"
#include "StringStream.H"
using namespace Foam;
......
......@@ -724,13 +724,13 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
}
// Open and check streams.
std::ifstream srcStream(src.c_str());
std::ifstream srcStream(src);
if (!srcStream)
{
return false;
}
std::ofstream destStream(destFile.c_str());
std::ofstream destStream(destFile);
if (!destStream)
{
return false;
......
......@@ -24,9 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "OStringStream.H"
#include "OSspecific.H"
#include "IFstream.H"
#include "StringStream.H"
#include <inttypes.h>
#include <cxxabi.h>
......@@ -55,7 +55,7 @@ string pOpen(const string &cmd, label line=0)
{
size_t linecap = 0;
ssize_t linelen;
linelen = getline(&buf, &linecap, cmdPipe);
linelen = ::getline(&buf, &linecap, cmdPipe);
if (linelen < 0)
{
......
......@@ -171,7 +171,7 @@ Tstreams = $(Streams)/Tstreams
$(Tstreams)/ITstream.C
StringStreams = $(Streams)/StringStreams
$(StringStreams)/StringStreamsPrint.C