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