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:
Mark Olesen
2019-01-10 14:24:11 +01:00
parent bef508dedc
commit 8071020518
20 changed files with 300 additions and 123 deletions

View File

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