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 "dictionary.H"
00027 #include <OpenFOAM/IFstream.H>
00028 #include <OpenFOAM/inputModeEntry.H>
00029 #include <OSspecific/regExp.H>
00030
00031
00032
00033 bool Foam::dictionary::read(Istream& is)
00034 {
00035 if (!is.good())
00036 {
00037 FatalIOErrorIn("dictionary::read(Istream&, const word&)", is)
00038 << "Istream not OK for reading dictionary "
00039 << exit(FatalIOError);
00040
00041 return false;
00042 }
00043
00044 token currToken(is);
00045 if (currToken != token::BEGIN_BLOCK)
00046 {
00047 is.putBack(currToken);
00048 }
00049
00050 while (!is.eof() && entry::New(*this, is))
00051 {}
00052
00053
00054 remove("FoamFile");
00055
00056 if (is.bad())
00057 {
00058 Info<< "dictionary::read(Istream&, const word&) : "
00059 << "Istream not OK after reading dictionary " << name()
00060 << endl;
00061
00062 return false;
00063 }
00064
00065 return true;
00066 }
00067
00068
00069 bool Foam::dictionary::substituteKeyword(const word& keyword)
00070 {
00071 word varName = keyword(1, keyword.size()-1);
00072
00073
00074 const entry* ePtr = lookupEntryPtr(varName, true, true);
00075
00076
00077 if (ePtr != NULL)
00078 {
00079 const dictionary& addDict = ePtr->dict();
00080
00081 forAllConstIter(IDLList<entry>, addDict, iter)
00082 {
00083 add(iter());
00084 }
00085
00086 return true;
00087 }
00088
00089 return false;
00090 }
00091
00092
00093
00094
00095 Foam::dictionary::dictionary
00096 (
00097 const fileName& name,
00098 const dictionary& parentDict,
00099 Istream& is
00100 )
00101 :
00102 dictionaryName(parentDict.name() + "::" + name),
00103 parent_(parentDict)
00104 {
00105 read(is);
00106 }
00107
00108
00109 Foam::dictionary::dictionary(Istream& is)
00110 :
00111 dictionaryName(is.name()),
00112 parent_(dictionary::null)
00113 {
00114
00115 functionEntries::inputModeEntry::clear();
00116
00117 read(is);
00118 }
00119
00120
00121 Foam::autoPtr<Foam::dictionary> Foam::dictionary::New(Istream& is)
00122 {
00123 return autoPtr<dictionary>(new dictionary(is));
00124 }
00125
00126
00127
00128
00129 Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
00130 {
00131
00132 functionEntries::inputModeEntry::clear();
00133
00134 dict.clear();
00135 dict.name() = is.name();
00136 dict.read(is);
00137
00138 return is;
00139 }
00140
00141
00142
00143
00144 void Foam::dictionary::write(Ostream& os, bool subDict) const
00145 {
00146 if (subDict)
00147 {
00148 os << nl << indent << token::BEGIN_BLOCK << incrIndent << nl;
00149 }
00150
00151 forAllConstIter(IDLList<entry>, *this, iter)
00152 {
00153 const entry& e = *iter;
00154
00155
00156 os << e;
00157
00158
00159 if (!subDict && parent() == dictionary::null && e != *last())
00160 {
00161 os << nl;
00162 }
00163
00164
00165 if (!os.good())
00166 {
00167 WarningIn("dictionary::write(Ostream&, bool subDict)")
00168 << "Can't write entry " << iter().keyword()
00169 << " for dictionary " << name()
00170 << endl;
00171 }
00172 }
00173
00174 if (subDict)
00175 {
00176 os << decrIndent << indent << token::END_BLOCK << endl;
00177 }
00178 }
00179
00180
00181 Foam::Ostream& Foam::operator<<(Ostream& os, const dictionary& dict)
00182 {
00183 dict.write(os, true);
00184 return os;
00185 }
00186
00187
00188