mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add PackedList::unpack() method
- allows for simpler unpacking of a full list, or list range into any
sufficiently large integral type.
For example,
processorPolyPatch pp = ...;
UOPstream toNbr(pp.neighbProcNo(), pBufs);
toNbr << faceValues.unpack<char>(pp.range());
This commit is contained in:
@ -38,30 +38,30 @@ Description
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<unsigned nBits>
|
||||
template<unsigned Width>
|
||||
inline void reportInfo()
|
||||
{
|
||||
const unsigned offset = PackedList<nBits>::elem_per_block;
|
||||
const unsigned offset = PackedList<Width>::elem_per_block;
|
||||
|
||||
unsigned useSHL = ((1u << (nBits * offset)) - 1);
|
||||
unsigned useSHR = (~0u >> (sizeof(unsigned)*CHAR_BIT - nBits * offset));
|
||||
unsigned useSHL = ((1u << (Width * offset)) - 1);
|
||||
unsigned useSHR = (~0u >> (sizeof(unsigned)*CHAR_BIT - Width * offset));
|
||||
|
||||
Info<< nl
|
||||
<< "PackedList<" << nBits << ">" << nl
|
||||
<< " max_value: " << PackedList<nBits>::max_value << nl
|
||||
<< " packing: " << PackedList<nBits>::elem_per_block << nl
|
||||
<< " utilization: " << (nBits * offset) << nl;
|
||||
<< "PackedList<" << Width << ">" << nl
|
||||
<< " max_value: " << PackedList<Width>::max_value << nl
|
||||
<< " packing: " << PackedList<Width>::elem_per_block << nl
|
||||
<< " utilization: " << (Width * offset) << nl;
|
||||
|
||||
Info<< " Masking:" << nl
|
||||
<< " shift << "
|
||||
<< unsigned(nBits * offset) << nl
|
||||
<< unsigned(Width * offset) << nl
|
||||
<< " shift >> "
|
||||
<< unsigned((sizeof(unsigned)*CHAR_BIT) - nBits * offset)
|
||||
<< unsigned((sizeof(unsigned)*CHAR_BIT) - Width * offset)
|
||||
<< nl;
|
||||
|
||||
hex(Info);
|
||||
Info<< " maskLower: "
|
||||
<< PackedList<nBits>::mask_lower(PackedList<nBits>::elem_per_block)
|
||||
<< PackedList<Width>::mask_lower(PackedList<Width>::elem_per_block)
|
||||
<< nl
|
||||
<< " useSHL: " << useSHL << nl
|
||||
<< " useSHR: " << useSHR << nl;
|
||||
|
||||
@ -118,6 +118,18 @@ int main(int argc, char *argv[])
|
||||
list1.set(14, 2);
|
||||
report(list1);
|
||||
|
||||
Info<< "values() : " << flatOutput(list1.unpack<char>()) << nl
|
||||
<< "values(5,8) : " << flatOutput(list1.unpack<char>(labelRange(5,8)))
|
||||
<< nl;
|
||||
|
||||
{
|
||||
labelList locations({-5, -2, 2, 1, 8});
|
||||
|
||||
Info<< "values at " << flatOutput(locations) << " = "
|
||||
<< flatOutput(list1.unpack<char>(locations))
|
||||
<< nl;
|
||||
}
|
||||
|
||||
Info<< "\ntest operator== between references\n";
|
||||
if (list1[1] == list1[8])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user