mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add readContiguous detail (#1378)
- allows some internal handling for reading dissimilar storage types. Eg, scalars written as float (WM_SP), but read as double (WM_DP) - reading binary parcel coordinates with dissimilar storage types is still pending
This commit is contained in:
committed by
Andrew Heather
parent
1d79c0452c
commit
39834d8f45
@ -119,6 +119,8 @@ Foam::Istream& Foam::PackedList<Width>::read(Istream& is)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// NOTE: binary content should be independent of WM_LABEL_SIZE
|
||||||
|
|
||||||
if (len)
|
if (len)
|
||||||
{
|
{
|
||||||
is.read
|
is.read
|
||||||
|
|||||||
@ -223,7 +223,12 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, N>& list)
|
|||||||
{
|
{
|
||||||
// Binary and contiguous
|
// Binary and contiguous
|
||||||
|
|
||||||
is.read(reinterpret_cast<char*>(list.data()), N*sizeof(T));
|
Detail::readContiguous<T>
|
||||||
|
(
|
||||||
|
is,
|
||||||
|
reinterpret_cast<char*>(list.data()),
|
||||||
|
N*sizeof(T)
|
||||||
|
);
|
||||||
|
|
||||||
is.fatalCheck
|
is.fatalCheck
|
||||||
(
|
(
|
||||||
|
|||||||
@ -126,7 +126,12 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& list)
|
|||||||
{
|
{
|
||||||
// Non-empty, binary, contiguous
|
// Non-empty, binary, contiguous
|
||||||
|
|
||||||
is.read(reinterpret_cast<char*>(list.data()), len*sizeof(T));
|
Detail::readContiguous<T>
|
||||||
|
(
|
||||||
|
is,
|
||||||
|
reinterpret_cast<char*>(list.data()),
|
||||||
|
len*sizeof(T)
|
||||||
|
);
|
||||||
|
|
||||||
is.fatalCheck
|
is.fatalCheck
|
||||||
(
|
(
|
||||||
|
|||||||
@ -259,7 +259,12 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list)
|
|||||||
{
|
{
|
||||||
// Non-empty, binary, contiguous
|
// Non-empty, binary, contiguous
|
||||||
|
|
||||||
is.read(reinterpret_cast<char*>(list.data()), len*sizeof(T));
|
Detail::readContiguous<T>
|
||||||
|
(
|
||||||
|
is,
|
||||||
|
reinterpret_cast<char*>(list.data()),
|
||||||
|
len*sizeof(T)
|
||||||
|
);
|
||||||
|
|
||||||
is.fatalCheck
|
is.fatalCheck
|
||||||
(
|
(
|
||||||
|
|||||||
@ -47,6 +47,7 @@ SourceFiles
|
|||||||
|
|
||||||
#include "IOstream.H"
|
#include "IOstream.H"
|
||||||
#include "token.H"
|
#include "token.H"
|
||||||
|
#include "contiguous.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -194,10 +195,50 @@ inline Istream& operator>>(Istream& is, IOstreamManip f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
//- Read binary block of contiguous data, possibly with conversion
|
||||||
|
template<class T>
|
||||||
|
void readContiguous(Istream& is, char* data, std::streamsize byteCount)
|
||||||
|
{
|
||||||
|
is.beginRawRead();
|
||||||
|
|
||||||
|
if (is_contiguous_label<T>::value)
|
||||||
|
{
|
||||||
|
readRawLabel
|
||||||
|
(
|
||||||
|
is,
|
||||||
|
reinterpret_cast<label*>(data),
|
||||||
|
byteCount/sizeof(label)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (is_contiguous_scalar<T>::value)
|
||||||
|
{
|
||||||
|
readRawScalar
|
||||||
|
(
|
||||||
|
is,
|
||||||
|
reinterpret_cast<scalar*>(data),
|
||||||
|
byteCount/sizeof(scalar)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
is.readRaw(data, byteCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
is.endRawRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End namespace Detail
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef NoRepository
|
#ifdef NoRepository
|
||||||
|
|||||||
@ -112,7 +112,12 @@ bool Foam::Matrix<Form, Type>::readMatrix(Istream& is)
|
|||||||
{
|
{
|
||||||
if (len)
|
if (len)
|
||||||
{
|
{
|
||||||
is.read(reinterpret_cast<char*>(v_), len*sizeof(Type));
|
Detail::readContiguous<Type>
|
||||||
|
(
|
||||||
|
is,
|
||||||
|
reinterpret_cast<char*>(v_),
|
||||||
|
len*sizeof(Type)
|
||||||
|
);
|
||||||
|
|
||||||
is.fatalCheck("readMatrix : reading the binary block");
|
is.fatalCheck("readMatrix : reading the binary block");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -305,8 +305,9 @@ Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is.read
|
Detail::readContiguous<boundBox>
|
||||||
(
|
(
|
||||||
|
is,
|
||||||
reinterpret_cast<char*>(&bb.min_),
|
reinterpret_cast<char*>(&bb.min_),
|
||||||
sizeof(boundBox)
|
sizeof(boundBox)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -134,7 +134,12 @@ inline Foam::Istream& Foam::operator>>(Istream& is, labelledTri& t)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is.read(reinterpret_cast<char*>(&t), sizeof(labelledTri));
|
Detail::readContiguous<labelledTri>
|
||||||
|
(
|
||||||
|
is,
|
||||||
|
reinterpret_cast<char*>(&t),
|
||||||
|
sizeof(labelledTri)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
is.check(FUNCTION_NAME);
|
is.check(FUNCTION_NAME);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd |
|
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011 OpenFOAM Foundation
|
| Copyright (C) 2011 OpenFOAM Foundation
|
||||||
@ -61,8 +61,9 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, Foam::refinementData& wDist)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is.read
|
Detail::readContiguous<refinementData>
|
||||||
(
|
(
|
||||||
|
is,
|
||||||
reinterpret_cast<char*>(&wDist.refinementCount_),
|
reinterpret_cast<char*>(&wDist.refinementCount_),
|
||||||
sizeof(refinementData)
|
sizeof(refinementData)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -495,21 +495,20 @@ Foam::Istream& Foam::operator>>(Istream& is, AABBTree<Type>& tree)
|
|||||||
if (is.format() == IOstream::ASCII)
|
if (is.format() == IOstream::ASCII)
|
||||||
{
|
{
|
||||||
is >> tree.maxLevel_
|
is >> tree.maxLevel_
|
||||||
>> tree.minLeafSize_
|
>> tree.minLeafSize_;
|
||||||
>> tree.boundBoxes_
|
|
||||||
>> tree.addressing_;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is.read
|
is.beginRawRead();
|
||||||
(
|
|
||||||
reinterpret_cast<char*>(&tree.maxLevel_),
|
readRawLabel(is, &tree.maxLevel_);
|
||||||
sizeof(tree.maxLevel_)
|
readRawLabel(is, &tree.minLeafSize_);
|
||||||
+ sizeof(tree.minLeafSize_)
|
|
||||||
);
|
is.endRawRead();
|
||||||
|
}
|
||||||
|
|
||||||
is >> tree.boundBoxes_
|
is >> tree.boundBoxes_
|
||||||
>> tree.addressing_;
|
>> tree.addressing_;
|
||||||
}
|
|
||||||
|
|
||||||
is.check(FUNCTION_NAME);
|
is.check(FUNCTION_NAME);
|
||||||
return is;
|
return is;
|
||||||
|
|||||||
Reference in New Issue
Block a user