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