reworked IOstreams

- Istream and Ostream now retain backslashes when reading/writing strings.
  The previous implementation simply discarded them, except when used to
  escape a double-quote or a newline. It is now vitally important to retain
  them, eg for quoting regular expression meta-characters.

  The backslash continues to be used as an escape character for double-quote
  and newline, but otherwise get passed through "as-is" without any other
  special meaning (ie, they are *NOT* C-style strings). This helps avoid
  'backslash hell'!
  For example,
     string:   "match real dots \.+, question mark \? or any char .*"
     C-style:  "match real dots \\.+, question mark \\? or any char .*"

- combined subfiles in db/IOstreams, some had more copyright info than code
- OPstreamI.H contained only private methods, moved into OPstream.C

Are these really correct?
   IOstreams/Istream.H:#   include "HashTable.C"
   token/token.H:#define NoHashTableC
This commit is contained in:
Mark Olesen
2009-01-03 12:52:27 +01:00
parent cf488912bb
commit 1d866d7fe8
48 changed files with 1276 additions and 1757 deletions

View File

@ -48,11 +48,16 @@ int main(int argc, char *argv[])
Info<< string(test).expand() << endl; Info<< string(test).expand() << endl;
string test2("~OpenFOAM/controlDict"); string test2("~OpenFOAM/controlDict");
Info<< test2.expand() << endl; Info<< test2 << " => " << test2.expand() << endl;
string s; string s;
Sin.getLine(s); Sin.getLine(s);
Info<< s.expand() << endl;
string s2(s.expand());
cout<< "output string with " << s2.length() << " characters\n";
cout<< "ostream<< >" << s2 << "<\n";
Info<< "Ostream<< >" << s2 << "<\n";
Info << "End\n" << endl; Info << "End\n" << endl;

View File

@ -65,21 +65,15 @@ $(Streams)/token/tokenIO.C
IOstreams = $(Streams)/IOstreams IOstreams = $(Streams)/IOstreams
$(IOstreams)/IOstream.C $(IOstreams)/IOstream.C
$(IOstreams)/versionNumber.C
$(IOstreams)/Istream.C $(IOstreams)/Istream.C
$(IOstreams)/IOprint.C
$(IOstreams)/IOcheck.C
$(IOstreams)/Ostream.C $(IOstreams)/Ostream.C
Sstreams = $(Streams)/Sstreams Sstreams = $(Streams)/Sstreams
$(Sstreams)/ISread.C $(Sstreams)/ISstream.C
$(Sstreams)/ISnextValid.C $(Sstreams)/OSstream.C
$(Sstreams)/ISreadToken.C $(Sstreams)/SstreamsPrint.C
$(Sstreams)/readHexLabel.C $(Sstreams)/readHexLabel.C
$(Sstreams)/OSwrite.C $(Sstreams)/prefixOSstream.C
$(Sstreams)/Sprint.C
$(Sstreams)/prefixOSstream/prefixOSwrite.C
$(Sstreams)/prefixOSstream/prefixOSprint.C
gzstream = $(Streams)/gzstream gzstream = $(Streams)/gzstream
$(gzstream)/gzstream.C $(gzstream)/gzstream.C
@ -89,19 +83,17 @@ $(Fstreams)/IFstream.C
$(Fstreams)/OFstream.C $(Fstreams)/OFstream.C
Tstreams = $(Streams)/Tstreams Tstreams = $(Streams)/Tstreams
$(Tstreams)/ITread.C $(Tstreams)/ITstream.C
$(Tstreams)/Tprint.C
StringStreams = $(Streams)/StringStreams StringStreams = $(Streams)/StringStreams
$(StringStreams)/StringStreamPrint.C $(StringStreams)/StringStreamsPrint.C
Pstreams = $(Streams)/Pstreams Pstreams = $(Streams)/Pstreams
$(Pstreams)/Pstream.C $(Pstreams)/Pstream.C
$(Pstreams)/PstreamCommsStruct.C $(Pstreams)/PstreamCommsStruct.C
$(Pstreams)/IPread.C $(Pstreams)/IPstream.C
$(Pstreams)/OPwrite.C $(Pstreams)/OPstream.C
$(Pstreams)/Pprint.C $(Pstreams)/PstreamsPrint.C
$(Pstreams)/IPreadToken.C
dictionary = db/dictionary dictionary = db/dictionary
$(dictionary)/dictionary.C $(dictionary)/dictionary.C
@ -335,17 +327,15 @@ $(globalMeshData)/globalIndex.C
$(polyMesh)/syncTools/syncTools.C $(polyMesh)/syncTools/syncTools.C
zones = $(polyMesh)/zones cellZone = $(polyMesh)/zones/cellZone
cellZone = $(zones)/cellZone
$(cellZone)/cellZone.C $(cellZone)/cellZone.C
$(cellZone)/newCellZone.C $(cellZone)/newCellZone.C
faceZone = $(zones)/faceZone faceZone = $(polyMesh)/zones/faceZone
$(faceZone)/faceZone.C $(faceZone)/faceZone.C
$(faceZone)/newFaceZone.C $(faceZone)/newFaceZone.C
pointZone = $(zones)/pointZone pointZone = $(polyMesh)/zones/pointZone
$(pointZone)/pointZone.C $(pointZone)/pointZone.C
$(pointZone)/newPointZone.C $(pointZone)/newPointZone.C
@ -462,6 +452,7 @@ $(Fields)/diagTensorField/diagTensorIOField.C
$(Fields)/symmTensorField/symmTensorIOField.C $(Fields)/symmTensorField/symmTensorIOField.C
$(Fields)/tensorField/tensorIOField.C $(Fields)/tensorField/tensorIOField.C
$(Fields)/transformField/transformField.C $(Fields)/transformField/transformField.C
pointPatchFields = fields/pointPatchFields pointPatchFields = fields/pointPatchFields
$(pointPatchFields)/pointPatchField/pointPatchFields.C $(pointPatchFields)/pointPatchField/pointPatchFields.C

View File

