void printstate(const std::ios &ios) { if (ios.good()) { std::cout << "ios.good" << std::endl; } else if (ios.eof()){ std::cout << "ios.eof" << std::endl; } else if (ios.fail()){ std::cout << "ios.fail" << std::endl; } else if (ios.bad()){ std::cout << "ios.bad" << std::endl; } }
void throwIfNotGood(const std::ios& stream, const std::string& file) { if (!stream.good()) { std::stringstream ss; ss << "Cannot open file " << file; throw std::runtime_error(ss.str()); } }
void show_results( std::ios& stm ) { std::cout << std::boolalpha << "bad: " << stm.bad() << " fail: " << stm.fail() << " eof: " << stm.eof() << " good: " << stm.good() << " bool(stm): " << bool(stm) << " !stm: " << !stm << '\n' ; }
void print_state (const std::ios& stream) { std::cout << " good()=" << stream.good(); std::cout << " eof()=" << stream.eof(); std::cout << " fail()=" << stream.fail(); std::cout << " bad()=" << stream.bad(); }
int main(int, char**) { const std::ios ios(0); assert(ios.fill() == ' '); return 0; }
void DenseLinAlgPack::LinAlgPackIO::ios_format_memento::set_format(std::ios& s) const { s.flags(flags_); s.precision(prec_); s.width(wdt_); s.fill(fill_); }
DenseLinAlgPack::LinAlgPackIO::ios_format_memento DenseLinAlgPack::LinAlgPackIO::ios_format_memento::save_format(const std::ios& s) { ios_format_memento m; m.flags_ = s.flags(); m.prec_ = s.precision(); m.wdt_ = s.width(); m.fill_ = s.fill(); return m; }
IO::Mode set_ascii_mode(std::ios& i) { IO::Mode m = get_mode(i); i.iword(IO::mode) = IO::ASCII; return m; }
explicit StreamStateSaver(std::ios &stream) : stream(stream) , state(nullptr) { // Save the stream's state. state.copyfmt(stream); }
IO::Mode set_mode(std::ios& i, IO::Mode m) { IO::Mode old = get_mode(i); i.iword(IO::mode) = m; return old; }
IO::Mode set_pretty_mode(std::ios& i) { IO::Mode m = get_mode(i); i.iword(IO::mode) = IO::PRETTY; return m; }
IO::Mode set_binary_mode(std::ios& i) { IO::Mode m = get_mode(i); i.iword(IO::mode) = IO::BINARY; return m; }
void FragmentedFileWriter::turnExceptionsOn(std::ios& stream) { stream.exceptions( std::ios_base::badbit|std::ios_base::failbit); }
//prints the error flags when an attempt to open a file fails void util::print_state (const std::ios& stream) { cerr << " good()=" << stream.good(); cerr << " eof()=" << stream.eof(); cerr << " fail()=" << stream.fail(); cerr << " bad()=" << stream.bad(); }
explicit StreamRedirector(std::ios& stream, std::streambuf* newBuf) : savedBuf_(stream.rdbuf()), stream_(stream) { stream_.rdbuf(newBuf); }
ios_guard(std::ios& x) : guarded(x), old(0) { old.copyfmt(guarded); }
RedirectStreamBuffer(std::ios &stream, std::streambuf * new_sb) : stream(stream) { orig_sb = stream.rdbuf( new_sb ); }
bool is_binary(std::ios& i) { return i.iword(IO::mode) == IO::BINARY; }
bool is_ascii(std::ios& i) { return i.iword(IO::mode) == IO::ASCII; }
bool is_pretty(std::ios& i) { return i.iword(IO::mode) == IO::PRETTY; }
IO::Mode get_mode(std::ios& i) { return static_cast<IO::Mode>(i.iword(IO::mode)); }
void DenseLinAlgPack::LinAlgPackIO::format::set_format(std::ios& s) const { s.flags(ios_base_flags().flags()); s.precision(precision()); s.width(width()); s.fill(fill()); }
void DenseLinAlgPack::LinAlgPackIO::format::copy_format(const std::ios& s) { ios_base_flags().flags(s.flags()); precision(s.precision()); width(s.width()); fill(s.fill()); }