PtrListIO.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 "PtrList.H"
00028 #include "SLList.H"
00029 #include "Istream.H"
00030 #include "Ostream.H"
00031 #include "INew.H"
00032
00033
00034
00035 template<class T>
00036 template<class INew>
00037 void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
00038 {
00039 is.fatalCheck("PtrList<T>::read(Istream&, const INew&)");
00040
00041 token firstToken(is);
00042
00043 is.fatalCheck
00044 (
00045 "PtrList<T>::read(Istream&, const INew&) : "
00046 "reading first token"
00047 );
00048
00049 if (firstToken.isLabel())
00050 {
00051
00052 label s = firstToken.labelToken();
00053
00054 setSize(s);
00055
00056
00057 char delimiter = is.readBeginList("PtrList");
00058
00059 if (s)
00060 {
00061 if (delimiter == token::BEGIN_LIST)
00062 {
00063 forAll(*this, i)
00064 {
00065 set(i, inewt(is));
00066
00067 is.fatalCheck
00068 (
00069 "PtrList<T>::read(Istream&, const INew&) : "
00070 "reading entry"
00071 );
00072 }
00073 }
00074 else
00075 {
00076 T* tPtr = inewt(is).ptr();
00077 set(0, tPtr);
00078
00079 is.fatalCheck
00080 (
00081 "PtrList<T>::read(Istream&, const INew&) : "
00082 "reading the single entry"
00083 );
00084
00085 for (label i=1; i<s; i++)
00086 {
00087 set(i, tPtr->clone());
00088 }
00089 }
00090 }
00091
00092
00093 is.readEndList("PtrList");
00094 }
00095 else if (firstToken.isPunctuation())
00096 {
00097 if (firstToken.pToken() != token::BEGIN_LIST)
00098 {
00099 FatalIOErrorIn
00100 (
00101 "PtrList<T>::read(Istream&, const INew&)",
00102 is
00103 ) << "incorrect first token, '(', found " << firstToken.info()
00104 << exit(FatalIOError);
00105 }
00106
00107 SLList<T*> sllPtrs;
00108
00109 token lastToken(is);
00110 while
00111 (
00112 !(
00113 lastToken.isPunctuation()
00114 && lastToken.pToken() == token::END_LIST
00115 )
00116 )
00117 {
00118 is.putBack(lastToken);
00119 sllPtrs.append(inewt(is).ptr());
00120 is >> lastToken;
00121 }
00122
00123 setSize(sllPtrs.size());
00124
00125 label i = 0;
00126 for
00127 (
00128 typename SLList<T*>::iterator iter = sllPtrs.begin();
00129 iter != sllPtrs.end();
00130 ++iter
00131 )
00132 {
00133 set(i++, iter());
00134 }
00135 }
00136 else
00137 {
00138 FatalIOErrorIn
00139 (
00140 "PtrList<T>::read(Istream&, const INew&)",
00141 is
00142 ) << "incorrect first token, expected <int> or '(', found "
00143 << firstToken.info()
00144 << exit(FatalIOError);
00145 }
00146 }
00147
00148
00149
00150
00151 template<class T>
00152 template<class INew>
00153 Foam::PtrList<T>::PtrList(Istream& is, const INew& inewt)
00154 {
00155 read(is, inewt);
00156 }
00157
00158
00159 template<class T>
00160 Foam::PtrList<T>::PtrList(Istream& is)
00161 {
00162 read(is, INew<T>());
00163 }
00164
00165
00166
00167
00168 template<class T>
00169 Foam::Istream& Foam::operator>>(Istream& is, PtrList<T>& L)
00170 {
00171 L.clear();
00172 L.read(is, INew<T>());
00173
00174 return is;
00175 }
00176
00177
00178
00179
00180 template<class T>
00181 Foam::Ostream& Foam::operator<<(Ostream& os, const PtrList<T>& L)
00182 {
00183
00184 os << nl << L.size() << nl << token::BEGIN_LIST;
00185
00186
00187 forAll(L, i)
00188 {
00189 os << nl << L[i];
00190 }
00191
00192
00193 os << nl << token::END_LIST << nl;
00194
00195
00196 os.check("Ostream& operator<<(Ostream&, const PtrList&)");
00197
00198 return os;
00199 }
00200
00201
00202
Copyright © 2000-2009 OpenCFD Ltd