1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "primitiveEntry.H"
28 #include "dictionaryEntry.H"
29 #include "functionEntry.H"
30 #include "includeEntry.H"
31 #include "inputModeEntry.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 bool Foam::entry::getKeyword(word& keyword, Istream& is)
39 // Read the next valid token discarding spurious ';'s
44 is.read(keywordToken).bad()
46 || !keywordToken.good()
52 while (keywordToken == token::END_STATEMENT);
54 // If the token is a valid keyword set 'keyword' return true...
55 if (keywordToken.isWord())
57 keyword = keywordToken.wordToken();
60 // If it is the end of the dictionary or file return false...
61 else if (keywordToken == token::END_BLOCK || is.eof())
65 // Otherwise the token is invalid
68 cerr<< "--> FOAM Warning : " << std::endl
70 << "entry::getKeyword(word& keyword, Istream& is)" << std::endl
71 << " in file " << __FILE__
72 << " at line " << __LINE__ << std::endl
73 << " Reading " << is.name().c_str() << std::endl
74 << " found " << keywordToken << std::endl
75 << " expected either " << token::END_BLOCK << " or EOF"
83 bool Foam::entry::New(dictionary& parentDict, Istream& is)
85 is.fatalCheck("entry::New(const dictionary& parentDict, Istream& is)");
89 // Get the next keyword and if invalid return false
90 if (!getKeyword(keyword, is))
94 else // Keyword starts entry ...
96 if (keyword[0] == '#') // ... Function entry
98 word functionName = keyword(1, keyword.size()-1);
99 return functionEntry::execute(functionName, parentDict, is);
101 else if (keyword[0] == '$') // ... Substitution entry
103 parentDict.substituteKeyword(keyword);
106 else if (keyword == "include") // ... For backward compatibility
108 return functionEntries::includeEntry::execute(parentDict, is);
110 else // ... Data entries
113 is.putBack(nextToken);
115 // Deal with duplicate entries
116 bool mergeEntry = false;
118 entry* existingPtr = parentDict.lookupEntryPtr(keyword);
121 if (functionEntries::inputModeEntry::overwrite())
123 // clear dictionary so merge acts like overwrite
124 if (existingPtr->isDict())
126 existingPtr->dict().clear();
130 else if (functionEntries::inputModeEntry::merge())
136 if (nextToken == token::BEGIN_BLOCK)
138 return parentDict.add
140 new dictionaryEntry(keyword, parentDict, is),
146 return parentDict.add
148 new primitiveEntry(keyword, parentDict, is),
157 Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is)
159 is.fatalCheck("entry::New(Istream& is)");
163 // Get the next keyword and if invalid return false
164 if (!getKeyword(keyword, is))
166 return autoPtr<entry>(NULL);
168 else // Keyword starts entry ...
171 is.putBack(nextToken);
173 if (nextToken == token::BEGIN_BLOCK)
175 return autoPtr<entry>
177 new dictionaryEntry(keyword, dictionary::null, is)
182 return autoPtr<entry>
184 new primitiveEntry(keyword, is)
191 // * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * * //
193 Foam::Ostream& Foam::operator<<(Ostream& os, const entry& e)
200 // ************************************************************************* //