@ -28,18 +28,16 @@ License
#include "OSspecific.H" #include "OSspecific.H"
#include "gzstream.h" #include "gzstream.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(IFstream, 0);
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // }
defineTypeNameAndDebug(IFstream, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
IFstreamAllocator::IFstreamAllocator(const fileName& pathname) Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
: :
ifPtr_(NULL), ifPtr_(NULL),
compression_(IOstream::UNCOMPRESSED) compression_(IOstream::UNCOMPRESSED)
@ -48,10 +46,8 @@ IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
{ {
if (IFstream::debug) if (IFstream::debug)
{ {
Info<< "IFstreamAllocator::IFstreamAllocator" Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : "
"(const fileName& pathname) : " "cannot open null file " << endl;
"can't open null file "
<< endl;
} }
} }
@ -62,10 +58,8 @@ IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
{ {
if (IFstream::debug) if (IFstream::debug)
{ {
Info<< "IFstreamAllocator::IFstreamAllocator" Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : "
"(const fileName& pathname) : " "decompressing " << pathname + ".gz" << endl;
"decompressing " << pathname + ".gz"
<< endl;
} }
delete ifPtr_; delete ifPtr_;
@ -80,18 +74,18 @@ IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
} }
IFstreamAllocator::~IFstreamAllocator() Foam::IFstreamAllocator::~IFstreamAllocator()
{ {
delete ifPtr_; delete ifPtr_;
} }
istream& IFstreamAllocator::stdStream() std::istream& Foam::IFstreamAllocator::stdStream()
{ {
if (!ifPtr_) if (!ifPtr_)
{ {
FatalErrorIn("IFstreamAllocator::stdStream()") FatalErrorIn("IFstreamAllocator::stdStream()")
<< "No stream allocated." << abort(FatalError); << "No stream allocated" << abort(FatalError);
} }
return *ifPtr_; return *ifPtr_;
} }
@ -99,7 +93,7 @@ istream& IFstreamAllocator::stdStream()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
IFstream::IFstream Foam::IFstream::IFstream
( (
const fileName& pathname, const fileName& pathname,
streamFormat format, streamFormat format,
@ -120,15 +114,15 @@ IFstream::IFstream
setClosed(); setClosed();
setState(ifPtr_->rdstate()); setState(ifPtr_->rdstate());
if (!good()) if (!good())
{ {
if (debug) if (debug)
{ {
Info<< "IFstream::IFstream(const fileName& pathname," Info<< "IFstream::IFstream(const fileName&,"
"streamFormat format=ASCII," "streamFormat format=ASCII,"
"versionNumber version=currentVersion) : " "versionNumber version=currentVersion) : "
"couldn't open File for input" "could not open file for input"
<< endl << info() << endl; << endl << info() << endl;
} }
@ -138,20 +132,20 @@ IFstream::IFstream
{ {
setOpened(); setOpened();
} }
lineNumber_ = 1; lineNumber_ = 1;
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
IFstream::~IFstream() Foam::IFstream::~IFstream()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void IFstream::print(Ostream& os) const void Foam::IFstream::print(Ostream& os) const
{ {
// Print File data // Print File data
os << "IFstream: "; os << "IFstream: ";
@ -159,10 +153,9 @@ void IFstream::print(Ostream& os) const
} }
//- Return a non-const reference to const Istream // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
// Needed for read-constructors where the stream argument is temporary:
// e.g. thing thisThing(IFstream("thingFileName")()); Foam::IFstream& Foam::IFstream::operator()() const
IFstream& IFstream::operator()() const
{ {
if (!good()) if (!good())
{ {
@ -183,8 +176,4 @@ IFstream& IFstream::operator()() const
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -28,18 +28,17 @@ License
#include "OSspecific.H" #include "OSspecific.H"
#include "gzstream.h" #include "gzstream.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(OFstream, 0);
}
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(OFstream, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OFstreamAllocator::OFstreamAllocator Foam::OFstreamAllocator::OFstreamAllocator
( (
const fileName& pathname, const fileName& pathname,
IOstream::compressionType compression IOstream::compressionType compression
@ -51,11 +50,8 @@ OFstreamAllocator::OFstreamAllocator
{ {
if (OFstream::debug) if (OFstream::debug)
{ {
Info Info<< "OFstreamAllocator::OFstreamAllocator(const fileName&) : "
<< "OFstreamAllocator::OFstreamAllocator" "cannot open null file " << endl;
"(const fileName& pathname) : "
"can't open null file "
<< endl;
} }
} }
@ -80,13 +76,13 @@ OFstreamAllocator::OFstreamAllocator
} }
OFstreamAllocator::~OFstreamAllocator() Foam::OFstreamAllocator::~OFstreamAllocator()
{ {
delete ofPtr_; delete ofPtr_;
} }
ostream& OFstreamAllocator::stdStream() std::ostream& Foam::OFstreamAllocator::stdStream()
{ {
if (!ofPtr_) if (!ofPtr_)
{ {
@ -99,7 +95,7 @@ ostream& OFstreamAllocator::stdStream()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
OFstream::OFstream Foam::OFstream::OFstream
( (
const fileName& pathname, const fileName& pathname,
streamFormat format, streamFormat format,
@ -112,17 +108,16 @@ OFstream::OFstream
pathname_(pathname) pathname_(pathname)
{ {
setClosed(); setClosed();
setState(ofPtr_->rdstate()); setState(ofPtr_->rdstate());
if (!good()) if (!good())
{ {
if (debug) if (debug)
{ {
Info<< "IFstream::IFstream(const fileName& pathname," Info<< "IFstream::IFstream(const fileName&,"
"streamFormat format=ASCII," "streamFormat format=ASCII,"
"versionNumber version=currentVersion) : " "versionNumber version=currentVersion) : "
"couldn't open File for input\n" "could not open file for input\n"
"in stream " << info() << Foam::endl; "in stream " << info() << Foam::endl;
} }
@ -132,29 +127,24 @@ OFstream::OFstream
{ {
setOpened(); setOpened();
} }
lineNumber_ = 1; lineNumber_ = 1;
} }
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
OFstream::~OFstream() Foam::OFstream::~OFstream()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void OFstream::print(Ostream& os) const void Foam::OFstream::print(Ostream& os) const
{ {
// Print File data
os << " OFstream: "; os << " OFstream: ";
OSstream::print(os); OSstream::print(os);
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,85 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
IOstream check.
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IOstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
fileName IOstream::name_("IOstream");
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// check file status for given operation
bool IOstream::check(const char* operation) const
{
if (bad())
{
FatalIOErrorIn
(
"IOstream::check(const char* operation) const", *this
) << "IOstream::check(const char* operation) : "
<< "error in IOstream " << name() << " for operation "
<< operation
<< exit(FatalIOError);
}
return !bad();
}
//- Check IOstream status for given operation
// print IOstream state if error has occured and exit
void IOstream::fatalCheck(const char* operation) const
{
if (bad())
{
FatalIOErrorIn
(
"IOstream::fatalCheck(const char* operation) const", *this
) << "IOstream::check(const char* operation) : "
<< "error in IOstream " << name() << " for operation "
<< operation
<< exit(FatalIOError);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,119 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Prints out a description of the IOstream to Serr.
\*---------------------------------------------------------------------------*/
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void IOstream::print(Ostream& os) const
{
os << "IOstream: " << "Version " << version_ << ", format ";
switch (format_)
{
case ASCII:
os << "ASCII";
break;
case BINARY:
os << "BINARY";
break;
}
os << ", line " << lineNumber();
if (opened())
{
os << ", OPENED";
}
if (closed())
{
os << ", CLOSED";
}
if (good())
{
os << ", GOOD";
}
if (eof())
{
os << ", EOF";
}
if (fail())
{
os << ", FAIL";
}
if (bad())
{
os << ", BAD";
}
os << endl;
}
void IOstream::print(Ostream& os, const int streamState) const
{
if (streamState == ios_base::goodbit)
{
os << "ios_base::goodbit set : the last operation on stream succeeded"
<< endl;
}
else if (streamState & ios_base::badbit)
{
os << "ios_base::badbit set : characters possibly lost"
<< endl;
}
else if (streamState & ios_base::failbit)
{
os << "ios_base::failbit set : some kind of formatting error"
<< endl;
}
else if (streamState & ios_base::eofbit)
{
os << "ios_base::eofbit set : at end of stream"
<< endl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -28,15 +28,17 @@ Description
#include "IOstream.H" #include "IOstream.H"
#include "error.H" #include "error.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam Foam::fileName Foam::IOstream::name_("IOstream");
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
IOstream::streamFormat IOstream::formatEnum(const word& format) // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
Foam::IOstream::streamFormat
Foam::IOstream::formatEnum(const word& format)
{ {
if (format == "ascii") if (format == "ascii")
{ {
@ -49,8 +51,7 @@ IOstream::streamFormat IOstream::formatEnum(const word& format)
else else
{ {
WarningIn("IOstream::formatEnum(const word&)") WarningIn("IOstream::formatEnum(const word&)")
<< "bad format specifier " << "bad format specifier '" << format << "', using 'ascii'"
<< format << " using ASCII"
<< endl; << endl;
return IOstream::ASCII; return IOstream::ASCII;
@ -58,7 +59,8 @@ IOstream::streamFormat IOstream::formatEnum(const word& format)
} }
IOstream::compressionType IOstream::compressionEnum(const word& compression) Foam::IOstream::compressionType
Foam::IOstream::compressionEnum(const word& compression)
{ {
if (compression == "uncompressed") if (compression == "uncompressed")
{ {
@ -71,10 +73,8 @@ IOstream::compressionType IOstream::compressionEnum(const word& compression)
else else
{ {
WarningIn("IOstream::compressionEnum(const word&)") WarningIn("IOstream::compressionEnum(const word&)")
<< "bad compression specifier " << "bad compression specifier '" << compression
<< '\'' << compression << '\'' << "', using 'uncompressed'"
<< ", use 'compressed' or 'uncompressed'. "
"Defaulting to uncompressed"
<< endl; << endl;
return IOstream::UNCOMPRESSED; return IOstream::UNCOMPRESSED;
@ -82,9 +82,125 @@ IOstream::compressionType IOstream::compressionEnum(const word& compression)
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::IOstream::check(const char* operation) const
{
if (bad())
{
FatalIOErrorIn
(
"IOstream::check(const char*) const", *this
) << "error in IOstream " << name() << " for operation " << operation
<< exit(FatalIOError);
}
return !bad();
}
void Foam::IOstream::fatalCheck(const char* operation) const
{
if (bad())
{
FatalIOErrorIn
(
"IOstream::fatalCheck(const char*) const", *this
) << "error in IOstream " << name() << " for operation " << operation
<< exit(FatalIOError);
}
}
Foam::string Foam::IOstream::versionNumber::str() const
{
std::ostringstream os;
os.precision(1);
os.setf(ios_base::fixed, ios_base::floatfield);
os << versionNumber_;
return os.str();
}
void Foam::IOstream::print(Ostream& os) const
{
os << "IOstream: " << "Version " << version_ << ", format ";
switch (format_)
{
case ASCII:
os << "ASCII";
break;
case BINARY:
os << "BINARY";
break;
}
os << ", line " << lineNumber();
if (opened())
{
os << ", OPENED";
}
if (closed())
{
os << ", CLOSED";
}
if (good())
{
os << ", GOOD";
}
if (eof())
{
os << ", EOF";
}
if (fail())
{
os << ", FAIL";
}
if (bad())
{
os << ", BAD";
}
os << endl;
}
void Foam::IOstream::print(Ostream& os, const int streamState) const
{
if (streamState == ios_base::goodbit)
{
os << "ios_base::goodbit set : the last operation on stream succeeded"
<< endl;
}
else if (streamState & ios_base::badbit)
{
os << "ios_base::badbit set : characters possibly lost"
<< endl;
}
else if (streamState & ios_base::failbit)
{
os << "ios_base::failbit set : some type of formatting error"
<< endl;
}
else if (streamState & ios_base::eofbit)
{
os << "ios_base::eofbit set : at end of stream"
<< endl;
}
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Ostream& operator<<(Ostream& os, const IOstream::streamFormat& sf) Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::streamFormat& sf)
{ {
if (sf == IOstream::ASCII) if (sf == IOstream::ASCII)
{ {
@ -99,18 +215,27 @@ Ostream& operator<<(Ostream& os, const IOstream::streamFormat& sf)
} }
#if defined (__GNUC__) Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::versionNumber& vn)
template<>
#endif
Ostream& operator<<(Ostream& os, const InfoProxy<IOstream>& iostr)
{ {
iostr.t_.print(os); os << vn.str().c_str();
return os; return os;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam namespace Foam
{
# if defined (__GNUC__)
template<>
# endif
Ostream& operator<<(Ostream& os, const InfoProxy<IOstream>& ip)
{
ip.t_.print(os);
return os;
}
} // end namespace
// ************************************************************************* // // ************************************************************************* //

View File

@ -36,8 +36,7 @@ Description
sequence one can read token by token, and then analyse. sequence one can read token by token, and then analyse.
SourceFiles SourceFiles
IOprint.C IOstream.C
IOcheck.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/

View File

@ -28,20 +28,15 @@ License
#include "bool.H" #include "bool.H"
#include "token.H" #include "token.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Set t to the put back token if there is one and return true, // Set t to the put back token if there is one and return true,
// otherwise return false // otherwise return false
bool Istream::getBack(token& t) bool Foam::Istream::getBack(token& t)
{ {
if (bad()) if (bad())
{ {
FatalIOErrorIn("void Istream::getBack(token& t)", *this) FatalIOErrorIn("void Istream::getBack(token&)", *this)
<< "Attempt to get back from bad stream" << "Attempt to get back from bad stream"
<< exit(FatalIOError); << exit(FatalIOError);
@ -53,25 +48,23 @@ bool Istream::getBack(token& t)
putBack_ = false; putBack_ = false;
return true; return true;
} }
else
{ return false;
return false;
}
} }
// Keep the put back token // Keep the put back token
void Istream::putBack(const token& t) void Foam::Istream::putBack(const token& t)
{ {
if (bad()) if (bad())
{ {
FatalIOErrorIn("void Istream::putBack(const token& t)", *this) FatalIOErrorIn("void Istream::putBack(const token&)", *this)
<< "Attempt to put back onto bad stream" << "Attempt to put back onto bad stream"
<< exit(FatalIOError); << exit(FatalIOError);
} }
else if (putBack_) else if (putBack_)
{ {
FatalIOErrorIn("void Istream::putBack(const token& t)", *this) FatalIOErrorIn("void Istream::putBack(const token&)", *this)
<< "Attempt to put back another token" << "Attempt to put back another token"
<< exit(FatalIOError); << exit(FatalIOError);
} }
@ -85,15 +78,15 @@ void Istream::putBack(const token& t)
// Functions for reading object delimiters ( ... ) // Functions for reading object delimiters ( ... )
Istream& Istream::readBegin(const char* funcName) Foam::Istream& Foam::Istream::readBegin(const char* funcName)
{ {
token delimiter(*this); token delimiter(*this);
if (delimiter != token::BEGIN_LIST) if (delimiter != token::BEGIN_LIST)
{ {
setBad(); setBad();
FatalIOErrorIn("Istream::readBegin(const char*)", *this) FatalIOErrorIn("Istream::readBegin(const char*)", *this)
<< "Expected a " << '\'' << token:: BEGIN_LIST << '\'' << "Expected a '" << token::BEGIN_LIST
<< " while reading " << funcName << "' while reading " << funcName
<< ", found " << delimiter.info() << ", found " << delimiter.info()
<< exit(FatalIOError); << exit(FatalIOError);
} }
@ -102,15 +95,15 @@ Istream& Istream::readBegin(const char* funcName)
} }
Istream& Istream::readEnd(const char* funcName) Foam::Istream& Foam::Istream::readEnd(const char* funcName)
{ {
token delimiter(*this); token delimiter(*this);
if (delimiter != token::END_LIST) if (delimiter != token::END_LIST)
{ {
setBad(); setBad();
FatalIOErrorIn("Istream::readEnd(const char*)", *this) FatalIOErrorIn("Istream::readEnd(const char*)", *this)
<< "Expected a " << '\'' << token::END_LIST << '\'' << "Expected a '" << token::END_LIST
<< " while reading " << funcName << "' while reading " << funcName
<< ", found " << delimiter.info() << ", found " << delimiter.info()
<< exit(FatalIOError); << exit(FatalIOError);
} }
@ -119,7 +112,7 @@ Istream& Istream::readEnd(const char* funcName)
} }
Istream& Istream::readEndBegin(const char* funcName) Foam::Istream& Foam::Istream::readEndBegin(const char* funcName)
{ {
readEnd(funcName); readEnd(funcName);
return readBegin(funcName); return readBegin(funcName);
@ -128,17 +121,17 @@ Istream& Istream::readEndBegin(const char* funcName)
// Functions for reading List delimiters ( ... ) or { ... } // Functions for reading List delimiters ( ... ) or { ... }
char Istream::readBeginList(const char* funcName) char Foam::Istream::readBeginList(const char* funcName)
{ {
token delimiter(*this); token delimiter(*this);
if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK) if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK)
{ {
setBad(); setBad();
FatalIOErrorIn("Istream::readBeginList(const char*)", *this) FatalIOErrorIn("Istream::readBeginList(const char*)", *this)
<< "Expected a " << '\'' << token::BEGIN_LIST << '\'' << "Expected a '" << token::BEGIN_LIST
<< " or a " << '\'' << token::BEGIN_BLOCK << '\'' << "' or a '" << token::BEGIN_BLOCK
<< " while reading " << funcName << "' while reading " << funcName
<< ", found " << delimiter.info() << ", found " << delimiter.info()
<< exit(FatalIOError); << exit(FatalIOError);
@ -149,7 +142,7 @@ char Istream::readBeginList(const char* funcName)
} }
char Istream::readEndList(const char* funcName) char Foam::Istream::readEndList(const char* funcName)
{ {
token delimiter(*this); token delimiter(*this);
@ -157,9 +150,9 @@ char Istream::readEndList(const char* funcName)
{ {
setBad(); setBad();
FatalIOErrorIn("Istream::readEndList(const char*)", *this) FatalIOErrorIn("Istream::readEndList(const char*)", *this)
<< "Expected a " << '\'' << token::END_LIST << '\'' << "Expected a '" << token::END_LIST
<< " or a " << '\'' << token::END_BLOCK << '\'' << "' or a '" << token::END_BLOCK
<< " while reading " << funcName << "' while reading " << funcName
<< ", found " << delimiter.info() << ", found " << delimiter.info()
<< exit(FatalIOError); << exit(FatalIOError);
@ -170,10 +163,7 @@ char Istream::readEndList(const char* funcName)
} }
//- Return a non-const reference to const Istream Foam::Istream& Foam::Istream::operator()() const
// Needed for read-constructors where the stream argument is temporary:
// e.g. thing thisThing(IFstream("thingFileName")());
Istream& Istream::operator()() const
{ {
if (!good()) if (!good())
{ {
@ -185,8 +175,4 @@ Istream& Istream::operator()() const
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -36,6 +36,9 @@ Description
were reading a stream on unknown data sequence one can read token by were reading a stream on unknown data sequence one can read token by
token, and then analyse. token, and then analyse.
SourceFiles
Istream.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef Istream_H #ifndef Istream_H

View File

@ -32,21 +32,6 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Write keyType
Foam::Ostream& Foam::Ostream::write(const keyType& kw)
{
// Write as word or string
if (kw.isPattern())
{
return write(static_cast<const string&>(kw));
}
else
{
return write(static_cast<const word&>(kw));
}
}
// Decrement the indent level // Decrement the indent level
void Foam::Ostream::decrIndent() void Foam::Ostream::decrIndent()
{ {
@ -62,6 +47,21 @@ void Foam::Ostream::decrIndent()
} }
// Write keyType
Foam::Ostream& Foam::Ostream::write(const keyType& kw)
{
// Write as word or string
if (kw.isPattern())
{
return write(static_cast<const string&>(kw));
}
else
{
return write(static_cast<const word&>(kw));
}
}
// Write the keyword followed by appropriate indentation // Write the keyword followed by appropriate indentation
Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw) Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw)
{ {

View File

@ -29,6 +29,9 @@ Description
An Ostream is an abstract base class for all output systems An Ostream is an abstract base class for all output systems
(streams, files, token lists, etc). (streams, files, token lists, etc).
SourceFiles
Ostream.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef Ostream_H #ifndef Ostream_H
@ -42,6 +45,7 @@ Description
namespace Foam namespace Foam
{ {
// Forward declaration of classes
class token; class token;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\

View File

@ -1,63 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "IOstream.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
string IOstream::versionNumber::str() const
{
std::ostringstream osBuffer;
osBuffer.precision(1);
osBuffer.setf(ios_base::fixed, ios_base::floatfield);
osBuffer << versionNumber_;
return osBuffer.str();
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
Ostream& operator<<(Ostream& os, const IOstream::versionNumber& vn)
{
os << vn.str().c_str();
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,156 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Read token and binary block from IPstream
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IPstream.H"
#include "int.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
inline void IPstream::checkEof()
{
if (bufPosition_ == messageSize_)
{
setEof();
}
}
template<class T>
inline void IPstream::readFromBuffer(T& t)
{
t = reinterpret_cast<T&>(buf_[bufPosition_]);
bufPosition_ += sizeof(T);
checkEof();
//readFromBuffer(&t, sizeof(T));
}
inline void IPstream::readFromBuffer(void* data, size_t count)
{
register const char* bufPtr = &buf_[bufPosition_];
register char* dataPtr = reinterpret_cast<char*>(data);
register size_t i = count;
while (i--) *dataPtr++ = *bufPtr++;
bufPosition_ += count;
checkEof();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
IPstream::~IPstream()
{}
Istream& IPstream::read(char& c)
{
c = buf_[bufPosition_];
bufPosition_++;
checkEof();
return *this;
}
Istream& IPstream::read(word& w)
{
size_t ws;
readFromBuffer(ws);
w = &buf_[bufPosition_];
bufPosition_ += ws + 1;
checkEof();
return *this;
}
Istream& IPstream::read(string& s)
{
size_t ss;
readFromBuffer(ss);
s = &buf_[bufPosition_];
bufPosition_ += ss + 1;
checkEof();
return *this;
}
Istream& IPstream::read(label& l)
{
readFromBuffer(l);
return *this;
}
Istream& IPstream::read(floatScalar& s)
{
readFromBuffer(s);
return *this;
}
Istream& IPstream::read(doubleScalar& s)
{
readFromBuffer(s);
return *this;
}
Istream& IPstream::read(char* data, std::streamsize count)
{
if (format() != BINARY)
{
FatalErrorIn("IPstream::read(char*, std::streamsize)")
<< "stream format not binary"
<< Foam::abort(FatalError);
}
readFromBuffer(data, count);
return *this;
}
Istream& IPstream::rewind()
{
bufPosition_ = 0;
return *this;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -24,18 +24,55 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H"
#include "IPstream.H" #include "IPstream.H"
#include "int.H"
#include "token.H" #include "token.H"
#include <cctype> #include <cctype>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam // * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
inline void Foam::IPstream::checkEof()
{ {
if (bufPosition_ == messageSize_)
{
setEof();
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Istream& IPstream::read(token& t) template<class T>
inline void Foam::IPstream::readFromBuffer(T& t)
{
t = reinterpret_cast<T&>(buf_[bufPosition_]);
bufPosition_ += sizeof(T);
checkEof();
// readFromBuffer(&t, sizeof(T));
}
inline void Foam::IPstream::readFromBuffer(void* data, size_t count)
{
register const char* bufPtr = &buf_[bufPosition_];
register char* dataPtr = reinterpret_cast<char*>(data);
register size_t i = count;
while (i--) *dataPtr++ = *bufPtr++;
bufPosition_ += count;
checkEof();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::IPstream::~IPstream()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Istream& Foam::IPstream::read(token& t)
{ {
// Return the put back token if it exists // Return the put back token if it exists
if (Istream::getBack(t)) if (Istream::getBack(t))
@ -81,22 +118,22 @@ Istream& IPstream::read(token& t)
// Word // Word
case token::WORD : case token::WORD :
{ {
word* wPtr = new word; word* pval = new word;
if (read(*wPtr)) if (read(*pval))
{ {
if (token::compound::isCompound(*wPtr)) if (token::compound::isCompound(*pval))
{ {
t = token::compound::New(*wPtr, *this).ptr(); t = token::compound::New(*pval, *this).ptr();
delete wPtr; delete pval;
} }
else else
{ {
t = wPtr; t = pval;
} }
} }
else else
{ {
delete wPtr; delete pval;
t.setBad(); t.setBad();
} }
return *this; return *this;
@ -105,14 +142,14 @@ Istream& IPstream::read(token& t)
// String // String
case token::STRING : case token::STRING :
{ {
string* sPtr = new string; string* pval = new string;
if (read(*sPtr)) if (read(*pval))
{ {
t = sPtr; t = pval;
} }
else else
{ {
delete sPtr; delete pval;
t.setBad(); t.setBad();
} }
return *this; return *this;
@ -121,10 +158,10 @@ Istream& IPstream::read(token& t)
// Label // Label
case token::LABEL : case token::LABEL :
{ {
label l; label val;
if (read(l)) if (read(val))
{ {
t = l; t = val;
} }
else else
{ {
@ -136,10 +173,10 @@ Istream& IPstream::read(token& t)
// floatScalar // floatScalar
case token::FLOAT_SCALAR : case token::FLOAT_SCALAR :
{ {
floatScalar s; floatScalar val;
if (read(s)) if (read(val))
{ {
t = s; t = val;
} }
else else
{ {
@ -151,10 +188,10 @@ Istream& IPstream::read(token& t)
// doubleScalar // doubleScalar
case token::DOUBLE_SCALAR : case token::DOUBLE_SCALAR :
{ {
doubleScalar s; doubleScalar val;
if (read(s)) if (read(val))
{ {
t = s; t = val;
} }
else else
{ {
@ -181,8 +218,77 @@ Istream& IPstream::read(token& t)
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Foam::Istream& Foam::IPstream::read(char& c)
{
c = buf_[bufPosition_];
bufPosition_++;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(word& str)
{
size_t len;
readFromBuffer(len);
str = &buf_[bufPosition_];
bufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(string& str)
{
size_t len;
readFromBuffer(len);
str = &buf_[bufPosition_];
bufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(label& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(floatScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(doubleScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(char* data, std::streamsize count)
{
if (format() != BINARY)
{
FatalErrorIn("IPstream::read(char*, std::streamsize)")
<< "stream format not binary"
<< Foam::abort(FatalError);
}
readFromBuffer(data, count);
return *this;
}
Foam::Istream& Foam::IPstream::rewind()
{
bufPosition_ = 0;
return *this;
}
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -30,7 +30,6 @@ Description
SourceFiles SourceFiles
IPstream.C IPstream.C
IPread.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/

View File

@ -35,14 +35,49 @@ Description
#include <cctype> #include <cctype>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
namespace Foam template<class T>
inline void Foam::OPstream::writeToBuffer(const T& t)
{ {
// (T&)(buf_[bufPosition_]) = t;
// bufPosition_ += sizeof(T);
writeToBuffer(&t, sizeof(T));
}
inline void Foam::OPstream::writeToBuffer(const char& c)
{
if (size_t(buf_.size()) < bufPosition_ + 1U)
{
enlargeBuffer(1);
}
buf_[bufPosition_] = c;
bufPosition_ ++;
}
inline void Foam::OPstream::writeToBuffer(const void* data, size_t count)
{
if (size_t(buf_.size()) < bufPosition_ + count)
{
enlargeBuffer(count);
}
register char* bufPtr = &buf_[bufPosition_];
register const char* dataPtr = reinterpret_cast<const char*>(data);
register size_t i = count;
while (i--) *bufPtr++ = *dataPtr++;
bufPosition_ += count;
}
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
OPstream::OPstream Foam::OPstream::OPstream
( (
const commsTypes commsType, const commsTypes commsType,
const int toProcNo, const int toProcNo,
@ -65,9 +100,9 @@ OPstream::OPstream
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Ostream& OPstream::write(const token&) Foam::Ostream& Foam::OPstream::write(const token&)
{ {
notImplemented("Ostream& OPstream::write(const token&)"); notImplemented("Ostream& OPstream::write(const token&)");
setBad(); setBad();
@ -75,7 +110,7 @@ Ostream& OPstream::write(const token&)
} }
Ostream& OPstream::write(const char c) Foam::Ostream& Foam::OPstream::write(const char c)
{ {
if (!isspace(c)) if (!isspace(c))
{ {
@ -86,9 +121,9 @@ Ostream& OPstream::write(const char c)
} }
Ostream& OPstream::write(const char* s) Foam::Ostream& Foam::OPstream::write(const char* str)
{ {
word nonWhiteChars(string::validate<word>(s)); word nonWhiteChars(string::validate<word>(str));
if (nonWhiteChars.size() == 0) if (nonWhiteChars.size() == 0)
{ {
@ -105,61 +140,55 @@ Ostream& OPstream::write(const char* s)
} }
Ostream& OPstream::write(const word& w) Foam::Ostream& Foam::OPstream::write(const word& str)
{ {
write(char(token::WORD)); write(char(token::WORD));
size_t ws = w.size(); size_t len = str.size();
writeToBuffer(ws); writeToBuffer(len);
writeToBuffer(w.c_str(), ws + 1); writeToBuffer(str.c_str(), len + 1);
return *this; return *this;
} }
Ostream& OPstream::write(const string& s) Foam::Ostream& Foam::OPstream::write(const string& str)
{ {
write(char(token::STRING)); write(char(token::STRING));
size_t ss = s.size(); size_t len = str.size();
writeToBuffer(ss); writeToBuffer(len);
writeToBuffer(s.c_str(), ss + 1); writeToBuffer(str.c_str(), len + 1);
return *this; return *this;
} }
Ostream& OPstream::write(const label l) Foam::Ostream& Foam::OPstream::write(const label val)
{ {
write(char(token::LABEL)); write(char(token::LABEL));
writeToBuffer(val);
writeToBuffer(l);
return *this; return *this;
} }
Ostream& OPstream::write(const floatScalar s) Foam::Ostream& Foam::OPstream::write(const floatScalar val)
{ {
write(char(token::FLOAT_SCALAR)); write(char(token::FLOAT_SCALAR));
writeToBuffer(val);
writeToBuffer(s);
return *this; return *this;
} }
Ostream& OPstream::write(const doubleScalar s) Foam::Ostream& Foam::OPstream::write(const doubleScalar val)
{ {
write(char(token::DOUBLE_SCALAR)); write(char(token::DOUBLE_SCALAR));
writeToBuffer(val);
writeToBuffer(s);
return *this; return *this;
} }
Ostream& OPstream::write(const char* data, std::streamsize count) Foam::Ostream& Foam::OPstream::write(const char* data, std::streamsize count)
{ {
if (format() != BINARY) if (format() != BINARY)
{ {
@ -169,13 +198,8 @@ Ostream& OPstream::write(const char* data, std::streamsize count)
} }
writeToBuffer(data, count); writeToBuffer(data, count);
return *this; return *this;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -29,8 +29,7 @@ Description
Output inter-processor communications stream. Output inter-processor communications stream.
SourceFiles SourceFiles
OPstreamI.H OPstream.C
OPwrite.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -211,11 +210,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// include inline implementaions
# include "OPstreamI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,79 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
template<class T>
inline void OPstream::writeToBuffer(const T& t)
{
//(T&)(buf_[bufPosition_]) = t;
//bufPosition_ += sizeof(T);
writeToBuffer(&t, sizeof(T));
}
inline void OPstream::writeToBuffer(const char& c)
{
if (size_t(buf_.size()) < bufPosition_ + 1U)
{
enlargeBuffer(1);
}
buf_[bufPosition_] = c;
bufPosition_ ++;
}
inline void OPstream::writeToBuffer(const void* data, size_t count)
{
if (size_t(buf_.size()) < bufPosition_ + count)
{
enlargeBuffer(count);
}
register char* bufPtr = &buf_[bufPosition_];
register const char* dataPtr = reinterpret_cast<const char*>(data);
register size_t i = count;
while (i--) *bufPtr++ = *dataPtr++;
bufPosition_ += count;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -76,7 +76,7 @@ void Foam::Pstream::calcLinearComm(const label nProcs)
); );
// Slaves. Have no below processors, only communicate up to master // Slaves. Have no below processors, only communicate up to master
for(label procID = 1; procID < nProcs; procID++) for (label procID = 1; procID < nProcs; procID++)
{ {
linearCommunication_[procID] = commsStruct linearCommunication_[procID] = commsStruct
( (
@ -122,7 +122,7 @@ void Foam::Pstream::collectReceives
// //
// The sends/receives for all levels are collected per processor (one send per // The sends/receives for all levels are collected per processor (one send per
// processor; multiple receives possible) creating a table: // processor; multiple receives possible) creating a table:
// //
// So per processor: // So per processor:
// proc receives from sends to // proc receives from sends to
// ---- ------------- -------- // ---- ------------- --------
@ -137,7 +137,7 @@ void Foam::Pstream::collectReceives
void Foam::Pstream::calcTreeComm(label nProcs) void Foam::Pstream::calcTreeComm(label nProcs)
{ {
label nLevels = 1; label nLevels = 1;
while((1 << nLevels) < nProcs) while ((1 << nLevels) < nProcs)
{ {
nLevels++; nLevels++;
} }
@ -145,15 +145,15 @@ void Foam::Pstream::calcTreeComm(label nProcs)
List<DynamicList<label> > receives(nProcs); List<DynamicList<label> > receives(nProcs);
labelList sends(nProcs, -1); labelList sends(nProcs, -1);
//Info<< "Using " << nLevels << " communication levels" << endl; // Info<< "Using " << nLevels << " communication levels" << endl;
label offset = 2; label offset = 2;
label childOffset = offset/2; label childOffset = offset/2;
for(label level = 0; level < nLevels; level++) for (label level = 0; level < nLevels; level++)
{ {
label receiveID = 0; label receiveID = 0;
while(receiveID < nProcs) while (receiveID < nProcs)
{ {
// Determine processor that sends and we receive from // Determine processor that sends and we receive from
label sendID = receiveID + childOffset; label sendID = receiveID + childOffset;
@ -166,6 +166,7 @@ void Foam::Pstream::calcTreeComm(label nProcs)
receiveID += offset; receiveID += offset;
} }
offset <<= 1; offset <<= 1;
childOffset <<= 1; childOffset <<= 1;
} }
@ -173,15 +174,15 @@ void Foam::Pstream::calcTreeComm(label nProcs)
// For all processors find the processors it receives data from // For all processors find the processors it receives data from
// (and the processors they receive data from etc.) // (and the processors they receive data from etc.)
List<DynamicList<label> > allReceives(nProcs); List<DynamicList<label> > allReceives(nProcs);
for(label procID = 0; procID < nProcs; procID++) for (label procID = 0; procID < nProcs; procID++)
{ {
collectReceives(procID, receives, allReceives[procID]); collectReceives(procID, receives, allReceives[procID]);
} }
treeCommunication_.setSize(nProcs); treeCommunication_.setSize(nProcs);
for(label procID = 0; procID < nProcs; procID++) for (label procID = 0; procID < nProcs; procID++)
{ {
treeCommunication_[procID] = commsStruct treeCommunication_[procID] = commsStruct
( (

View File

@ -30,9 +30,8 @@ Description
SourceFiles SourceFiles
Pstream.C Pstream.C
IPread.C PstreamsPrint.C
OPwrite.C PstreamCommsStruct.C
Pprint.C
gatherScatter.C gatherScatter.C
combineGatherScatter.C combineGatherScatter.C
gatherScatterList.C gatherScatterList.C

View File

@ -29,7 +29,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Null constructor
Foam::Pstream::commsStruct::commsStruct() Foam::Pstream::commsStruct::commsStruct()
: :
above_(-1), above_(-1),
@ -39,7 +38,6 @@ Foam::Pstream::commsStruct::commsStruct()
{} {}
// Construct from components
Foam::Pstream::commsStruct::commsStruct Foam::Pstream::commsStruct::commsStruct
( (
const label above, const label above,
@ -55,7 +53,6 @@ Foam::Pstream::commsStruct::commsStruct
{} {}
// Construct from components
Foam::Pstream::commsStruct::commsStruct Foam::Pstream::commsStruct::commsStruct
( (
const label nProcs, const label nProcs,
@ -114,11 +111,7 @@ bool Foam::Pstream::commsStruct::operator!=(const commsStruct& comm) const
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<< Foam::Ostream& Foam::operator<<(Ostream& os, const Pstream::commsStruct& comm)
(
Ostream& os,
const Foam::Pstream::commsStruct& comm
)
{ {
os << comm.above_ << token::SPACE os << comm.above_ << token::SPACE
<< comm.below_ << token::SPACE << comm.below_ << token::SPACE
@ -127,7 +120,7 @@ Foam::Ostream& Foam::operator<<
os.check os.check
( (
"Ostream& operator<<(Ostream& f, const commsStruct& comm)" "Ostream& operator<<(Ostream&, const commsStruct&)"
); );
return os; return os;

View File

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description Description
Prints out a description of the Sstreams to Serr. Prints out a description of the streams
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -32,27 +32,18 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam void Foam::IPstream::print(Ostream& os) const
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void IPstream::print(Ostream& os) const
{ {
os << "Reading from processor " << fromProcNo_ os << "Reading from processor " << fromProcNo_
<< " to processor " << myProcNo() << Foam::endl; << " to processor " << myProcNo() << Foam::endl;
} }
void OPstream::print(Ostream& os) const void Foam::OPstream::print(Ostream& os) const
{ {
os << "Writing from processor " << toProcNo_ os << "Writing from processor " << toProcNo_
<< " to processor " << myProcNo() << Foam::endl; << " to processor " << myProcNo() << Foam::endl;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,103 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Implementation of lexer. Return next semantically valid character in
the given input stream, or zero if an error is encountered.
\*---------------------------------------------------------------------------*/
#include "ISstream.H"
#include <cctype>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
char Foam::ISstream::nextValid()
{
char c = 0;
for (;;)
{
// Get next non-whitespace character
while (get(c) && isspace(c))
{}
// Return if stream is bad
if (bad() || isspace(c))
{
return 0;
}
// Is this the start of a C/C++ comment
if (c == '/')
{
// If cannot get another charater, return this one
if (!get(c))
{
return '/';
}
if (c == '/') // This is the start of a C++ style one line comment
{
while (get(c) && c != '\n')
{}
}
else if (c == '*') // This is the start of a C style comment
{
for (;;)
{
if (get(c) && c == '*')
{
if (get(c) && c == '/')
{
break;
}
else
{
putback(c);
}
}
if (!good())
{
return 0;
}
}
}
else // A lone '/' so return it.
{
putback(c);
return '/';
}
}
else // c is a valid character so return it
{
return c;
}
}
}
// ************************************************************************* //

View File

@ -1,283 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Read token and binary block from ISstream
\*---------------------------------------------------------------------------*/
#include "ISstream.H"
#include "int.H"
#include "token.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Istream& ISstream::read(char& c)
{
c = nextValid();
return *this;
}
Istream& ISstream::read(word& w)
{
static const int MAX_WORD = 1024;
static char wordBuffer[MAX_WORD];
register int i = 0;
register int bc = 0;
char c;
while (get(c) && word::valid(c))
{
if (fail())
{
if (i < MAX_WORD-1)
{
wordBuffer[i] = '\0';
}
else
{
wordBuffer[MAX_WORD-1] = '\0';
}
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "problem while reading word '" << wordBuffer << '\''
<< exit(FatalIOError);
return *this;
}
if (i >= MAX_WORD)
{
wordBuffer[MAX_WORD-1] = '\0';
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "word " << wordBuffer << " too long" << endl
<< " maximum number of characters allowed = " << MAX_WORD
<< exit(FatalIOError);
return *this;
}
if (c == token::BEGIN_LIST)
{
bc++;
}
else if (c == token::END_LIST)
{
bc--;
if (bc == -1)
{
break;
}
}
wordBuffer[i++] = c;
}
if (i == 0)
{
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "invalid first character found : " << c
<< exit(FatalIOError);
}
wordBuffer[i] = '\0'; // Terminator.
w = wordBuffer;
putback(c);
return *this;
}
Istream& ISstream::read(string& s)
{
static const int MAX_STR = 1024;
static const int MAX_ERROR_STR = 80;
static char stringBuffer[MAX_STR];
char c;
if (!get(c))
{
stringBuffer[0] = '\0';
FatalIOErrorIn("ISstream::read(string& s)", *this)
<< "cannot read start of string"
<< exit(FatalIOError);
return *this;
}
if (c != token::BEGIN_STRING)
{
stringBuffer[0] = '\0';
FatalIOErrorIn("ISstream::read(string& s)", *this)
<< "Incorrect start of string character"
<< exit(FatalIOError);
return *this;
}
register int i = 0;
bool escape = false;
while (get(c))
{
if (c == token::END_STRING && !escape)
{
stringBuffer[i] = '\0';
s = stringBuffer;
return *this;
}
if (c == '\n' && !escape)
{
stringBuffer[i] = '\0';
stringBuffer[MAX_ERROR_STR] = '\0';
FatalIOErrorIn("ISstream::read(string& s)", *this)
<< "found a '\\n' while reading string \""
<< stringBuffer << '"'
<< exit(FatalIOError);
return *this;
}
if (c != '\\')
{
escape = false;
stringBuffer[i] = c;
if (i++ == MAX_STR)
{
stringBuffer[MAX_STR - 1] = '\0';
FatalIOErrorIn("ISstream::read(string& s)", *this)
<< " string " << stringBuffer << "is too long" << endl
<< " maximum number of characters allowed = " << MAX_STR
<< exit(FatalIOError);
return *this;
}
}
else
{
escape = true;
}
}
stringBuffer[i] = '\0';
stringBuffer[MAX_ERROR_STR] = '\0';
FatalIOErrorIn("ISstream::read(string& s)", *this)
<< "problem while reading string \"" << stringBuffer << "...\""
<< exit(FatalIOError);
return *this;
}
Istream& ISstream::read(label& l)
{
is_ >> l;
setState(is_.rdstate());
return *this;
}
Istream& ISstream::read(floatScalar& s)
{
is_ >> s;
setState(is_.rdstate());
return *this;
}
Istream& ISstream::read(doubleScalar& s)
{
is_ >> s;
setState(is_.rdstate());
return *this;
}
// read binary block
Istream& ISstream::read(char* buf, std::streamsize count)
{
if (format() != BINARY)
{
FatalIOErrorIn("ISstream::read(char*, std::streamsize)", *this)
<< "stream format not binary"
<< exit(FatalIOError);
}
readBegin("binaryBlock");
is_.read(buf, count);
readEnd("binaryBlock");
setState(is_.rdstate());
return *this;
}
//- Rewind the ISstream so that it may be read again
Istream& ISstream::rewind()
{
stream().rdbuf()->pubseekpos(0);
return *this;
}
// Set flags of output stream
ios_base::fmtflags ISstream::flags() const
{
return is_.flags();
}
// Set flags of given field of output stream
ios_base::fmtflags ISstream::flags(const ios_base::fmtflags f)
{
return is_.flags(f);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,206 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "ISstream.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Istream& ISstream::read(token& t)
{
static char numberBuffer[100];
// Return the put back token if it exists
if (Istream::getBack(t))
{
return *this;
}
// Assume that the streams supplied are in working order.
// Lines are counted by '\n'
// Get next 'valid character': i.e. proceed through any white space
// and/or comments until a semantically valid character is hit upon.
char c = nextValid();
// Set the line number of this token to the current stream line number
t.lineNumber() = lineNumber();
// return on error
if (!c)
{
t.setBad();
return *this;
}
// Analyse input starting with this character.
switch (c)
{
// First check for punctuation characters.
case token::END_STATEMENT :
case token::BEGIN_LIST :
case token::END_LIST :
case token::BEGIN_SQR :
case token::END_SQR :
case token::BEGIN_BLOCK :
case token::END_BLOCK :
case token::COLON :
case token::COMMA :
case token::ASSIGN :
case token::ADD :
// case token::SUBTRACT : // Handled later as the posible start of a number
case token::MULTIPLY :
case token::DIVIDE :
{
t = token::punctuationToken(c);
return *this;
}
// Strings: enclosed by double quotes.
case token::BEGIN_STRING :
{
putback(c);
string* sPtr = new string;
if (!read(*sPtr).bad())
{
t = sPtr;
}
else
{
delete sPtr;
t.setBad();
}
return *this;
}
// Numbers: do not distinguish at this point between Types.
case '-' :
case '.' :
case '0' : case '1' : case '2' : case '3' : case '4' :
case '5' : case '6' : case '7' : case '8' : case '9' :
{
bool isScalar = false;
if (c == '.')
{
isScalar = true;
}
int i=0;
numberBuffer[i++] = c;
while
(
is_.get(c)
&& (
isdigit(c)
|| c == '.'
|| c == 'e'
|| c == 'E'
|| c == '+'
|| c == '-'
)
)
{
numberBuffer[i++] = c;
if (!isdigit(c))
{
isScalar = true;
}
}
numberBuffer[i] = '\0';
setState(is_.rdstate());
if (!is_.bad())
{
is_.putback(c);
if (i == 1 && numberBuffer[0] == '-')
{
t = token::punctuationToken(token::SUBTRACT);
}
else if (isScalar)
{
t = scalar(atof(numberBuffer));
}
else
{
t = label(atol(numberBuffer));
}
}
else
{
t.setBad();
}
return *this;
}
// Should be a word (which can be a single character)
default:
{
putback(c);
word* wPtr = new word;
if (!read(*wPtr).bad())
{
if (token::compound::isCompound(*wPtr))
{
t = token::compound::New(*wPtr, *this).ptr();
delete wPtr;
}
else
{
t = wPtr;
}
}
else
{
delete wPtr;
t.setBad();
}
return *this;
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,527 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "ISstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
char Foam::ISstream::nextValid()
{
char c = 0;
while (true)
{
// Get next non-whitespace character
while (get(c) && isspace(c))
{}
// Return if stream is bad
if (bad() || isspace(c))
{
return 0;
}
// Is this the start of a C/C++ comment?
if (c == '/')
{
// If cannot get another character, return this one
if (!get(c))
{
return '/';
}
if (c == '/')
{
// This is the start of a C++ style one-line comment
while (get(c) && c != '\n')
{}
}
else if (c == '*')
{
// This is the start of a C style comment
while (true)
{
if (get(c) && c == '*')
{
if (get(c) && c == '/')
{
break;
}
else
{
putback(c);
}
}
if (!good())
{
return 0;
}
}
}
else // A lone '/' so return it.
{
putback(c);
return '/';
}
}
else // c is a valid character so return it
{
return c;
}
}
}
Foam::Istream& Foam::ISstream::read(token& t)
{
static char numberBuffer[100];
// Return the put back token if it exists
if (Istream::getBack(t))
{
return *this;
}
// Assume that the streams supplied are in working order.
// Lines are counted by '\n'
// Get next 'valid character': i.e. proceed through any white space
// and/or comments until a semantically valid character is hit upon.
char c = nextValid();
// Set the line number of this token to the current stream line number
t.lineNumber() = lineNumber();
// return on error
if (!c)
{
t.setBad();
return *this;
}
// Analyse input starting with this character.
switch (c)
{
// First check for punctuation characters.
case token::END_STATEMENT :
case token::BEGIN_LIST :
case token::END_LIST :
case token::BEGIN_SQR :
case token::END_SQR :
case token::BEGIN_BLOCK :
case token::END_BLOCK :
case token::COLON :
case token::COMMA :
case token::ASSIGN :
case token::ADD :
// case token::SUBTRACT : // Handled later as the posible start of a number
case token::MULTIPLY :
case token::DIVIDE :
{
t = token::punctuationToken(c);
return *this;
}
// Strings: enclosed by double quotes.
case token::BEGIN_STRING :
{
putback(c);
string* sPtr = new string;
if (!read(*sPtr).bad())
{
t = sPtr;
}
else
{
delete sPtr;
t.setBad();
}
return *this;
}
// Numbers: do not distinguish at this point between Types.
case '-' :
case '.' :
case '0' : case '1' : case '2' : case '3' : case '4' :
case '5' : case '6' : case '7' : case '8' : case '9' :
{
bool isScalar = false;
if (c == '.')
{
isScalar = true;
}
int i=0;
numberBuffer[i++] = c;
while
(
is_.get(c)
&& (
isdigit(c)
|| c == '.'
|| c == 'e'
|| c == 'E'
|| c == '+'
|| c == '-'
)
)
{
numberBuffer[i++] = c;
if (!isdigit(c))
{
isScalar = true;
}
}
numberBuffer[i] = '\0';
setState(is_.rdstate());
if (!is_.bad())
{
is_.putback(c);
if (i == 1 && numberBuffer[0] == '-')
{
t = token::punctuationToken(token::SUBTRACT);
}
else if (isScalar)
{
t = scalar(atof(numberBuffer));
}
else
{
t = label(atol(numberBuffer));
}
}
else
{
t.setBad();
}
return *this;
}
// Should be a word (which can be a single character)
default:
{
putback(c);
word* wPtr = new word;
if (!read(*wPtr).bad())
{
if (token::compound::isCompound(*wPtr))
{
t = token::compound::New(*wPtr, *this).ptr();
delete wPtr;
}
else
{
t = wPtr;
}
}
else
{
delete wPtr;
t.setBad();
}
return *this;
}
}
}
Foam::Istream& Foam::ISstream::read(char& c)
{
c = nextValid();
return *this;
}
Foam::Istream& Foam::ISstream::read(word& str)
{
static const int maxLen = 1024;
static const int errLen = 80; // truncate error message for readability
static char buf[maxLen];
register int i = 0;
register int bc = 0;
char c;
while (get(c) && word::valid(c))
{
if (fail())
{
if (i < maxLen-1)
{
buf[i] = '\0';
}
else
{
buf[maxLen-1] = '\0';
}
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "problem while reading word '" << buf << "'\n"
<< exit(FatalIOError);
return *this;
}
if (i >= maxLen)
{
buf[maxLen-1] = '\0';
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "word '" << buf << "' ...\n"
<< " is too long (max. " << maxLen << " characters)"
<< exit(FatalIOError);
return *this;
}
if (c == token::BEGIN_LIST)
{
bc++;
}
else if (c == token::END_LIST)
{
bc--;
if (bc == -1)
{
break;
}
}
buf[i++] = c;
}
if (i == 0)
{
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "invalid first character found : " << c
<< exit(FatalIOError);
}
buf[i] = '\0'; // Terminator
str = buf;
putback(c);
return *this;
}
Foam::Istream& Foam::ISstream::read(string& str)
{
static const int maxLen = 1024;
static const int errLen = 80; // truncate error message for readability
static char buf[maxLen];
char c;
if (!get(c))
{
buf[0] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "cannot read start of string"
<< exit(FatalIOError);
return *this;
}
if (c != token::BEGIN_STRING)
{
buf[0] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "Incorrect start of string character"
<< exit(FatalIOError);
return *this;
}
register int i = 0;
bool escaped = false;
while (get(c))
{
switch (c)
{
case token::END_STRING :
if (escaped)
{
escaped = false;
i--; // overwrite backslash
}
else
{
// done reading string
buf[i] = '\0';
str = buf;
return *this;
}
break;
case token::NL :
if (escaped)
{
escaped = false;
i--; // overwrite backslash
}
else
{
buf[i] = '\0';
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "found '\\n' while reading string \""
<< buf << "...\""
<< exit(FatalIOError);
return *this;
}
break;
case '\\':
escaped = !escaped; // toggle state (retains backslashes)
break;
default:
escaped = false;
break;
}
buf[i] = c;
if (i++ == maxLen)
{
buf[maxLen-1] = '\0';
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "string \"" << buf << "...\"\n"
<< " is too long (max. " << maxLen << " characters)"
<< exit(FatalIOError);
return *this;
}
}
// don't worry about a dangling backslash if string terminated prematurely
buf[i] = '\0';
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "problem while reading string \"" << buf << "...\""
<< exit(FatalIOError);
return *this;
}
Foam::Istream& Foam::ISstream::read(label& val)
{
is_ >> val;
setState(is_.rdstate());
return *this;
}
Foam::Istream& Foam::ISstream::read(floatScalar& val)
{
is_ >> val;
setState(is_.rdstate());
return *this;
}
Foam::Istream& Foam::ISstream::read(doubleScalar& val)
{
is_ >> val;
setState(is_.rdstate());
return *this;
}
// read binary block
Foam::Istream& Foam::ISstream::read(char* buf, std::streamsize count)
{
if (format() != BINARY)
{
FatalIOErrorIn("ISstream::read(char*, std::streamsize)", *this)
<< "stream format not binary"
<< exit(FatalIOError);
}
readBegin("binaryBlock");
is_.read(buf, count);
readEnd("binaryBlock");
setState(is_.rdstate());
return *this;
}
Foam::Istream& Foam::ISstream::rewind()
{
stream().rdbuf()->pubseekpos(0);
return *this;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
std::ios_base::fmtflags Foam::ISstream::flags() const
{
return is_.flags();
}
std::ios_base::fmtflags Foam::ISstream::flags(const ios_base::fmtflags f)
{
return is_.flags(f);
}
// ************************************************************************* //

View File

@ -154,7 +154,9 @@ public:
//- Read a word //- Read a word
virtual Istream& read(word&); virtual Istream& read(word&);
// Read a string (including enclosing double-quotes) //- Read a string (including enclosing double-quotes).
// Backslashes are retained, except when escaping double-quotes
// and an embedded newline character.
virtual Istream& read(string&); virtual Istream& read(string&);
//- Read a label //- Read a label

View File

@ -26,7 +26,34 @@ License
#include "ISstream.H" #include "ISstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::ISstream::ISstream
(
istream& is,
const string& name,
streamFormat format,
versionNumber version,
compressionType compression
)
:
Istream(format, version, compression),
name_(name),
is_(is)
{
if (is_.good())
{
setOpened();
setGood();
}
else
{
setState(is_.rdstate());
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
inline Foam::ISstream& Foam::ISstream::get(char& c) inline Foam::ISstream& Foam::ISstream::get(char& c)
{ {
@ -70,31 +97,4 @@ inline Foam::ISstream& Foam::ISstream::putback(const char& c)
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::ISstream::ISstream
(
istream& is,
const string& name,
streamFormat format,
versionNumber version,
compressionType compression
)
:
Istream(format, version, compression),
name_(name),
is_(is)
{
if (is_.good())
{
setOpened();
setGood();
}
else
{
setState(is_.rdstate());
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -30,18 +30,13 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam Foam::Ostream& Foam::OSstream::write(const token&)
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Ostream& OSstream::write(const token&)
{ {
return *this; return *this;
} }
Ostream& OSstream::write(const char c) Foam::Ostream& Foam::OSstream::write(const char c)
{ {
os_ << c; os_ << c;
if (c == token::NL) if (c == token::NL)
@ -53,85 +48,95 @@ Ostream& OSstream::write(const char c)
} }
Ostream& OSstream::write(const char* s) Foam::Ostream& Foam::OSstream::write(const char* str)
{ {
lineNumber_ += string(s).count(token::NL); lineNumber_ += string(str).count(token::NL);
os_ << s; os_ << str;
setState(os_.rdstate()); setState(os_.rdstate());
return *this; return *this;
} }
Ostream& OSstream::write(const word& w) Foam::Ostream& Foam::OSstream::write(const word& str)
{ {
os_ << w; os_ << str;
setState(os_.rdstate()); setState(os_.rdstate());
return *this; return *this;
} }
Ostream& OSstream::write(const string& s) Foam::Ostream& Foam::OSstream::write(const string& str)
{ {
os_ << '\"'; os_ << token::BEGIN_STRING;
for register int backslash = 0;
( for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter)
string::const_iterator iter = s.begin();
iter != s.end();
++iter
)
{ {
register char c = *iter; register char c = *iter;
if (c == token::NL) switch (c)
{ {
os_ << '\\'; case '\\' :
lineNumber_++; backslash++;
// suppress output until we know if other characters follow
continue;
break;
case token::NL :
lineNumber_++;
backslash++; // backslash escape for newline
break;
case token::END_STRING :
backslash++; // backslash escape for double-quote
break;
} }
if (c == '"') // output pending backslashes
while (backslash)
{ {
os_ << '\\'; os_ << '\\'; // escape for new-line
backslash--;
} }
if (c != '\\') os_ << c;
{
os_ << c;
}
} }
os_ << '\"'; // silently drop any trailing backslashes
// they would otherwise appear like an escaped double-quote
os_ << token::END_STRING;
setState(os_.rdstate()); setState(os_.rdstate());
return *this; return *this;
} }
Ostream& OSstream::write(const label l) Foam::Ostream& Foam::OSstream::write(const label val)
{ {
os_ << l; os_ << val;
setState(os_.rdstate()); setState(os_.rdstate());
return *this; return *this;
} }
Ostream& OSstream::write(const floatScalar s) Foam::Ostream& Foam::OSstream::write(const floatScalar val)
{ {
os_ << s; os_ << val;
setState(os_.rdstate()); setState(os_.rdstate());
return *this; return *this;
} }
Ostream& OSstream::write(const doubleScalar s) Foam::Ostream& Foam::OSstream::write(const doubleScalar val)
{ {
os_ << s; os_ << val;
setState(os_.rdstate()); setState(os_.rdstate());
return *this; return *this;
} }
Ostream& OSstream::write(const char* buf, std::streamsize count) Foam::Ostream& Foam::OSstream::write(const char* buf, std::streamsize count)
{ {
if (format() != BINARY) if (format() != BINARY)
{ {
@ -150,8 +155,7 @@ Ostream& OSstream::write(const char* buf, std::streamsize count)
} }
//- Add indentation characters void Foam::OSstream::indent()
void OSstream::indent()
{ {
for (register unsigned short i = 0; i < indentLevel_*indentSize_; i++) for (register unsigned short i = 0; i < indentLevel_*indentSize_; i++)
{ {
@ -160,62 +164,60 @@ void OSstream::indent()
} }
// Flush stream void Foam::OSstream::flush()
void OSstream::flush()
{ {
os_.flush(); os_.flush();
} }
// Add carriage return and flush stream // Add carriage return and flush stream
void OSstream::endl() void Foam::OSstream::endl()
{ {
write('\n'); write('\n');
os_.flush(); os_.flush();
} }
// Set flags of output stream // Get flags of output stream
ios_base::fmtflags OSstream::flags() const std::ios_base::fmtflags Foam::OSstream::flags() const
{ {
return os_.flags(); return os_.flags();
} }
// Set flags of given field of output stream // Set flags of output stream
ios_base::fmtflags OSstream::flags(const ios_base::fmtflags f) std::ios_base::fmtflags Foam::OSstream::flags(const ios_base::fmtflags f)
{ {
return os_.flags(f); return os_.flags(f);
} }
//- Get width of output field // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int OSstream::width() const
// Get width of output field
int Foam::OSstream::width() const
{ {
return os_.width(); return os_.width();
} }
// Set width of output field (and return old width) // Set width of output field (and return old width)
int OSstream::width(const int w) int Foam::OSstream::width(const int w)
{ {
return os_.width(w); return os_.width(w);
} }
//- Get precision of output field // Get precision of output field
int OSstream::precision() const int Foam::OSstream::precision() const
{ {
return os_.precision(); return os_.precision();
} }
// Set precision of output field (and return old precision) // Set precision of output field (and return old precision)
int OSstream::precision(const int p) int Foam::OSstream::precision(const int p)
{ {
return os_.precision(p); return os_.precision(p);
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -30,7 +30,7 @@ Description
SourceFiles SourceFiles
OSstreamI.H OSstreamI.H
OSwrite.C OSstream.C
chkStream.C chkStream.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -136,6 +136,9 @@ public:
virtual Ostream& write(const word&); virtual Ostream& write(const word&);
//- Write string //- Write string
// In the rare case that the string contains a final trailing
// backslash, it will be dropped to the appearance of an escaped
// double-quote.
virtual Ostream& write(const string&); virtual Ostream& write(const string&);
//- Write label //- Write label

View File

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description Description
Prints out a description of the Sstreams to cout. Prints out a description of the streams
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -32,12 +32,7 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam void Foam::ISstream::print(Ostream& os) const
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void ISstream::print(Ostream& os) const
{ {
os << "ISstream: " << name().c_str() << ' '; os << "ISstream: " << name().c_str() << ' ';
@ -46,7 +41,7 @@ void ISstream::print(Ostream& os) const
} }
void OSstream::print(Ostream& os) const void Foam::OSstream::print(Ostream& os) const
{ {
os << "OSstream: " << name().c_str() << ' '; os << "OSstream: " << name().c_str() << ' ';
@ -55,8 +50,4 @@ void OSstream::print(Ostream& os) const
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -28,14 +28,21 @@ License
#include "Pstream.H" #include "Pstream.H"
#include "token.H" #include "token.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
namespace Foam inline void Foam::prefixOSstream::checkWritePrefix()
{ {
if (printPrefix_ && prefix_.size())
{
OSstream::write(prefix_.c_str());
printPrefix_ = false;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
prefixOSstream::prefixOSstream // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::prefixOSstream::prefixOSstream
( (
ostream& os, ostream& os,
const string& name, const string& name,
@ -50,23 +57,22 @@ prefixOSstream::prefixOSstream
{} {}
inline void prefixOSstream::checkWritePrefix() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::prefixOSstream::print(Ostream& os) const
{ {
if (printPrefix_ && prefix_.size()) os << "prefixOSstream ";
{ OSstream::print(os);
OSstream::write(prefix_.c_str());
printPrefix_ = false;
}
} }
Ostream& prefixOSstream::write(const token&) Foam::Ostream& Foam::prefixOSstream::write(const token&)
{ {
return *this; return *this;
} }
Ostream& prefixOSstream::write(const char c) Foam::Ostream& Foam::prefixOSstream::write(const char c)
{ {
checkWritePrefix(); checkWritePrefix();
OSstream::write(c); OSstream::write(c);
@ -80,13 +86,13 @@ Ostream& prefixOSstream::write(const char c)
} }
Ostream& prefixOSstream::write(const char* s) Foam::Ostream& Foam::prefixOSstream::write(const char* str)
{ {
checkWritePrefix(); checkWritePrefix();
OSstream::write(s); OSstream::write(str);
size_t sl = strlen(s); size_t len = strlen(str);
if (sl && s[sl - 1] == token::NL) if (len && str[len-1] == token::NL)
{ {
printPrefix_ = true; printPrefix_ = true;
} }
@ -95,58 +101,56 @@ Ostream& prefixOSstream::write(const char* s)
} }
Ostream& prefixOSstream::write(const word& w) Foam::Ostream& Foam::prefixOSstream::write(const word& val)
{ {
checkWritePrefix(); checkWritePrefix();
return OSstream::write(w); return OSstream::write(val);
} }
Ostream& prefixOSstream::write(const string& s) Foam::Ostream& Foam::prefixOSstream::write(const string& val)
{ {
checkWritePrefix(); checkWritePrefix();
return OSstream::write(s); return OSstream::write(val);
} }
Ostream& prefixOSstream::write(const label l) Foam::Ostream& Foam::prefixOSstream::write(const label val)
{ {
checkWritePrefix(); checkWritePrefix();
return OSstream::write(l); return OSstream::write(val);
} }
Ostream& prefixOSstream::write(const floatScalar s) Foam::Ostream& Foam::prefixOSstream::write(const floatScalar val)
{ {
checkWritePrefix(); checkWritePrefix();
return OSstream::write(s); return OSstream::write(val);
} }
Ostream& prefixOSstream::write(const doubleScalar s) Foam::Ostream& Foam::prefixOSstream::write(const doubleScalar val)
{ {
checkWritePrefix(); checkWritePrefix();
return OSstream::write(s); return OSstream::write(val);
} }
Ostream& prefixOSstream::write(const char* buf, std::streamsize count) Foam::Ostream& Foam::prefixOSstream::write
(
const char* buf,
std::streamsize count
)
{ {
checkWritePrefix(); checkWritePrefix();
return OSstream::write(buf, count); return OSstream::write(buf, count);
} }
//- Add indentation characters void Foam::prefixOSstream::indent()
void prefixOSstream::indent()
{ {
checkWritePrefix(); checkWritePrefix();
OSstream::indent(); OSstream::indent();
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -32,8 +32,7 @@ Description
to be automatically prepended to each message line. to be automatically prepended to each message line.
SourceFiles SourceFiles
prefixOSwrite.C prefixOSstream.C
prefixOSprint.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/

View File

@ -1,50 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Prints out a description of the prefixOSstream to cout.
\*---------------------------------------------------------------------------*/
#include "prefixOSstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void prefixOSstream::print(Ostream& os) const
{
os << "prefixOSstream ";
OSstream::print(os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -33,27 +33,26 @@ Description
Foam::label Foam::readHexLabel(ISstream& is) Foam::label Foam::readHexLabel(ISstream& is)
{ {
register label result = 0; // Takes into account that 'a' (or 'A') is 10
static const label alphaOffset = toupper('A') - 10;
char c = 0; // Takes into account that '0' is 0
static const label zeroOffset = int('0'); static const label zeroOffset = int('0');
// This takes into account that a is 10 char c = 0;
static const label alphaOffset = toupper('A') - 10;
// Get next non-whitespace character // Get next non-whitespace character
while (is.get(c) && isspace(c)) while (is.get(c) && isspace(c))
{} {}
register label result = 0;
do do
{ {
if (isspace(c) || c == 0) break; if (isspace(c) || c == 0) break;
if (!isxdigit(c)) if (!isxdigit(c))
{ {
FatalIOErrorIn("readHexLabel(ISstream& is)", is) FatalIOErrorIn("readHexLabel(ISstream&)", is)
<< "Illegal hex digit: \"" << c << "\"" << "Illegal hex digit: '" << c << "'"
<< exit(FatalIOError); << exit(FatalIOError);
} }

View File

@ -29,7 +29,7 @@ Description
Input from memory buffer stream. Input from memory buffer stream.
SourceFiles SourceFiles
Mprint.C StringStreamsPrint.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -37,7 +37,6 @@ SourceFiles
#define IStringStream_H #define IStringStream_H
#include "ISstream.H" #include "ISstream.H"
#include <sstream> #include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -114,7 +113,7 @@ public:
// Print // Print
//- Print description of IOstream to Ostream //- Print description to Ostream
void print(Ostream&) const; void print(Ostream&) const;

View File

@ -29,7 +29,7 @@ Description
Output to memory buffer stream. Output to memory buffer stream.
SourceFiles SourceFiles
Mprint.C StringStreamsPrint.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -37,7 +37,6 @@ SourceFiles
#define OStringStream_H #define OStringStream_H
#include "OSstream.H" #include "OSstream.H"
#include <sstream> #include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,7 +45,7 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OStringStream Declaration Class OStringStream Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class OStringStream class OStringStream
@ -128,7 +127,7 @@ public:
// Print // Print
//- Print description OM IOstream to Ostream //- Print description to Ostream
void print(Ostream&) const; void print(Ostream&) const;
}; };

View File

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description Description
Prints out a description of the StringStream to Serr. Prints out a description of the StringStream
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -32,12 +32,7 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam void Foam::IStringStream::print(Ostream& os) const
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void IStringStream::print(Ostream& os) const
{ {
os << "IStringStream " << name() << " : " os << "IStringStream " << name() << " : "
<< "buffer = \n" << str() << Foam::endl; << "buffer = \n" << str() << Foam::endl;
@ -46,7 +41,7 @@ void IStringStream::print(Ostream& os) const
} }
void OStringStream::print(Ostream& os) const void Foam::OStringStream::print(Ostream& os) const
{ {
os << "OStringStream " << name() << " : " os << "OStringStream " << name() << " : "
<< "buffer = \n" << str() << Foam::endl; << "buffer = \n" << str() << Foam::endl;
@ -55,8 +50,4 @@ void OStringStream::print(Ostream& os) const
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -29,12 +29,32 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam void Foam::ITstream::print(Ostream& os) const
{ {
os << "ITstream : " << name_.c_str();
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // if (size())
{
if (begin()->lineNumber() == rbegin()->lineNumber())
{
os << ", line " << begin()->lineNumber() << ", ";
}
else
{
os << ", lines " << begin()->lineNumber()
<< '-' << rbegin()->lineNumber() << ", ";
}
}
else
{
os << ", line " << lineNumber() << ", ";
}
Istream& ITstream::read(token& t) IOstream::print(os);
}
Foam::Istream& Foam::ITstream::read(token& t)
{ {
// Return the put back token if it exists // Return the put back token if it exists
if (Istream::getBack(t)) if (Istream::getBack(t))
@ -88,48 +108,49 @@ Istream& ITstream::read(token& t)
} }
Istream& ITstream::read(char&) Foam::Istream& Foam::ITstream::read(char&)
{ {
notImplemented("Istream& ITstream::read(char& c)"); notImplemented("Istream& ITstream::read(char& c)");
return *this; return *this;
} }
Istream& ITstream::read(word&)
Foam::Istream& Foam::ITstream::read(word&)
{ {
notImplemented("Istream& ITstream::read(word&)"); notImplemented("Istream& ITstream::read(word&)");
return *this; return *this;
} }
Istream& ITstream::read(string&) Foam::Istream& Foam::ITstream::read(string&)
{ {
notImplemented("Istream& ITstream::read(string&)"); notImplemented("Istream& ITstream::read(string&)");
return *this; return *this;
} }
Istream& ITstream::read(label&) Foam::Istream& Foam::ITstream::read(label&)
{ {
notImplemented("Istream& ITstream::read(label&)"); notImplemented("Istream& ITstream::read(label&)");
return *this; return *this;
} }
Istream& ITstream::read(floatScalar&) Foam::Istream& Foam::ITstream::read(floatScalar&)
{ {
notImplemented("Istream& ITstream::read(floatScalar&)"); notImplemented("Istream& ITstream::read(floatScalar&)");
return *this; return *this;
} }
Istream& ITstream::read(doubleScalar&) Foam::Istream& Foam::ITstream::read(doubleScalar&)
{ {
notImplemented("Istream& ITstream::read(doubleScalar&)"); notImplemented("Istream& ITstream::read(doubleScalar&)");
return *this; return *this;
} }
Istream& ITstream::read(char*, std::streamsize) Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
{ {
notImplemented("Istream& ITstream::read(char*, std::streamsize)"); notImplemented("Istream& ITstream::read(char*, std::streamsize)");
return *this; return *this;
@ -137,7 +158,7 @@ Istream& ITstream::read(char*, std::streamsize)
// Rewind the token stream so that it may be read again // Rewind the token stream so that it may be read again
Istream& ITstream::rewind() Foam::Istream& Foam::ITstream::rewind()
{ {
tokenIndex_ = 0; tokenIndex_ = 0;
@ -152,8 +173,4 @@ Istream& ITstream::rewind()
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -29,8 +29,7 @@ Description
Input token stream. Input token stream.
SourceFiles SourceFiles
ITread.C ITstream.C
ITprint.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/

View File

@ -1,65 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "ITstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void ITstream::print(Ostream& os) const
{
os << "ITstream : " << name_.c_str();
if (size())
{
if (begin()->lineNumber() == rbegin()->lineNumber())
{
os << ", line " << begin()->lineNumber() << ", ";
}
else
{
os << ", lines " << begin()->lineNumber()
<< '-' << rbegin()->lineNumber() << ", ";
}
}
else
{
os << ", line " << lineNumber() << ", ";
}
IOstream::print(os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -50,12 +50,13 @@ void Foam::token::parseError(const char* expected) const
Foam::token::compound::~compound() Foam::token::compound::~compound()
{} {}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::token::compound> Foam::token::compound::New Foam::autoPtr<Foam::token::compound> Foam::token::compound::New
( (
const Foam::word& compoundType, const word& compoundType,
Foam::Istream& is Istream& is
) )
{ {
IstreamConstructorTable::iterator cstrIter = IstreamConstructorTable::iterator cstrIter =
@ -63,10 +64,9 @@ Foam::autoPtr<Foam::token::compound> Foam::token::compound::New
if (cstrIter == IstreamConstructorTablePtr_->end()) if (cstrIter == IstreamConstructorTablePtr_->end())
{ {
FatalErrorIn("token::compound::New(Istream&)") FatalErrorIn("token::compound::New(const word&, Istream&)")
<< "Unknown compound type " << compoundType << "Unknown compound type " << compoundType << nl << nl
<< endl << endl << "Valid compound types:" << endl
<< "Valid compound types are :" << endl
<< IstreamConstructorTablePtr_->toc() << IstreamConstructorTablePtr_->toc()
<< abort(FatalError); << abort(FatalError);
} }
@ -77,7 +77,7 @@ Foam::autoPtr<Foam::token::compound> Foam::token::compound::New
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::token::compound::isCompound(const Foam::word& name) bool Foam::token::compound::isCompound(const word& name)
{ {
return return
( (

View File

@ -30,8 +30,8 @@ Description
SourceFiles SourceFiles
tokenI.H tokenI.H
token.C
tokenIO.C tokenIO.C
printToken.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -165,7 +165,7 @@ public:
// Selectors // Selectors
//- Select null constructed //- Select null constructed
static autoPtr<compound> New(const word& type, Istream& is); static autoPtr<compound> New(const word& type, Istream&);
// Destructor // Destructor
@ -291,22 +291,22 @@ public:
inline token(const token&); inline token(const token&);
//- Construct punctuation character token //- Construct punctuation character token
inline token(punctuationToken p, label lineNumber=0); inline token(punctuationToken, label lineNumber=0);
//- Construct word token //- Construct word token
inline token(const word& w, label lineNumber=0); inline token(const word&, label lineNumber=0);
//- Construct string token //- Construct string token
inline token(const string& s, label lineNumber=0); inline token(const string&, label lineNumber=0);
//- Construct label token //- Construct label token
inline token(const label, label lineNumber=0); inline token(const label, label lineNumber=0);
//- Construct floatScalar token //- Construct floatScalar token
inline token(const floatScalar s, label lineNumber=0); inline token(const floatScalar, label lineNumber=0);
//- Construct doubleScalar token //- Construct doubleScalar token
inline token(const doubleScalar s, label lineNumber=0); inline token(const doubleScalar, label lineNumber=0);
//- Construct from Istream //- Construct from Istream
token(Istream&); token(Istream&);

View File

@ -28,20 +28,14 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
#include "token.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "scalar.H" #include "scalar.H"
#include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from Istream Foam::token::token(Istream& is)
token::token(Istream& is)
: :
type_(UNDEFINED) type_(UNDEFINED)
{ {
@ -51,20 +45,20 @@ token::token(Istream& is)
// * * * * * * * * * * * * IOstream operators * * * * * * * * * * * * * * * // // * * * * * * * * * * * * IOstream operators * * * * * * * * * * * * * * * //
Istream& operator>>(Istream& is, token& t) Foam::Istream& Foam::operator>>(Istream& is, token& t)
{ {
t.clear(); t.clear();
return is.read(t); return is.read(t);
} }
Ostream& operator<<(Ostream& os, const token& t) Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
{ {
switch (t.type_) switch (t.type_)
{ {
case token::UNDEFINED: case token::UNDEFINED:
os << "UNDEFINED"; os << "UNDEFINED";
WarningIn("Ostream& operator<< (Ostream&, const token&)") WarningIn("Ostream& operator<<(Ostream&, const token&)")
<< "Undefined token" << endl; << "Undefined token" << endl;
break; break;
@ -98,13 +92,13 @@ Ostream& operator<<(Ostream& os, const token& t)
case token::ERROR: case token::ERROR:
os << "ERROR"; os << "ERROR";
WarningIn("Ostream& operator<< (Ostream&, const token&)") WarningIn("Ostream& operator<<(Ostream&, const token&)")
<< "Error token" << endl; << "Error token" << endl;
break; break;
default: default:
os << "UNKNOWN"; os << "UNKNOWN";
SeriousErrorIn("Ostream& operator<< (Ostream&, const token&)") SeriousErrorIn("Ostream& operator<<(Ostream&, const token&)")
<< "Unknown token" << "Unknown token"
<< endl; << endl;
} }
@ -116,17 +110,96 @@ Ostream& operator<<(Ostream& os, const token& t)
} }
Ostream& operator<<(Ostream& os, const token::punctuationToken& pt) ostream& Foam::operator<<(ostream& os, const token::punctuationToken& pt)
{ {
return os << char(pt); return os << char(pt);
} }
ostream& operator<<(ostream& os, const token::punctuationToken& pt)
Foam::Ostream& Foam::operator<<(Ostream& os, const token::punctuationToken& pt)
{ {
return os << char(pt); return os << char(pt);
} }
Foam::Ostream& Foam::operator<<(Ostream& os, const token::compound& ct)
{
os << ct.type() << token::SPACE;
ct.write(os);
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
{
const token& t = ip.t_;
os << "on line " << t.lineNumber();
switch (t.type())
{
case token::UNDEFINED:
os << " an undefined token";
break;
case token::PUNCTUATION:
os << " the punctuation token " << '\'' << t.pToken() << '\'';
break;
case token::WORD:
os << " the word " << '\'' << t.wordToken() << '\'';
break;
case token::STRING:
os << " the string " << t.stringToken();
break;
case token::LABEL:
os << " the label " << t.labelToken();
break;
case token::FLOAT_SCALAR:
os << " the floatScalar " << t.floatScalarToken();
break;
case token::DOUBLE_SCALAR:
os << " the doubleScalar " << t.doubleScalarToken();
break;
case token::COMPOUND:
{
if (t.compoundToken().empty())
{
os << " the empty compound of type "
<< t.compoundToken().type();
}
else
{
os << " the compound of type "
<< t.compoundToken().type();
}
}
break;
case token::ERROR:
os << " an error";
break;
default:
os << " an unknown token type " << '\'' << int(t.type()) << '\'';
}
return os;
}
// template specialization
namespace Foam
{
#if defined (__GNUC__) #if defined (__GNUC__)
template<> template<>
#endif #endif
@ -193,78 +266,6 @@ Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip)
} }
ostream& operator<<(ostream& os, const InfoProxy<token>& ip)
{
const token& t = ip.t_;
os << "on line " << t.lineNumber();
switch (t.type())
{
case token::UNDEFINED:
os << " an undefined token";
break;
case token::PUNCTUATION:
os << " the punctuation token " << '\'' << t.pToken() << '\'';
break;
case token::WORD:
os << " the word " << '\'' << t.wordToken() << '\'';
break;
case token::STRING:
os << " the string " << t.stringToken();
break;
case token::LABEL:
os << " the label " << t.labelToken();
break;
case token::FLOAT_SCALAR:
os << " the floatScalar " << t.floatScalarToken();
break;
case token::DOUBLE_SCALAR:
os << " the doubleScalar " << t.doubleScalarToken();
break;
case token::COMPOUND:
{
if (t.compoundToken().empty())
{
os << " the empty compound of type "
<< t.compoundToken().type();
}
else
{
os << " the compound of type "
<< t.compoundToken().type();
}
}
break;
case token::ERROR:
os << " an error";
break;
default:
os << " an unknown token type " << '\'' << int(t.type()) << '\'';
}
return os;
}
Ostream& operator<<(Ostream& os, const token::compound& ct)
{
os << ct.type() << token::SPACE;
ct.write(os);
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -131,7 +131,7 @@ public:
//- Count and return the number of a given character in the string //- Count and return the number of a given character in the string
size_type count(const char) const; size_type count(const char) const;
//- Is this string type valid //- Is this string type valid?
template<class String> template<class String>
static inline bool valid(const string&); static inline bool valid(const string&);

View File

@ -32,9 +32,9 @@ inline Foam::string::string()
{} {}
inline Foam::string::string(const std::string& stdStr) inline Foam::string::string(const std::string& str)
: :
std::string(stdStr) std::string(str)
{} {}
@ -64,18 +64,14 @@ inline Foam::string::string(const char c)
template<class String> template<class String>
inline bool Foam::string::valid(const string& s) inline bool Foam::string::valid(const string& s)
{ {
bool iv = false;
for (const_iterator iter = s.begin(); iter != s.end(); iter++) for (const_iterator iter = s.begin(); iter != s.end(); iter++)
{ {
if (!String::valid(*iter)) if (!String::valid(*iter))
{ {
iv = true; return false;
break;
} }
} }
return true;
return !iv;
} }
@ -114,9 +110,9 @@ inline bool Foam::string::stripInvalid(string& s)
template<class String> template<class String>
inline String Foam::string::validate(const string& s) inline String Foam::string::validate(const string& str)
{ {
string ss = s; string ss = str;
stripInvalid<String>(ss); stripInvalid<String>(ss);
return ss; return ss;
} }