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