functionObjectList.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 "functionObjectList.H"
00028 #include "Time.H"
00029
00030
00031
00032 Foam::functionObject*
00033 Foam::functionObjectList::remove(const word& key, label& oldIndex)
00034 {
00035 functionObject* ptr = 0;
00036
00037
00038 HashTable<label>::iterator fnd = indices_.find(key);
00039
00040 if (fnd != indices_.end())
00041 {
00042 oldIndex = fnd();
00043
00044
00045 ptr = this->set(oldIndex, 0).ptr();
00046 indices_.erase(fnd);
00047 }
00048 else
00049 {
00050 oldIndex = -1;
00051 }
00052
00053 return ptr;
00054 }
00055
00056
00057
00058
00059 Foam::functionObjectList::functionObjectList
00060 (
00061 const Time& t,
00062 const bool execution
00063 )
00064 :
00065 PtrList<functionObject>(),
00066 digests_(),
00067 indices_(),
00068 time_(t),
00069 parentDict_(t.controlDict()),
00070 execution_(execution),
00071 updated_(false)
00072 {}
00073
00074
00075 Foam::functionObjectList::functionObjectList
00076 (
00077 const Time& t,
00078 const dictionary& parentDict,
00079 const bool execution
00080 )
00081 :
00082 PtrList<functionObject>(),
00083 digests_(),
00084 indices_(),
00085 time_(t),
00086 parentDict_(parentDict),
00087 execution_(execution),
00088 updated_(false)
00089 {}
00090
00091
00092
00093
00094 Foam::functionObjectList::~functionObjectList()
00095 {}
00096
00097
00098
00099
00100 void Foam::functionObjectList::clear()
00101 {
00102 PtrList<functionObject>::clear();
00103 digests_.clear();
00104 indices_.clear();
00105 updated_ = false;
00106 }
00107
00108
00109 void Foam::functionObjectList::on()
00110 {
00111 execution_ = true;
00112 }
00113
00114
00115 void Foam::functionObjectList::off()
00116 {
00117
00118 updated_ = execution_ = false;
00119 }
00120
00121
00122 bool Foam::functionObjectList::status() const
00123 {
00124 return execution_;
00125 }
00126
00127
00128 bool Foam::functionObjectList::start()
00129 {
00130 return read();
00131 }
00132
00133
00134 bool Foam::functionObjectList::execute()
00135 {
00136 bool ok = true;
00137
00138 if (execution_)
00139 {
00140 if (!updated_)
00141 {
00142 read();
00143 }
00144
00145 forAllIter
00146 (
00147 PtrList<functionObject>,
00148 static_cast<PtrList<functionObject>&>(*this),
00149 iter
00150 )
00151 {
00152 ok = iter().execute() && ok;
00153 }
00154 }
00155
00156 return ok;
00157 }
00158
00159
00160 bool Foam::functionObjectList::end()
00161 {
00162 bool ok = true;
00163
00164 if (execution_)
00165 {
00166 if (!updated_)
00167 {
00168 read();
00169 }
00170
00171 forAllIter
00172 (
00173 PtrList<functionObject>,
00174 static_cast<PtrList<functionObject>&>(*this),
00175 iter
00176 )
00177 {
00178 ok = iter().end() && ok;
00179 }
00180 }
00181
00182 return ok;
00183 }
00184
00185
00186 bool Foam::functionObjectList::read()
00187 {
00188 bool ok = true;
00189 updated_ = execution_;
00190
00191
00192 if (!execution_)
00193 {
00194 return ok;
00195 }
00196
00197
00198 const entry* entryPtr = parentDict_.lookupEntryPtr("functions",false,false);
00199 if (entryPtr)
00200 {
00201 PtrList<functionObject> newPtrs;
00202 List<SHA1Digest> newDigs;
00203 HashTable<label> newIndices;
00204
00205 label nFunc = 0;
00206
00207 if (entryPtr->isDict())
00208 {
00209
00210 const dictionary& functionDicts = entryPtr->dict();
00211
00212 newPtrs.setSize(functionDicts.size());
00213 newDigs.setSize(functionDicts.size());
00214
00215 forAllConstIter(dictionary, functionDicts, iter)
00216 {
00217
00218 if (!iter().isDict())
00219 {
00220 continue;
00221 }
00222 const word& key = iter().keyword();
00223 const dictionary& dict = iter().dict();
00224
00225 newDigs[nFunc] = dict.digest();
00226
00227 label oldIndex;
00228 functionObject* objPtr = remove(key, oldIndex);
00229 if (objPtr)
00230 {
00231
00232 if (newDigs[nFunc] != digests_[oldIndex])
00233 {
00234 ok = objPtr->read(dict) && ok;
00235 }
00236 }
00237 else
00238 {
00239
00240 objPtr = functionObject::New(key, time_, dict).ptr();
00241 ok = objPtr->start() && ok;
00242 }
00243
00244 newPtrs.set(nFunc, objPtr);
00245 newIndices.insert(key, nFunc);
00246 nFunc++;
00247 }
00248 }
00249 else
00250 {
00251
00252 PtrList<entry> functionDicts(entryPtr->stream());
00253
00254 newPtrs.setSize(functionDicts.size());
00255 newDigs.setSize(functionDicts.size());
00256
00257 forAllIter(PtrList<entry>, functionDicts, iter)
00258 {
00259
00260 if (!iter().isDict())
00261 {
00262 continue;
00263 }
00264 const word& key = iter().keyword();
00265 const dictionary& dict = iter().dict();
00266
00267 newDigs[nFunc] = dict.digest();
00268
00269 label oldIndex;
00270 functionObject* objPtr = remove(key, oldIndex);
00271 if (objPtr)
00272 {
00273
00274 if (newDigs[nFunc] != digests_[oldIndex])
00275 {
00276 ok = objPtr->read(dict) && ok;
00277 }
00278 }
00279 else
00280 {
00281
00282 objPtr = functionObject::New(key, time_, dict).ptr();
00283 ok = objPtr->start() && ok;
00284 }
00285
00286 newPtrs.set(nFunc, objPtr);
00287 newIndices.insert(key, nFunc);
00288 nFunc++;
00289 }
00290 }
00291
00292
00293 newPtrs.setSize(nFunc);
00294 newDigs.setSize(nFunc);
00295
00296
00297
00298 PtrList<functionObject>::transfer(newPtrs);
00299 digests_.transfer(newDigs);
00300 indices_.transfer(newIndices);
00301 }
00302 else
00303 {
00304 PtrList<functionObject>::clear();
00305 digests_.clear();
00306 indices_.clear();
00307 }
00308
00309 return ok;
00310 }
00311
00312
00313
Copyright © 2000-2009 OpenCFD Ltd