diff --git a/applications/test/string/stringTest.C b/applications/test/string/stringTest.C index 0fc756bb9f..e9ac6532f6 100644 --- a/applications/test/string/stringTest.C +++ b/applications/test/string/stringTest.C @@ -48,11 +48,16 @@ int main(int argc, char *argv[]) Info<< string(test).expand() << endl; string test2("~OpenFOAM/controlDict"); - Info<< test2.expand() << endl; + Info<< test2 << " => " << test2.expand() << endl; string 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; diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 9162050cc0..6f0ee79faa 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -65,21 +65,15 @@ $(Streams)/token/tokenIO.C IOstreams = $(Streams)/IOstreams $(IOstreams)/IOstream.C -$(IOstreams)/versionNumber.C $(IOstreams)/Istream.C -$(IOstreams)/IOprint.C -$(IOstreams)/IOcheck.C $(IOstreams)/Ostream.C Sstreams = $(Streams)/Sstreams -$(Sstreams)/ISread.C -$(Sstreams)/ISnextValid.C -$(Sstreams)/ISreadToken.C +$(Sstreams)/ISstream.C +$(Sstreams)/OSstream.C +$(Sstreams)/SstreamsPrint.C $(Sstreams)/readHexLabel.C -$(Sstreams)/OSwrite.C -$(Sstreams)/Sprint.C -$(Sstreams)/prefixOSstream/prefixOSwrite.C -$(Sstreams)/prefixOSstream/prefixOSprint.C +$(Sstreams)/prefixOSstream.C gzstream = $(Streams)/gzstream $(gzstream)/gzstream.C @@ -89,19 +83,17 @@ $(Fstreams)/IFstream.C $(Fstreams)/OFstream.C Tstreams = $(Streams)/Tstreams -$(Tstreams)/ITread.C -$(Tstreams)/Tprint.C +$(Tstreams)/ITstream.C StringStreams = $(Streams)/StringStreams -$(StringStreams)/StringStreamPrint.C +$(StringStreams)/StringStreamsPrint.C Pstreams = $(Streams)/Pstreams $(Pstreams)/Pstream.C $(Pstreams)/PstreamCommsStruct.C -$(Pstreams)/IPread.C -$(Pstreams)/OPwrite.C -$(Pstreams)/Pprint.C -$(Pstreams)/IPreadToken.C +$(Pstreams)/IPstream.C +$(Pstreams)/OPstream.C +$(Pstreams)/PstreamsPrint.C dictionary = db/dictionary $(dictionary)/dictionary.C @@ -335,17 +327,15 @@ $(globalMeshData)/globalIndex.C $(polyMesh)/syncTools/syncTools.C -zones = $(polyMesh)/zones - -cellZone = $(zones)/cellZone +cellZone = $(polyMesh)/zones/cellZone $(cellZone)/cellZone.C $(cellZone)/newCellZone.C -faceZone = $(zones)/faceZone +faceZone = $(polyMesh)/zones/faceZone $(faceZone)/faceZone.C $(faceZone)/newFaceZone.C -pointZone = $(zones)/pointZone +pointZone = $(polyMesh)/zones/pointZone $(pointZone)/pointZone.C $(pointZone)/newPointZone.C @@ -462,6 +452,7 @@ $(Fields)/diagTensorField/diagTensorIOField.C $(Fields)/symmTensorField/symmTensorIOField.C $(Fields)/tensorField/tensorIOField.C $(Fields)/transformField/transformField.C + pointPatchFields = fields/pointPatchFields $(pointPatchFields)/pointPatchField/pointPatchFields.C diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C index cdc4a9273a..18cf8b891a 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C @@ -28,18 +28,16 @@ License #include "OSspecific.H" #include "gzstream.h" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -defineTypeNameAndDebug(IFstream, 0); + defineTypeNameAndDebug(IFstream, 0); +} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -IFstreamAllocator::IFstreamAllocator(const fileName& pathname) +Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) : ifPtr_(NULL), compression_(IOstream::UNCOMPRESSED) @@ -48,10 +46,8 @@ IFstreamAllocator::IFstreamAllocator(const fileName& pathname) { if (IFstream::debug) { - Info<< "IFstreamAllocator::IFstreamAllocator" - "(const fileName& pathname) : " - "can't open null file " - << endl; + Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : " + "cannot open null file " << endl; } } @@ -62,10 +58,8 @@ IFstreamAllocator::IFstreamAllocator(const fileName& pathname) { if (IFstream::debug) { - Info<< "IFstreamAllocator::IFstreamAllocator" - "(const fileName& pathname) : " - "decompressing " << pathname + ".gz" - << endl; + Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : " + "decompressing " << pathname + ".gz" << endl; } delete ifPtr_; @@ -80,18 +74,18 @@ IFstreamAllocator::IFstreamAllocator(const fileName& pathname) } -IFstreamAllocator::~IFstreamAllocator() +Foam::IFstreamAllocator::~IFstreamAllocator() { delete ifPtr_; } -istream& IFstreamAllocator::stdStream() +std::istream& Foam::IFstreamAllocator::stdStream() { if (!ifPtr_) { FatalErrorIn("IFstreamAllocator::stdStream()") - << "No stream allocated." << abort(FatalError); + << "No stream allocated" << abort(FatalError); } return *ifPtr_; } @@ -99,7 +93,7 @@ istream& IFstreamAllocator::stdStream() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -IFstream::IFstream +Foam::IFstream::IFstream ( const fileName& pathname, streamFormat format, @@ -120,15 +114,15 @@ IFstream::IFstream setClosed(); setState(ifPtr_->rdstate()); - + if (!good()) { if (debug) { - Info<< "IFstream::IFstream(const fileName& pathname," + Info<< "IFstream::IFstream(const fileName&," "streamFormat format=ASCII," "versionNumber version=currentVersion) : " - "couldn't open File for input" + "could not open file for input" << endl << info() << endl; } @@ -138,20 +132,20 @@ IFstream::IFstream { setOpened(); } - + lineNumber_ = 1; } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -IFstream::~IFstream() +Foam::IFstream::~IFstream() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void IFstream::print(Ostream& os) const +void Foam::IFstream::print(Ostream& os) const { // Print File data os << "IFstream: "; @@ -159,10 +153,9 @@ void IFstream::print(Ostream& os) const } -//- Return a non-const reference to const Istream -// Needed for read-constructors where the stream argument is temporary: -// e.g. thing thisThing(IFstream("thingFileName")()); -IFstream& IFstream::operator()() const +// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // + +Foam::IFstream& Foam::IFstream::operator()() const { if (!good()) { @@ -183,8 +176,4 @@ IFstream& IFstream::operator()() const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C index d705117e41..b78e5f07de 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C @@ -28,18 +28,17 @@ License #include "OSspecific.H" #include "gzstream.h" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { + defineTypeNameAndDebug(OFstream, 0); +} -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -defineTypeNameAndDebug(OFstream, 0); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -OFstreamAllocator::OFstreamAllocator +Foam::OFstreamAllocator::OFstreamAllocator ( const fileName& pathname, IOstream::compressionType compression @@ -51,11 +50,8 @@ OFstreamAllocator::OFstreamAllocator { if (OFstream::debug) { - Info - << "OFstreamAllocator::OFstreamAllocator" - "(const fileName& pathname) : " - "can't open null file " - << endl; + Info<< "OFstreamAllocator::OFstreamAllocator(const fileName&) : " + "cannot open null file " << endl; } } @@ -80,13 +76,13 @@ OFstreamAllocator::OFstreamAllocator } -OFstreamAllocator::~OFstreamAllocator() +Foam::OFstreamAllocator::~OFstreamAllocator() { delete ofPtr_; } -ostream& OFstreamAllocator::stdStream() +std::ostream& Foam::OFstreamAllocator::stdStream() { if (!ofPtr_) { @@ -99,7 +95,7 @@ ostream& OFstreamAllocator::stdStream() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -OFstream::OFstream +Foam::OFstream::OFstream ( const fileName& pathname, streamFormat format, @@ -112,17 +108,16 @@ OFstream::OFstream pathname_(pathname) { setClosed(); - setState(ofPtr_->rdstate()); - + if (!good()) { if (debug) { - Info<< "IFstream::IFstream(const fileName& pathname," + Info<< "IFstream::IFstream(const fileName&," "streamFormat format=ASCII," "versionNumber version=currentVersion) : " - "couldn't open File for input\n" + "could not open file for input\n" "in stream " << info() << Foam::endl; } @@ -132,29 +127,24 @@ OFstream::OFstream { setOpened(); } - + lineNumber_ = 1; } // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * // -OFstream::~OFstream() +Foam::OFstream::~OFstream() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void OFstream::print(Ostream& os) const +void Foam::OFstream::print(Ostream& os) const { - // Print File data os << " OFstream: "; OSstream::print(os); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOcheck.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOcheck.C deleted file mode 100644 index 4a88b42042..0000000000 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOcheck.C +++ /dev/null @@ -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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOprint.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOprint.C deleted file mode 100644 index 22ec698b74..0000000000 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOprint.C +++ /dev/null @@ -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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C index e12a8fd23e..864993c974 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C @@ -28,15 +28,17 @@ Description #include "IOstream.H" #include "error.H" +#include -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * 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") { @@ -49,8 +51,7 @@ IOstream::streamFormat IOstream::formatEnum(const word& format) else { WarningIn("IOstream::formatEnum(const word&)") - << "bad format specifier " - << format << " using ASCII" + << "bad format specifier '" << format << "', using 'ascii'" << endl; 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") { @@ -71,10 +73,8 @@ IOstream::compressionType IOstream::compressionEnum(const word& compression) else { WarningIn("IOstream::compressionEnum(const word&)") - << "bad compression specifier " - << '\'' << compression << '\'' - << ", use 'compressed' or 'uncompressed'. " - "Defaulting to uncompressed" + << "bad compression specifier '" << compression + << "', using 'uncompressed'" << endl; 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 * * * * * * * * * * * * * // -Ostream& operator<<(Ostream& os, const IOstream::streamFormat& sf) +Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::streamFormat& sf) { if (sf == IOstream::ASCII) { @@ -99,18 +215,27 @@ Ostream& operator<<(Ostream& os, const IOstream::streamFormat& sf) } -#if defined (__GNUC__) -template<> -#endif -Ostream& operator<<(Ostream& os, const InfoProxy& iostr) +Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::versionNumber& vn) { - iostr.t_.print(os); + os << vn.str().c_str(); return os; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam +namespace Foam +{ + +# if defined (__GNUC__) + template<> +# endif + Ostream& operator<<(Ostream& os, const InfoProxy& ip) + { + ip.t_.print(os); + return os; + } + +} // end namespace + // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H index 1c0558d931..56f94a688b 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H @@ -36,8 +36,7 @@ Description sequence one can read token by token, and then analyse. SourceFiles - IOprint.C - IOcheck.C + IOstream.C \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C index 9dbc03d218..4717894b79 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C @@ -28,20 +28,15 @@ License #include "bool.H" #include "token.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * 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 -bool Istream::getBack(token& t) +bool Foam::Istream::getBack(token& t) { if (bad()) { - FatalIOErrorIn("void Istream::getBack(token& t)", *this) + FatalIOErrorIn("void Istream::getBack(token&)", *this) << "Attempt to get back from bad stream" << exit(FatalIOError); @@ -53,25 +48,23 @@ bool Istream::getBack(token& t) putBack_ = false; return true; } - else - { - return false; - } + + return false; } // Keep the put back token -void Istream::putBack(const token& t) +void Foam::Istream::putBack(const token& t) { if (bad()) { - FatalIOErrorIn("void Istream::putBack(const token& t)", *this) + FatalIOErrorIn("void Istream::putBack(const token&)", *this) << "Attempt to put back onto bad stream" << exit(FatalIOError); } else if (putBack_) { - FatalIOErrorIn("void Istream::putBack(const token& t)", *this) + FatalIOErrorIn("void Istream::putBack(const token&)", *this) << "Attempt to put back another token" << exit(FatalIOError); } @@ -85,15 +78,15 @@ void Istream::putBack(const token& t) // Functions for reading object delimiters ( ... ) -Istream& Istream::readBegin(const char* funcName) +Foam::Istream& Foam::Istream::readBegin(const char* funcName) { token delimiter(*this); if (delimiter != token::BEGIN_LIST) { setBad(); FatalIOErrorIn("Istream::readBegin(const char*)", *this) - << "Expected a " << '\'' << token:: BEGIN_LIST << '\'' - << " while reading " << funcName + << "Expected a '" << token::BEGIN_LIST + << "' while reading " << funcName << ", found " << delimiter.info() << 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); if (delimiter != token::END_LIST) { setBad(); FatalIOErrorIn("Istream::readEnd(const char*)", *this) - << "Expected a " << '\'' << token::END_LIST << '\'' - << " while reading " << funcName + << "Expected a '" << token::END_LIST + << "' while reading " << funcName << ", found " << delimiter.info() << 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); return readBegin(funcName); @@ -128,17 +121,17 @@ Istream& Istream::readEndBegin(const char* funcName) // Functions for reading List delimiters ( ... ) or { ... } -char Istream::readBeginList(const char* funcName) +char Foam::Istream::readBeginList(const char* funcName) { token delimiter(*this); if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK) { setBad(); - FatalIOErrorIn("Istream::readBeginList(const char*)", *this) - << "Expected a " << '\'' << token::BEGIN_LIST << '\'' - << " or a " << '\'' << token::BEGIN_BLOCK << '\'' - << " while reading " << funcName + FatalIOErrorIn("Istream::readBeginList(const char*)", *this) + << "Expected a '" << token::BEGIN_LIST + << "' or a '" << token::BEGIN_BLOCK + << "' while reading " << funcName << ", found " << delimiter.info() << 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); @@ -157,9 +150,9 @@ char Istream::readEndList(const char* funcName) { setBad(); FatalIOErrorIn("Istream::readEndList(const char*)", *this) - << "Expected a " << '\'' << token::END_LIST << '\'' - << " or a " << '\'' << token::END_BLOCK << '\'' - << " while reading " << funcName + << "Expected a '" << token::END_LIST + << "' or a '" << token::END_BLOCK + << "' while reading " << funcName << ", found " << delimiter.info() << exit(FatalIOError); @@ -170,10 +163,7 @@ char Istream::readEndList(const char* funcName) } -//- Return a non-const reference to const Istream -// Needed for read-constructors where the stream argument is temporary: -// e.g. thing thisThing(IFstream("thingFileName")()); -Istream& Istream::operator()() const +Foam::Istream& Foam::Istream::operator()() const { if (!good()) { @@ -185,8 +175,4 @@ Istream& Istream::operator()() const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index 6536249a35..f446f2938f 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -36,6 +36,9 @@ Description were reading a stream on unknown data sequence one can read token by token, and then analyse. +SourceFiles + Istream.C + \*---------------------------------------------------------------------------*/ #ifndef Istream_H diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C index 52d5938558..18a93e93bc 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C @@ -32,21 +32,6 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Write keyType -Foam::Ostream& Foam::Ostream::write(const keyType& kw) -{ - // Write as word or string - if (kw.isPattern()) - { - return write(static_cast(kw)); - } - else - { - return write(static_cast(kw)); - } -} - - // Decrement the indent level 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(kw)); + } + else + { + return write(static_cast(kw)); + } +} + + // Write the keyword followed by appropriate indentation Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw) { diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index bff21532ab..30ecf298dc 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -29,6 +29,9 @@ Description An Ostream is an abstract base class for all output systems (streams, files, token lists, etc). +SourceFiles + Ostream.C + \*---------------------------------------------------------------------------*/ #ifndef Ostream_H @@ -42,6 +45,7 @@ Description namespace Foam { +// Forward declaration of classes class token; /*---------------------------------------------------------------------------*\ diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/versionNumber.C b/src/OpenFOAM/db/IOstreams/IOstreams/versionNumber.C deleted file mode 100644 index 8362bd5d1c..0000000000 --- a/src/OpenFOAM/db/IOstreams/IOstreams/versionNumber.C +++ /dev/null @@ -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 - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPread.C b/src/OpenFOAM/db/IOstreams/Pstreams/IPread.C deleted file mode 100644 index 7c8a251904..0000000000 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPread.C +++ /dev/null @@ -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 -inline void IPstream::readFromBuffer(T& t) -{ - t = reinterpret_cast(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(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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPreadToken.C b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C similarity index 57% rename from src/OpenFOAM/db/IOstreams/Pstreams/IPreadToken.C rename to src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C index d3b75c8c93..0ee14360b9 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPreadToken.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C @@ -24,18 +24,55 @@ License \*---------------------------------------------------------------------------*/ +#include "error.H" #include "IPstream.H" +#include "int.H" #include "token.H" #include -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam +// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * // + +inline void Foam::IPstream::checkEof() { + if (bufPosition_ == messageSize_) + { + setEof(); + } +} -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Istream& IPstream::read(token& t) +template +inline void Foam::IPstream::readFromBuffer(T& t) +{ + t = reinterpret_cast(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(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 if (Istream::getBack(t)) @@ -81,22 +118,22 @@ Istream& IPstream::read(token& t) // Word case token::WORD : { - word* wPtr = new word; - if (read(*wPtr)) + word* pval = new word; + if (read(*pval)) { - if (token::compound::isCompound(*wPtr)) + if (token::compound::isCompound(*pval)) { - t = token::compound::New(*wPtr, *this).ptr(); - delete wPtr; + t = token::compound::New(*pval, *this).ptr(); + delete pval; } else { - t = wPtr; + t = pval; } } else { - delete wPtr; + delete pval; t.setBad(); } return *this; @@ -105,14 +142,14 @@ Istream& IPstream::read(token& t) // String case token::STRING : { - string* sPtr = new string; - if (read(*sPtr)) + string* pval = new string; + if (read(*pval)) { - t = sPtr; + t = pval; } else { - delete sPtr; + delete pval; t.setBad(); } return *this; @@ -121,10 +158,10 @@ Istream& IPstream::read(token& t) // Label case token::LABEL : { - label l; - if (read(l)) + label val; + if (read(val)) { - t = l; + t = val; } else { @@ -136,10 +173,10 @@ Istream& IPstream::read(token& t) // floatScalar case token::FLOAT_SCALAR : { - floatScalar s; - if (read(s)) + floatScalar val; + if (read(val)) { - t = s; + t = val; } else { @@ -151,10 +188,10 @@ Istream& IPstream::read(token& t) // doubleScalar case token::DOUBLE_SCALAR : { - doubleScalar s; - if (read(s)) + doubleScalar val; + if (read(val)) { - t = s; + t = val; } 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 // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H index 06a16dfe6e..3dcbdc3de7 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H @@ -30,7 +30,6 @@ Description SourceFiles IPstream.C - IPread.C \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPwrite.C b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C similarity index 62% rename from src/OpenFOAM/db/IOstreams/Pstreams/OPwrite.C rename to src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C index 98e54561bd..4dbfc1badd 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPwrite.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C @@ -35,14 +35,49 @@ Description #include -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * // -namespace Foam +template +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(data); + register size_t i = count; + while (i--) *bufPtr++ = *dataPtr++; + + bufPosition_ += count; +} + // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // -OPstream::OPstream +Foam::OPstream::OPstream ( const commsTypes commsType, 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&)"); 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)) { @@ -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(s)); + word nonWhiteChars(string::validate(str)); 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)); - size_t ws = w.size(); - writeToBuffer(ws); - writeToBuffer(w.c_str(), ws + 1); + size_t len = str.size(); + writeToBuffer(len); + writeToBuffer(str.c_str(), len + 1); return *this; } -Ostream& OPstream::write(const string& s) +Foam::Ostream& Foam::OPstream::write(const string& str) { write(char(token::STRING)); - size_t ss = s.size(); - writeToBuffer(ss); - writeToBuffer(s.c_str(), ss + 1); + size_t len = str.size(); + writeToBuffer(len); + writeToBuffer(str.c_str(), len + 1); return *this; } -Ostream& OPstream::write(const label l) +Foam::Ostream& Foam::OPstream::write(const label val) { write(char(token::LABEL)); - - writeToBuffer(l); - + writeToBuffer(val); return *this; } -Ostream& OPstream::write(const floatScalar s) +Foam::Ostream& Foam::OPstream::write(const floatScalar val) { write(char(token::FLOAT_SCALAR)); - - writeToBuffer(s); - + writeToBuffer(val); return *this; } -Ostream& OPstream::write(const doubleScalar s) +Foam::Ostream& Foam::OPstream::write(const doubleScalar val) { write(char(token::DOUBLE_SCALAR)); - - writeToBuffer(s); - + writeToBuffer(val); 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) { @@ -169,13 +198,8 @@ Ostream& OPstream::write(const char* data, std::streamsize count) } writeToBuffer(data, count); - return *this; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H index 9bc20f8933..7391b36741 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H @@ -29,8 +29,7 @@ Description Output inter-processor communications stream. SourceFiles - OPstreamI.H - OPwrite.C + OPstream.C \*---------------------------------------------------------------------------*/ @@ -211,11 +210,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// include inline implementaions -# include "OPstreamI.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstreamI.H b/src/OpenFOAM/db/IOstreams/Pstreams/OPstreamI.H deleted file mode 100644 index cf53461dec..0000000000 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstreamI.H +++ /dev/null @@ -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 -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(data); - register size_t i = count; - while (i--) *bufPtr++ = *dataPtr++; - - bufPosition_ += count; -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C index 2c594c9e0d..531b15b8fc 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C @@ -76,7 +76,7 @@ void Foam::Pstream::calcLinearComm(const label nProcs) ); // 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 ( @@ -122,7 +122,7 @@ void Foam::Pstream::collectReceives // // The sends/receives for all levels are collected per processor (one send per // processor; multiple receives possible) creating a table: -// +// // So per processor: // proc receives from sends to // ---- ------------- -------- @@ -137,7 +137,7 @@ void Foam::Pstream::collectReceives void Foam::Pstream::calcTreeComm(label nProcs) { label nLevels = 1; - while((1 << nLevels) < nProcs) + while ((1 << nLevels) < nProcs) { nLevels++; } @@ -145,15 +145,15 @@ void Foam::Pstream::calcTreeComm(label nProcs) List > receives(nProcs); labelList sends(nProcs, -1); - //Info<< "Using " << nLevels << " communication levels" << endl; + // Info<< "Using " << nLevels << " communication levels" << endl; label offset = 2; label childOffset = offset/2; - for(label level = 0; level < nLevels; level++) + for (label level = 0; level < nLevels; level++) { label receiveID = 0; - while(receiveID < nProcs) + while (receiveID < nProcs) { // Determine processor that sends and we receive from label sendID = receiveID + childOffset; @@ -166,6 +166,7 @@ void Foam::Pstream::calcTreeComm(label nProcs) receiveID += offset; } + offset <<= 1; childOffset <<= 1; } @@ -173,15 +174,15 @@ void Foam::Pstream::calcTreeComm(label nProcs) // For all processors find the processors it receives data from // (and the processors they receive data from etc.) List > allReceives(nProcs); - for(label procID = 0; procID < nProcs; procID++) + for (label procID = 0; procID < nProcs; procID++) { collectReceives(procID, receives, allReceives[procID]); } - + treeCommunication_.setSize(nProcs); - for(label procID = 0; procID < nProcs; procID++) + for (label procID = 0; procID < nProcs; procID++) { treeCommunication_[procID] = commsStruct ( diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H index fe772e6792..ba7904639c 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H @@ -30,9 +30,8 @@ Description SourceFiles Pstream.C - IPread.C - OPwrite.C - Pprint.C + PstreamsPrint.C + PstreamCommsStruct.C gatherScatter.C combineGatherScatter.C gatherScatterList.C diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCommsStruct.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCommsStruct.C index c925295840..3a2d7f12f5 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCommsStruct.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCommsStruct.C @@ -29,7 +29,6 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Null constructor Foam::Pstream::commsStruct::commsStruct() : above_(-1), @@ -39,7 +38,6 @@ Foam::Pstream::commsStruct::commsStruct() {} -// Construct from components Foam::Pstream::commsStruct::commsStruct ( const label above, @@ -55,7 +53,6 @@ Foam::Pstream::commsStruct::commsStruct {} -// Construct from components Foam::Pstream::commsStruct::commsStruct ( const label nProcs, @@ -114,11 +111,7 @@ bool Foam::Pstream::commsStruct::operator!=(const commsStruct& comm) const // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // -Foam::Ostream& Foam::operator<< -( - Ostream& os, - const Foam::Pstream::commsStruct& comm -) +Foam::Ostream& Foam::operator<<(Ostream& os, const Pstream::commsStruct& comm) { os << comm.above_ << token::SPACE << comm.below_ << token::SPACE @@ -127,7 +120,7 @@ Foam::Ostream& Foam::operator<< os.check ( - "Ostream& operator<<(Ostream& f, const commsStruct& comm)" + "Ostream& operator<<(Ostream&, const commsStruct&)" ); return os; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pprint.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamsPrint.C similarity index 83% rename from src/OpenFOAM/db/IOstreams/Pstreams/Pprint.C rename to src/OpenFOAM/db/IOstreams/Pstreams/PstreamsPrint.C index 3f8f7dc909..2e744303b3 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pprint.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamsPrint.C @@ -23,7 +23,7 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 IPstream::print(Ostream& os) const +void Foam::IPstream::print(Ostream& os) const { os << "Reading from processor " << fromProcNo_ << " to processor " << myProcNo() << Foam::endl; } -void OPstream::print(Ostream& os) const +void Foam::OPstream::print(Ostream& os) const { os << "Writing from processor " << toProcNo_ << " to processor " << myProcNo() << Foam::endl; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISnextValid.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISnextValid.C deleted file mode 100644 index cde1e90d8e..0000000000 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISnextValid.C +++ /dev/null @@ -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 - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -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; - } - } -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISread.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISread.C deleted file mode 100644 index e8f2696a0d..0000000000 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISread.C +++ /dev/null @@ -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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISreadToken.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISreadToken.C deleted file mode 100644 index ee5d3881a2..0000000000 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISreadToken.C +++ /dev/null @@ -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 - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C new file mode 100644 index 0000000000..c2e27d5d16 --- /dev/null +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -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 + + +// * * * * * * * * * * * * * * 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); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H index cc607a1998..45dc5a607c 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H @@ -154,7 +154,9 @@ public: //- Read a 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&); //- Read a label diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H index 3f93500044..1fedf76229 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H @@ -26,7 +26,34 @@ License #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) { @@ -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()); - } -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSwrite.C b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C similarity index 59% rename from src/OpenFOAM/db/IOstreams/Sstreams/OSwrite.C rename to src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C index a27222351d..5c60ada59f 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSwrite.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C @@ -30,18 +30,13 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -Ostream& OSstream::write(const token&) +Foam::Ostream& Foam::OSstream::write(const token&) { return *this; } -Ostream& OSstream::write(const char c) +Foam::Ostream& Foam::OSstream::write(const char c) { os_ << c; 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); - os_ << s; + lineNumber_ += string(str).count(token::NL); + os_ << str; setState(os_.rdstate()); return *this; } -Ostream& OSstream::write(const word& w) +Foam::Ostream& Foam::OSstream::write(const word& str) { - os_ << w; + os_ << str; setState(os_.rdstate()); return *this; } -Ostream& OSstream::write(const string& s) +Foam::Ostream& Foam::OSstream::write(const string& str) { - os_ << '\"'; + os_ << token::BEGIN_STRING; - for - ( - string::const_iterator iter = s.begin(); - iter != s.end(); - ++iter - ) + register int backslash = 0; + for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter) { register char c = *iter; - if (c == token::NL) + switch (c) { - os_ << '\\'; - lineNumber_++; + case '\\' : + 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()); return *this; } -Ostream& OSstream::write(const label l) +Foam::Ostream& Foam::OSstream::write(const label val) { - os_ << l; + os_ << val; setState(os_.rdstate()); return *this; } -Ostream& OSstream::write(const floatScalar s) +Foam::Ostream& Foam::OSstream::write(const floatScalar val) { - os_ << s; + os_ << val; setState(os_.rdstate()); return *this; } -Ostream& OSstream::write(const doubleScalar s) +Foam::Ostream& Foam::OSstream::write(const doubleScalar val) { - os_ << s; + os_ << val; setState(os_.rdstate()); 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) { @@ -150,8 +155,7 @@ Ostream& OSstream::write(const char* buf, std::streamsize count) } -//- Add indentation characters -void OSstream::indent() +void Foam::OSstream::indent() { for (register unsigned short i = 0; i < indentLevel_*indentSize_; i++) { @@ -160,62 +164,60 @@ void OSstream::indent() } -// Flush stream -void OSstream::flush() +void Foam::OSstream::flush() { os_.flush(); } // Add carriage return and flush stream -void OSstream::endl() +void Foam::OSstream::endl() { write('\n'); os_.flush(); } -// Set flags of output stream -ios_base::fmtflags OSstream::flags() const +// Get flags of output stream +std::ios_base::fmtflags Foam::OSstream::flags() const { return os_.flags(); } -// Set flags of given field of output stream -ios_base::fmtflags OSstream::flags(const ios_base::fmtflags f) +// Set flags of output stream +std::ios_base::fmtflags Foam::OSstream::flags(const ios_base::fmtflags 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(); } // 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); } -//- Get precision of output field -int OSstream::precision() const +// Get precision of output field +int Foam::OSstream::precision() const { return os_.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); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H index 5111f6015d..816021f8c5 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H @@ -30,7 +30,7 @@ Description SourceFiles OSstreamI.H - OSwrite.C + OSstream.C chkStream.C \*---------------------------------------------------------------------------*/ @@ -136,6 +136,9 @@ public: virtual Ostream& write(const word&); //- 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&); //- Write label diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/Sprint.C b/src/OpenFOAM/db/IOstreams/Sstreams/SstreamsPrint.C similarity index 83% rename from src/OpenFOAM/db/IOstreams/Sstreams/Sprint.C rename to src/OpenFOAM/db/IOstreams/Sstreams/SstreamsPrint.C index 9d5fc3333b..75301d4d31 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/Sprint.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/SstreamsPrint.C @@ -23,7 +23,7 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 ISstream::print(Ostream& os) const +void Foam::ISstream::print(Ostream& os) const { 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() << ' '; @@ -55,8 +50,4 @@ void OSstream::print(Ostream& os) const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSwrite.C b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C similarity index 64% rename from src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSwrite.C rename to src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C index 03f16876f0..79aa6d5a03 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSwrite.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C @@ -28,14 +28,21 @@ License #include "Pstream.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, 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()) - { - OSstream::write(prefix_.c_str()); - printPrefix_ = false; - } + os << "prefixOSstream "; + OSstream::print(os); } -Ostream& prefixOSstream::write(const token&) +Foam::Ostream& Foam::prefixOSstream::write(const token&) { return *this; } -Ostream& prefixOSstream::write(const char c) +Foam::Ostream& Foam::prefixOSstream::write(const char c) { checkWritePrefix(); 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(); - OSstream::write(s); + OSstream::write(str); - size_t sl = strlen(s); - if (sl && s[sl - 1] == token::NL) + size_t len = strlen(str); + if (len && str[len-1] == token::NL) { 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(); - return OSstream::write(w); + return OSstream::write(val); } -Ostream& prefixOSstream::write(const string& s) +Foam::Ostream& Foam::prefixOSstream::write(const string& val) { checkWritePrefix(); - return OSstream::write(s); + return OSstream::write(val); } -Ostream& prefixOSstream::write(const label l) +Foam::Ostream& Foam::prefixOSstream::write(const label val) { checkWritePrefix(); - return OSstream::write(l); + return OSstream::write(val); } -Ostream& prefixOSstream::write(const floatScalar s) +Foam::Ostream& Foam::prefixOSstream::write(const floatScalar val) { checkWritePrefix(); - return OSstream::write(s); + return OSstream::write(val); } -Ostream& prefixOSstream::write(const doubleScalar s) +Foam::Ostream& Foam::prefixOSstream::write(const doubleScalar val) { 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(); return OSstream::write(buf, count); } -//- Add indentation characters -void prefixOSstream::indent() +void Foam::prefixOSstream::indent() { checkWritePrefix(); OSstream::indent(); } - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H similarity index 99% rename from src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSstream.H rename to src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H index 04126aaaf2..85e909bdcb 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H @@ -32,8 +32,7 @@ Description to be automatically prepended to each message line. SourceFiles - prefixOSwrite.C - prefixOSprint.C + prefixOSstream.C \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSprint.C b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSprint.C deleted file mode 100644 index bb481625d2..0000000000 --- a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream/prefixOSprint.C +++ /dev/null @@ -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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.C b/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.C index dfd581cbe8..ea931a96fa 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.C @@ -33,27 +33,26 @@ Description Foam::label Foam::readHexLabel(ISstream& is) { - register label result = 0; - - char c = 0; - + // Takes into account that 'a' (or 'A') is 10 + static const label alphaOffset = toupper('A') - 10; + // Takes into account that '0' is 0 static const label zeroOffset = int('0'); - // This takes into account that a is 10 - static const label alphaOffset = toupper('A') - 10; + char c = 0; // Get next non-whitespace character while (is.get(c) && isspace(c)) {} + register label result = 0; do { if (isspace(c) || c == 0) break; if (!isxdigit(c)) { - FatalIOErrorIn("readHexLabel(ISstream& is)", is) - << "Illegal hex digit: \"" << c << "\"" + FatalIOErrorIn("readHexLabel(ISstream&)", is) + << "Illegal hex digit: '" << c << "'" << exit(FatalIOError); } diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H index e612eef85f..760b4cfed1 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H +++ b/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H @@ -29,7 +29,7 @@ Description Input from memory buffer stream. SourceFiles - Mprint.C + StringStreamsPrint.C \*---------------------------------------------------------------------------*/ @@ -37,7 +37,6 @@ SourceFiles #define IStringStream_H #include "ISstream.H" - #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -114,7 +113,7 @@ public: // Print - //- Print description of IOstream to Ostream + //- Print description to Ostream void print(Ostream&) const; diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H index 8fa6dfce5d..c50ac7babc 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H +++ b/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H @@ -29,7 +29,7 @@ Description Output to memory buffer stream. SourceFiles - Mprint.C + StringStreamsPrint.C \*---------------------------------------------------------------------------*/ @@ -37,7 +37,6 @@ SourceFiles #define OStringStream_H #include "OSstream.H" - #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -46,7 +45,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class OStringStream Declaration + Class OStringStream Declaration \*---------------------------------------------------------------------------*/ class OStringStream @@ -128,7 +127,7 @@ public: // Print - //- Print description OM IOstream to Ostream + //- Print description to Ostream void print(Ostream&) const; }; diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/StringStreamPrint.C b/src/OpenFOAM/db/IOstreams/StringStreams/StringStreamsPrint.C similarity index 82% rename from src/OpenFOAM/db/IOstreams/StringStreams/StringStreamPrint.C rename to src/OpenFOAM/db/IOstreams/StringStreams/StringStreamsPrint.C index ebac10aaf7..b1f2b658c7 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/StringStreamPrint.C +++ b/src/OpenFOAM/db/IOstreams/StringStreams/StringStreamsPrint.C @@ -23,7 +23,7 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 IStringStream::print(Ostream& os) const +void Foam::IStringStream::print(Ostream& os) const { os << "IStringStream " << name() << " : " << "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() << " : " << "buffer = \n" << str() << Foam::endl; @@ -55,8 +50,4 @@ void OStringStream::print(Ostream& os) const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITread.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C similarity index 77% rename from src/OpenFOAM/db/IOstreams/Tstreams/ITread.C rename to src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 61d005bf4a..ca11e5e2b9 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITread.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -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 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)"); return *this; } -Istream& ITstream::read(word&) + +Foam::Istream& Foam::ITstream::read(word&) { notImplemented("Istream& ITstream::read(word&)"); return *this; } -Istream& ITstream::read(string&) +Foam::Istream& Foam::ITstream::read(string&) { notImplemented("Istream& ITstream::read(string&)"); return *this; } -Istream& ITstream::read(label&) +Foam::Istream& Foam::ITstream::read(label&) { notImplemented("Istream& ITstream::read(label&)"); return *this; } -Istream& ITstream::read(floatScalar&) +Foam::Istream& Foam::ITstream::read(floatScalar&) { notImplemented("Istream& ITstream::read(floatScalar&)"); return *this; } -Istream& ITstream::read(doubleScalar&) +Foam::Istream& Foam::ITstream::read(doubleScalar&) { notImplemented("Istream& ITstream::read(doubleScalar&)"); return *this; } -Istream& ITstream::read(char*, std::streamsize) +Foam::Istream& Foam::ITstream::read(char*, std::streamsize) { notImplemented("Istream& ITstream::read(char*, std::streamsize)"); return *this; @@ -137,7 +158,7 @@ Istream& ITstream::read(char*, std::streamsize) // Rewind the token stream so that it may be read again -Istream& ITstream::rewind() +Foam::Istream& Foam::ITstream::rewind() { tokenIndex_ = 0; @@ -152,8 +173,4 @@ Istream& ITstream::rewind() } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H index 2f866c3583..3a34761db7 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H @@ -29,8 +29,7 @@ Description Input token stream. SourceFiles - ITread.C - ITprint.C + ITstream.C \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/Tprint.C b/src/OpenFOAM/db/IOstreams/Tstreams/Tprint.C deleted file mode 100644 index bbf338af9f..0000000000 --- a/src/OpenFOAM/db/IOstreams/Tstreams/Tprint.C +++ /dev/null @@ -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 - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/token/CompoundToken/CompoundToken.H b/src/OpenFOAM/db/IOstreams/token/CompoundToken.H similarity index 100% rename from src/OpenFOAM/db/IOstreams/token/CompoundToken/CompoundToken.H rename to src/OpenFOAM/db/IOstreams/token/CompoundToken.H diff --git a/src/OpenFOAM/db/IOstreams/token/token.C b/src/OpenFOAM/db/IOstreams/token/token.C index d32818a69e..f74dbd7381 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.C +++ b/src/OpenFOAM/db/IOstreams/token/token.C @@ -50,12 +50,13 @@ void Foam::token::parseError(const char* expected) const Foam::token::compound::~compound() {} + // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // Foam::autoPtr Foam::token::compound::New ( - const Foam::word& compoundType, - Foam::Istream& is + const word& compoundType, + Istream& is ) { IstreamConstructorTable::iterator cstrIter = @@ -63,10 +64,9 @@ Foam::autoPtr Foam::token::compound::New if (cstrIter == IstreamConstructorTablePtr_->end()) { - FatalErrorIn("token::compound::New(Istream&)") - << "Unknown compound type " << compoundType - << endl << endl - << "Valid compound types are :" << endl + FatalErrorIn("token::compound::New(const word&, Istream&)") + << "Unknown compound type " << compoundType << nl << nl + << "Valid compound types:" << endl << IstreamConstructorTablePtr_->toc() << abort(FatalError); } @@ -77,7 +77,7 @@ Foam::autoPtr Foam::token::compound::New // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::token::compound::isCompound(const Foam::word& name) +bool Foam::token::compound::isCompound(const word& name) { return ( diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index 5de72aa61e..b265739572 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -30,8 +30,8 @@ Description SourceFiles tokenI.H + token.C tokenIO.C - printToken.C \*---------------------------------------------------------------------------*/ @@ -165,7 +165,7 @@ public: // Selectors //- Select null constructed - static autoPtr New(const word& type, Istream& is); + static autoPtr New(const word& type, Istream&); // Destructor @@ -291,22 +291,22 @@ public: inline token(const token&); //- Construct punctuation character token - inline token(punctuationToken p, label lineNumber=0); + inline token(punctuationToken, label lineNumber=0); //- Construct word token - inline token(const word& w, label lineNumber=0); + inline token(const word&, label lineNumber=0); //- Construct string token - inline token(const string& s, label lineNumber=0); + inline token(const string&, label lineNumber=0); //- Construct label token inline token(const label, label lineNumber=0); //- Construct floatScalar token - inline token(const floatScalar s, label lineNumber=0); + inline token(const floatScalar, label lineNumber=0); //- Construct doubleScalar token - inline token(const doubleScalar s, label lineNumber=0); + inline token(const doubleScalar, label lineNumber=0); //- Construct from Istream token(Istream&); diff --git a/src/OpenFOAM/db/IOstreams/token/tokenIO.C b/src/OpenFOAM/db/IOstreams/token/tokenIO.C index 97950b375e..7cef14b24d 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenIO.C +++ b/src/OpenFOAM/db/IOstreams/token/tokenIO.C @@ -28,20 +28,14 @@ Description \*---------------------------------------------------------------------------*/ #include "error.H" +#include "token.H" #include "IOstreams.H" #include "scalar.H" -#include "HashTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct from Istream -token::token(Istream& is) +Foam::token::token(Istream& is) : type_(UNDEFINED) { @@ -51,20 +45,20 @@ token::token(Istream& is) // * * * * * * * * * * * * IOstream operators * * * * * * * * * * * * * * * // -Istream& operator>>(Istream& is, token& t) +Foam::Istream& Foam::operator>>(Istream& is, token& t) { t.clear(); return is.read(t); } -Ostream& operator<<(Ostream& os, const token& t) +Foam::Ostream& Foam::operator<<(Ostream& os, const token& t) { switch (t.type_) { case token::UNDEFINED: os << "UNDEFINED"; - WarningIn("Ostream& operator<< (Ostream&, const token&)") + WarningIn("Ostream& operator<<(Ostream&, const token&)") << "Undefined token" << endl; break; @@ -98,13 +92,13 @@ Ostream& operator<<(Ostream& os, const token& t) case token::ERROR: os << "ERROR"; - WarningIn("Ostream& operator<< (Ostream&, const token&)") + WarningIn("Ostream& operator<<(Ostream&, const token&)") << "Error token" << endl; break; default: os << "UNKNOWN"; - SeriousErrorIn("Ostream& operator<< (Ostream&, const token&)") + SeriousErrorIn("Ostream& operator<<(Ostream&, const token&)") << "Unknown token" << 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); } -ostream& operator<<(ostream& os, const token::punctuationToken& pt) + +Foam::Ostream& Foam::operator<<(Ostream& os, const token::punctuationToken& 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& 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__) template<> #endif @@ -193,78 +266,6 @@ Ostream& operator<<(Ostream& os, const InfoProxy& ip) } -ostream& operator<<(ostream& os, const InfoProxy& 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 diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 8ec6f7e4a0..193cc0f2a7 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -131,7 +131,7 @@ public: //- Count and return the number of a given character in the string size_type count(const char) const; - //- Is this string type valid + //- Is this string type valid? template static inline bool valid(const string&); diff --git a/src/OpenFOAM/primitives/strings/string/stringI.H b/src/OpenFOAM/primitives/strings/string/stringI.H index 36a0a6a470..e391810720 100644 --- a/src/OpenFOAM/primitives/strings/string/stringI.H +++ b/src/OpenFOAM/primitives/strings/string/stringI.H @@ -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 inline bool Foam::string::valid(const string& s) { - bool iv = false; - for (const_iterator iter = s.begin(); iter != s.end(); iter++) { if (!String::valid(*iter)) { - iv = true; - break; + return false; } } - - return !iv; + return true; } @@ -114,9 +110,9 @@ inline bool Foam::string::stripInvalid(string& s) template -inline String Foam::string::validate(const string& s) +inline String Foam::string::validate(const string& str) { - string ss = s; + string ss = str; stripInvalid(ss); return ss; }