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 "FixedList.H"
00027 #include <OpenFOAM/Istream.H>
00028 #include <OpenFOAM/Ostream.H>
00029 #include <OpenFOAM/token.H>
00030 #include <OpenFOAM/contiguous.H>
00031
00032
00033
00034 template<class T, unsigned Size>
00035 Foam::FixedList<T, Size>::FixedList(Istream& is)
00036 {
00037 operator>>(is, *this);
00038 }
00039
00040
00041 template<class T, unsigned Size>
00042 Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
00043 {
00044 is.fatalCheck("operator>>(Istream&, FixedList<T, Size>&)");
00045
00046 if (is.format() == IOstream::ASCII || !contiguous<T>())
00047 {
00048 token firstToken(is);
00049
00050 is.fatalCheck
00051 (
00052 "operator>>(Istream&, FixedList<T, Size>&) : reading first token"
00053 );
00054
00055 if (firstToken.isCompound())
00056 {
00057 L = dynamicCast<token::Compound<List<T> > >
00058 (
00059 firstToken.transferCompoundToken()
00060 );
00061 }
00062 else if (firstToken.isLabel())
00063 {
00064 label s = firstToken.labelToken();
00065
00066
00067 L.checkSize(s);
00068 }
00069 else if (!firstToken.isPunctuation())
00070 {
00071 FatalIOErrorIn("operator>>(Istream&, FixedList<T, Size>&)", is)
00072 << "incorrect first token, expected <label> "
00073 "or '(' or '{', found "
00074 << firstToken.info()
00075 << exit(FatalIOError);
00076 }
00077 else
00078 {
00079
00080 is.putBack(firstToken);
00081 }
00082
00083
00084 char delimiter = is.readBeginList("FixedList");
00085
00086 if (delimiter == token::BEGIN_LIST)
00087 {
00088 for (register unsigned i=0; i<Size; i++)
00089 {
00090 is >> L[i];
00091
00092 is.fatalCheck
00093 (
00094 "operator>>(Istream&, FixedList<T, Size>&) : "
00095 "reading entry"
00096 );
00097 }
00098 }
00099 else
00100 {
00101 T element;
00102 is >> element;
00103
00104 is.fatalCheck
00105 (
00106 "operator>>(Istream&, FixedList<T, Size>&) : "
00107 "reading the single entry"
00108 );
00109
00110 for (register unsigned i=0; i<Size; i++)
00111 {
00112 L[i] = element;
00113 }
00114 }
00115
00116
00117 is.readEndList("FixedList");
00118 }
00119 else
00120 {
00121 is.read(reinterpret_cast<char*>(L.data()), Size*sizeof(T));
00122
00123 is.fatalCheck
00124 (
00125 "operator>>(Istream&, FixedList<T, Size>&) : "
00126 "reading the binary block"
00127 );
00128 }
00129
00130 return is;
00131 }
00132
00133
00134
00135
00136 template<class T, unsigned Size>
00137 void Foam::FixedList<T, Size>::writeEntry(Ostream& os) const
00138 {
00139 if
00140 (
00141 size()
00142 && token::compound::isCompound
00143 (
00144 "List<" + word(pTraits<T>::typeName) + '>'
00145 )
00146 )
00147 {
00148 os << word("List<" + word(pTraits<T>::typeName) + '>') << " ";
00149 }
00150
00151 os << *this;
00152 }
00153
00154
00155 template<class T, unsigned Size>
00156 void Foam::FixedList<T, Size>::writeEntry
00157 (
00158 const word& keyword,
00159 Ostream& os
00160 ) const
00161 {
00162 os.writeKeyword(keyword);
00163 writeEntry(os);
00164 os << token::END_STATEMENT << endl;
00165 }
00166
00167
00168 template<class T, unsigned Size>
00169 Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
00170 {
00171
00172 if (os.format() == IOstream::ASCII || !contiguous<T>())
00173 {
00174 bool uniform = false;
00175
00176 if (Size > 1 && contiguous<T>())
00177 {
00178 uniform = true;
00179
00180 forAll(L, i)
00181 {
00182 if (L[i] != L[0])
00183 {
00184 uniform = false;
00185 break;
00186 }
00187 }
00188 }
00189
00190 if (uniform)
00191 {
00192
00193 os << L.size() << token::BEGIN_BLOCK;
00194
00195
00196 os << L[0];
00197
00198
00199 os << token::END_BLOCK;
00200 }
00201 else if (Size < 11 && contiguous<T>())
00202 {
00203
00204 os << token::BEGIN_LIST;
00205
00206
00207 forAll(L, i)
00208 {
00209 if (i > 0) os << token::SPACE;
00210 os << L[i];
00211 }
00212
00213
00214 os << token::END_LIST;
00215 }
00216 else
00217 {
00218
00219 os << nl << token::BEGIN_LIST;
00220
00221
00222 forAll(L, i)
00223 {
00224 os << nl << L[i];
00225 }
00226
00227
00228 os << nl << token::END_LIST << nl;
00229 }
00230 }
00231 else
00232 {
00233 os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
00234 }
00235
00236
00237 os.check("Ostream& operator<<(Ostream&, const FixedList&)");
00238
00239 return os;
00240 }
00241
00242
00243