mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: minor simplification of check for uniform contents
This commit is contained in:
@ -42,13 +42,13 @@ Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T, Container>& lst)
|
||||
{
|
||||
is >> lst.offsets_ >> lst.m_;
|
||||
// Note: empty list gets output as two empty lists
|
||||
if (lst.offsets_.size() == 0)
|
||||
if (lst.offsets_.size())
|
||||
{
|
||||
lst.size_ = 0;
|
||||
lst.size_ = lst.offsets_.size()-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lst.size_ = lst.offsets_.size()-1;
|
||||
lst.size_ = 0;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
@ -118,6 +118,8 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// contents are binary and contiguous
|
||||
|
||||
is.read(reinterpret_cast<char*>(L.data()), Size*sizeof(T));
|
||||
|
||||
is.fatalCheck
|
||||
@ -167,12 +169,10 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII || !contiguous<T>())
|
||||
{
|
||||
bool uniform = false;
|
||||
|
||||
if (Size > 1 && contiguous<T>())
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (Size > 1 && contiguous<T>());
|
||||
if (uniform)
|
||||
{
|
||||
uniform = true;
|
||||
|
||||
forAll(L, i)
|
||||
{
|
||||
if (L[i] != L[0])
|
||||
@ -194,7 +194,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
|
||||
// Write end delimiter
|
||||
os << token::END_BLOCK;
|
||||
}
|
||||
else if (Size <= 1 ||(Size < 11 && contiguous<T>()))
|
||||
else if (Size <= 1 || (Size < 11 && contiguous<T>()))
|
||||
{
|
||||
// Write start delimiter
|
||||
os << token::BEGIN_LIST;
|
||||
@ -202,7 +202,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
|
||||
// Write contents
|
||||
forAll(L, i)
|
||||
{
|
||||
if (i > 0) os << token::SPACE;
|
||||
if (i) os << token::SPACE;
|
||||
os << L[i];
|
||||
}
|
||||
|
||||
@ -226,6 +226,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
|
||||
// write(...) includes surrounding start/end delimiters
|
||||
os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
|
||||
}
|
||||
|
||||
|
||||
@ -92,6 +92,8 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// uniform content (delimiter == token::BEGIN_BLOCK)
|
||||
|
||||
T element;
|
||||
is >> element;
|
||||
|
||||
@ -113,6 +115,8 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// contents are binary and contiguous
|
||||
|
||||
if (s)
|
||||
{
|
||||
is.read(reinterpret_cast<char*>(L.data()), s*sizeof(T));
|
||||
|
||||
@ -407,12 +407,10 @@ Foam::Ostream& Foam::PackedList<nBits>::write
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII)
|
||||
{
|
||||
bool uniform = false;
|
||||
|
||||
if (sz > 1 && !indexedOutput)
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (sz > 1 && !indexedOutput);
|
||||
if (uniform)
|
||||
{
|
||||
uniform = true;
|
||||
|
||||
forAll(lst, i)
|
||||
{
|
||||
if (lst[i] != lst[0])
|
||||
@ -475,9 +473,12 @@ Foam::Ostream& Foam::PackedList<nBits>::write
|
||||
}
|
||||
else
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
|
||||
os << nl << sz << nl;
|
||||
if (sz)
|
||||
{
|
||||
// write(...) includes surrounding start/end delimiters
|
||||
os.write
|
||||
(
|
||||
reinterpret_cast<const char*>(lst.storage().cdata()),
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -40,12 +40,10 @@ Foam::Ostream& Foam::operator<<
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII || !contiguous<T>())
|
||||
{
|
||||
bool uniform = false;
|
||||
|
||||
if (L.size() > 1 && contiguous<T>())
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (L.size() > 1 && contiguous<T>());
|
||||
if (uniform)
|
||||
{
|
||||
uniform = true;
|
||||
|
||||
forAll(L, i)
|
||||
{
|
||||
if (L[i] != L[0])
|
||||
@ -99,14 +97,15 @@ Foam::Ostream& Foam::operator<<
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is annoying, and wasteful, but there's currently no alternative
|
||||
|
||||
// Contents are binary and contiguous
|
||||
os << nl << L.size() << nl;
|
||||
|
||||
if (L.size())
|
||||
{
|
||||
// This is annoying, and wasteful, but currently no alternative
|
||||
List<T> lst = L();
|
||||
|
||||
// write(...) includes surrounding start/end delimiters
|
||||
os.write
|
||||
(
|
||||
reinterpret_cast<const char*>(lst.cdata()),
|
||||
|
||||
@ -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.
|
||||
@ -65,12 +65,10 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII || !contiguous<T>())
|
||||
{
|
||||
bool uniform = false;
|
||||
|
||||
if (L.size() > 1 && contiguous<T>())
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (L.size() > 1 && contiguous<T>());
|
||||
if (uniform)
|
||||
{
|
||||
uniform = true;
|
||||
|
||||
forAll(L, i)
|
||||
{
|
||||
if (L[i] != L[0])
|
||||
@ -100,7 +98,7 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
|
||||
// Write contents
|
||||
forAll(L, i)
|
||||
{
|
||||
if (i > 0) os << token::SPACE;
|
||||
if (i) os << token::SPACE;
|
||||
os << L[i];
|
||||
}
|
||||
|
||||
@ -124,10 +122,13 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
os << nl << L.size() << nl;
|
||||
|
||||
if (L.size())
|
||||
{
|
||||
os.write(reinterpret_cast<const char*>(L.v_), L.byteSize());
|
||||
// write(...) includes surrounding start/end delimiters
|
||||
os.write(reinterpret_cast<const char*>(L.cdata()), L.byteSize());
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,6 +209,8 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// uniform content (delimiter == token::BEGIN_BLOCK)
|
||||
|
||||
T element;
|
||||
is >> element;
|
||||
|
||||
@ -229,6 +232,8 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// contents are binary and contiguous
|
||||
|
||||
if (s)
|
||||
{
|
||||
is.read(reinterpret_cast<char*>(L.data()), s*sizeof(T));
|
||||
|
||||
@ -727,12 +727,10 @@ void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const
|
||||
{
|
||||
os.writeKeyword(keyword);
|
||||
|
||||
bool uniform = false;
|
||||
|
||||
if (this->size() && contiguous<Type>())
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (this->size() && contiguous<Type>());
|
||||
if (uniform)
|
||||
{
|
||||
uniform = true;
|
||||
|
||||
forAll(*this, i)
|
||||
{
|
||||
if (this->operator[](i) != this->operator[](0))
|
||||
|
||||
@ -160,15 +160,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& M)
|
||||
{
|
||||
if (mn)
|
||||
{
|
||||
bool uniform = false;
|
||||
|
||||
const Type* v = M.v_;
|
||||
|
||||
if (mn > 1 && contiguous<Type>())
|
||||
// can the contents be considered 'uniform' (ie, identical)
|
||||
bool uniform = (mn > 1 && contiguous<Type>());
|
||||
if (uniform)
|
||||
{
|
||||
uniform = true;
|
||||
|
||||
for (label i=0; i<mn; i++)
|
||||
for (label i=0; i<mn; ++i)
|
||||
{
|
||||
if (v[i] != v[0])
|
||||
{
|
||||
@ -180,18 +178,18 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& M)
|
||||
|
||||
if (uniform)
|
||||
{
|
||||
// Write size of list and start contents delimiter
|
||||
// Write start delimiter
|
||||
os << token::BEGIN_BLOCK;
|
||||
|
||||
// Write list contents
|
||||
// Write contents
|
||||
os << v[0];
|
||||
|
||||
// Write end of contents delimiter
|
||||
// Write end delimiter
|
||||
os << token::END_BLOCK;
|
||||
}
|
||||
else if (mn < 10 && contiguous<Type>())
|
||||
{
|
||||
// Write size of list and start contents delimiter
|
||||
// Write start contents delimiter
|
||||
os << token::BEGIN_LIST;
|
||||
|
||||
label k = 0;
|
||||
@ -204,7 +202,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& M)
|
||||
// Write row
|
||||
for (label j=0; j< M.n(); j++)
|
||||
{
|
||||
if (j > 0) os << token::SPACE;
|
||||
if (j) os << token::SPACE;
|
||||
os << v[k++];
|
||||
}
|
||||
|
||||
@ -216,7 +214,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& M)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write size of list and start contents delimiter
|
||||
// Write start contents delimiter
|
||||
os << nl << token::BEGIN_LIST;
|
||||
|
||||
label k = 0;
|
||||
|
||||
Reference in New Issue
Block a user