ENH: add OListStream::swap(DynamicList<char>&)

- allows full recovery of allocated space, not just addressable range.

  This can be particularly useful for code patterns that repeatedly
  reuse the same buffer space. For example,

      DynamicList<char> buf(1024);

      // some loop
      {
          OListStream os(std::move(buf));
          os << ...

          os.swap(buf);
      }

   Can read back from this buffer as a second operation:

      {
          UIListStream is(buf);
          is >> ...
      }
This commit is contained in:
Mark Olesen
2019-07-31 11:31:40 +02:00
committed by Andrew Heather
parent b0d32ce1b4
commit 6f8da834a9
5 changed files with 59 additions and 23 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -147,7 +147,7 @@ int main(int argc, char *argv[])
// Create from other storage types
List<char> written;
DynamicList<char> written;
Info<< nl;
{
Info<<"create std::move(List)" << endl;
@ -157,6 +157,11 @@ int main(int argc, char *argv[])
toString(Info, list) << endl;
OListStream buf1(std::move(list));
Info<<"orig:";
toString(Info, list) << endl;
printInfo(buf1);
for (label i = 0; i < 26; ++i)
{
buf1 << char('A' +i);
@ -179,6 +184,9 @@ int main(int argc, char *argv[])
Info<<"'captured' content ";
toString(Info, written);
Info<< nl
<< "content size=" << written.size()
<< " capacity=" << written.capacity() << nl;
Info<< "\nEnd\n" << endl;