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