ENH: add low-level readRawLabels, readRawScalars (#1378)

- these use the additional byte-size checks in IOstream to handle
  native vs non-native sizes
This commit is contained in:
Mark Olesen
2019-07-29 16:01:34 +02:00
committed by Andrew Heather
parent b0ffdbcfb1
commit ef9bb4ae16
10 changed files with 356 additions and 53 deletions

View File

@ -30,7 +30,8 @@ Description
\*---------------------------------------------------------------------------*/
#include "scalar.H"
#include "label.H"
#include "FlatOutput.H"
#include "ListStream.H"
#include "StringStream.H"
#include "NASCore.H"
#include "parsing.H"
@ -67,6 +68,19 @@ void printInfo(const Switch& sw)
}
Ostream& toString(Ostream& os, const UList<char>& list)
{
os << '"';
for (const char c : list)
{
os << c;
}
os << '"';
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T>
@ -280,6 +294,59 @@ int main(int argc, char *argv[])
);
}
if (true)
{
#ifdef WM_DP
typedef float otherType;
#else
typedef double otherType;
#endif
Info<< nl << "Test raw binary read of scalar list:"
<< " write " << sizeof(otherType)
<< " read " << sizeof(scalar) << nl;
List<otherType> srcList(15);
forAll(srcList, i)
{
srcList[i] = 1 + 10*i;
}
DynamicList<char> buf;
OListStream os(std::move(buf), IOstream::BINARY);
os << srcList;
os.swap(buf); // Recover buffer
// Read back
List<scalar> dstList;
UIListStream is(buf, IOstream::BINARY);
is.setScalarByteSize(sizeof(otherType));
Info<< "Stream scalar-size ("
<< is.scalarByteSize() << ") is native: "
<< Switch(is.checkScalarSize<otherType>()) << nl;
token firstToken(is);
Info<< "List has " << firstToken.info() << " scalar items" << nl;
dstList.resize(firstToken.labelToken(), 3.14159);
is.beginRawRead();
// for (scalar& val : dstList)
// {
// val = readRawScalar(is);
// }
readRawScalars(is, dstList.data(), dstList.size());
is.endRawRead();
Info<< "Wrote " << flatOutput(srcList) << nl
<< "Read " << flatOutput(dstList) << nl;
}
if (nFail)
{
Info<< nl << "failed " << nFail << " tests" << nl;