mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: static parse methods for ITstream
This commit is contained in:
@ -236,23 +236,23 @@ public:
|
||||
inline void append(const UIndirectList<T>& lst);
|
||||
|
||||
//- Transfer the contents of the argument List into this list
|
||||
// and annul the argument list
|
||||
//- and annul the argument list
|
||||
void transfer(List<T>& lst);
|
||||
|
||||
//- Transfer the contents of the argument List into this list
|
||||
// and annul the argument list
|
||||
//- and annul the argument list
|
||||
template<int SizeMin>
|
||||
void transfer(DynamicList<T, SizeMin>& lst);
|
||||
|
||||
//- Transfer the contents of the argument List into this list
|
||||
// and annul the argument list
|
||||
//- and annul the argument list
|
||||
void transfer(SortableList<T>& lst);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<List<T>> xfer();
|
||||
|
||||
//- Return subscript-checked element of UList.
|
||||
// Resize list if required.
|
||||
//- Return subscript-checked element of UList and resizing the list
|
||||
//- if required.
|
||||
inline T& newElmt(const label i);
|
||||
|
||||
|
||||
@ -301,7 +301,10 @@ public:
|
||||
|
||||
//- Read List from Istream, discarding contents of existing List
|
||||
friend Istream& operator>> <T>
|
||||
(Istream& is, List<T>& L);
|
||||
(
|
||||
Istream& is,
|
||||
List<T>& L
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -27,23 +27,72 @@ License
|
||||
#include "ITstream.H"
|
||||
#include "UIListStream.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
void Foam::ITstream::toTokenList(ISstream& is)
|
||||
Foam::label Foam::ITstream::parseStream(ISstream& is, tokenList& tokens)
|
||||
{
|
||||
tokenIndex_ = 0;
|
||||
label nTok = 0;
|
||||
|
||||
tokens.clear();
|
||||
tokens.setSize(64, token::undefinedToken);
|
||||
|
||||
token tok;
|
||||
|
||||
while (!is.read(tok).bad() && tok.good())
|
||||
{
|
||||
newElmt(tokenIndex()++) = std::move(tok);
|
||||
tokens.newElmt(nTok++) = std::move(tok);
|
||||
}
|
||||
|
||||
tokenList::setSize(tokenIndex());
|
||||
tokens.setSize(nTok);
|
||||
|
||||
setOpened();
|
||||
ITstream::rewind();
|
||||
return nTok;
|
||||
}
|
||||
|
||||
|
||||
Foam::tokenList Foam::ITstream::parse
|
||||
(
|
||||
const UList<char>& input,
|
||||
streamFormat format
|
||||
)
|
||||
{
|
||||
UIListStream is(input, format, IOstream::currentVersion);
|
||||
|
||||
tokenList tokens;
|
||||
parseStream(is, tokens);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
Foam::tokenList Foam::ITstream::parse
|
||||
(
|
||||
const std::string& input,
|
||||
streamFormat format
|
||||
)
|
||||
{
|
||||
UIListStream is
|
||||
(
|
||||
input.data(),
|
||||
input.size(),
|
||||
format,
|
||||
IOstream::currentVersion
|
||||
);
|
||||
|
||||
tokenList tokens;
|
||||
parseStream(is, tokens);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
Foam::tokenList Foam::ITstream::parse
|
||||
(
|
||||
const char* input,
|
||||
streamFormat format
|
||||
)
|
||||
{
|
||||
UIListStream is(input, strlen(input), format, IOstream::currentVersion);
|
||||
|
||||
tokenList tokens;
|
||||
parseStream(is, tokens);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
@ -58,13 +107,14 @@ Foam::ITstream::ITstream
|
||||
)
|
||||
:
|
||||
Istream(format, version),
|
||||
tokenList(16, token::undefinedToken),
|
||||
tokenList(),
|
||||
name_(name),
|
||||
tokenIndex_(0)
|
||||
{
|
||||
UIListStream is(input, format, version);
|
||||
|
||||
toTokenList(is);
|
||||
parseStream(is, static_cast<tokenList&>(*this));
|
||||
ITstream::rewind();
|
||||
}
|
||||
|
||||
|
||||
@ -77,13 +127,14 @@ Foam::ITstream::ITstream
|
||||
)
|
||||
:
|
||||
Istream(format, version),
|
||||
tokenList(16, token::undefinedToken),
|
||||
tokenList(),
|
||||
name_(name),
|
||||
tokenIndex_(0)
|
||||
{
|
||||
UIListStream is(input.data(), input.size(), format, version);
|
||||
|
||||
toTokenList(is);
|
||||
parseStream(is, static_cast<tokenList&>(*this));
|
||||
ITstream::rewind();
|
||||
}
|
||||
|
||||
|
||||
@ -96,14 +147,14 @@ Foam::ITstream::ITstream
|
||||
)
|
||||
:
|
||||
Istream(format, version),
|
||||
tokenList(16, token::undefinedToken),
|
||||
tokenList(),
|
||||
name_(name),
|
||||
tokenIndex_(0)
|
||||
{
|
||||
const size_t len = strlen(input);
|
||||
UIListStream is(input, len, format, version);
|
||||
UIListStream is(input, strlen(input), format, version);
|
||||
|
||||
toTokenList(is);
|
||||
parseStream(is, static_cast<tokenList&>(*this));
|
||||
ITstream::rewind();
|
||||
}
|
||||
|
||||
|
||||
@ -245,6 +296,7 @@ void Foam::ITstream::rewind()
|
||||
lineNumber_ = tokenList::first().lineNumber();
|
||||
}
|
||||
|
||||
setOpened();
|
||||
setGood();
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ Class
|
||||
Foam::ITstream
|
||||
|
||||
Description
|
||||
Input token stream.
|
||||
An input stream of tokens.
|
||||
|
||||
SourceFiles
|
||||
ITstream.C
|
||||
@ -46,7 +46,6 @@ namespace Foam
|
||||
// Forward declaration
|
||||
class ISstream;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class ITstream Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -67,8 +66,9 @@ class ITstream
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Convert input sequence into tokens and append to the token list
|
||||
void toTokenList(ISstream& input);
|
||||
//- Convert input sequence into a list of tokens.
|
||||
// \return the number of tokens in the resulting list.
|
||||
static label parseStream(ISstream& input, tokenList& tokens);
|
||||
|
||||
|
||||
public:
|
||||
@ -164,6 +164,33 @@ public:
|
||||
{}
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Create token list by parsing the input character sequence until
|
||||
//- no good tokens remain.
|
||||
static tokenList parse
|
||||
(
|
||||
const UList<char>& input,
|
||||
streamFormat format=ASCII
|
||||
);
|
||||
|
||||
//- Create token list by parsing the input string until
|
||||
//- no good tokens remain.
|
||||
static tokenList parse
|
||||
(
|
||||
const std::string& input,
|
||||
streamFormat format=ASCII
|
||||
);
|
||||
|
||||
//- Create token list by parsing the input character sequence until
|
||||
//- no good tokens remain.
|
||||
static tokenList parse
|
||||
(
|
||||
const char* input,
|
||||
streamFormat format=ASCII
|
||||
);
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Inquiry
|
||||
|
||||
@ -223,10 +223,7 @@ Foam::tokenList Foam::dictionary::tokens() const
|
||||
}
|
||||
|
||||
// String re-parsed as a list of tokens
|
||||
return static_cast<tokenList>
|
||||
(
|
||||
ITstream("tokens", os.str(), os.format(), os.version())
|
||||
);
|
||||
return ITstream::parse(os.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -96,15 +96,18 @@ bool Foam::primitiveEntry::expandVariable
|
||||
return false;
|
||||
}
|
||||
|
||||
// String parsed as a list of tokens
|
||||
ITstream its("env", str);
|
||||
appendTokenList(std::move(static_cast<tokenList&>(its)));
|
||||
// Parse string into a series of tokens
|
||||
|
||||
tokenList toks(ITstream::parse(str, IOstream::ASCII));
|
||||
|
||||
appendTokenList(std::move(toks));
|
||||
}
|
||||
else if (eptr->isDict())
|
||||
{
|
||||
// Found dictionary entry
|
||||
|
||||
tokenList toks(eptr->dict().tokens().xfer());
|
||||
|
||||
appendTokenList(std::move(toks));
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user