Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <OpenFOAM/primitiveEntry.H>
00027 #include <OpenFOAM/dictionaryEntry.H>
00028 #include <OpenFOAM/functionEntry.H>
00029 #include <OpenFOAM/includeEntry.H>
00030 #include <OpenFOAM/inputModeEntry.H>
00031
00032
00033
00034 bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
00035 {
00036 token keywordToken;
00037
00038
00039 do
00040 {
00041 if
00042 (
00043 is.read(keywordToken).bad()
00044 || is.eof()
00045 || !keywordToken.good()
00046 )
00047 {
00048 return false;
00049 }
00050 }
00051 while (keywordToken == token::END_STATEMENT);
00052
00053
00054 if (keywordToken.isWord())
00055 {
00056 keyword = keywordToken.wordToken();
00057 return true;
00058 }
00059 else if (keywordToken.isString())
00060 {
00061
00062 keyword = keywordToken.stringToken();
00063 return true;
00064 }
00065
00066 else if (keywordToken == token::END_BLOCK || is.eof())
00067 {
00068 return false;
00069 }
00070
00071 else
00072 {
00073 cerr<< "--> FOAM Warning : " << std::endl
00074 << " From function "
00075 << "entry::getKeyword(keyType&, Istream&)" << std::endl
00076 << " in file " << __FILE__
00077 << " at line " << __LINE__ << std::endl
00078 << " Reading " << is.name().c_str() << std::endl
00079 << " found " << keywordToken << std::endl
00080 << " expected either " << token::END_BLOCK << " or EOF"
00081 << std::endl;
00082
00083 return false;
00084 }
00085 }
00086
00087
00088 bool Foam::entry::New(dictionary& parentDict, Istream& is)
00089 {
00090 is.fatalCheck("entry::New(const dictionary& parentDict, Istream&)");
00091
00092 keyType keyword;
00093
00094
00095 if (!getKeyword(keyword, is))
00096 {
00097 return false;
00098 }
00099 else
00100 {
00101 if (keyword[0] == '#')
00102 {
00103 word functionName = keyword(1, keyword.size()-1);
00104 return functionEntry::execute(functionName, parentDict, is);
00105 }
00106 else if (keyword[0] == '$')
00107 {
00108 parentDict.substituteKeyword(keyword);
00109 return true;
00110 }
00111 else if (keyword == "include")
00112 {
00113 return functionEntries::includeEntry::execute(parentDict, is);
00114 }
00115 else
00116 {
00117 token nextToken(is);
00118 is.putBack(nextToken);
00119
00120
00121 bool mergeEntry = false;
00122
00123
00124 entry* existingPtr = parentDict.lookupEntryPtr
00125 (
00126 keyword,
00127 false,
00128 false
00129 );
00130
00131 if (existingPtr)
00132 {
00133 if (functionEntries::inputModeEntry::merge())
00134 {
00135 mergeEntry = true;
00136 }
00137 else if (functionEntries::inputModeEntry::overwrite())
00138 {
00139
00140 if (existingPtr->isDict())
00141 {
00142 existingPtr->dict().clear();
00143 }
00144 mergeEntry = true;
00145 }
00146 else if (functionEntries::inputModeEntry::protect())
00147 {
00148
00149 if (nextToken == token::BEGIN_BLOCK)
00150 {
00151 dictionaryEntry dummy(keyword, parentDict, is);
00152 }
00153 else
00154 {
00155 primitiveEntry dummy(keyword, parentDict, is);
00156 }
00157 return true;
00158 }
00159 else if (functionEntries::inputModeEntry::error())
00160 {
00161 FatalIOErrorIn
00162 (
00163 "entry::New(const dictionary& parentDict, Istream&)",
00164 is
00165 )
00166 << "ERROR! duplicate entry: " << keyword
00167 << exit(FatalIOError);
00168
00169 return false;
00170 }
00171 }
00172
00173 if (nextToken == token::BEGIN_BLOCK)
00174 {
00175 return parentDict.add
00176 (
00177 new dictionaryEntry(keyword, parentDict, is),
00178 mergeEntry
00179 );
00180 }
00181 else
00182 {
00183 return parentDict.add
00184 (
00185 new primitiveEntry(keyword, parentDict, is),
00186 mergeEntry
00187 );
00188 }
00189 }
00190 }
00191 }
00192
00193
00194 Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is)
00195 {
00196 is.fatalCheck("entry::New(Istream&)");
00197
00198 keyType keyword;
00199
00200
00201 if (!getKeyword(keyword, is))
00202 {
00203 return autoPtr<entry>(NULL);
00204 }
00205 else
00206 {
00207 token nextToken(is);
00208 is.putBack(nextToken);
00209
00210 if (nextToken == token::BEGIN_BLOCK)
00211 {
00212 return autoPtr<entry>
00213 (
00214 new dictionaryEntry(keyword, dictionary::null, is)
00215 );
00216 }
00217 else
00218 {
00219 return autoPtr<entry>
00220 (
00221 new primitiveEntry(keyword, is)
00222 );
00223 }
00224 }
00225 }
00226
00227
00228
00229
00230 Foam::Ostream& Foam::operator<<(Ostream& os, const entry& e)
00231 {
00232 e.write(os);
00233 return os;
00234 }
00235
00236
00237