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