Commit f9190e2a authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: primitiveEntry construct with empty token list

- contents to be filled with a later assignment.

  This can help avoid deduction issues when populating from a list of
  tokens, and the templated version is selected:

  ```
  template<class T>
  primitiveEntry(const keyType&, const T&);
  ```

ENH: support construct empty ITstream with given name

- populate contents later by assigment
parent a415f044
......@@ -425,7 +425,7 @@ void Foam::ITstream::append(token&& t, const bool lazy)
}
void Foam::ITstream::append(const tokenList& newTokens, const bool lazy)
void Foam::ITstream::append(const UList<token>& newTokens, const bool lazy)
{
reserveCapacity(tokenIndex_ + newTokens.size(), lazy);
tokenList& toks = *this;
......@@ -438,7 +438,7 @@ void Foam::ITstream::append(const tokenList& newTokens, const bool lazy)
}
void Foam::ITstream::append(tokenList&& newTokens, const bool lazy)
void Foam::ITstream::append(List<token>&& newTokens, const bool lazy)
{
reserveCapacity(tokenIndex_ + newTokens.size(), lazy);
tokenList& toks = *this;
......@@ -465,7 +465,7 @@ void Foam::ITstream::operator=(const ITstream& is)
}
void Foam::ITstream::operator=(const tokenList& toks)
void Foam::ITstream::operator=(const UList<token>& toks)
{
tokenList::operator=(toks);
......@@ -473,7 +473,7 @@ void Foam::ITstream::operator=(const tokenList& toks)
}
void Foam::ITstream::operator=(tokenList&& toks)
void Foam::ITstream::operator=(List<token>&& toks)
{
tokenList::operator=(std::move(toks));
......
......@@ -99,6 +99,22 @@ public:
setGood();
}
//- Construct empty stream with given name
explicit ITstream
(
const string& name,
IOstreamOption streamOpt = IOstreamOption()
)
:
Istream(streamOpt),
tokenList(),
name_(name),
tokenIndex_(0)
{
setOpened();
setGood();
}
//- Construct from components
ITstream
(
......@@ -300,21 +316,21 @@ public:
//- incrementing the index.
void append(token&& t, const bool lazy);
//- Copy append a tokenList at the current tokenIndex,
//- Copy append a list of tokens at the current tokenIndex,
//- incrementing the index.
//
// \param newTokens the list of tokens to copy append
// \param lazy leaves any excess capacity for further appends.
// The caller will be responsible for resizing later.
void append(const tokenList& newTokens, const bool lazy);
void append(const UList<token>& newTokens, const bool lazy);
//- Move append a tokenList at the current tokenIndex,
//- Move append a list of tokens at the current tokenIndex,
//- incrementing the index.
//
// \param newTokens the list of tokens to move append
// \param lazy leaves any excess capacity for further appends.
// The caller will be responsible for resizing later.
void append(tokenList&& newTokens, const bool lazy);
void append(List<token>&& newTokens, const bool lazy);
//- Set flags of stream
ios_base::fmtflags flags(const ios_base::fmtflags)
......@@ -339,10 +355,10 @@ public:
void operator=(const ITstream& is);
//- Copy assignment of tokens, with rewind()
void operator=(const tokenList& toks);
void operator=(const UList<token>& toks);
//- Move assignment of tokens, with rewind()
void operator=(tokenList&& toks);
void operator=(List<token>&& toks);
};
......
......@@ -80,12 +80,8 @@ public:
versionNumber ver = currentVersion
)
:
Ostream(fmt, ver),
DynamicList<token>()
{
setOpened();
setGood();
}
OTstream(IOstreamOption(fmt, ver))
{}
//- Copy construct
OTstream(const OTstream& os)
......
......@@ -187,7 +187,7 @@ public:
public:
//- Construct null
//- Default construct
Searcher()
:
dict_(nullptr),
......@@ -388,7 +388,7 @@ public:
// Constructors
//- Construct top-level dictionary null
//- Default construct, a top-level empty dictionary
dictionary();
//- Construct top-level empty dictionary with given name
......
......@@ -213,13 +213,11 @@ bool Foam::primitiveEntry::expandVariable
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& is)
Foam::primitiveEntry::primitiveEntry(const keyType& key)
:
entry(key),
ITstream(is)
{
name() += '.' + keyword();
}
ITstream(key, tokenList())
{}
Foam::primitiveEntry::primitiveEntry(const keyType& key, const token& tok)
......@@ -251,6 +249,15 @@ Foam::primitiveEntry::primitiveEntry
{}
Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& is)
:
entry(key),
ITstream(is)
{
name() += '.' + key;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::primitiveEntry::startLineNumber() const
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -54,6 +54,7 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class dictionary;
/*---------------------------------------------------------------------------*\
......@@ -104,14 +105,9 @@ public:
// Constructors
//- Construct from keyword and a Istream
primitiveEntry(const keyType& key, Istream& is);
//- Construct from keyword, parent dictionary and Istream
primitiveEntry(const keyType& key, const dictionary& dict, Istream& is);
//- Construct from keyword and a ITstream
primitiveEntry(const keyType& key, const ITstream& is);
//- Construct from keyword and no tokens.
// Contents to be filled with a later assignment
explicit primitiveEntry(const keyType& key);
//- Construct from keyword and a single token
primitiveEntry(const keyType& key, const token& tok);
......@@ -122,10 +118,20 @@ public:
//- Construct from keyword and by transferring a list of tokens
primitiveEntry(const keyType& key, List<token>&& tokens);
//- Construct from keyword and a T
//- Construct from keyword and ITstream tokens
primitiveEntry(const keyType& key, const ITstream& is);
//- Construct from keyword and Istream
primitiveEntry(const keyType& key, Istream& is);
//- Construct from keyword, parent dictionary and Istream
primitiveEntry(const keyType& key, const dictionary& dict, Istream& is);
//- Construct from keyword and a value. Uses string stream serialization
template<class T>
primitiveEntry(const keyType& key, const T& val);
//- Clone the entry
autoPtr<entry> clone(const dictionary&) const
{
return autoPtr<entry>(new primitiveEntry(*this));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment