Beispiel #1
0
FeltFile::FeltFile(const path & file)
	: fileName_(file), changeEndianness_(false)
{
	if ( ! exists(file) )
		throw runtime_error("Cannot find file " + file.native_file_string() );
	if ( is_directory(file) )
		throw runtime_error(file.native_directory_string() + " is a directory, not a file");

	string fileName = file.native_file_string();
	feltFile_ = new boost::filesystem::ifstream(file);

	word head;
	feltFile_->read(reinterpret_cast<char*>(& head), sizeof(word));
	if ( head < 997 or 999 < head )
		changeEndianness_ = true;

	// Block 1
	block1_ = getBlock_(0);

	if ( not complete() )
		throw std::runtime_error("File update is not complete yet");

	const size_t fieldCount = block1_[9];
	fields_.reserve(fieldCount);
	int i = 0;
	while ( fields_.size() < fieldCount )
	{
		boost::shared_ptr<FeltField> f(new FeltField(*this, i ++));
		if ( f->valid() )
			fields_.push_back(f);
	}
}