ENH: provision for delayed reading of compound tokens (#2953)

- the construction of compound tokens is now split into two stages:
    - default construct
    - read contents
  This permits a larger variety of handling.

- the new token::readCompoundToken(..) method allows for simpler
  more failsafe invocations.

- forward resize(), read() methods for compound tokens to support
  separate read and population.
  Top-level refCompoundToken() method for modify access.

ENH: split off a private readCompoundToken() method within ISstream

- this allows overloading and alternative tokenisation handling for
  derived classes
This commit is contained in:
Mark Olesen
2023-08-02 11:23:41 +02:00
parent 43f8b477b7
commit 268de43afc
22 changed files with 1083 additions and 197 deletions

View File

@ -69,6 +69,19 @@ inline static label byteAlign(const label pos, const size_t align)
);
}
// Read into compound token (assumed to be a known type)
inline static bool readCompoundToken
(
token& tok,
const word& compoundType,
Istream& is
)
{
// The isCompound() check is not needed (already checked by caller)
return tok.readCompoundToken(compoundType, is);
}
} // End namespace Foam
@ -339,11 +352,11 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t)
word val;
if (readString(val))
{
if (token::compound::isCompound(val))
{
t = token::compound::New(val, *this).ptr();
}
else
if
(
!token::compound::isCompound(val)
|| !readCompoundToken(t, val, *this)
)
{
t = std::move(val);
t.setType(token::tokenType(c));