ENH: make OSstream indentation adjustable

- this is principally for cases where reduced indentation is desired,
  such as when streaming to a memory location. If the indentation size
  is zero or one, only a single space will be used to separate the
  key/value.

  This change does not affect the stream allocation size, since the
  extra data falls within the padding.

ENH: relocate label/scalar sizes from Istream to IOstream.

- could allow future use for output streams as well?

  Due to padding, reorganization has no effect on allocated size
  of output streams.

STYLE: add read/write name qualifier to beginRaw, endRaw

- removes ambiguity for bi-directional streams

STYLE: fix inconsistent 'const' qualifier on std::streamsize

- base Ostream was without const, some derived streams with const
This commit is contained in:
Mark Olesen
2019-07-31 12:51:54 +02:00
committed by Andrew Heather
parent 6f8da834a9
commit 8b3d77badc
23 changed files with 189 additions and 141 deletions

View File

@ -73,6 +73,17 @@ void printTokens(Istream& is)
}
// Generate some dictionary-like content
template<class OS>
void outputDict(OS& os)
{
os.beginBlock("testDict");
os.writeEntry("bool", "false");
os.writeEntry("scalar", 3.14159);
os.endBlock();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -188,6 +199,28 @@ int main(int argc, char *argv[])
<< "content size=" << written.size()
<< " capacity=" << written.capacity() << nl;
Info<< nl << "Test dictionary" << nl;
{
OListStream os1;
outputDict(os1);
Info<< "Regular" << nl;
printInfo(os1);
}
{
OListStream os2;
os2.indentSize() = 0;
outputDict(os2);
Info<< "Compact" << nl;
printInfo(os2);
}
Info<< "\nEnd\n" << endl;
return 0;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2009-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation
@ -62,6 +62,19 @@ using namespace Foam;
int main(int argc, char *argv[])
{
cout<<"sizeof\n------\n";
if (true)
{
cout<<"IOstream:" << sizeof(IOstream) << nl;
cout<<"Istream:" << sizeof(Istream) << nl;
cout<<"IPstream:" << sizeof(IPstream) << nl;
cout<<"ISstream:" << sizeof(ISstream) << nl;
cout<<"Ostream:" << sizeof(Ostream) << nl;
cout<<"OPstream:" << sizeof(OPstream) << nl;
cout<<"OSstream:" << sizeof(OSstream) << nl;
}
{
nil x;
cout<<"nil:" << sizeof(x) << nl;