ENH: suppress keyword indentation when keyword is empty (List, Field)

- output the "uniform", "nonuniform" Field entry tags as words instead
  of raw character strings, which can help for direct tokenization or
  when sending/receiving via Pstreams.
This commit is contained in:
Mark Olesen
2019-12-03 07:50:19 +01:00
parent dac0dd137e
commit 68de05285a
5 changed files with 24 additions and 9 deletions

View File

@ -266,7 +266,10 @@ void Foam::PackedList<Width>::writeEntry
Ostream& os Ostream& os
) const ) const
{ {
os.writeKeyword(keyword); if (keyword.size())
{
os.writeKeyword(keyword);
}
writeEntry(os); writeEntry(os);
os << token::END_STATEMENT << endl; os << token::END_STATEMENT << endl;
} }

View File

@ -103,7 +103,10 @@ void Foam::bitSet::writeEntry
Ostream& os Ostream& os
) const ) const
{ {
os.writeKeyword(keyword); if (keyword.size())
{
os.writeKeyword(keyword);
}
writeEntry(os); writeEntry(os);
os << token::END_STATEMENT << endl; os << token::END_STATEMENT << endl;
} }

View File

@ -39,7 +39,7 @@ void Foam::FixedList<T, N>::writeEntry(Ostream& os) const
const word tag = "List<" + word(pTraits<T>::typeName) + '>'; const word tag = "List<" + word(pTraits<T>::typeName) + '>';
if (token::compound::isCompound(tag)) if (token::compound::isCompound(tag))
{ {
os << tag << ' '; os << tag << token::SPACE;
} }
os << *this; os << *this;
} }
@ -54,7 +54,10 @@ void Foam::FixedList<T, N>::writeEntry
Ostream& os Ostream& os
) const ) const
{ {
os.writeKeyword(keyword); if (keyword.size())
{
os.writeKeyword(keyword);
}
writeEntry(os); writeEntry(os);
os << token::END_STATEMENT << endl; os << token::END_STATEMENT << endl;
} }

View File

@ -42,7 +42,7 @@ void Foam::UList<T>::writeEntry(Ostream& os) const
const word tag = "List<" + word(pTraits<T>::typeName) + '>'; const word tag = "List<" + word(pTraits<T>::typeName) + '>';
if (token::compound::isCompound(tag)) if (token::compound::isCompound(tag))
{ {
os << tag << ' '; os << tag << token::SPACE;
} }
os << *this; os << *this;
} }
@ -64,7 +64,10 @@ void Foam::UList<T>::writeEntry(Ostream& os) const
template<class T> template<class T>
void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const
{ {
os.writeKeyword(keyword); if (keyword.size())
{
os.writeKeyword(keyword);
}
writeEntry(os); writeEntry(os);
os << token::END_STATEMENT << endl; os << token::END_STATEMENT << endl;
} }

View File

@ -630,18 +630,21 @@ Foam::tmp<Foam::Field<Type>> Foam::Field<Type>::T() const
template<class Type> template<class Type>
void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const
{ {
os.writeKeyword(keyword); if (keyword.size())
{
os.writeKeyword(keyword);
}
// The contents are 'uniform' if the list is non-empty // The contents are 'uniform' if the list is non-empty
// and all entries have identical values. // and all entries have identical values.
if (is_contiguous<Type>::value && List<Type>::uniform()) if (is_contiguous<Type>::value && List<Type>::uniform())
{ {
os << "uniform " << this->first(); os << word("uniform") << token::SPACE << this->first();
} }
else else
{ {
os << "nonuniform "; os << word("nonuniform") << token::SPACE;
List<Type>::writeEntry(os); List<Type>::writeEntry(os);
} }