diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C index 4131da7af459435835a59018b292d4834d6c0988..754c5fb1859c243573b5371b9327f2ca1bac0dfe 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C @@ -79,11 +79,9 @@ Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw) } -Foam::Ostream& Foam::Ostream::beginBlock(const word& keyword) +Foam::Ostream& Foam::Ostream::beginBlock(const keyType& keyword) { - indent(); - write(keyword); - endl(); + indent(); write(keyword); write('\n'); beginBlock(); return *this; @@ -92,8 +90,7 @@ Foam::Ostream& Foam::Ostream::beginBlock(const word& keyword) Foam::Ostream& Foam::Ostream::beginBlock() { - indent(); - write(char(token::BEGIN_BLOCK)); + indent(); write(char(token::BEGIN_BLOCK)); write('\n'); incrIndent(); return *this; @@ -103,8 +100,15 @@ Foam::Ostream& Foam::Ostream::beginBlock() Foam::Ostream& Foam::Ostream::endBlock() { decrIndent(); - indent(); - write(char(token::END_BLOCK)); + indent(); write(char(token::END_BLOCK)); write('\n'); + + return *this; +} + + +Foam::Ostream& Foam::Ostream::endEntry() +{ + write(char(token::END_STATEMENT)); write('\n'); return *this; } diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index 0bd02a5b55363c2c47ce1c17f64a5e91fcd5e0a5..1634689c641170380f8f11a4fc390245a88e9f40 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -154,33 +154,47 @@ public: return indentLevel_; } - //- Incrememt the indent level + //- Increment the indent level void incrIndent() { ++indentLevel_; } - //- Decrememt the indent level + //- Decrement the indent level void decrIndent(); //- Write the keyword followed by an appropriate indentation virtual Ostream& writeKeyword(const keyType&); //- Write begin block group with the given name - // Uses the appropriate indentation, - // does not include a trailing newline. - virtual Ostream& beginBlock(const word&); + // Increments indentation, adds newline. + virtual Ostream& beginBlock(const keyType&); //- Write begin block group without a name - // Uses the appropriate indentation, - // does not include a trailing newline. + // Increments indentation, adds newline. virtual Ostream& beginBlock(); //- Write end block group - // Uses the appropriate indentation, - // does not include a trailing newline. + // Decrements indentation, adds newline. virtual Ostream& endBlock(); + //- Write end entry (';') followed by newline. + virtual Ostream& endEntry(); + + //- Write a keyword/value entry. + // The following two are functionally equivalent: + // \code + // os.writeEntry(key, value); + // + // os.writeKeyword(key) << value << endEntry; + // \endcode + template<class T> + Ostream& writeEntry(const keyType& key, const T& value) + { + writeKeyword(key) << value; + return endEntry(); + } + // Stream state functions @@ -273,6 +287,32 @@ inline Ostream& endl(Ostream& os) } +//- Write begin block group without a name +// Increments indentation, adds newline. +inline Ostream& beginBlock(Ostream& os) +{ + os.beginBlock(); + return os; +} + + +//- Write end block group +// Decrements indentation, adds newline. +inline Ostream& endBlock(Ostream& os) +{ + os.endBlock(); + return os; +} + + +//- Write end entry (';') followed by newline. +inline Ostream& endEntry(Ostream& os) +{ + os.endEntry(); + return os; +} + + // Useful aliases for tab and newline characters static const char tab = '\t'; static const char nl = '\n'; diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index d2880798fc4489cc60e404b8c9a06bd03c48269d..b9db794b8039d7be8df06de1579f41b13fd897a3 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -175,7 +175,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const if (subDict) { os << nl; - os.beginBlock() << nl; + os.beginBlock(); } forAllConstIter(IDLList<entry>, *this, iter) @@ -203,7 +203,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const if (subDict) { - os.endBlock() << endl; + os.endBlock() << flush; } } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C index fe43d9225db276ae5d9f2fc50cd57373e7d0be0d..7e273aa9fd26af46e829988578f7fd626eab7351 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C @@ -569,16 +569,16 @@ template<class Type, template<class> class PatchField, class GeoMesh> void Foam::GeometricField<Type, PatchField, GeoMesh>::Boundary:: writeEntry(const word& keyword, Ostream& os) const { - os.beginBlock(keyword) << nl; + os.beginBlock(keyword); forAll(*this, patchi) { - os.beginBlock(this->operator[](patchi).patch().name()) << nl; + os.beginBlock(this->operator[](patchi).patch().name()); os << this->operator[](patchi); - os.endBlock() << endl; + os.endBlock(); } - os.endBlock() << endl; + os.endBlock() << flush; // Check state of IOstream os.check diff --git a/src/OpenFOAM/global/profiling/profiling.C b/src/OpenFOAM/global/profiling/profiling.C index 647102285050efd93a02d7e877d8436ac7a26aeb..10c61852ad093c76a5833b32051326887f953956 100644 --- a/src/OpenFOAM/global/profiling/profiling.C +++ b/src/OpenFOAM/global/profiling/profiling.C @@ -41,17 +41,6 @@ Foam::label Foam::profiling::Information::nextId_(0); // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -// file-scope function -template<class T> -inline static void writeEntry -( - Foam::Ostream& os, const Foam::word& key, const T& value -) -{ - os.writeKeyword(key) << value << Foam::token::END_STATEMENT << '\n'; -} - - Foam::label Foam::profiling::Information::getNextId() { return nextId_++; @@ -369,7 +358,7 @@ void Foam::profiling::Information::update(const scalar& elapsed) bool Foam::profiling::writeData(Ostream& os) const { - os.beginBlock("profiling") << nl; // FUTURE: without nl + os.beginBlock("profiling"); // Add extra new line between entries label nTrigger = 0; @@ -420,22 +409,22 @@ bool Foam::profiling::writeData(Ostream& os) const } } - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); if (sysInfo_) { os << nl; - os.beginBlock("sysInfo") << nl; // FUTURE: without nl + os.beginBlock("sysInfo"); sysInfo_->write(os); - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); } if (cpuInfo_) { os << nl; - os.beginBlock("cpuInfo") << nl; // FUTURE: without nl + os.beginBlock("cpuInfo"); cpuInfo_->write(os); - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); } if (memInfo_) @@ -443,10 +432,10 @@ bool Foam::profiling::writeData(Ostream& os) const memInfo_->update(); os << nl; - os.beginBlock("memInfo") << nl; // FUTURE: without nl + os.beginBlock("memInfo"); memInfo_->write(os); - writeEntry(os, "units", "kB"); - os.endBlock() << nl; // FUTURE: without nl + os.writeEntry("units", "kB"); + os.endBlock(); } return os; @@ -536,26 +525,24 @@ Foam::Ostream& Foam::profiling::Information::write { // write in dictionary format - os.beginBlock("trigger" + Foam::name(id_)) << nl; // FUTURE: without nl - - // FUTURE: os.writeEntry(key, value); + os.beginBlock(word("trigger" + Foam::name(id_))); - writeEntry(os, "id", id_); + os.writeEntry("id", id_); if (id_ != parent().id()) { - writeEntry(os, "parentId", parent().id()); + os.writeEntry("parentId", parent().id()); } - writeEntry(os, "description", description()); - writeEntry(os, "calls", calls() + (offset ? 1 : 0)); - writeEntry(os, "totalTime", totalTime() + elapsedTime); - writeEntry(os, "childTime", childTime() + childTimes); + os.writeEntry("description", description()); + os.writeEntry("calls", calls() + (offset ? 1 : 0)); + os.writeEntry("totalTime", totalTime() + elapsedTime); + os.writeEntry("childTime", childTime() + childTimes); if (maxMem_) { - writeEntry(os, "maxMem", maxMem_); + os.writeEntry("maxMem", maxMem_); } - writeEntry(os, "onStack", Switch(onStack())); + os.writeEntry("onStack", Switch(onStack())); - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); return os; } diff --git a/src/OpenFOAM/global/profiling/profilingSysInfo.C b/src/OpenFOAM/global/profiling/profilingSysInfo.C index 9b6ff2f34b9f2ac463fc5fc7d93a9dd7d1ef22ab..51b060173648af2c5d25d7a5314caa799c99a8bc 100644 --- a/src/OpenFOAM/global/profiling/profilingSysInfo.C +++ b/src/OpenFOAM/global/profiling/profilingSysInfo.C @@ -29,17 +29,6 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -// file-scope function -template<class T> -inline static void writeEntry -( - Foam::Ostream& os, const Foam::word& key, const T& value -) -{ - os.writeKeyword(key) << value << Foam::token::END_STATEMENT << '\n'; -} - - // file-scope function inline static void printEnv ( @@ -49,7 +38,7 @@ inline static void printEnv const std::string value = getEnv(envName); if (!value.empty()) { - writeEntry(os, key, value); + os.writeEntry(key, value); } } @@ -74,12 +63,12 @@ Foam::Ostream& Foam::profiling::sysInfo::write Ostream& os ) const { - writeEntry(os, "host", hostName(false)); // short name - writeEntry(os, "date", clock::dateTime()); + os.writeEntry("host", hostName(false)); // short name + os.writeEntry("date", clock::dateTime()); // compile-time information - writeEntry(os, "version", std::string(FOAMversion)); - writeEntry(os, "build", std::string(FOAMbuild)); + os.writeEntry("version", std::string(FOAMversion)); + os.writeEntry("build", std::string(FOAMbuild)); printEnv(os, "arch", "WM_ARCH"); printEnv(os, "compilerType", "WM_COMPILER_TYPE"); diff --git a/src/OpenFOAM/global/profiling/profilingSysInfo.H b/src/OpenFOAM/global/profiling/profilingSysInfo.H index 26201fac3607f5d41fca160b3a7b7d96cc2720ef..b2e84f888f74e19a66cb0081ee6b644479fe693f 100644 --- a/src/OpenFOAM/global/profiling/profilingSysInfo.H +++ b/src/OpenFOAM/global/profiling/profilingSysInfo.H @@ -51,12 +51,6 @@ class Ostream; class profiling::sysInfo { - // Private Static Data Members - - - // Private Data Members - - // Private Member Functions //- Disallow default bitwise copy construct @@ -72,9 +66,6 @@ protected: friend class profiling; - - // Member Functions - public: @@ -90,11 +81,6 @@ public: // Member Functions - // Access - - - // Edit - //- Update it with a new timing information void update(); diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index aa619792c3a5fd3c83e73bafe23d6f0af70d3619..edb37c727bfc5424f691a678221689847f9f4f83 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -1120,9 +1120,9 @@ bool Foam::polyBoundaryMesh::writeData(Ostream& os) const forAll(patches, patchi) { - os.beginBlock(patches[patchi].name()) << nl; + os.beginBlock(patches[patchi].name()); os << patches[patchi]; - os.endBlock() << endl; + os.endBlock(); } os << decrIndent << token::END_LIST; diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index 06a08a3598080788d1de25fd3f2344ef3f4cb3f2..99539ee2c680e207fb5d11847706baaa07f675fe 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -449,15 +449,14 @@ Foam::point Foam::plane::mirror(const point& p) const void Foam::plane::writeDict(Ostream& os) const { - os.writeKeyword("planeType") << "pointAndNormal" - << token::END_STATEMENT << nl; + os.writeEntry("planeType", "pointAndNormal"); - os.beginBlock("pointAndNormalDict") << nl; + os.beginBlock("pointAndNormalDict"); - os.writeKeyword("point") << point_ << token::END_STATEMENT << nl; - os.writeKeyword("normal") << normal_ << token::END_STATEMENT << nl; + os.writeEntry("point", point_); + os.writeEntry("normal", normal_); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C index a929f868ee562ed0cf03f63ad3c8cee6cddf9736..9d2d8581744257db01d59e0f56e0f717ac34a068 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C @@ -263,41 +263,28 @@ template<class Type> void Foam::Function1Types::CSV<Type>::writeData(Ostream& os) const { Function1<Type>::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); // Note: for TableBase write the dictionary entries it needs but not // the values themselves TableBase<Type>::writeEntries(os); - os.writeKeyword("nHeaderLine") << nHeaderLine_ - << token::END_STATEMENT << nl; - os.writeKeyword("refColumn") << refColumn_ - << token::END_STATEMENT << nl; + os.writeEntry("nHeaderLine", nHeaderLine_); + os.writeEntry("refColumn", refColumn_); // Force writing labelList in ascii - os.writeKeyword("componentColumns"); - if (os.format() == IOstream::BINARY) - { - os.format(IOstream::ASCII); - os << componentColumns_; - os.format(IOstream::BINARY); - } - else - { - os << componentColumns_; - } - os << token::END_STATEMENT << nl; + const enum IOstream::streamFormat fmt = os.format(); + os.format(IOstream::ASCII); + os.writeEntry("componentColumns", componentColumns_); + os.format(fmt); - os.writeKeyword("separator") << string(separator_) - << token::END_STATEMENT << nl; - os.writeKeyword("mergeSeparators") << mergeSeparators_ - << token::END_STATEMENT << nl; - os.writeKeyword("fileName") << fName_ - << token::END_STATEMENT << nl; + os.writeEntry("separator", string(separator_)); + os.writeEntry("mergeSeparators", mergeSeparators_); + os.writeEntry("fileName", fName_); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C index 85a7aefe04261d1eee76d753877e8c73de3f61c9..a11acd4df832588b90316e675c41027d8c14d778 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C @@ -89,17 +89,17 @@ template<class Type> void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const { Function1<Type>::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); - os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl; + os.writeEntry("t0", t0_); amplitude_->writeData(os); frequency_->writeData(os); scale_->writeData(os); level_->writeData(os); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C index 9c55e8800e6fe7a7a43bbce37b3f0f27c228cec7..0e258bc30eace0e6e611fce3c5eaa92c11933b5e 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C +++ b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C @@ -102,18 +102,18 @@ template<class Type> void Foam::Function1Types::Square<Type>::writeData(Ostream& os) const { Function1<Type>::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); - os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl; - os.writeKeyword("markSpace") << markSpace_ << token::END_STATEMENT << nl; + os.writeEntry("t0", t0_); + os.writeEntry("markSpace", markSpace_); amplitude_->writeData(os); frequency_->writeData(os); scale_->writeData(os); level_->writeData(os); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C index 414e6160772df7b07ef2a610c2c47f9d54288dc7..3682836999f4ce95ca3927370e053f27b2510af3 100644 --- a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C +++ b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C @@ -78,16 +78,17 @@ template<class Type> void Foam::Function1Types::TableFile<Type>::writeData(Ostream& os) const { Function1<Type>::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); // Note: for TableBase write the dictionary entries it needs but not // the values themselves TableBase<Type>::writeEntries(os); - os.writeKeyword("fileName")<< fName_ << token::END_STATEMENT << nl; - os.endBlock() << endl; + os.writeEntry("fileName", fName_); + + os.endBlock() << flush; }