UPtrList: Added writeEntry and writeEntryList

to write the list as a dictionary entry.  Consistent with the equivalent
functions in UList.
This commit is contained in:
Henry Weller
2019-03-12 17:23:19 +00:00
parent 59b533e961
commit 6b5f0928e5
2 changed files with 74 additions and 2 deletions

View File

@ -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

View File

@ -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<class T>
void Foam::UPtrList<T>::writeEntry(Ostream& os) const
{
if
(
size()
&& token::compound::isCompound
(
"List<" + word(pTraits<T>::typeName) + '>'
)
)
{
os << word("List<" + word(pTraits<T>::typeName) + '>') << " ";
}
os << *this;
}
template<class T>
void Foam::UPtrList<T>::writeEntry(const word& keyword, Ostream& os) const
{
os.writeKeyword(keyword);
writeEntry(os);
os << token::END_STATEMENT << endl;
}
template<class T>
void Foam::UPtrList<T>::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<class T>
void Foam::UPtrList<T>::writeEntryList(const word& keyword, Ostream& os) const
{
os.writeKeyword(keyword);
writeEntryList(os);
os << token::END_STATEMENT << endl;
}
// * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
template<class T>