/** * Reads the headers of a region file: chunk offsets/timestamps */ bool RegionFile::readHeaders(std::ifstream& file) { if (!file) return false; containing_chunks.clear(); for (int i = 0; i < 1024; i++) { chunk_offsets[i] = 0; chunk_timestamps[i] = 0; } file.seekg(0, std::ios::end); int filesize = file.tellg(); file.seekg(0, std::ios::beg); // make sure the region file has a header if (filesize < 8192) { return false; } for (int x = 0; x < 32; x++) { for (int z = 0; z < 32; z++) { file.seekg(4 * (x + z * 32), std::ios::beg); int tmp; file.read(reinterpret_cast<char*>(&tmp), 4); if (tmp == 0) continue; int offset = util::bigEndian32(tmp << 8) * 4096; //uint8_t sectors = ((uint8_t*) &tmp)[3]; file.seekg(4096, std::ios::cur); int timestamp; file.read(reinterpret_cast<char*>(×tamp), 4); timestamp = util::bigEndian32(timestamp); ChunkPos pos(x + regionpos.x * 32, z + regionpos.z * 32); if (rotation) pos.rotate(rotation); containing_chunks.insert(pos); chunk_offsets[z * 32 + x] = offset; chunk_timestamps[z * 32 + x] = timestamp; } } return true; }
void Mz::decodeSubMesh( std::ifstream& f, int s ) { if (mVersion >= 20) { mSubmeshes.resize(s / sizeof(sSubMesh), sSubMeshWithName()); size_t i = 0; while (s > 0) { f.read((char*)&mSubmeshes[i], sizeof(sSubMesh)); f.read(mSubmeshes[i].name, mSubmeshes[i].nameLen); s -= (sizeof(sSubMesh) + mSubmeshes[i].nameLen); ++i; } mSubmeshes.resize(i); } else { mSubmeshes.resize(s / sizeof(sSubMeshWithName_V3), sSubMeshWithName()); size_t i = 0; sSubMeshWithName_V3 v3; while (s > 0) { f.read((char*)&v3, sizeof(sSubMeshWithName_V3)); memcpy(&mSubmeshes[i], &v3, sizeof(sSubMesh) - sizeof(u8)); mSubmeshes[i].nameLen = strlen(v3.name); memcpy(mSubmeshes[i].name, v3.name, sizeof(mSubmeshes[i].name)); s -= sizeof(sSubMeshWithName_V3); ++i; } } for(int i = 0; i != mSubmeshes.size(); ++i) { sSubMeshWithName& s = mSubmeshes[i]; for(int k = 0; k != 128; ++k) { if(s.name[k] == '|' || s.name[k] == ' ') { s.name[k] = '_'; } } } }
void Producer::populateSegments(std::ifstream& ifs) { BOOST_ASSERT(m_segments.size() == 0); // calculate how many segments are needed std::streampos begin, end; begin = ifs.tellg(); ifs.seekg(0, std::ios::end); end = ifs.tellg(); int num_segments = (end-begin) / m_maxSegmentSize; if ((end-begin) % m_maxSegmentSize != 0) num_segments++; std::cout << "Size of the file: " << (end-begin) << " bytes." << std::endl; std::cout << "Maximum size of a segment: " << m_maxSegmentSize << " bytes." << std::endl; std::cout << "Number of segments: " << num_segments << std::endl; std::vector<uint8_t> buffer(m_maxSegmentSize); ifs.seekg(0, std::ios::beg); for (int i = 0; i < (end-begin) / m_maxSegmentSize; ++i) { ifs.read(reinterpret_cast<char*>(buffer.data()), m_maxSegmentSize); auto data = make_shared<Data>(Name(m_prefix).appendSegment(i)); data->setFreshnessPeriod(m_freshnessPeriod); data->setContent(&buffer[0], m_maxSegmentSize); //std::cout << *data << std::endl; m_segments.push_back(data); } if ((end-begin) % m_maxSegmentSize != 0) { ifs.read(reinterpret_cast<char*>(buffer.data()), (end-begin) % m_maxSegmentSize); auto data = make_shared<Data>(Name(m_prefix).appendSegment(m_segments.size())); data->setFreshnessPeriod(m_freshnessPeriod); data->setContent(&buffer[0], (end-begin) % m_maxSegmentSize); //std::cout << *data << std::endl; m_segments.push_back(data); } auto finalBlockId = name::Component::fromSegment(m_segments.size() - 1); for (const auto& data : m_segments) { data->setFinalBlockId(finalBlockId); m_keyChain.sign(*data, m_signingInfo); } }
/* * Read a string from the file stream. */ std::string FileInput::ReadString8(std::ifstream &instr, int32_t len) { char *buf = new char [len+1]; instr.read(buf, len); buf[len]=0; std::string s=buf; delete[] buf; return s; }
/**@brief read one char from file handle * * @return read a char read from file_ */ inline const unsigned char nextChar() { char out; if (file_.read(&out, 1)) { return out; } else { throw Exception(__PRETTY_FUNCTION__, "Error reading file."); } }
static void loadVec3Array(std::ifstream& fin, std::vector<ml::vec3f>& array) { int array_size; fin.read((char*)(&array_size), sizeof(int)); array.resize(array_size); for (int i = 0; i < array_size; ++i) { loadVec3(fin, array[i]); } return; }
// Helper function to read a null terminated c-str from an ifstream. std::string readNullTermString(std::ifstream & fileHandle) { std::string value; while (true) { char c; fileHandle.read(&c, sizeof(char)); if (c != '\0') { value.push_back(c); } else { return value; } } }
CartridgeHeader RomParser::parse(std::ifstream& rom) { CartridgeHeader header; rom.seekg(0x100, std::ios::beg); rom.read((char*)&header, sizeof(CartridgeHeader)); return header; }
ByteString read_bytes_from_stream(std::ifstream& stream, size_t size) { char* cbuff = new char[size]; stream.read(cbuff, size); ByteString bytes(reinterpret_cast<uint8_t*>(cbuff), size); delete[] cbuff; return bytes; }
unsigned char iReadByte (std::ifstream & ifile) { // will read 1 byte from the file char b; ifile.read(&b, 1); return b; }
BitVector::BitVector(std::ifstream& file) : rank_index(0), select_index(0) { file.read((char*)&(this->size), sizeof(this->size)); file.read((char*)&(this->items), sizeof(this->items)); file.read((char*)&(this->number_of_blocks), sizeof(this->number_of_blocks)); file.read((char*)&(this->block_size), sizeof(this->block_size)); usint* array_buffer = new usint[this->block_size * this->number_of_blocks]; file.read((char*)(array_buffer), this->block_size * this->number_of_blocks * sizeof(usint)); this->array = array_buffer; this->integer_bits = length(this->size); this->samples = new ReadBuffer(file, 2 * (this->number_of_blocks + 1), this->integer_bits); this->indexForRank(); this->indexForSelect(); }
binary_reader::market_message::market_message( std::ifstream& _in ) : m_type(readValue<boost::uint32_t>(_in)) , m_time(readValue<boost::uint32_t>(_in)) , m_len(readValue<boost::uint32_t>(_in)) { m_msg = new char[m_len + 1]; _in.read(&m_msg[0], m_len); m_msg[m_len] = '\0'; }
bool VCFont::ParseCommon(std::ifstream& f) { char blockType = ReadInt8(f); int blockSize = ReadInt32(f); f.read((char*) &Common, 15); return true; }
/*---------------------------------------------------------*/ bool NOMAD::Cache_File_Point::read ( std::ifstream & fin ) { reset(); // 1. _eval_status: fin.read ( (char *) &_eval_status , sizeof(_eval_status) ); if ( fin.fail() || _eval_status > 3 ) return false; // 2. _n: fin.read ( (char *) &_n , sizeof(_n) ); if ( fin.fail() || _n <= 0 ) { _n = 0; return false; } // 3. _m: fin.read ( (char *) &_m , sizeof(_m) ); if ( fin.fail() || _m < 0 ) { _n = _m = 0; return false; } // 4. _m_def: fin.read ( (char *) &_m_def , sizeof(_m_def) ); if ( fin.fail() || _m_def < 0 ) { _m_def = _n = _m = 0; return false; } // 5. _coords: _coords = new double [_n]; fin.read ( (char *) _coords , _n*sizeof(double) ); if ( fin.fail() ) { reset(); return false; } if ( _m_def > 0 ) { // 6. _bb_def: _bbo_def = new double [_m_def]; fin.read ( (char *) _bbo_def , _m_def*sizeof(double) ); if ( fin.fail() ) { reset(); return false; } // 7. _bbo_index: _bbo_index = new int [_m_def]; fin.read ( (char *) _bbo_index , _m_def*sizeof(int) ); if ( fin.fail() ) { reset(); return false; } } return true; }
bool WLMatLib::MATReader::readMatrixDouble( Eigen::MatrixXd* const matrix, const ElementInfo_t& element, std::ifstream& ifs, const FileInfo_t& info ) { // Check some errors // // ----------------- // if( matrix == NULL ) { wlog::error( LIBNAME ) << "Matrix object is null!"; return false; } if( info.fileSize <= static_cast< size_t >( element.posData ) ) { wlog::error( LIBNAME ) << "Data position is beyond file end!"; return false; } if( element.dataType != DataTypes::miMATRIX ) { wlog::error( LIBNAME ) << "Data type is not a matrix: " << element.dataType; return false; } const mArrayType_t arrayType = ArrayFlags::getArrayType( element.arrayFlags ); if( arrayType != ArrayTypes::mxDOUBLE_CLASS ) { wlog::error( LIBNAME ) << "Numeric Types does not match!"; return false; } const std::streampos pos = ifs.tellg(); // Read data // // --------- // ifs.seekg( element.posData ); mDataType_t type; mNumBytes_t bytes; if( !readTagField( &type, &bytes, ifs ) ) { wlog::error( LIBNAME ) << "Could not read Data Element!"; ifs.seekg( pos ); return false; } if( type != DataTypes::miDOUBLE ) { wlog::error( LIBNAME ) << "Numeric Types does not match or compressed data, which is not supported: " << type; ifs.seekg( pos ); return false; } matrix->resize( element.rows, element.cols ); ifs.read( ( char* )matrix->data(), bytes ); nextElement( ifs, element.posData, bytes ); return true; }
bool Archiver::readFooter(std::ifstream &tar) { String footer(12, '\0'); const char FOOTER[] = "END ARCHIVE\0"; if (tar.read(&footer[0], footer.length())) { for (unsigned char i = 0; i < footer.length(); i++) if (footer[i] != FOOTER[i]) return false; return true; } return false; }
bool Archiver::readHeader(std::ifstream &tar) { String header(8, '\0'); const char HEADER[] = "ARCHIVE\0"; if (tar.read(&header[0], header.length())) { for (unsigned char i = 0; i < header.length(); i++) if (header[i] != HEADER[i]) return false; return true; } return false; }
/* ** Unserialize std::string */ inline void unserialize(std::ifstream &file, std::string & a) { int strSize; unserialize(file, strSize); char *str = new char[strSize + 1](); file.read(str, strSize); str[strSize] = '\0'; a.assign(str); delete[] str; }
/** Loads and checks both bitmap file and info headers. @param[in] FileStream The input file stream. @param[out] FileHeader The bitmap file header read from the file. @param[out] InfoHeader The bitmap info header read from the file. @return One of #BitmapLoadStatus codes. */ static BitmapLoadStatus LoadAndValidateHeaders(std::ifstream& FileStream, BitmapFileHeader* FileHeader, BitmapInfoHeader* InfoHeader) { FileStream.read(reinterpret_cast<char*>(FileHeader), sizeof(*FileHeader)); if (FileStream.bad()) { return INVALID_FILE_HEADER; } if (!ValidateFileHeader(*FileHeader)) { return INVALID_FILE_HEADER; } FileStream.read(reinterpret_cast<char*>(InfoHeader), sizeof(*InfoHeader)); if (FileStream.bad() || !ValidateInfoHeader(*InfoHeader)) { return INVALID_INFO_HEADER; } return LOAD_SUCCESS; }
int iReadInt(std::ifstream & ifile) { // will use 4 bytes from the file to read an int (according to the MSG definition of int) unsigned char buf [4]; ifile.read((char*)buf, 4); int iResult = (buf[0]<<24)+(buf[1]<<16)+(buf[2]<<8)+buf[3]; return iResult; }
tile::tile(std::ifstream& file) : contours() { int contourCount = 0; file.read((char*)&contourCount, 4); for(int i = 0; i < contourCount; i++) { contour c(file); contours.push_back(c); } }
std::unique_ptr<TorchStage> ParallelTable::loadFromFile(std::ifstream& file) { int n_nodes; file.read(reinterpret_cast<char*>(&n_nodes), sizeof(n_nodes)); std::unique_ptr<ParallelTable> ret(new ParallelTable()); ret->network_.reserve(n_nodes); for (int32_t i = 0; i < n_nodes; i++) { ret->network_.push_back(TorchStage::loadFromFile(file)); } return std::unique_ptr<TorchStage>(std::move(ret)); }
void STLFile::read_binary( std::ifstream &ifstr ) { // Skip header char buf[80]; ifstr.read( buf, 80 ); // Read number of triangles uint32_t tcount; ifstr.read( (char *)(&tcount), 4 ); // Check if sensible if( tcount > 10000000 ) throw( ErrorUnimplemented( ERROR_LOCATION, "Too high number of triangles" ) ); _tri.reserve( tcount ); // Read triangles for( uint32_t a = 0; a < tcount; a++ ) _tri.push_back( Triangle( ifstr ) ); }
static bool readIStat( std::ifstream &in, int sflg, char *flag ) { if ( sflg == CF_FLAG_SIZE ) { in.read( flag, sflg ); if ( !in ) return true; // error } else { int istat; in.read( reinterpret_cast< char * >( &istat ), sflg ); if ( !in ) return true; // error else *flag = ( istat == 1 ); } return false; }
void ReadSharedArray(std::ifstream &saIn) { std::cout << "reading a shared suffix array index." << std::endl; saIn.read((char*) &this->length, sizeof(int)); indexHandle = "suffixarray.index." + shmIdTag; AllocateMappedShare(indexHandle, this->length + 1, indexShared, indexID); std::cout << "the shared index is: " << indexShared << std::endl; this->index = indexShared; std::cout << "the index used is: " << this->index << std::endl; this->ReadAllocatedArray(saIn); }
inline void load(std::ifstream& ifs, MatD& params){ Real val = 0.0; for (int i = 0; i < params.cols(); ++i){ for (int j = 0; j < params.rows(); ++j){ ifs.read((char*)&val, sizeof(Real)); params.coeffRef(j, i) = val; } } }
std::string CMuleCollection::ReadString(std::ifstream& infile, int TagType = 0x02) { if (TagType >= 0x11 && TagType <= 0x20) { std::vector<char> buffer(TagType - 0x10); infile.read(&buffer[0], TagType - 0x10); return buffer.empty() ? std::string() : std::string (buffer.begin(), buffer.end()); } if (TagType == 0x02) { uint16_t TagStringSize = ReadInt<uint16_t>(infile); std::vector<char> buffer (TagStringSize); infile.read(&buffer[0], TagStringSize); return buffer.empty() ? std::string() : std::string (buffer.begin(), buffer.end()); } return std::string(); }
bool LightRecord::loadFromStream(std::ifstream& inStream) { if (!inStream.good()) { DuskLog() << "LightRecord::loadFromStream: ERROR: stream contains errors.\n"; return false; } char ID_Buffer[256]; uint32_t Header = 0; inStream.read((char*) &Header, sizeof(uint32_t)); if (Header != cHeaderLight) { DuskLog() << "LightRecord::loadFromStream: ERROR: invalid record header.\n"; return false; } //read ID length Header = 0; inStream.read((char*) &Header, sizeof(uint32_t)); if (Header>255) { DuskLog() << "LightRecord::loadFromStream: ERROR: ID is longer than 255" << "characters.\n"; return false; } //read ID memset(ID_Buffer, 0, Header+1); inStream.read(ID_Buffer, Header); if (!inStream.good()) { DuskLog() << "LightRecord::loadFromStream: ERROR while reading light's" << " ID from stream.\n"; return false; } ID_Buffer[Header] = '\0'; //make sure it's NUL-terminated ID = std::string(ID_Buffer); //read RGB and radius inStream.read((char*) &red, sizeof(float)); inStream.read((char*) &green, sizeof(float)); inStream.read((char*) &blue, sizeof(float)); inStream.read((char*) &radius, sizeof(float)); //read light type inStream.read((char*) &type, sizeof(Ogre::Light::LightTypes)); if (!inStream.good()) { DuskLog() << "LightRecord::loadFromStream: ERROR while reading light's" << " colour values from stream.\n"; return false; } //normalise values, just to be safe normalise(); return true; }
// biSize以外を読み込む.biSizeはヘッダ識別のために既に読み込んでいるはずだから飛ばす. int LoadInfoHeader( std::ifstream& ifs, BITMAPINFOHEADER& header ) { ifs.read( reinterpret_cast< char* >( &header.biWidth ), 4 ); ifs.read( reinterpret_cast< char* >( &header.biHeight ), 4 ); ifs.read( reinterpret_cast< char* >( &header.biPlanes ), 2 ); ifs.read( reinterpret_cast< char* >( &header.biBitCount ), 2 ); ifs.read( reinterpret_cast< char* >( &header.biCompression ), 4 ); ifs.read( reinterpret_cast< char* >( &header.biSizeImage ), 4 ); ifs.read( reinterpret_cast< char* >( &header.biXPelsPerMeter ), 4 ); ifs.read( reinterpret_cast< char* >( &header.biYPelsPerMeter ), 4 ); ifs.read( reinterpret_cast< char* >( &header.biClrUsed ), 4 ); ifs.read( reinterpret_cast< char* >( &header.biClrImportant ), 4 ); return ifs.fail(); }
/*! \param[in] ifs input file stream \param[out] in_mat mat to load */ bool readMatBinary(std::ifstream& ifs, cv::Mat& in_mat) { if(!ifs.is_open()){ return false; } int rows, cols, type; ifs.read((char*)(&rows), sizeof(int)); if(rows==0){ return true; } ifs.read((char*)(&cols), sizeof(int)); ifs.read((char*)(&type), sizeof(int)); in_mat.release(); in_mat.create(rows, cols, type); ifs.read((char*)(in_mat.data), in_mat.elemSize() * in_mat.total()); return true; }