Skip to content

Commit

Permalink
print buffer name on error
Browse files Browse the repository at this point in the history
  • Loading branch information
karasikov committed Jan 15, 2021
1 parent b18ba9c commit dc0c73c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions include/sdsl/int_vector_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class int_vector_buffer
uint64_t m_size = 0; // size of int_vector_buffer
uint64_t m_begin = 0; // number in elements

void throw_error(const std::string &message) const {
throw std::ios_base::failure("int_vector_buffer " + m_filename + " error: " + message);
}

//! Read block containing element at index idx.
void read_block(const uint64_t idx)
{
Expand All @@ -71,15 +75,15 @@ class int_vector_buffer
m_ifile->seekg(pos);
m_ifile_pos = pos;
if (!m_ifile->good())
throw std::ios_base::failure("Error when seeking in int_vector_buffer");
throw_error("seekg error");
}
if (m_size-m_begin<m_buffersize)
util::set_to_value(m_buffer, 0);
uint64_t wb = std::min(m_buffersize*width(), (m_size-m_begin)*width()+7)/8;
m_ifile->read(reinterpret_cast<char*>(m_buffer.data()), wb);
m_ifile_pos += wb;
if (!m_ifile->good())
throw std::ios_base::failure("Error when reading block in int_vector_buffer");
throw_error("read block error");
}
}

Expand All @@ -93,14 +97,14 @@ class int_vector_buffer
m_ofile->seekp(pos);
m_ofile_pos = pos;
if (!m_ofile->good())
throw std::ios_base::failure("Error when seeking in int_vector_buffer");
throw_error("seekp error");
}
uint64_t wb = std::min(m_buffersize*width(), (m_size-m_begin)*width()+7)/8;
m_ofile->write(reinterpret_cast<char*>(m_buffer.data()), wb);
m_ofile_pos += wb;
m_ofile->flush();
if (!m_ofile->good())
throw std::ios_base::failure("Error when writing block in int_vector_buffer");
throw_error("write block error");
m_need_to_write = false;
}
}
Expand Down Expand Up @@ -169,16 +173,16 @@ class int_vector_buffer
if (mode & std::ios::out) {
m_ofile->open(m_filename, mode|(m_start ? std::ios::in : std::ios::openmode(0))|std::ios::binary);
if (!m_ofile->good())
throw std::ios_base::failure("int_vector_buffer error: Could not open file for write " + m_filename);
throw_error("Could not open file for write");
m_ofile_pos = 0;
}

m_ifile->open(m_filename, std::ios::in|std::ios::binary);
if (!m_ifile->good())
throw std::ios_base::failure("int_vector_buffer error: Could not open file for read " + m_filename);
throw_error("Could not open file for read");
m_ifile->seekg(m_start);
if (!m_ifile->good())
throw std::ios_base::failure("int_vector_buffer error: Seek failed for " + m_filename);
throw_error("seekg failed");

if (mode & std::ios::in) {
// load size and width
Expand All @@ -190,7 +194,7 @@ class int_vector_buffer
uint8_t width = 0;
int_vector<t_width>::read_header(size, width, *m_ifile);
if (!m_ifile->good())
throw std::ios_base::failure("int_vector_buffer error: Could not read header in " + m_filename);
throw_error("Could not read header");
m_buffer.width(width);
}
m_size = size/width();
Expand Down Expand Up @@ -284,7 +288,7 @@ class int_vector_buffer
}
m_ofile->flush();
if (!m_ofile->good())
throw std::ios_base::failure("int_vector_buffer error: flush failed");
throw_error("flush failed");
}

//! Delete all content and set size to 0
Expand Down Expand Up @@ -340,11 +344,11 @@ class int_vector_buffer
}
m_ifile->close();
if (!m_ifile->good())
throw std::ios_base::failure("int_vector_buffer error: Could not close read stream " + m_filename);
throw_error("Could not close read stream");
if (m_ofile->is_open()) {
m_ofile->close();
if (!m_ofile->good())
throw std::ios_base::failure("int_vector_buffer error: Could not close write stream " + m_filename);
throw_error("Could not close write stream");
}
if (remove_file) {
sdsl::remove(m_filename);
Expand Down

0 comments on commit dc0c73c

Please sign in to comment.