BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / dictionary / primitiveEntry / primitiveEntry.C
blobbda2bfef9ab67c46ca260f4dd4e0e0f08776459a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "primitiveEntry.H"
27 #include "dictionary.H"
28 #include "OSspecific.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 void Foam::primitiveEntry::append(const UList<token>& varTokens)
34     forAll(varTokens, i)
35     {
36         newElmt(tokenIndex()++) = varTokens[i];
37     }
41 bool Foam::primitiveEntry::expandVariable
43     const word& w,
44     const dictionary& dict
47     word varName = w(1, w.size()-1);
49     // lookup the variable name in the given dictionary....
50     // Note: allow wildcards to match? For now disabled since following
51     // would expand internalField to wildcard match and not expected
52     // internalField:
53     //      internalField XXX;
54     //      boundaryField { ".*" {YYY;} movingWall {value $internalField;}
55     const entry* ePtr = dict.lookupEntryPtr(varName, true, false);
57     // ...if defined append its tokens into this
58     if (ePtr)
59     {
60         append(ePtr->stream());
61     }
62     else
63     {
64         // not in the dictionary - try an environment variable
65         string envStr = getEnv(varName);
67         if (envStr.empty())
68         {
69             return false;
70         }
71         append(tokenList(IStringStream('(' + envStr + ')')()));
72     }
73     return true;
77 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
79 Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& is)
81     entry(key),
82     ITstream(is)
84     name() += "::" + keyword();
88 Foam::primitiveEntry::primitiveEntry(const keyType& key, const token& t)
90     entry(key),
91     ITstream(key, tokenList(1, t))
95 Foam::primitiveEntry::primitiveEntry
97     const keyType& key,
98     const UList<token>& tokens
101     entry(key),
102     ITstream(key, tokens)
106 Foam::primitiveEntry::primitiveEntry
108     const keyType& key,
109     const Xfer<List<token> >& tokens
112     entry(key),
113     ITstream(key, tokens)
117 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
119 Foam::label Foam::primitiveEntry::startLineNumber() const
121     const tokenList& tokens = *this;
123     if (tokens.empty())
124     {
125         return -1;
126     }
127     else
128     {
129         return tokens.first().lineNumber();
130     }
134 Foam::label Foam::primitiveEntry::endLineNumber() const
136     const tokenList& tokens = *this;
138     if (tokens.empty())
139     {
140         return -1;
141     }
142     else
143     {
144         return tokens.last().lineNumber();
145     }
149 Foam::ITstream& Foam::primitiveEntry::stream() const
151     ITstream& is = const_cast<primitiveEntry&>(*this);
152     is.rewind();
153     return is;
157 const Foam::dictionary& Foam::primitiveEntry::dict() const
159     FatalErrorIn("const dictionary& primitiveEntry::dict() const")
160         << "Attempt to return primitive entry " << info()
161         << " as a sub-dictionary"
162         << abort(FatalError);
164     return dictionary::null;
168 Foam::dictionary& Foam::primitiveEntry::dict()
170     FatalErrorIn("const dictionary& primitiveEntry::dict()")
171         << "Attempt to return primitive entry " << info()
172         << " as a sub-dictionary"
173         << abort(FatalError);
175     return const_cast<dictionary&>(dictionary::null);
179 // ************************************************************************* //