primitiveEntryIO.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
00028
00029
00030 #include "primitiveEntry.H"
00031 #include "OSspecific.H"
00032 #include "functionEntry.H"
00033
00034
00035
00036 void Foam::primitiveEntry::append
00037 (
00038 const token& currToken,
00039 const dictionary& dict,
00040 Istream& is
00041 )
00042 {
00043 if (currToken.isWord())
00044 {
00045 const word& w = currToken.wordToken();
00046
00047 if
00048 (
00049 w.size() == 1
00050 || (
00051 !(w[0] == '$' && expandVariable(w, dict))
00052 && !(w[0] == '#' && expandFunction(w, dict, is))
00053 )
00054 )
00055 {
00056 newElmt(tokenIndex()++) = currToken;
00057 }
00058 }
00059 else
00060 {
00061 newElmt(tokenIndex()++) = currToken;
00062 }
00063 }
00064
00065
00066 void Foam::primitiveEntry::append(const tokenList& varTokens)
00067 {
00068 forAll(varTokens, i)
00069 {
00070 newElmt(tokenIndex()++) = varTokens[i];
00071 }
00072 }
00073
00074
00075 bool Foam::primitiveEntry::expandVariable
00076 (
00077 const word& w,
00078 const dictionary& dict
00079 )
00080 {
00081 word varName = w(1, w.size()-1);
00082
00083
00084 const entry* ePtr = dict.lookupEntryPtr(varName, true, true);
00085
00086
00087 if (ePtr != NULL)
00088 {
00089 append(ePtr->stream());
00090 return true;
00091 }
00092 else
00093 {
00094
00095
00096
00097 string enVarString = getEnv(varName);
00098
00099 if (enVarString.size())
00100 {
00101 append(tokenList(IStringStream('(' + enVarString + ')')()));
00102 return true;
00103 }
00104
00105 return false;
00106 }
00107 }
00108
00109
00110 bool Foam::primitiveEntry::expandFunction
00111 (
00112 const word& keyword,
00113 const dictionary& parentDict,
00114 Istream& is
00115 )
00116 {
00117 word functionName = keyword(1, keyword.size()-1);
00118 return functionEntry::execute(functionName, parentDict, *this, is);
00119 }
00120
00121
00122 bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
00123 {
00124 is.fatalCheck
00125 (
00126 "primitiveEntry::readData(const dictionary&, Istream&)"
00127 );
00128
00129 label blockCount = 0;
00130 token currToken;
00131
00132 if
00133 (
00134 !is.read(currToken).bad()
00135 && currToken.good()
00136 && currToken != token::END_STATEMENT
00137 )
00138 {
00139 append(currToken, dict, is);
00140
00141 if
00142 (
00143 currToken == token::BEGIN_BLOCK
00144 || currToken == token::BEGIN_LIST
00145 )
00146 {
00147 blockCount++;
00148 }
00149
00150 while
00151 (
00152 !is.read(currToken).bad()
00153 && currToken.good()
00154 && !(currToken == token::END_STATEMENT && blockCount == 0)
00155 )
00156 {
00157 if
00158 (
00159 currToken == token::BEGIN_BLOCK
00160 || currToken == token::BEGIN_LIST
00161 )
00162 {
00163 blockCount++;
00164 }
00165 else if
00166 (
00167 currToken == token::END_BLOCK
00168 || currToken == token::END_LIST
00169 )
00170 {
00171 blockCount--;
00172 }
00173
00174 append(currToken, dict, is);
00175 }
00176 }
00177
00178 is.fatalCheck
00179 (
00180 "primitiveEntry::readData(const dictionary&, Istream&)"
00181 );
00182
00183 if (currToken.good())
00184 {
00185 return true;
00186 }
00187 else
00188 {
00189 return false;
00190 }
00191 }
00192
00193
00194 void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is)
00195 {
00196 label keywordLineNumber = is.lineNumber();
00197 tokenIndex() = 0;
00198
00199 if (read(dict, is))
00200 {
00201 setSize(tokenIndex());
00202 tokenIndex() = 0;
00203 }
00204 else
00205 {
00206 FatalIOErrorIn
00207 (
00208 "primitiveEntry::readEntry(const dictionary&, Istream&)",
00209 is
00210 ) << "ill defined primitiveEntry starting at keyword '"
00211 << keyword() << '\''
00212 << " on line " << keywordLineNumber
00213 << " and ending at line " << is.lineNumber()
00214 << exit(FatalIOError);
00215 }
00216 }
00217
00218
00219 Foam::primitiveEntry::primitiveEntry
00220 (
00221 const keyType& key,
00222 const dictionary& dict,
00223 Istream& is
00224 )
00225 :
00226 entry(key),
00227 ITstream
00228 (
00229 is.name() + "::" + key,
00230 tokenList(10),
00231 is.format(),
00232 is.version()
00233 )
00234 {
00235 readEntry(dict, is);
00236 }
00237
00238
00239 Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is)
00240 :
00241 entry(key),
00242 ITstream
00243 (
00244 is.name() + "::" + key,
00245 tokenList(10),
00246 is.format(),
00247 is.version()
00248 )
00249 {
00250 readEntry(dictionary::null, is);
00251 }
00252
00253
00254
00255
00256 void Foam::primitiveEntry::write(Ostream& os) const
00257 {
00258 os.writeKeyword(keyword());
00259
00260 for (label i=0; i<size(); i++)
00261 {
00262 os << operator[](i);
00263
00264 if (i < size()-1)
00265 {
00266 os << token::SPACE;
00267 }
00268 }
00269
00270 os << token::END_STATEMENT << endl;
00271 }
00272
00273
00274
00275
00276 template<>
00277 Foam::Ostream& Foam::operator<<
00278 (
00279 Ostream& os,
00280 const InfoProxy<primitiveEntry>& ip
00281 )
00282 {
00283 const primitiveEntry& e = ip.t_;
00284
00285 e.print(os);
00286
00287 const label nPrintTokens = 10;
00288
00289 os << " primitiveEntry '" << e.keyword() << "' comprises ";
00290
00291 for (label i=0; i<min(e.size(), nPrintTokens); i++)
00292 {
00293 os << nl << " " << e[i].info();
00294 }
00295
00296 if (e.size() > nPrintTokens)
00297 {
00298 os << " ...";
00299 }
00300
00301 os << endl;
00302
00303 return os;
00304 }
00305
00306
00307
Copyright © 2000-2009 OpenCFD Ltd