ENH: unify read/write for containers

- handle binary/contiguous first as being the most obvious, followed
  by increasing complexity of ascii.
  Structure reading and writing routines similarly by introducing a
  readList method to compliment the writeList method.
This commit is contained in:
Mark Olesen
2021-02-26 18:10:42 +01:00
committed by Andrew Heather
parent a76a3d760c
commit 498de8a74a
29 changed files with 728 additions and 642 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -37,6 +37,8 @@ Description
#include "HashSet.H"
#include "ListOps.H"
#include "cpuTime.H"
#include "StringStream.H"
#include "FlatOutput.H"
#include <vector>
#include <unordered_set>
@ -65,6 +67,28 @@ inline Ostream& report
}
// Create equivalent to flat output
inline void undecorated
(
Ostream& os,
const bitSet& list
)
{
const label len = list.size();
os << token::BEGIN_LIST;
// Contents
for (label i=0; i < len; ++i)
{
if (i) os << token::SPACE;
os << label(list.get(i));
}
os << token::END_LIST;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
@ -97,6 +121,28 @@ int main(int argc, char *argv[])
Info<<"bits used: " << flatOutput(set3b.toc()) << nl;
Info<<"inverted: " << flatOutput(invert(set3b)) << nl;
Info<< "Test read/write (ASCII)" << nl;
OStringStream ostr;
undecorated(ostr, set3a); // like flatOutput
ostr << bitSet();
set3a.flip();
undecorated(ostr, set3a); // like flatOutput
{
IStringStream istr(ostr.str());
Info<< "parse: " << istr.str() << nl;
bitSet bset1(istr);
bitSet bset2(istr);
bitSet bset3(istr);
Info<< "got: " << bset1 << nl
<< "and: " << bset2 << nl
<< "and: " << bset3 << nl;
}
}
Info<< "End\n" << endl;