STYLE: IOobject/regIOobject - noexcept methods, isolate local functions

- local writeHeaderEntry helper was not marked as file-scope static.

- use do/while to simplify handling of padding spaces

ENH: IOobject - copy construct, resetting name and local component

- when copying with a new local component, this is simpler than
  constructing from all of the components, which was previously the
  only possibility for setting a new local component.
This commit is contained in:
Mark Olesen
2022-05-03 10:33:31 +02:00
parent 0e01e530a8
commit cb6f908798
11 changed files with 143 additions and 117 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,24 +36,27 @@ License
namespace Foam
{
inline void writeSpaces(Ostream& os, label nSpaces)
// Like Ostream::writeEntry, but with fewer spaces
template<class T>
static inline void writeHeaderEntry
(
Ostream& os,
const word& key,
const T& value
)
{
if (nSpaces < 1)
{
nSpaces = 1;
}
while (nSpaces--)
os.indent();
os.write(key);
label padding = (12 - label(key.size()));
// Write padding spaces (always at least one)
do
{
os.write(char(token::SPACE));
}
}
while (--padding > 0);
// Similar to writeEntry, but with fewer spaces
template<class T>
inline void writeHeaderEntry(Ostream& os, const word& key, const T& value)
{
os << indent << key;
writeSpaces(os, 12 - label(key.size()));
os << value << char(token::END_STATEMENT) << nl;
}