IOobjectList.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 "IOobjectList.H"
00028 #include "Time.H"
00029 #include "OSspecific.H"
00030
00031
00032
00033
00034 Foam::IOobjectList::IOobjectList(const label nIoObjects)
00035 :
00036 HashPtrTable<IOobject>(nIoObjects)
00037 {}
00038
00039
00040 Foam::IOobjectList::IOobjectList
00041 (
00042 const objectRegistry& db,
00043 const fileName& instance,
00044 const fileName& local
00045 )
00046 :
00047 HashPtrTable<IOobject>()
00048 {
00049 word newInstance = instance;
00050
00051 if (!isDir(db.path(instance)))
00052 {
00053 newInstance = db.time().findInstancePath(instant(instance));
00054
00055 if (newInstance.empty())
00056 {
00057 return;
00058 }
00059 }
00060
00061
00062 fileNameList ObjectNames =
00063 readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
00064
00065 forAll(ObjectNames, i)
00066 {
00067 IOobject* objectPtr = new IOobject
00068 (
00069 ObjectNames[i],
00070 newInstance,
00071 local,
00072 db,
00073 IOobject::MUST_READ,
00074 IOobject::NO_WRITE
00075 );
00076
00077 if (objectPtr->headerOk())
00078 {
00079 insert(ObjectNames[i], objectPtr);
00080 }
00081 else
00082 {
00083 delete objectPtr;
00084 }
00085 }
00086 }
00087
00088
00089 Foam::IOobjectList::IOobjectList(const IOobjectList& ioOL)
00090 :
00091 HashPtrTable<IOobject>(ioOL)
00092 {}
00093
00094
00095
00096
00097 Foam::IOobjectList::~IOobjectList()
00098 {}
00099
00100
00101
00102
00103 bool Foam::IOobjectList::add(IOobject& io)
00104 {
00105 return insert(io.name(), &io);
00106 }
00107
00108
00109 bool Foam::IOobjectList::remove(IOobject& io)
00110 {
00111 HashPtrTable<IOobject>::iterator iter =
00112 HashPtrTable<IOobject>::find(io.name());
00113
00114 if (iter != end())
00115 {
00116 return erase(iter);
00117 }
00118 else
00119 {
00120 return false;
00121 }
00122 }
00123
00124
00125 Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
00126 {
00127 HashPtrTable<IOobject>::const_iterator iter = find(name);
00128
00129 if (iter != end())
00130 {
00131 if (IOobject::debug)
00132 {
00133 Info<< "IOobjectList::lookup : found " << name
00134 << endl;
00135 }
00136
00137 return const_cast<IOobject*>(*iter);
00138 }
00139 else
00140 {
00141 if (IOobject::debug)
00142 {
00143 Info<< "IOobjectList::lookup : could not find " << name
00144 << endl;
00145 }
00146
00147 return NULL;
00148 }
00149 }
00150
00151
00152 Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const
00153 {
00154 IOobjectList IOobjectsOfClass(size());
00155
00156 for
00157 (
00158 HashPtrTable<IOobject>::const_iterator iter = begin();
00159 iter != end();
00160 ++iter
00161 )
00162 {
00163 if (iter()->headerClassName() == ClassName)
00164 {
00165 if (IOobject::debug)
00166 {
00167 Info<< "IOobjectList::lookupClass : found "
00168 << iter()->name()
00169 << endl;
00170 }
00171
00172 IOobjectsOfClass.insert(iter()->name(), new IOobject(*iter()));
00173 }
00174 }
00175
00176 return IOobjectsOfClass;
00177 }
00178
00179
00180 Foam::wordList Foam::IOobjectList::names() const
00181 {
00182 wordList objectNames(size());
00183
00184 label count = 0;
00185 for
00186 (
00187 HashPtrTable<IOobject>::const_iterator iter = begin();
00188 iter != end();
00189 ++iter
00190 )
00191 {
00192 objectNames[count++] = iter()->name();
00193 }
00194
00195 return objectNames;
00196 }
00197
00198
00199 Foam::wordList Foam::IOobjectList::names(const word& ClassName) const
00200 {
00201 wordList objectNames(size());
00202
00203 label count = 0;
00204 for
00205 (
00206 HashPtrTable<IOobject>::const_iterator iter = begin();
00207 iter != end();
00208 ++iter
00209 )
00210 {
00211 if (iter()->headerClassName() == ClassName)
00212 {
00213 objectNames[count++] = iter()->name();
00214 }
00215 }
00216
00217 objectNames.setSize(count);
00218
00219 return objectNames;
00220 }
00221
00222
00223
Copyright © 2000-2009 OpenCFD Ltd