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