diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C index ab95c8c19f..4131da7af4 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,7 +40,7 @@ void Foam::Ostream::decrIndent() } else { - indentLevel_--; + --indentLevel_; } } @@ -79,4 +79,35 @@ Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw) } +Foam::Ostream& Foam::Ostream::beginBlock(const word& keyword) +{ + indent(); + write(keyword); + endl(); + beginBlock(); + + return *this; +} + + +Foam::Ostream& Foam::Ostream::beginBlock() +{ + indent(); + write(char(token::BEGIN_BLOCK)); + incrIndent(); + + return *this; +} + + +Foam::Ostream& Foam::Ostream::endBlock() +{ + decrIndent(); + indent(); + write(char(token::END_BLOCK)); + + return *this; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index aada0b4f9a..0bd02a5b55 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -109,8 +109,8 @@ public: virtual Ostream& write(const word&) = 0; //- Write keyType - // write regular expression as quoted string - // write plain word as word (unquoted) + // A plain word is written unquoted. + // A regular expression is written as a quoted string. virtual Ostream& write(const keyType&); //- Write string @@ -157,14 +157,29 @@ public: //- Incrememt the indent level void incrIndent() { - indentLevel_++; + ++indentLevel_; } //- Decrememt the indent level void decrIndent(); //- Write the keyword followed by an appropriate indentation - Ostream& writeKeyword(const keyType&); + 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&); + + //- Write begin block group without a name + // Uses the appropriate indentation, + // does not include a trailing newline. + virtual Ostream& beginBlock(); + + //- Write end block group + // Uses the appropriate indentation, + // does not include a trailing newline. + virtual Ostream& endBlock(); // Stream state functions diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index f27d326d8c..3cef23692f 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -174,7 +174,8 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const { if (subDict) { - os << nl << indent << token::BEGIN_BLOCK << incrIndent << nl; + os << nl; + os.beginBlock() << nl; } forAllConstIter(IDLList, *this, iter) @@ -202,7 +203,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const if (subDict) { - os << decrIndent << indent << token::END_BLOCK << endl; + os.endBlock() << endl; } } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C index 717f7d609f..de5ec76d2f 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C @@ -569,17 +569,16 @@ template class PatchField, class GeoMesh> void Foam::GeometricField::GeometricBoundaryField:: writeEntry(const word& keyword, Ostream& os) const { - os << keyword << nl << token::BEGIN_BLOCK << incrIndent << nl; + os.beginBlock(keyword) << nl; forAll(*this, patchi) { - os << indent << this->operator[](patchi).patch().name() << nl - << indent << token::BEGIN_BLOCK << nl - << incrIndent << this->operator[](patchi) << decrIndent - << indent << token::END_BLOCK << endl; + os.beginBlock(this->operator[](patchi).patch().name()) << nl; + os << this->operator[](patchi); + os.endBlock() << endl; } - os << decrIndent << token::END_BLOCK << endl; + os.endBlock() << endl; // Check state of IOstream os.check diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index e15618b552..6b8403a454 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -1116,10 +1116,9 @@ bool Foam::polyBoundaryMesh::writeData(Ostream& os) const forAll(patches, patchI) { - os << indent << patches[patchI].name() << nl - << indent << token::BEGIN_BLOCK << nl - << incrIndent << patches[patchI] << decrIndent - << indent << token::END_BLOCK << endl; + os.beginBlock(patches[patchI].name()) << nl; + os << patches[patchI]; + os.endBlock() << endl; } os << decrIndent << token::END_LIST; diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index 482142bb2a..a6d05b7f73 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -437,12 +437,15 @@ void Foam::plane::writeDict(Ostream& os) const { os.writeKeyword("planeType") << "pointAndNormal" << token::END_STATEMENT << nl; - os << indent << "pointAndNormalDict" << nl - << indent << token::BEGIN_BLOCK << incrIndent << nl; - os.writeKeyword("basePoint") << basePoint_ << token::END_STATEMENT << nl; - os.writeKeyword("normalVector") << unitVector_ << token::END_STATEMENT - << nl; - os << decrIndent << indent << token::END_BLOCK << endl; + + os.beginBlock("pointAndNormalDict") << nl; + + os.writeKeyword("basePoint") << basePoint_ + << token::END_STATEMENT << nl; + os.writeKeyword("normalVector") << unitVector_ + << token::END_STATEMENT << nl; + + os.endBlock() << endl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C index 513298f8c7..a929f868ee 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -264,16 +264,17 @@ void Foam::Function1Types::CSV::writeData(Ostream& os) const { Function1::writeData(os); os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; + + os.beginBlock(word(this->name() + "Coeffs")) << nl; // Note: for TableBase write the dictionary entries it needs but not // the values themselves TableBase::writeEntries(os); - os.writeKeyword("nHeaderLine") << nHeaderLine_ << token::END_STATEMENT - << nl; - os.writeKeyword("refColumn") << refColumn_ << token::END_STATEMENT << nl; + os.writeKeyword("nHeaderLine") << nHeaderLine_ + << token::END_STATEMENT << nl; + os.writeKeyword("refColumn") << refColumn_ + << token::END_STATEMENT << nl; // Force writing labelList in ascii os.writeKeyword("componentColumns"); @@ -293,8 +294,10 @@ void Foam::Function1Types::CSV::writeData(Ostream& os) const << token::END_STATEMENT << nl; os.writeKeyword("mergeSeparators") << mergeSeparators_ << token::END_STATEMENT << nl; - os.writeKeyword("fileName") << fName_ << token::END_STATEMENT << nl; - os << decrIndent << indent << token::END_BLOCK << endl; + os.writeKeyword("fileName") << fName_ + << token::END_STATEMENT << nl; + + os.endBlock() << endl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C index 6031096643..85a7aefe04 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,14 +90,16 @@ void Foam::Function1Types::Sine::writeData(Ostream& os) const { Function1::writeData(os); os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; + + os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl; amplitude_->writeData(os); frequency_->writeData(os); scale_->writeData(os); level_->writeData(os); - os << decrIndent << indent << token::END_BLOCK << endl; + + os.endBlock() << endl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C index 213e768321..9c55e8800e 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C +++ b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -103,15 +103,17 @@ void Foam::Function1Types::Square::writeData(Ostream& os) const { Function1::writeData(os); os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; + + os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl; os.writeKeyword("markSpace") << markSpace_ << token::END_STATEMENT << nl; amplitude_->writeData(os); frequency_->writeData(os); scale_->writeData(os); level_->writeData(os); - os << decrIndent << indent << token::END_BLOCK << endl; + + os.endBlock() << endl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C index 8551d1a84a..414e616077 100644 --- a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C +++ b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,17 +78,16 @@ template void Foam::Function1Types::TableFile::writeData(Ostream& os) const { Function1::writeData(os); + os << token::END_STATEMENT << nl; - os << token::END_STATEMENT << nl - << indent << word(this->name() + "Coeffs") << nl - << indent << token::BEGIN_BLOCK << nl << incrIndent; + os.beginBlock(word(this->name() + "Coeffs")) << nl; // Note: for TableBase write the dictionary entries it needs but not // the values themselves TableBase::writeEntries(os); - os.writeKeyword("fileName")<< fName_ << token::END_STATEMENT << nl; - os << decrIndent << indent << token::END_BLOCK << endl; + + os.endBlock() << endl; }