void Foam::UList<double>::writeNonUniform(Ostream& os) const { //Pout<< "width:" << os.width() << endl; //Pout<< "precision:" << os.precision() << endl; //Pout<< "fmtflags:" << os.flags() << endl; //Pout<< "boolalpha:" << (os.flags() & ios_base::boolalpha) << endl; //Pout<< "showbase:" << (os.flags() & ios_base::showbase) << endl; //Pout<< "showpoint:" << (os.flags() & ios_base::showpoint) << endl; //Pout<< "showpos:" << (os.flags() & ios_base::showpos) << endl; //Pout<< "skipws:" << (os.flags() & ios_base::skipws) << endl; //Pout<< "unitbuf:" << (os.flags() & ios_base::unitbuf) << endl; //Pout<< "uppercase:" << (os.flags() & ios_base::uppercase) << endl; // //Pout<< "dec:" << (os.flags() & ios_base::showbase) << endl; //Pout<< "hex:" << (os.flags() & ios_base::hex) << endl; //Pout<< "oct:" << (os.flags() & ios_base::oct) << endl; // //Pout<< "fixed:" << (os.flags() & ios_base::fixed) << endl; //Pout<< "scientific:" << (os.flags() & ios_base::scientific) << endl; // //Pout<< "internal:" << (os.flags() & ios_base::internal) << endl; //Pout<< "left:" << (os.flags() & ios_base::left) << endl; //Pout<< "right:" << (os.flags() & ios_base::right) << endl; const Foam::UList<double>& L = *this; // Write size and start delimiter os << nl << L.size() << nl << token::BEGIN_LIST; if ( (os.width() == 0) && !(os.flags() & ios_base::showbase) && !(os.flags() & ios_base::showpoint) && !(os.flags() & ios_base::showpos) && !(os.flags() & ios_base::unitbuf) && !(os.flags() & ios_base::uppercase) && !(os.flags() & ios_base::hex) && !(os.flags() & ios_base::oct) && !(os.flags() & ios_base::fixed) && !(os.flags() & ios_base::scientific) && !(os.flags() & ios_base::internal) && !(os.flags() & ios_base::right) && isA<OFstream>(os) ) { OFstream& ofs = dynamic_cast<OFstream&>(os); // Can do optimised Pout<< "Optimised" << endl; const string singleFmt("\n%-." + Foam::name(ofs.precision()) + "lg"); string fmt; for (int i = 0; i < 8; i++) { fmt += singleFmt; } //Pout<< "Format string:" << fmt << endl; const char* fmt_ptr = fmt.c_str(); const int bufLen = 4096; char buf[bufLen]; int free = 0; label i = 0; for (label outer = 0; outer < L.size()/8; outer++) { const int nFree = bufLen-free; int n = snprintf ( &buf[free], nFree, fmt_ptr, L[i], L[i+1], L[i+2], L[i+3], L[i+4], L[i+5], L[i+6], L[i+7] ); if (n >= nFree) { // Failed. Flush buffer so far ofs.stdStream().write(buf, free); free = 0; // Re-print current entry (assume it succeeds) n = snprintf ( &buf[free], bufLen-free, fmt_ptr, L[i], L[i+1], L[i+2], L[i+3], L[i+4], L[i+5], L[i+6], L[i+7] ); } i += 8; free += n; } // Do remainder element by element const char* sptr = singleFmt.c_str(); while (i < L.size()) { const int nFree = bufLen-free; int n = snprintf(&buf[free], nFree, sptr, L[i]); if (n >= nFree) { ofs.stdStream().write(buf, free); free = 0; // Re-print current entry n = snprintf(&buf[free], bufLen-free, sptr, L[i]); } free += n; i++; } if (free > 0) { ofs.stdStream().write(buf, free); } } else { // Write contents forAll(L, i) { os << nl << L[i]; } } // Write end delimiter os << nl << token::END_LIST << nl; }
void Foam::UList<Foam::Vector<double>>::writeNonUniform(Ostream& os) const { //Pout<< "width:" << os.width() << endl; //Pout<< "precision:" << os.precision() << endl; //Pout<< "fmtflags:" << os.flags() << endl; //Pout<< "boolalpha:" << (os.flags() & ios_base::boolalpha) << endl; //Pout<< "showbase:" << (os.flags() & ios_base::showbase) << endl; //Pout<< "showpoint:" << (os.flags() & ios_base::showpoint) << endl; //Pout<< "showpos:" << (os.flags() & ios_base::showpos) << endl; //Pout<< "skipws:" << (os.flags() & ios_base::skipws) << endl; //Pout<< "unitbuf:" << (os.flags() & ios_base::unitbuf) << endl; //Pout<< "uppercase:" << (os.flags() & ios_base::uppercase) << endl; // //Pout<< "dec:" << (os.flags() & ios_base::showbase) << endl; //Pout<< "hex:" << (os.flags() & ios_base::hex) << endl; //Pout<< "oct:" << (os.flags() & ios_base::oct) << endl; // //Pout<< "fixed:" << (os.flags() & ios_base::fixed) << endl; //Pout<< "scientific:" << (os.flags() & ios_base::scientific) << endl; // //Pout<< "internal:" << (os.flags() & ios_base::internal) << endl; //Pout<< "left:" << (os.flags() & ios_base::left) << endl; //Pout<< "right:" << (os.flags() & ios_base::right) << endl; const Foam::UList<Vector<double>>& L = *this; // Write size and start delimiter os << nl << L.size() << nl << token::BEGIN_LIST; if ( (os.width() == 0) && !(os.flags() & ios_base::showbase) && !(os.flags() & ios_base::showpoint) && !(os.flags() & ios_base::showpos) && !(os.flags() & ios_base::unitbuf) && !(os.flags() & ios_base::uppercase) && !(os.flags() & ios_base::hex) && !(os.flags() & ios_base::oct) && !(os.flags() & ios_base::fixed) && !(os.flags() & ios_base::scientific) && !(os.flags() & ios_base::internal) && !(os.flags() & ios_base::right) && isA<OFstream>(os) ) { OFstream& ofs = dynamic_cast<OFstream&>(os); // Can do optimised Pout<< "Optimised" << endl; const string sFmt("%-." + Foam::name(ofs.precision()) + "lg"); string fmt("\n("+sFmt+' '+sFmt+' '+sFmt+')'); Pout<< "Format string:" << fmt << endl; const char* fmt_ptr = fmt.c_str(); const int bufLen = 4096; char buf[bufLen]; int free = 0; forAll(L, i) { const Vector<double>& p = L[i]; const int nFree = bufLen-free; int n = snprintf(&buf[free], nFree, fmt_ptr, p.x(), p.y(), p.z()); if (n >= nFree) { ofs.stdStream().write(buf, free); free = 0; // Re-print current entry n = snprintf(&buf[free], bufLen, fmt_ptr, p.x(), p.y(), p.z()); } free += n; } if (free > 0) { ofs.stdStream().write(buf, free); } }