Merge branch 'listoutput' into 'develop'

Flat list output

See merge request !93
This commit is contained in:
Sergio Ferraris
2017-02-20 18:47:24 +00:00
30 changed files with 574 additions and 360 deletions

View File

@ -40,7 +40,6 @@ See also
#include "IStringStream.H"
#include "scalar.H"
#include "vector.H"
#include "ListOps.H"
#include "labelRange.H"
#include "ListOps.H"
@ -140,11 +139,36 @@ int main(int argc, char *argv[])
Info<< "Elements " << map << " out of " << list3
<< " => " << subList3 << endl;
// test flattened output
{
Info<< nl;
labelList longLabelList = identity(15);
Info<< "labels (contiguous=" << contiguous<label>() << ")" << nl;
Info<< "normal: " << longLabelList << nl;
Info<< "flatOutput: " << flatOutput(longLabelList) << nl;
// Info<< "flatOutput(14): " << flatOutput(longLabelList, 14) << nl;
// Info<< "flatOutput(15): " << flatOutput(longLabelList, 15) << nl;
stringList longStringList(12);
forAll(longStringList, i)
{
longStringList[i].resize(3, 'a' + i);
}
Info<< "string (contiguous=" << contiguous<string>() << ")" << nl;
Info<< "normal: " << longStringList << nl;
Info<< "flatOutput: " << flatOutput(longStringList) << nl;
// contiguous longStringList[i].resize(3, 'a' + i);
}
wordReList reLst;
wordList wLst;
stringList sLst;
scalar xxx(-1);
if (args.optionFound("flag"))
@ -173,9 +197,9 @@ int main(int argc, char *argv[])
}
Info<< nl
<< "-reList: " << reLst << nl
<< "-wordList: " << wLst << nl
<< "-stringList: " << sLst << endl;
<< "-reList: " << flatOutput(reLst) << nl
<< "-wordList: " << flatOutput(wLst) << nl
<< "-stringList: " << flatOutput(sLst) << endl;
return 0;
}

View File

@ -143,7 +143,7 @@ int main(int argc, char *argv[])
Info<< "\ntest Istream constructor\n";
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() <<endl;
Info<< list4 << " indices: " << list4.used()() << nl;
Info<< "\nassign from labelList\n";
list4 = labelList
@ -155,7 +155,7 @@ int main(int argc, char *argv[])
);
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() <<endl;
Info<< list4 << " indices: " << list4.used()() << nl;
Info<< "\nassign from indices\n";
list4.read
@ -168,7 +168,7 @@ int main(int argc, char *argv[])
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() <<endl;
Info<< list4 << " indices: " << list4.used()() << nl;
List<bool> boolLst(list4.size());
forAll(list4, i)
@ -176,8 +176,7 @@ int main(int argc, char *argv[])
boolLst[i] = list4[i];
}
Info<< "List<bool>: " << boolLst <<endl;
Info<< "List<bool>: " << boolLst << nl;
// check roundabout assignments
PackedList<2> pl2
@ -188,7 +187,7 @@ int main(int argc, char *argv[])
)()
);
Info<< "roundabout assignment: " << pl2 << endl;
Info<< "roundabout assignment: " << pl2 << nl;
list4.clear();
forAll(pl2, i)
@ -196,7 +195,7 @@ int main(int argc, char *argv[])
list4[i] = pl2[i];
}
list4.write(Info, true) << endl;
list4.writeList(Info, -1) << nl; // indexed output
list4.writeEntry("PackedBoolList", Info);

View File

@ -47,10 +47,10 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
if (firstToken.isLabel())
{
label s = firstToken.labelToken();
const label s = firstToken.labelToken();
// Read beginning of contents
char delimiter = is.readBeginList("HashPtrTable<T, Key, Hash>");
const char delimiter = is.readBeginList("HashPtrTable<T, Key, Hash>");
if (s)
{

View File

@ -41,7 +41,7 @@ Foam::HashTable<T, Key, Hash>::HashTable(Istream& is, const label size)
{
table_ = new hashedEntry*[tableSize_];
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
for (label hashIdx = 0; hashIdx < tableSize_; ++hashIdx)
{
table_[hashIdx] = 0;
}
@ -116,10 +116,10 @@ Foam::Istream& Foam::operator>>
if (firstToken.isLabel())
{
label s = firstToken.labelToken();
const label s = firstToken.labelToken();
// Read beginning of contents
char delimiter = is.readBeginList("HashTable<T, Key, Hash>");
const char delimiter = is.readBeginList("HashTable<T, Key, Hash>");
if (s)
{
@ -130,7 +130,7 @@ Foam::Istream& Foam::operator>>
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
Key key;
is >> key;

View File

@ -44,10 +44,10 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
if (firstToken.isLabel())
{
label s = firstToken.labelToken();
const label s = firstToken.labelToken();
// Read beginning of contents
char delimiter = is.readBeginList("ILList<LListBase, T>");
const char delimiter = is.readBeginList("ILList<LListBase, T>");
if (s)
{

View File

@ -55,10 +55,10 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
if (firstToken.isLabel())
{
label s = firstToken.labelToken();
const label s = firstToken.labelToken();
// Read beginning of contents
char delimiter = is.readBeginList("LList<LListBase, T>");
const char delimiter = is.readBeginList("LList<LListBase, T>");
if (s)
{

View File

@ -49,10 +49,10 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
if (firstToken.isLabel())
{
label s = firstToken.labelToken();
const label s = firstToken.labelToken();
// Read beginning of contents
char delimiter = is.readBeginList("LPtrList<LListBase, T>");
const char delimiter = is.readBeginList("LPtrList<LListBase, T>");
if (s)
{

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -86,6 +86,14 @@ class FixedList
T v_[Size];
protected:
// Protected Member Functions
//- Write the FixedList with its compound type
void writeEntry(Ostream& os) const;
public:
//- Hashing function class.
@ -117,7 +125,7 @@ public:
inline FixedList();
//- Construct from value
explicit inline FixedList(const T&);
explicit inline FixedList(const T& t);
//- Construct from C-array
explicit inline FixedList(const T v[Size]);
@ -127,19 +135,19 @@ public:
inline FixedList(InputIterator first, InputIterator last);
//- Construct from an initializer list
inline FixedList(std::initializer_list<T>);
inline FixedList(std::initializer_list<T> lst);
//- Construct from UList
explicit inline FixedList(const UList<T>&);
explicit inline FixedList(const UList<T>& lst);
//- Construct from SLList
explicit inline FixedList(const SLList<T>&);
explicit inline FixedList(const SLList<T>& lst);
//- Copy constructor
inline FixedList(const FixedList<T, Size>&);
inline FixedList(const FixedList<T, Size>& lst);
//- Construct from Istream
FixedList(Istream&);
FixedList(Istream& is);
//- Clone
inline autoPtr<FixedList<T, Size>> clone() const;
@ -197,45 +205,39 @@ public:
//- Dummy resize function
// needed to make FixedList consistent with List
inline void resize(const label);
inline void resize(const label s);
//- Dummy setSize function
// needed to make FixedList consistent with List
inline void setSize(const label);
inline void setSize(const label s);
//- Copy (not transfer) the argument contents
// needed to make FixedList consistent with List
void transfer(const FixedList<T, Size>&);
//- Write the FixedList as a dictionary entry
void writeEntry(Ostream&) const;
//- Write the FixedList as a dictionary entry with keyword
void writeEntry(const word& keyword, Ostream&) const;
void transfer(const FixedList<T, Size>& lst);
// Member operators
//- Return element of FixedList
inline T& operator[](const label);
inline T& operator[](const label i);
//- Return element of constant FixedList
inline const T& operator[](const label) const;
inline const T& operator[](const label i) const;
//- Assignment to array operator. Takes linear time
inline void operator=(const T v[Size]);
inline void operator=(const T lst[Size]);
//- Assignment to UList operator. Takes linear time
inline void operator=(const UList<T>&);
inline void operator=(const UList<T>& lst);
//- Assignment to SLList operator. Takes linear time
inline void operator=(const SLList<T>&);
inline void operator=(const SLList<T>& lst);
//- Assignment to an initializer list. Takes linear time
inline void operator=(std::initializer_list<T>);
inline void operator=(std::initializer_list<T> lst);
//- Assignment of all entries to the given value
inline void operator=(const T&);
inline void operator=(const T& t);
// STL type definitions
@ -331,7 +333,7 @@ public:
inline bool empty() const;
//- Swap two FixedLists of the same type in constant time
void swap(FixedList<T, Size>&);
void swap(FixedList<T, Size>& a);
// STL member operators
@ -339,35 +341,48 @@ public:
//- Equality operation on FixedLists of the same type.
// Returns true when the FixedLists are elementwise equal
// (using FixedList::value_type::operator==). Takes linear time
bool operator==(const FixedList<T, Size>&) const;
bool operator==(const FixedList<T, Size>& a) const;
//- The opposite of the equality operation. Takes linear time
bool operator!=(const FixedList<T, Size>&) const;
bool operator!=(const FixedList<T, Size>& a) const;
//- Compare two FixedLists lexicographically. Takes linear time
bool operator<(const FixedList<T, Size>&) const;
bool operator<(const FixedList<T, Size>& a) const;
//- Compare two FixedLists lexicographically. Takes linear time
bool operator>(const FixedList<T, Size>&) const;
bool operator>(const FixedList<T, Size>& a) const;
//- Return true if !(a > b). Takes linear time
bool operator<=(const FixedList<T, Size>&) const;
bool operator<=(const FixedList<T, Size>& a) const;
//- Return true if !(a < b). Takes linear time
bool operator>=(const FixedList<T, Size>&) const;
bool operator>=(const FixedList<T, Size>& a) const;
// Writing
//- Write the List as a dictionary entry with keyword
void writeEntry(const word& keyword, Ostream& os) const;
//- Write the List, with line-breaks in ASCII if the list length
// exceeds shortListLen. Using '0' suppresses line-breaks entirely.
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
// IOstream operators
//- Read List from Istream, discarding contents of existing List
friend Istream& operator>> <T, Size>
(Istream&, FixedList<T, Size>&);
(
Istream& is,
FixedList<T, Size>& L
);
//- Write FixedList to Ostream
//- Write List to Ostream, as per writeList() with shortListLen=10
friend Ostream& operator<< <T, Size>
(
Ostream&,
const FixedList<T, Size>&
Ostream& os,
const FixedList<T, Size>& L
);
};

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,6 +29,123 @@ License
#include "token.H"
#include "contiguous.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class T, unsigned Size>
void Foam::FixedList<T, Size>::writeEntry(Ostream& os) const
{
const word tag = "List<" + word(pTraits<T>::typeName) + '>';
if (token::compound::isCompound(tag))
{
os << tag << ' ';
}
os << *this;
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class T, unsigned Size>
void Foam::FixedList<T, Size>::writeEntry
(
const word& keyword,
Ostream& os
) const
{
os.writeKeyword(keyword);
writeEntry(os);
os << token::END_STATEMENT << endl;
}
template<class T, unsigned Size>
Foam::Ostream& Foam::FixedList<T, Size>::writeList
(
Ostream& os,
const label shortListLen
) const
{
const FixedList<T, Size>& L = *this;
// Write list contents depending on data format
if (os.format() == IOstream::ASCII || !contiguous<T>())
{
// Can the contents be considered 'uniform' (ie, identical)?
bool uniform = (Size > 1 && contiguous<T>());
if (uniform)
{
forAll(L, i)
{
if (L[i] != L[0])
{
uniform = false;
break;
}
}
}
if (uniform)
{
// Write size (so it is valid dictionary entry) and start delimiter
os << Size << token::BEGIN_BLOCK;
// Write contents
os << L[0];
// Write end delimiter
os << token::END_BLOCK;
}
else if
(
Size <= 1 || !shortListLen
|| (Size <= shortListLen && contiguous<T>())
)
{
// Write start delimiter
os << token::BEGIN_LIST;
// Write contents
forAll(L, i)
{
if (i) os << token::SPACE;
os << L[i];
}
// Write end delimiter
os << token::END_LIST;
}
else
{
// Write start delimiter
os << nl << token::BEGIN_LIST << nl;
// Write contents
forAll(L, i)
{
os << L[i] << nl;
}
// Write end delimiter
os << token::END_LIST << nl;
}
}
else
{
// Contents are binary and contiguous
// write(...) includes surrounding start/end delimiters
os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
}
// Check state of IOstream
os.check("const FixedList::writeList(Ostream&)");
return os;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, unsigned Size>
@ -81,11 +198,11 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
}
// Read beginning of contents
char delimiter = is.readBeginList("FixedList");
const char delimiter = is.readBeginList("FixedList");
if (delimiter == token::BEGIN_LIST)
{
for (unsigned i=0; i<Size; i++)
for (unsigned i=0; i<Size; ++i)
{
is >> L[i];
@ -107,7 +224,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
"reading the single entry"
);
for (unsigned i=0; i<Size; i++)
for (unsigned i=0; i<Size; ++i)
{
L[i] = element;
}
@ -133,107 +250,10 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class T, unsigned Size>
void Foam::FixedList<T, Size>::writeEntry(Ostream& os) const
{
const word tag = "List<" + word(pTraits<T>::typeName) + '>';
if (token::compound::isCompound(tag))
{
os << tag << " ";
}
os << *this;
}
template<class T, unsigned Size>
void Foam::FixedList<T, Size>::writeEntry
(
const word& keyword,
Ostream& os
) const
{
os.writeKeyword(keyword);
writeEntry(os);
os << token::END_STATEMENT << endl;
}
template<class T, unsigned Size>
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>())
{
// Can the contents be considered 'uniform' (ie, identical)?
bool uniform = (Size > 1 && contiguous<T>());
if (uniform)
{
forAll(L, i)
{
if (L[i] != L[0])
{
uniform = false;
break;
}
}
}
if (uniform)
{
// Write size (so it is valid dictionary entry) and start delimiter
os << L.size() << token::BEGIN_BLOCK;
// Write contents
os << L[0];
// Write end delimiter
os << token::END_BLOCK;
}
else if (Size <= 1 || (Size < 11 && contiguous<T>()))
{
// Write start delimiter
os << token::BEGIN_LIST;
// Write contents
forAll(L, i)
{
if (i) os << token::SPACE;
os << L[i];
}
// Write end delimiter
os << token::END_LIST;
}
else
{
// Write start delimiter
os << nl << token::BEGIN_LIST;
// Write contents
forAll(L, i)
{
os << nl << L[i];
}
// Write end delimiter
os << nl << token::END_LIST << nl;
}
}
else
{
// Contents are binary and contiguous
// write(...) includes surrounding start/end delimiters
os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
}
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const FixedList&)");
return os;
return L.writeList(os, 10);
}

View File

@ -74,13 +74,13 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
if (is.format() == IOstream::ASCII || !contiguous<T>())
{
// Read beginning of contents
char delimiter = is.readBeginList("List");
const char delimiter = is.readBeginList("List");
if (s)
{
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
is >> L[i];
@ -103,7 +103,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
"reading the single entry"
);
for (label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
L[i] = element;
}

View File

@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::FlatOutput
Description
Simple output adapter for list output on a single line.
The backend type must support a two-argument \c writeList() method.
\*---------------------------------------------------------------------------*/
#ifndef FlatOutput_H
#define FlatOutput_H
#include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template<class Container> class FlatOutput;
template<class Container>
Ostream& operator<<(Ostream& os, const FlatOutput<Container>& obj);
/*---------------------------------------------------------------------------*\
Class FlatOutput Declaration
\*---------------------------------------------------------------------------*/
template<class Container>
class FlatOutput
{
const Container& ref_;
const label len_;
public:
//- Construct from components
inline FlatOutput(const Container& obj, label len)
:
ref_(obj),
len_(len)
{}
//- Ostream operator
inline friend Ostream& operator<<
(
Ostream& os,
const FlatOutput<Container>& wrapped
)
{
return wrapped.ref_.writeList(os, wrapped.len_);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Global flatOutput function
template<class Container>
FlatOutput<Container> flatOutput(const Container& obj, label len=0)
{
return FlatOutput<Container>(obj, len);
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,6 +36,7 @@ SourceFiles
#ifndef ListOps_H
#define ListOps_H
#include "FlatOutput.H"
#include "labelList.H"
#include "ops.H"
@ -51,7 +52,7 @@ extern const labelList emptyLabelList;
template<class Type>
static const List<Type>& emptyList()
{
return *reinterpret_cast<const List<Type>* >(&emptyLabelList);
return *reinterpret_cast<const List<Type>*>(&emptyLabelList);
}
//- Renumber the values (not the indices) of a list.
@ -263,7 +264,7 @@ public:
};
//- Helper class for list to append unique elelements of y onto the end of x
//- Helper class for list to append unique elements of y onto the end of x
template<class T>
class ListUniqueEqOp
{

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,27 +26,35 @@ License
#include "PackedList.H"
#include "IOstreams.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<unsigned nBits>
void Foam::PackedList<nBits>::writeEntry(Ostream& os) const
{
os << *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#if (UINT_MAX == 0xFFFFFFFF)
// 32-bit counting, Hamming weight method
#define COUNT_PACKEDBITS(sum, x) \
// 32-bit counting, Hamming weight method
#define COUNT_PACKEDBITS(sum, x) \
{ \
x -= (x >> 1) & 0x55555555; \
x = (x & 0x33333333) + ((x >> 2) & 0x33333333); \
sum += (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; \
}
#elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF)
// 64-bit counting, Hamming weight method
#define COUNT_PACKEDBITS(sum, x) \
// 64-bit counting, Hamming weight method
#define COUNT_PACKEDBITS(sum, x) \
{ \
x -= (x >> 1) & 0x5555555555555555; \
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); \
sum += (((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56;\
sum += (((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56; \
}
#else
// Arbitrary number of bits, Brian Kernighan's method
// Arbitrary number of bits, Brian Kernighan's method
#define COUNT_PACKEDBITS(sum, x) for (; x; ++sum) { x &= x - 1; }
#endif
@ -69,6 +77,8 @@ unsigned int Foam::PackedList<nBits>::count() const
return c;
}
#undef COUNT_PACKEDBITS
template<unsigned nBits>
bool Foam::PackedList<nBits>::trim()
@ -395,12 +405,13 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
template<unsigned nBits>
Foam::Ostream& Foam::PackedList<nBits>::write
Foam::Ostream& Foam::PackedList<nBits>::writeList
(
Ostream& os,
const bool indexedOutput
const label shortListLen
) const
{
const bool indexedOutput = (shortListLen < 0);
const PackedList<nBits>& lst = *this;
const label sz = lst.size();
@ -446,36 +457,33 @@ Foam::Ostream& Foam::PackedList<nBits>::write
os << token::END_BLOCK << nl;
}
else if (sz < 11)
else if (!shortListLen || sz <= shortListLen)
{
// short list:
// Shorter list, or line-breaks suppressed
os << sz << token::BEGIN_LIST;
forAll(lst, i)
{
if (i)
{
os << token::SPACE;
}
if (i) os << token::SPACE;
os << lst[i];
}
os << token::END_LIST;
}
else
{
// longer list:
os << nl << sz << nl << token::BEGIN_LIST;
// Longer list
os << nl << sz << nl << token::BEGIN_LIST << nl;
forAll(lst, i)
{
os << nl << lst[i];
os << lst[i] << nl;
}
os << nl << token::END_LIST << nl;
os << token::END_LIST << nl;
}
}
else
{
// Contents are binary and contiguous
os << nl << sz << nl;
if (sz)
{
// write(...) includes surrounding start/end delimiters
@ -491,13 +499,6 @@ Foam::Ostream& Foam::PackedList<nBits>::write
}
template<unsigned nBits>
void Foam::PackedList<nBits>::writeEntry(Ostream& os) const
{
os << *this;
}
template<unsigned nBits>
void Foam::PackedList<nBits>::writeEntry
(
@ -559,7 +560,7 @@ Foam::Istream& Foam::operator>>(Istream& is, PackedList<nBits>& lst)
template<unsigned nBits>
Foam::Ostream& Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
{
return lst.write(os, false);
return lst.writeList(os, 10);
}

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -186,6 +186,14 @@ private:
label size_;
protected:
// Protected Member Functions
//- Write as a dictionary entry
void writeEntry(Ostream& os) const;
public:
// Public data
@ -224,19 +232,19 @@ public:
inline PackedList(const label size, const unsigned val);
//- Construct from Istream
inline PackedList(Istream&);
inline PackedList(Istream& is);
//- Copy constructor
inline PackedList(const PackedList<nBits>&);
inline PackedList(const PackedList<nBits>& lst);
//- Construct by transferring the parameter contents
inline PackedList(const Xfer<PackedList<nBits>>&);
inline PackedList(const Xfer<PackedList<nBits>>& lst);
//- Construct from a list of labels
explicit inline PackedList(const labelUList&);
explicit inline PackedList(const labelUList& lst);
//- Construct from an indirect list of labels
explicit inline PackedList(const UIndirectList<label>&);
explicit inline PackedList(const UIndirectList<label>& lst);
//- Clone
inline autoPtr<PackedList<nBits>> clone() const;
@ -257,16 +265,16 @@ public:
//- Get value at index I.
// Never auto-vivify entries.
inline unsigned int get(const label) const;
inline unsigned int get(const label i) const;
//- Set value at index I. Return true if value changed.
// Does auto-vivify for non-existent entries.
// Default value set is the max_value.
inline bool set(const label, const unsigned int val = ~0u);
inline bool set(const label i, const unsigned int val = ~0u);
//- Unset the entry at index I. Return true if value changed.
// Never auto-vivify entries.
inline bool unset(const label);
inline bool unset(const label i);
//- Return the underlying packed storage
// Manipulate with utmost caution
@ -322,10 +330,10 @@ public:
//- Reset addressable list size, does not shrink the allocated size.
// Optionally specify a value for new elements.
inline void resize(const label, const unsigned int& val = 0u);
inline void resize(const label, const unsigned int val = 0u);
//- Alias for resize()
inline void setSize(const label, const unsigned int& val = 0u);
inline void setSize(const label, const unsigned int val = 0u);
//- Reserve allocation space for at least this size.
// Never shrinks the allocated size.
@ -354,9 +362,12 @@ public:
// IO
//- Clear list and read from stream
Istream& read(Istream&);
Istream& read(Istream& is);
//- Write, optionally with indexedOutput
//- Write the List, with line-breaks in ASCII if the list length
// exceeds shortListLen. Using '0' suppresses line-breaks entirely.
// A special indexed output (ASCII only) is triggered by specifying
// a negative value for shortListLen.
//
// The indexed output may be convenient in some situations.
// The general format is a group of index/value pairs:
@ -368,20 +379,10 @@ public:
// \verbatim
// { index1 index2 index3 }
// \endverbatim
//
// Note the indexed output is only supported for ASCII streams.
Ostream& write
(
Ostream&,
const bool indexedOutput=false
) const;
//- Write as a dictionary entry
void writeEntry(Ostream&) const;
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
//- Write as a dictionary entry with keyword
void writeEntry(const word& keyword, Ostream&) const;
void writeEntry(const word& keyword, Ostream& os) const;
// Member operators
@ -394,24 +395,24 @@ public:
//- Get value at index I
// Never auto-vivify entries.
inline unsigned int operator[](const label) const;
inline unsigned int operator[](const label i) const;
//- Set value at index I.
// Returns iterator to perform the actual operation.
// Does not auto-vivify entries, but will when assigned to.
inline iteratorBase operator[](const label);
inline iteratorBase operator[](const label i);
//- Assignment of all entries to the given value. Takes linear time.
inline void operator=(const unsigned int val);
//- Assignment operator.
void operator=(const PackedList<nBits>&);
void operator=(const PackedList<nBits>& lst);
//- Assignment operator.
void operator=(const labelUList&);
void operator=(const labelUList& lst);
//- Assignment operator.
void operator=(const UIndirectList<label>&);
void operator=(const UIndirectList<label>& lst);
// Iterators and helpers

View File

@ -727,7 +727,7 @@ template<unsigned nBits>
inline void Foam::PackedList<nBits>::resize
(
const label newSize,
const unsigned int& val
const unsigned int val
)
{
reserve(newSize);
@ -821,7 +821,7 @@ template<unsigned nBits>
inline void Foam::PackedList<nBits>::setSize
(
const label newSize,
const unsigned int& val
const unsigned int val
)
{
resize(newSize, val);

View File

@ -48,12 +48,13 @@ void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
if (firstToken.isLabel())
{
// Read size of list
label s = firstToken.labelToken();
const label s = firstToken.labelToken();
// Set list length to that read
setSize(s);
// Read beginning of contents
char delimiter = is.readBeginList("PtrList");
const char delimiter = is.readBeginList("PtrList");
if (s)
{
@ -81,7 +82,7 @@ void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
"reading the single entry"
);
for (label i=1; i<s; i++)
for (label i=1; i<s; ++i)
{
set(i, tPtr->clone());
}

View File

@ -83,7 +83,7 @@ inline const Foam::SubList<T>& Foam::SubList<T>::null()
template<class T>
inline Foam::SubList<T>::operator const Foam::List<T>&() const
{
return *reinterpret_cast<const List<T>* >(this);
return *reinterpret_cast<const List<T>*>(this);
}

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,7 +70,11 @@ public:
// Constructors
//- Construct given the complete list and the addressing array
inline UIndirectList(const UList<T>&, const labelUList&);
inline UIndirectList
(
const UList<T>& completeList,
const labelUList& addr
);
// Member Functions
@ -108,19 +112,19 @@ public:
inline List<T> operator()() const;
//- Return non-const access to an element
inline T& operator[](const label);
inline T& operator[](const label i);
//- Return const access to an element
inline const T& operator[](const label) const;
inline const T& operator[](const label i) const;
//- Assignment to UList of addressed elements
inline void operator=(const UList<T>&);
inline void operator=(const UList<T>& ae);
//- Assignment to UIndirectList of addressed elements
inline void operator=(const UIndirectList<T>&);
inline void operator=(const UIndirectList<T>& ae);
//- Assignment of all entries to the given value
inline void operator=(const T&);
inline void operator=(const T& t);
// STL type definitions
@ -144,14 +148,21 @@ public:
typedef label size_type;
// Writing
//- Write the List, with line-breaks in ASCII if the list length
// exceeds shortListLen. Using '0' suppresses line-breaks entirely.
// Binary output is currently still a bit of an annoyance.
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
// Ostream operator
//- Write UIndirectList to Ostream
// Binary output is currently still a bit of a problem
//- Write List to Ostream, as per writeList() with shortListLen=10
friend Ostream& operator<< <T>
(
Ostream&,
const UIndirectList<T>&
Ostream& os,
const UIndirectList<T>& L
);
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,15 +28,17 @@ License
#include "token.H"
#include "contiguous.H"
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class T>
Foam::Ostream& Foam::operator<<
Foam::Ostream& Foam::UIndirectList<T>::writeList
(
Foam::Ostream& os,
const Foam::UIndirectList<T>& L
)
Ostream& os,
const label shortListLen
) const
{
const UIndirectList<T>& L = *this;
// Write list contents depending on data format
if (os.format() == IOstream::ASCII || !contiguous<T>())
{
@ -65,7 +67,11 @@ Foam::Ostream& Foam::operator<<
// Write end delimiter
os << token::END_BLOCK;
}
else if (L.size() <= 1 || (L.size() < 11 && contiguous<T>()))
else if
(
L.size() <= 1 || !shortListLen
|| (L.size() <= shortListLen && contiguous<T>())
)
{
// Write size and start delimiter
os << L.size() << token::BEGIN_LIST;
@ -83,16 +89,16 @@ Foam::Ostream& Foam::operator<<
else
{
// Write size and start delimiter
os << nl << L.size() << nl << token::BEGIN_LIST;
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
// Write contents
forAll(L, i)
{
os << nl << L[i];
os << L[i] << nl;
}
// Write end delimiter
os << nl << token::END_LIST << nl;
os << token::END_LIST << nl;
}
}
else
@ -115,10 +121,23 @@ Foam::Ostream& Foam::operator<<
}
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const UIndirectList&)");
os.check("UIndirectList::writeList(Ostream&)");
return os;
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class T>
Foam::Ostream& Foam::operator<<
(
Foam::Ostream& os,
const Foam::UIndirectList<T>& L
)
{
return L.writeList(os, 10);
}
// ************************************************************************* //

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -93,6 +93,14 @@ class UList
void operator=(const UList<T>&) = delete;
protected:
// Protected Member Functions
//- Write the UList with its compound type
void writeEntry(Ostream& os) const;
public:
// Related types
@ -214,33 +222,27 @@ public:
//- Copy the pointer held by the given UList
inline void shallowCopy(const UList<T>&);
inline void shallowCopy(const UList<T>& a);
//- Copy elements of the given UList
void deepCopy(const UList<T>&);
//- Write the UList with its compound type
void writeEntry(Ostream&) const;
//- Write the UList as a dictionary entry with keyword
void writeEntry(const word& keyword, Ostream&) const;
void deepCopy(const UList<T>& a);
// Member operators
//- Return element of UList
inline T& operator[](const label);
inline T& operator[](const label i);
//- Return element of constant UList
// Note that the bool specialization adds lazy evaluation so reading
// an out-of-range element returns false without any ill-effects
inline const T& operator[](const label) const;
inline const T& operator[](const label i) const;
//- Allow cast to a const List<T>&
inline operator const Foam::List<T>&() const;
//- Assignment of all entries to the given value
void operator=(const T&);
void operator=(const T& t);
//- Assignment of all entries to zero
void operator=(const zero);
@ -339,7 +341,7 @@ public:
inline bool empty() const;
//- Swap two ULists of the same type in constant time
void swap(UList<T>&);
void swap(UList<T>& a);
// STL member operators
@ -347,64 +349,74 @@ public:
//- Equality operation on ULists of the same type.
// Returns true when the ULists are element-wise equal
// (using UList::value_type::operator==). Takes linear time
bool operator==(const UList<T>&) const;
bool operator==(const UList<T>& a) const;
//- The opposite of the equality operation. Takes linear time
bool operator!=(const UList<T>&) const;
bool operator!=(const UList<T>& a) const;
//- Compare two ULists lexicographically. Takes linear time
bool operator<(const UList<T>&) const;
bool operator<(const UList<T>& a) const;
//- Compare two ULists lexicographically. Takes linear time
bool operator>(const UList<T>&) const;
bool operator>(const UList<T>& a) const;
//- Return true if !(a > b). Takes linear time
bool operator<=(const UList<T>&) const;
bool operator<=(const UList<T>& a) const;
//- Return true if !(a < b). Takes linear time
bool operator>=(const UList<T>&) const;
bool operator>=(const UList<T>& a) const;
// Ostream operator
// Writing
// Write UList to Ostream
//- Write the List as a dictionary entry with keyword
void writeEntry(const word& keyword, Ostream& os) const;
//- Write the List, with line-breaks in ASCII if the list length
// exceeds shortListLen. Using '0' suppresses line-breaks entirely.
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
// IOstream operators
//- Write List to Ostream, as per writeList() with shortListLen=10
friend Ostream& operator<< <T>
(
Ostream&,
const UList<T>&
Ostream& os,
const UList<T>& L
);
//- Read UList contents from Istream. Requires size to have been set
// before
//- Read List contents from Istream.
// Requires size to have been set before
friend Istream& operator>> <T>
(
Istream&,
UList<T>&
Istream& os,
UList<T>& L
);
};
template<class T>
void sort(UList<T>&);
void sort(UList<T>& a);
template<class T, class Cmp>
void sort(UList<T>&, const Cmp&);
void sort(UList<T>& a, const Cmp& cmp);
template<class T>
void stableSort(UList<T>&);
void stableSort(UList<T>& a);
template<class T, class Cmp>
void stableSort(UList<T>&, const Cmp&);
void stableSort(UList<T>& a, const Cmp& cmp);
template<class T>
void shuffle(UList<T>&);
void shuffle(UList<T>& a);
// Reverse the first n elements of the list
template<class T>
inline void reverse(UList<T>&, const label n);
inline void reverse(UList<T>& ul, const label n);
// Reverse all the elements of the list
template<class T>
inline void reverse(UList<T>&);
inline void reverse(UList<T>& ul);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -29,7 +29,7 @@ License
#include "SLList.H"
#include "contiguous.H"
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class T>
void Foam::UList<T>::writeEntry(Ostream& os) const
@ -56,6 +56,8 @@ void Foam::UList<T>::writeEntry(Ostream& os) const
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class T>
void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const
{
@ -66,8 +68,14 @@ void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const
template<class T>
Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
Foam::Ostream& Foam::UList<T>::writeList
(
Ostream& os,
const label shortListLen
) const
{
const UList<T>& L = *this;
// Write list contents depending on data format
if (os.format() == IOstream::ASCII || !contiguous<T>())
{
@ -96,7 +104,11 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
// Write end delimiter
os << token::END_BLOCK;
}
else if (L.size() <= 1 || (L.size() < 11 && contiguous<T>()))
else if
(
L.size() <= 1 || !shortListLen
|| (L.size() <= shortListLen && contiguous<T>())
)
{
// Write size and start delimiter
os << L.size() << token::BEGIN_LIST;
@ -114,16 +126,16 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
else
{
// Write size and start delimiter
os << nl << L.size() << nl << token::BEGIN_LIST;
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
// Write contents
forAll(L, i)
{
os << nl << L[i];
os << L[i] << nl;
}
// Write end delimiter
os << nl << token::END_LIST << nl;
os << token::END_LIST << nl;
}
}
else
@ -139,12 +151,21 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
}
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const UList&)");
os.check("UList<T>::writeList(Ostream&)");
return os;
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class T>
Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
{
return L.writeList(os, 10);
}
template<class T>
Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
{
@ -197,7 +218,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
if (is.format() == IOstream::ASCII || !contiguous<T>())
{
// Read beginning of contents
char delimiter = is.readBeginList("List");
const char delimiter = is.readBeginList("List");
if (s)
{

View File

@ -139,7 +139,7 @@ inline void Foam::SubField<Type>::operator=
template<class Type>
inline Foam::SubField<Type>::operator const Foam::Field<Type>&() const
{
return *reinterpret_cast<const Field<Type>* >(this);
return *reinterpret_cast<const Field<Type>*>(this);
}

View File

@ -37,21 +37,19 @@ void Foam::blockMeshTools::read
if (firstToken.isLabel())
{
label s = firstToken.labelToken();
const label s = firstToken.labelToken();
// Set list length to that read
L.setSize(s);
// Read list contents depending on data format
// Read beginning of contents
char delimiter = is.readBeginList("List");
const char delimiter = is.readBeginList("List");
if (s)
{
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
read(is, L[i], dict);
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -129,10 +129,10 @@ void Foam::MeshedSurface<Face>::write
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
// no direct writer, delegate to proxy if possible
wordHashSet supported = ProxyType::writeTypes();
// No direct writer, delegate to proxy if possible
const wordHashSet& delegate = ProxyType::writeTypes();
if (supported.found(ext))
if (delegate.found(ext))
{
MeshedSurfaceProxy<Face>(surf).write(name);
}
@ -140,8 +140,8 @@ void Foam::MeshedSurface<Face>::write
{
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< (supported | writeTypes())
<< "Valid types:" << nl
<< flatOutput((delegate | writeTypes()).sortedToc()) << nl
<< exit(FatalError);
}
}

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,6 +25,7 @@ License
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -42,25 +43,25 @@ Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext)
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
// no direct reader, delegate if possible
wordHashSet supported = FriendType::readTypes();
if (supported.found(ext))
// No direct reader, delegate to friend if possible
const wordHashSet& delegate = FriendType::readTypes();
if (delegate.found(ext))
{
// create indirectly
// Create indirectly
autoPtr<MeshedSurface<Face>> surf(new MeshedSurface<Face>);
surf().transfer(FriendType::New(name, ext)());
return surf;
}
// nothing left to try, issue error
supported += readTypes();
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << nl
<< supported
<< exit(FatalError);
else
{
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types:" << nl
<< flatOutput((delegate | readTypes()).sortedToc()) << nl
<< exit(FatalError);
}
}
return autoPtr<MeshedSurface<Face>>(cstrIter()(name));

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,9 +26,9 @@ License
#include "MeshedSurfaceProxy.H"
#include "Time.H"
#include "ListOps.H"
#include "surfMesh.H"
#include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -65,7 +65,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
InfoInFunction << "Writing to " << name << endl;
}
word ext = name.ext();
const word ext = name.ext();
typename writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
@ -74,8 +74,8 @@ void Foam::MeshedSurfaceProxy<Face>::write
{
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writeTypes()
<< "Valid types:" << nl
<< flatOutput(writeTypes().sortedToc()) << nl
<< exit(FatalError);
}
@ -91,7 +91,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
) const
{
// the surface name to be used
word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
if (debug)
{

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,6 +29,7 @@ License
#include "IFstream.H"
#include "OFstream.H"
#include "Time.H"
#include "ListOps.H"
#include "polyBoundaryMesh.H"
#include "polyMesh.H"
@ -117,10 +118,10 @@ void Foam::UnsortedMeshedSurface<Face>::write
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
// no direct writer, delegate to proxy if possible
wordHashSet supported = ProxyType::writeTypes();
// No direct writer, delegate to proxy if possible
const wordHashSet& delegate = ProxyType::writeTypes();
if (supported.found(ext))
if (delegate.found(ext))
{
MeshedSurfaceProxy<Face>(surf).write(name);
}
@ -128,8 +129,8 @@ void Foam::UnsortedMeshedSurface<Face>::write
{
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< (supported | writeTypes())
<< "Valid types:" << nl
<< flatOutput((delegate | writeTypes()).sortedToc()) << nl
<< exit(FatalError);
}
}

View File

@ -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) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "UnsortedMeshedSurface.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -41,11 +42,12 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
// no direct reader, use the parent if possible
wordHashSet supported = ParentType::readTypes();
if (supported.found(ext))
// No direct reader, delegate to parent if possible
const wordHashSet& delegate = ParentType::readTypes();
if (delegate.found(ext))
{
// create indirectly
// Create indirectly
autoPtr<UnsortedMeshedSurface<Face>> surf
(
new UnsortedMeshedSurface<Face>
@ -54,15 +56,14 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
return surf;
}
// nothing left but to issue an error
supported += readTypes();
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types are:" << nl
<< supported
<< exit(FatalError);
else
{
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types:" << nl
<< flatOutput((delegate | readTypes()).sortedToc()) << nl
<< exit(FatalError);
}
}
return autoPtr<UnsortedMeshedSurface<Face>>(cstrIter()(name));

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,9 +26,9 @@ License
#include "surfaceFormatsCore.H"
#include "Time.H"
#include "ListOps.H"
#include "IFstream.H"
#include "OFstream.H"
#include "SortableList.H"
#include "surfMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -167,18 +167,9 @@ bool Foam::fileFormats::surfaceFormatsCore::checkSupport
}
else if (verbose)
{
wordList toc = available.toc();
SortableList<word> known(toc.xfer());
Info<<"Unknown file extension for " << functionName
<< " : " << ext << nl
<<"Valid types: (";
// compact output:
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
<< "Valid types: " << flatOutput(available.sortedToc()) << endl;
}
return false;

View File

@ -62,8 +62,8 @@ class surfaceFormatsCore
{
protected:
//- Return a list with a single entry,
// the size corresponds to that of the container
//- Return a surfZone list with a single entry, the size of which
// corresponds to that of the container
template<class Container>
static List<surfZone> oneZone
(
@ -89,6 +89,7 @@ public:
// Static Member Functions
//- Helper function when checking if a file extension is supported.
static bool checkSupport
(
const wordHashSet& available,