Remove unused primitiveEntry::insert() private method.

Improve constructors.

    - Use (const UList<token>&) instead of (const List<token>&)

    - Add (const Xfer< List<token> >&) constructor.
This commit is contained in:
Mark Olesen 2009-12-15 17:35:21 +01:00
parent fb2bd52972
commit 23f5e5917a
6 changed files with 87 additions and 115 deletions

View File

@ -92,7 +92,7 @@ public:
const dictionary& dict const dictionary& dict
); );
//- Construct as copy for the given parentDict //- Construct as copy for the given parent dictionary
dictionaryEntry dictionaryEntry
( (
const dictionary& parentDict, const dictionary& parentDict,

View File

@ -79,7 +79,7 @@ void Foam::dictionaryEntry::write(Ostream& os) const
} }
// * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryEntry& de) Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryEntry& de)
{ {

View File

@ -26,33 +26,92 @@ License
#include "primitiveEntry.H" #include "primitiveEntry.H"
#include "dictionary.H" #include "dictionary.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::primitiveEntry::append(const UList<token>& varTokens)
{
forAll(varTokens, i)
{
newElmt(tokenIndex()++) = varTokens[i];
}
}
bool Foam::primitiveEntry::expandVariable
(
const word& w,
const dictionary& dict
)
{
word varName = w(1, w.size()-1);
// lookup the variable name in the given dictionary....
// Note: allow wildcards to match? For now disabled since following
// would expand internalField to wildcard match and not expected
// internalField:
// internalField XXX;
// boundaryField { ".*" {YYY;} movingWall {value $internalField;}
const entry* ePtr = dict.lookupEntryPtr(varName, true, false);
// ...if defined append its tokens into this
if (ePtr)
{
append(ePtr->stream());
}
else
{
// not in the dictionary - try an environment variable
string envStr = getEnv(varName);
if (envStr.empty())
{
return false;
}
append(tokenList(IStringStream('(' + envStr + ')')()));
}
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens) Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& is)
: :
entry(key), entry(key),
ITstream(tokens) ITstream(is)
{ {
name() += "::" + keyword(); name() += "::" + keyword();
} }
Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t) Foam::primitiveEntry::primitiveEntry(const keyType& key, const token& t)
: :
entry(keyword), entry(key),
ITstream(keyword, tokenList(1, t)) ITstream(key, tokenList(1, t))
{} {}
Foam::primitiveEntry::primitiveEntry Foam::primitiveEntry::primitiveEntry
( (
const keyType& keyword, const keyType& key,
const tokenList& tokens const UList<token>& tokens
) )
: :
entry(keyword), entry(key),
ITstream(keyword, tokens) ITstream(key, tokens)
{}
Foam::primitiveEntry::primitiveEntry
(
const keyType& key,
const Xfer< List<token> >& tokens
)
:
entry(key),
ITstream(key, tokens)
{} {}
@ -118,43 +177,4 @@ Foam::dictionary& Foam::primitiveEntry::dict()
} }
void Foam::primitiveEntry::insert
(
const tokenList& varTokens,
const label posI
)
{
tokenList& tokens = *this;
if (varTokens.empty())
{
label end = tokens.size() - 1;
for (label j = posI; j < end; j++)
{
tokens[j] = tokens[j+1];
}
tokens.setSize(tokens.size() - 1);
}
else if (varTokens.size() > 1)
{
tokens.setSize(tokens.size() + varTokens.size() - 1);
label end = tokens.size() - 1;
label offset = varTokens.size() - 1;
for (label j = end; j > posI; j--)
{
tokens[j] = tokens[j-offset];
}
}
forAll(varTokens, j)
{
tokens[posI + j] = varTokens[j];
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -68,6 +68,9 @@ class primitiveEntry
{ {
// Private member functions // Private member functions
//- Append the given tokens starting at the current tokenIndex
void append(const UList<token>&);
//- Append the given token to this entry //- Append the given token to this entry
void append void append
( (
@ -76,9 +79,6 @@ class primitiveEntry
Istream& Istream&
); );
//- Append the given tokens starting at the current tokenIndex
void append(const tokenList&);
//- Expand the given variable (keyword starts with $) //- Expand the given variable (keyword starts with $)
bool expandVariable(const word&, const dictionary&); bool expandVariable(const word&, const dictionary&);
@ -93,9 +93,6 @@ class primitiveEntry
//- Read the complete entry from the given stream //- Read the complete entry from the given stream
void readEntry(const dictionary&, Istream&); void readEntry(const dictionary&, Istream&);
//- Insert the given tokens at token posI
void insert(const tokenList&, const label posI);
public: public:
@ -110,11 +107,14 @@ public:
//- Construct from keyword and a ITstream //- Construct from keyword and a ITstream
primitiveEntry(const keyType&, const ITstream&); primitiveEntry(const keyType&, const ITstream&);
//- Construct from keyword and a token //- Construct from keyword and a single token
primitiveEntry(const keyType&, const token&); primitiveEntry(const keyType&, const token&);
//- Construct from keyword and a tokenList //- Construct from keyword and a list of tokens
primitiveEntry(const keyType&, const tokenList&); primitiveEntry(const keyType&, const UList<token>&);
//- Construct from keyword and by transferring a list of tokens
primitiveEntry(const keyType&, const Xfer< List<token> >&);
//- Construct from keyword and a T //- Construct from keyword and a T
template<class T> template<class T>
@ -166,7 +166,7 @@ public:
//- Read tokens from the given stream //- Read tokens from the given stream
bool read(const dictionary&, Istream&); bool read(const dictionary&, Istream&);
// Write //- Write
void write(Ostream&) const; void write(Ostream&) const;
//- Return info proxy. //- Return info proxy.

View File

@ -28,10 +28,9 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "primitiveEntry.H" #include "primitiveEntry.H"
#include "OSspecific.H"
#include "functionEntry.H" #include "functionEntry.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::primitiveEntry::append void Foam::primitiveEntry::append
( (
@ -63,55 +62,6 @@ void Foam::primitiveEntry::append
} }
void Foam::primitiveEntry::append(const tokenList& varTokens)
{
forAll(varTokens, i)
{
newElmt(tokenIndex()++) = varTokens[i];
}
}
bool Foam::primitiveEntry::expandVariable
(
const word& w,
const dictionary& dict
)
{
word varName = w(1, w.size()-1);
// lookup the variable name in the given dictionary....
// Note: allow wildcards to match? For now disabled since following
// would expand internalField to wildcard match and not expected
// internalField:
// internalField XXX;
// boundaryField { ".*" {YYY;} movingWall {value $internalField;}
const entry* ePtr = dict.lookupEntryPtr(varName, true, false);
// ...if defined insert its tokens into this
if (ePtr != NULL)
{
append(ePtr->stream());
return true;
}
else
{
// if not in the dictionary see if it is an environment
// variable
string enVarString = getEnv(varName);
if (enVarString.size())
{
append(tokenList(IStringStream('(' + enVarString + ')')()));
return true;
}
return false;
}
}
bool Foam::primitiveEntry::expandFunction bool Foam::primitiveEntry::expandFunction
( (
const word& keyword, const word& keyword,
@ -221,6 +171,8 @@ void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is)
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::primitiveEntry::primitiveEntry Foam::primitiveEntry::primitiveEntry
( (
const keyType& key, const keyType& key,

View File

@ -30,10 +30,10 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const T& t) Foam::primitiveEntry::primitiveEntry(const keyType& key, const T& t)
: :
entry(keyword), entry(key),
ITstream(keyword, tokenList(10)) ITstream(key, tokenList(10))
{ {
OStringStream os; OStringStream os;
os << t << token::END_STATEMENT; os << t << token::END_STATEMENT;