Ejemplo n.º 1
0
 /// open file for reading
 void open(const std::string& a_fname) {
     if (m_open) return;
     // make sure exception thrown in case of error
     m_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
     m_file.open(a_fname.c_str(), std::ios::in | std::ios::binary);
     // further read can set failbit in case there is not enough data
     // this case should not throw an exception in our class
     m_file.exceptions(std::ifstream::badbit);
     m_open = true;
     m_fname = a_fname;
     m_buf.reset();
     BOOST_ASSERT(m_buf.capacity() > 0);
 }
Ejemplo n.º 2
0
 void open(const std::string& a_fname, bool a_append = false) {
     using std::ios;
     using std::ios_base;
     if (m_open) return;
     m_file.exceptions(ios::failbit | ios::badbit);
     ios_base::openmode l_mode = ios::out | ios::binary;
     if (a_append)
         l_mode |= ios::app;
     else
         l_mode |= ios::trunc;
     m_file.open(a_fname.c_str(), l_mode);
     m_offset = m_file.tellp();
     m_open = true;
     m_fname = a_fname;
     m_buf.reset();
     BOOST_ASSERT(m_buf.capacity() > 0);
 }