From 6b5f0928e53a15bdb13aacd4ff4e25dc17f39bd2 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 12 Mar 2019 17:23:19 +0000 Subject: [PATCH] UPtrList: Added writeEntry and writeEntryList to write the list as a dictionary entry. Consistent with the equivalent functions in UList. --- .../containers/Lists/UPtrList/UPtrList.H | 17 +++++- .../containers/Lists/UPtrList/UPtrListIO.C | 59 ++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index 7b16344a84..4727b6ff53 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -154,6 +154,21 @@ public: void reorder(const labelUList&); + // Write + + //- Write the UPtrList as a dictionary entry + void writeEntry(Ostream&) const; + + //- Write the UPtrList as a dictionary entry with keyword + void writeEntry(const word& keyword, Ostream&) const; + + //- Write the UPtrList as a dictionary entry + void writeEntryList(Ostream&) const; + + //- Write the UPtrList as a dictionary entry with keyword + void writeEntryList(const word& keyword, Ostream&) const; + + // Member operators //- Return element const reference diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C index 804a1fcd95..05f9c17de2 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,6 +26,63 @@ License #include "UPtrList.H" #include "Ostream.H" +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::UPtrList::writeEntry(Ostream& os) const +{ + if + ( + size() + && token::compound::isCompound + ( + "List<" + word(pTraits::typeName) + '>' + ) + ) + { + os << word("List<" + word(pTraits::typeName) + '>') << " "; + } + + os << *this; +} + + +template +void Foam::UPtrList::writeEntry(const word& keyword, Ostream& os) const +{ + os.writeKeyword(keyword); + writeEntry(os); + os << token::END_STATEMENT << endl; +} + + +template +void Foam::UPtrList::writeEntryList(Ostream& os) const +{ + // Write size and start delimiter + os << nl << size() << nl << token::BEGIN_LIST; + + // Write contents + forAll(*this, i) + { + this->operator[](i).writeEntry(os); + os << nl; + } + + // Write end delimiter + os << nl << token::END_LIST << nl; +} + + +template +void Foam::UPtrList::writeEntryList(const word& keyword, Ostream& os) const +{ + os.writeKeyword(keyword); + writeEntryList(os); + os << token::END_STATEMENT << endl; +} + + // * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * // template