mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: make List output compile-time configurable (#1160)
- introduced a ListPolicy details to make the transition between a short list (space separated) and a long list (newline separated) more configurable. We suppress line breaks for commonly used types that often have short content: (word, wordRes, keyType).
This commit is contained in:
@ -46,6 +46,7 @@ See also
|
||||
#include "HashOps.H"
|
||||
#include "ListOps.H"
|
||||
#include "SubList.H"
|
||||
#include "ListPolicy.H"
|
||||
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
@ -64,9 +65,22 @@ public:
|
||||
using List<string>::List;
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace Detail
|
||||
{
|
||||
namespace ListPolicy
|
||||
{
|
||||
|
||||
// Override on a per-type basis
|
||||
template<> struct short_length<short> : std::integral_constant<short,20> {};
|
||||
|
||||
} // End namespace ListPolicy
|
||||
} // End namespace Detail
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T, class ListType>
|
||||
@ -92,6 +106,20 @@ void printMyString(const UList<string>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Ostream& printListOutputType(const char* what)
|
||||
{
|
||||
Info<< what
|
||||
<< " (contiguous="
|
||||
<< contiguous<T>() << " no_linebreak="
|
||||
<< Detail::ListPolicy::no_linebreak<T>::value
|
||||
<< " short_length="
|
||||
<< Detail::ListPolicy::short_length<T>::value << ')';
|
||||
|
||||
return Info;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
@ -251,23 +279,54 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<<"scalar identity:" << flatOutput(slist) << endl;
|
||||
|
||||
Info<< "labels (contiguous=" << contiguous<label>() << ")" << nl;
|
||||
printListOutputType<label>("labels") << nl;
|
||||
|
||||
Info<< "normal: " << longLabelList << nl;
|
||||
Info<< "flatOutput: " << flatOutput(longLabelList) << nl;
|
||||
// Info<< "flatOutput(14): " << flatOutput(longLabelList, 14) << nl;
|
||||
|
||||
auto shrtList = ListOps::create<short>
|
||||
(
|
||||
longLabelList,
|
||||
[](const label& val){ return val; }
|
||||
);
|
||||
|
||||
printListOutputType<short>("short") << nl;
|
||||
Info<< "normal: " << shrtList << nl;
|
||||
|
||||
|
||||
stringList longStringList(12);
|
||||
forAll(longStringList, i)
|
||||
{
|
||||
longStringList[i].resize(3, 'a' + i);
|
||||
}
|
||||
|
||||
Info<< "string (contiguous=" << contiguous<string>() << ")" << nl;
|
||||
printListOutputType<string>("string") << nl;
|
||||
|
||||
Info<< "normal: " << longStringList << nl;
|
||||
Info<< "flatOutput: " << flatOutput(longStringList) << nl;
|
||||
// contiguous longStringList[i].resize(3, 'a' + i);
|
||||
|
||||
auto wList = ListOps::create<word>
|
||||
(
|
||||
longStringList,
|
||||
[](const std::string& val){ return val; }
|
||||
);
|
||||
|
||||
printListOutputType<word>("word") << nl;
|
||||
|
||||
Info<< "normal: " << wList << nl;
|
||||
|
||||
// Shorten
|
||||
longStringList.resize(8);
|
||||
wList.resize(8);
|
||||
|
||||
Info<< "Test shorter lists" << nl;
|
||||
|
||||
printListOutputType<string>("string") << nl;
|
||||
Info<< "normal: " << longStringList << nl;
|
||||
|
||||
printListOutputType<word>("word") << nl;
|
||||
Info<< "normal: " << wList << nl;
|
||||
}
|
||||
|
||||
// test SubList and labelRange
|
||||
|
||||
@ -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) 2017-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -400,10 +400,9 @@ public:
|
||||
//- Clear list and read from stream
|
||||
Istream& read(Istream& is);
|
||||
|
||||
//- Write the List, with line-breaks in ASCII if the list length
|
||||
//- exceeds shortListLen.
|
||||
//- Write List, with line-breaks in ASCII when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
//- Write as a dictionary entry with keyword
|
||||
void writeEntry(const word& keyword, Ostream& os) const;
|
||||
@ -492,15 +491,20 @@ public:
|
||||
Istream& is,
|
||||
PackedList<Width>& list
|
||||
);
|
||||
|
||||
friend Ostream& operator<< <Width>
|
||||
(
|
||||
Ostream& os,
|
||||
const PackedList<Width>& list
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
//- Write List to Ostream, as per UList::writeList() with default length.
|
||||
// The default short-length is given by Detail::ListPolicy::short_length
|
||||
template<unsigned Width>
|
||||
Ostream& operator<<(Ostream& os, const PackedList<Width>& list)
|
||||
{
|
||||
return list.writeList(os, Detail::ListPolicy::short_length<void>::value);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -206,7 +206,7 @@ template<unsigned Width>
|
||||
Foam::Ostream& Foam::PackedList<Width>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
const PackedList<Width>& list = *this;
|
||||
@ -220,7 +220,7 @@ Foam::Ostream& Foam::PackedList<Width>::writeList
|
||||
// Two or more entries, and all entries have identical values.
|
||||
os << len << token::BEGIN_BLOCK << list[0] << token::END_BLOCK;
|
||||
}
|
||||
else if (!shortListLen || len <= shortListLen)
|
||||
else if (!shortLen || len <= shortLen)
|
||||
{
|
||||
// Shorter list, or line-breaks suppressed
|
||||
os << len << token::BEGIN_LIST;
|
||||
@ -284,13 +284,6 @@ Foam::Istream& Foam::operator>>(Istream& is, PackedList<Width>& list)
|
||||
}
|
||||
|
||||
|
||||
template<unsigned Width>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const PackedList<Width>& list)
|
||||
{
|
||||
return list.writeList(os, 10);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned Width>
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -541,10 +541,9 @@ public:
|
||||
|
||||
// IO
|
||||
|
||||
//- Write the bitSet, with line-breaks in ASCII if the size
|
||||
//- exceeds shortListLen.
|
||||
//- Write bitSet, with line-breaks (ASCII) when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
//- Write as a dictionary entry with keyword
|
||||
void writeEntry(const word& keyword, Ostream& os) const;
|
||||
@ -561,7 +560,7 @@ public:
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- \deprecated(2018-04) compatibility name for PackedBoolList
|
||||
//- Deprecated(2018-04) compatibility name for PackedBoolList
|
||||
// \deprecated(2018-04) - use toc() method
|
||||
inline labelList used() const { return toc(); }
|
||||
|
||||
@ -570,9 +569,13 @@ public:
|
||||
|
||||
// Global Operators
|
||||
|
||||
Ostream& operator<<(Ostream& os, const InfoProxy<bitSet>& info);
|
||||
//- Write bitset to Ostream, as per bitSet::writeList() with default length
|
||||
//- of 40 items.
|
||||
Ostream& operator<<(Ostream& os, const bitSet& bitset);
|
||||
|
||||
//- Output bitset information
|
||||
Ostream& operator<<(Ostream& os, const InfoProxy<bitSet>& info);
|
||||
|
||||
|
||||
//- Bitwise-AND of two bitsets.
|
||||
// See bitSet::operator&= for more details.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -39,7 +39,7 @@ void Foam::bitSet::writeEntry(Ostream& os) const
|
||||
Foam::Ostream& Foam::bitSet::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
const bitSet& list = *this;
|
||||
@ -53,7 +53,7 @@ Foam::Ostream& Foam::bitSet::writeList
|
||||
// Two or more entries, and all entries have identical values.
|
||||
os << len << token::BEGIN_BLOCK << list[0] << token::END_BLOCK;
|
||||
}
|
||||
else if (!shortListLen || len <= shortListLen)
|
||||
else if (!shortLen || len <= shortLen)
|
||||
{
|
||||
// Shorter list, or line-breaks suppressed
|
||||
os << len << token::BEGIN_LIST;
|
||||
@ -111,7 +111,7 @@ void Foam::bitSet::writeEntry
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const bitSet& bitset)
|
||||
{
|
||||
return bitset.writeList(os, 10);
|
||||
return bitset.writeList(os, 40);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -362,7 +362,7 @@ Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
|
||||
template<class Key, class Hash>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const HashSet<Key, Hash>& tbl)
|
||||
{
|
||||
return tbl.writeList(os, 10); // 10=consistent with UList
|
||||
return tbl.writeKeys(os, Detail::ListPolicy::short_length<Key>::value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -290,12 +290,12 @@ public:
|
||||
|
||||
// Writing
|
||||
|
||||
//- Write the unordered keys as a list, with line-breaks if list length
|
||||
//- exceeds shortListLen.
|
||||
//- Write unordered keys (list), with line-breaks
|
||||
//- when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const
|
||||
{
|
||||
return this->writeKeys(os, shortListLen);
|
||||
return this->writeKeys(os, shortLen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -870,10 +870,10 @@ public:
|
||||
//- Print information
|
||||
Ostream& printInfo(Ostream& os) const;
|
||||
|
||||
//- Write the unordered keys as a list, with line-breaks if list length
|
||||
//- exceeds shortListLen.
|
||||
//- Write unordered keys (list), with line-breaks
|
||||
//- when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeKeys(Ostream& os, const label shortListLen=0) const;
|
||||
Ostream& writeKeys(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
|
||||
// IOstream Operator
|
||||
|
||||
@ -115,7 +115,7 @@ template<class T, class Key, class Hash>
|
||||
Foam::Ostream& Foam::HashTable<T, Key, Hash>::writeKeys
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
// Similar to UList::writeList version except the following:
|
||||
@ -124,7 +124,11 @@ Foam::Ostream& Foam::HashTable<T, Key, Hash>::writeKeys
|
||||
|
||||
label i = this->size();
|
||||
|
||||
if (i <= 1 || !shortListLen || (i <= shortListLen))
|
||||
if
|
||||
(
|
||||
(i <= 1 || !shortLen)
|
||||
|| (i <= shortLen)
|
||||
)
|
||||
{
|
||||
// Write size and start delimiter
|
||||
os << i << token::BEGIN_LIST;
|
||||
|
||||
@ -294,10 +294,9 @@ public:
|
||||
|
||||
// IOstream operators
|
||||
|
||||
//- Write LList with line-breaks when its length exceeds
|
||||
//- shortListLen.
|
||||
//- Write LList with line-breaks when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
//- Read list from Istream
|
||||
friend Istream& operator>> <LListBase, T>
|
||||
@ -307,7 +306,7 @@ public:
|
||||
);
|
||||
|
||||
//- Write LList to Ostream with line breaks,
|
||||
//- as per writeList() with shortListLen=-1
|
||||
//- as per writeList with shortLen=-1
|
||||
friend Ostream& operator<< <LListBase, T>
|
||||
(
|
||||
Ostream& os,
|
||||
|
||||
@ -130,15 +130,15 @@ template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::LList<LListBase, T>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
const label len = this->size();
|
||||
|
||||
if
|
||||
(
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen)
|
||||
(len <= 1 || !shortLen)
|
||||
|| (len <= shortLen)
|
||||
)
|
||||
{
|
||||
// Size and start delimiter
|
||||
@ -179,7 +179,7 @@ Foam::Ostream& Foam::LList<LListBase, T>::writeList
|
||||
template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const LList<LListBase, T>& lst)
|
||||
{
|
||||
return lst.writeList(os, -1); // always with line breaks
|
||||
return lst.writeList(os, -1); // Always with line breaks
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -178,13 +178,12 @@ public:
|
||||
|
||||
// IOstream operators
|
||||
|
||||
//- Write UILList with line-breaks when its length exceeds
|
||||
//- shortListLen.
|
||||
//- Write UILList with line-breaks when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
//- Write UILList to Ostream with line breaks,
|
||||
//- as per writeList() with shortListLen=-1
|
||||
//- as per writeList() with shortLen=-1
|
||||
friend Ostream& operator<< <LListBase, T>
|
||||
(
|
||||
Ostream& os,
|
||||
|
||||
@ -33,15 +33,15 @@ template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::UILList<LListBase, T>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
const label len = this->size();
|
||||
|
||||
if
|
||||
(
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen)
|
||||
(len <= 1 || !shortLen)
|
||||
|| (len <= shortLen)
|
||||
)
|
||||
{
|
||||
// Size and start delimiter
|
||||
|
||||
@ -46,6 +46,7 @@ SourceFiles
|
||||
#include "Swap.H"
|
||||
#include "HashFwd.H"
|
||||
#include "SLListFwd.H"
|
||||
#include "ListPolicy.H"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
@ -400,8 +401,7 @@ public:
|
||||
//- 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 length
|
||||
//- exceeds shortLen.
|
||||
//- Write List, with line-breaks in ASCII when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
@ -480,11 +480,12 @@ struct Hash<FixedList<T, N>>
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
//- Write to Ostream, as per FixedList::writeList() with shortLen=10
|
||||
//- Write List to Ostream, as per FixedList::writeList() with default length.
|
||||
// The default short-length is given by Detail::ListPolicy::short_length
|
||||
template<class T, unsigned N>
|
||||
Ostream& operator<<(Ostream& os, const FixedList<T, N>& list)
|
||||
{
|
||||
return list.writeList(os, 10);
|
||||
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ template<class T, unsigned N>
|
||||
Foam::Ostream& Foam::FixedList<T, N>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
const FixedList<T, N>& list = *this;
|
||||
@ -77,8 +77,16 @@ Foam::Ostream& Foam::FixedList<T, N>::writeList
|
||||
{
|
||||
if
|
||||
(
|
||||
N <= 1 || !shortListLen
|
||||
|| (N <= unsigned(shortListLen) && contiguous<T>())
|
||||
(N <= 1 || !shortLen)
|
||||
||
|
||||
(
|
||||
(N <= unsigned(shortLen))
|
||||
&&
|
||||
(
|
||||
Detail::ListPolicy::no_linebreak<T>::value
|
||||
|| contiguous<T>()
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
// Start delimiter
|
||||
|
||||
@ -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) 2017-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -50,7 +50,6 @@ namespace Foam
|
||||
|
||||
// Forward declarations
|
||||
template<class T> class UIndirectList;
|
||||
template<class T> Ostream& operator<<(Ostream&, const UIndirectList<T>&);
|
||||
|
||||
// Commonly required list types
|
||||
typedef UIndirectList<bool> boolUIndList;
|
||||
@ -320,23 +319,23 @@ public:
|
||||
|
||||
// Writing
|
||||
|
||||
//- Write the list, with line-breaks in ASCII if its length
|
||||
//- exceeds shortListLen.
|
||||
//- Write List, with line-breaks in ASCII when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
|
||||
|
||||
// Ostream operator
|
||||
|
||||
//- Write list to Ostream, as per writeList() with shortListLen=10
|
||||
friend Ostream& operator<< <T>
|
||||
(
|
||||
Ostream& os,
|
||||
const UIndirectList<T>& list
|
||||
);
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
//- Write List to Ostream, as per UList::writeList() with default length.
|
||||
// The default short-length is given by Detail::ListPolicy::short_length
|
||||
template<class T>
|
||||
Ostream& operator<<(Ostream& os, const UIndirectList<T>& list)
|
||||
{
|
||||
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -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-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -34,7 +34,7 @@ template<class T>
|
||||
Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
const UIndirectList<T>& list = *this;
|
||||
@ -51,8 +51,16 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
}
|
||||
else if
|
||||
(
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen && contiguous<T>())
|
||||
(len <= 1 || !shortLen)
|
||||
||
|
||||
(
|
||||
(len <= shortLen)
|
||||
&&
|
||||
(
|
||||
Detail::ListPolicy::no_linebreak<T>::value
|
||||
|| contiguous<T>()
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
// Size and start delimiter
|
||||
@ -114,17 +122,4 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
Foam::Ostream& os,
|
||||
const Foam::UIndirectList<T>& list
|
||||
)
|
||||
{
|
||||
return list.writeList(os, 10);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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) 2017-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -51,6 +51,7 @@ SourceFiles
|
||||
#include "stdFoam.H"
|
||||
#include "Swap.H"
|
||||
#include "HashFwd.H"
|
||||
#include "ListPolicy.H"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
@ -66,8 +67,8 @@ class labelRange;
|
||||
template<class T> class List;
|
||||
template<class T> class SubList;
|
||||
template<class T> class UList;
|
||||
template<class T> Ostream& operator<<(Ostream&, const UList<T>&);
|
||||
template<class T> Istream& operator>>(Istream&, UList<T>&);
|
||||
template<class T> Ostream& operator<<(Ostream&, const UList<T>&);
|
||||
|
||||
// Common list types
|
||||
typedef UList<char> charUList;
|
||||
@ -471,20 +472,12 @@ public:
|
||||
//- 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.
|
||||
//- Write List, with line-breaks in ASCII when length exceeds shortLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
|
||||
// IOstream operators
|
||||
|
||||
//- Write List to Ostream, as per writeList() with shortListLen=10
|
||||
friend Ostream& operator<< <T>
|
||||
(
|
||||
Ostream& os,
|
||||
const UList<T>& list
|
||||
);
|
||||
// IOstream Operators
|
||||
|
||||
//- Read List contents from Istream.
|
||||
// Requires size to have been set before
|
||||
@ -562,6 +555,17 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
//- Write List to Ostream, as per UList::writeList() with default length.
|
||||
// The default short-length is given by Detail::ListPolicy::short_length
|
||||
template<class T>
|
||||
Ostream& operator<<(Ostream& os, const UList<T>& list)
|
||||
{
|
||||
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
|
||||
@ -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-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -71,7 +71,7 @@ template<class T>
|
||||
Foam::Ostream& Foam::UList<T>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
const UList<T>& list = *this;
|
||||
@ -88,8 +88,16 @@ Foam::Ostream& Foam::UList<T>::writeList
|
||||
}
|
||||
else if
|
||||
(
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen && contiguous<T>())
|
||||
(len <= 1 || !shortLen)
|
||||
||
|
||||
(
|
||||
(len <= shortLen)
|
||||
&&
|
||||
(
|
||||
Detail::ListPolicy::no_linebreak<T>::value
|
||||
|| contiguous<T>()
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
// Size and start delimiter
|
||||
@ -141,14 +149,7 @@ Foam::Ostream& Foam::UList<T>::writeList
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const UList<T>& list)
|
||||
{
|
||||
return list.writeList(os, 10);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list)
|
||||
|
||||
108
src/OpenFOAM/containers/Lists/policy/ListPolicy.H
Normal file
108
src/OpenFOAM/containers/Lists/policy/ListPolicy.H
Normal file
@ -0,0 +1,108 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 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/>.
|
||||
|
||||
Namespace
|
||||
Foam::Detail::ListPolicy
|
||||
|
||||
Description
|
||||
Additional compile-time controls of List behaviour
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef ListPolicy_H
|
||||
#define ListPolicy_H
|
||||
|
||||
#include "label.H"
|
||||
#include <type_traits>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
class word;
|
||||
class wordRe;
|
||||
class keyType;
|
||||
|
||||
namespace Detail
|
||||
{
|
||||
namespace ListPolicy
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Number of items before requiring line-breaks in the list ouput.
|
||||
//
|
||||
// Default definition: 10
|
||||
template<class T>
|
||||
struct short_length : std::integral_constant<label,10> {};
|
||||
|
||||
// Could override on a per-type basis
|
||||
// Eg,
|
||||
// template<> struct short_length<label> : std::integral_constant<label,20> {};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Can suppress additional line breaks separate ASCII data content
|
||||
//- when the data elements are primitives, or contiguous
|
||||
//
|
||||
// Default definition: (integral | floating-point) are contiguous and thus
|
||||
// never need any line breaks
|
||||
template<class T>
|
||||
struct no_linebreak
|
||||
:
|
||||
std::integral_constant
|
||||
<
|
||||
bool,
|
||||
std::is_integral<T>::value || std::is_floating_point<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
|
||||
// Specialization for word, wordRe, keyType
|
||||
// These elements are normally fairly short, so ok to output a few (eg, 10)
|
||||
// of them on a single line.
|
||||
|
||||
//- Suppress line-breaks for word
|
||||
template<> struct no_linebreak<word> : std::true_type {};
|
||||
|
||||
//- Suppress line-breaks for wordRe
|
||||
template<> struct no_linebreak<wordRe> : std::true_type {};
|
||||
|
||||
//- Suppress line-breaks for keyType
|
||||
template<> struct no_linebreak<keyType> : std::true_type {};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace ListPolicy
|
||||
} // End namespace Detail
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user