예제 #1
0
void file_storage::read (record& _record, const segment _segment) const throw (storage_exception&) {
	std::fstream file;
	file.open(__fileName.c_str(), std::ios::binary|std::ios::in|std::ios::out);
	if(!file.is_open())
		throw file_open("Error: '" + __fileName + "' can not be opened!");
	file.seekg(_segment.begin);
	_record.read(file);
	if ((_record.size() != _segment.size()) | (file.tellg() != _segment.end + (std::streamoff)1))
		throw io_error("I/O error during read: '" + __fileName + "' may be corrupt or there may be a bug in the program!");
	file.close();
}
예제 #2
0
void file_storage::append (const record& _record, segment& _segment) throw (storage_exception&) {
	std::fstream file;
	file.open(__fileName.c_str(), std::ios::binary|std::ios::in|std::ios::out|std::ios::ate);
	if(!file.is_open())
		throw file_open("Error: '" + __fileName + "' can not be opened!");
	_segment.begin = file.tellp();
	_record.write(file);
	_segment.end = file.tellp() - (std::streamoff)1;
	if (_record.size() != _segment.size())
		throw io_error("I/O error during append: '" + __fileName + "' may be corrupt or there may be a bug in the program!");
	file.close();
}