Esempio n. 1
0
double readDouble(istream& in)
{
  int num = sizeof(int64_t)/sizeof(char);
  char* s = new char [num];
  in.read(s, num);
  int64_t d = *((int64_t*)s);
  swap_endian(d);
  double ans = *((double*)&d);
  delete[] s;
  return ans;
}
Esempio n. 2
0
void quake3_bsp_map::read_visibility_data(istream& stream) {
#ifndef NDEBUG
    std::cout << "Reading visibility data" << std::endl;
#endif

    int visibility_length = m_lumps[iVisibleDataOffset].length;

    //Only read the visibility data if it exists
    if (visibility_length) {
        stream.seekg(m_lumps[iVisibleDataOffset].offset, std::ios_base::beg);
        stream.read(reinterpret_cast<char*>(&m_raw_cluster_data.totalClusters), sizeof(int));
        stream.read(reinterpret_cast<char*>(&m_raw_cluster_data.size), sizeof(int));

        uint num_clusters = m_raw_cluster_data.totalClusters * m_raw_cluster_data.size;

        m_raw_cluster_data.bitSet.resize(num_clusters);

        stream.read(reinterpret_cast<char*>(&m_raw_cluster_data.bitSet[0]), sizeof(unsigned char) * num_clusters);
    }
}
Esempio n. 3
0
/*! @brief Constructs a SaveJob from stream data
    @param time the time in ms to perform the save
    @param input the stream from which to read the job specific data
 */
SaveJob::SaveJob(double time, istream& input) : MotionJob(Job::MOTION_SAVE)
{
    m_job_time = time;

    // Temporary read buffers.
    unsigned int uintBuffer;
    float floatBuffer;

    // read in the save_position size
    input.read(reinterpret_cast<char*>(&uintBuffer), sizeof(unsigned int));
    unsigned int m_save_position_size = uintBuffer;
    
    // read in the save position vector
    m_save_position = vector<float>(m_save_position_size, 0);
    for (unsigned int i=0; i<m_save_position_size; i++)
    {
        input.read(reinterpret_cast<char*>(&floatBuffer), sizeof(float));
        m_save_position[i] = floatBuffer;
    }
}
Esempio n. 4
0
	void load(istream &in){

		ulint a_size;

		in.read((char*)&a_size,sizeof(a_size));
		in.read((char*)&terminator_position,sizeof(terminator_position));

		for(ulint i=0;i<a_size;++i){

			char_type a;
			in.read((char*)&a,sizeof(a));

			alphabet.insert(a);

		}

		F.load(in);
		L.load(in);

	}
Esempio n. 5
0
bool
SDKMeshHandler::doCanRead(istream& stream) const noexcept
{
	SDKMESH_HEADER hdr;
	if (stream.read((char*)&hdr, sizeof(hdr)))
	{
		return hdr.Version == SDKMESH_FILE_VERSION;
	}

	return false;
}
Esempio n. 6
0
inline string GetString(istream& input,const char terminator='\0')
{
    // TODO: make this check for FEOF condition! and also more efficient
    char c=' ';
    string s;
    while (c!=terminator && input)
    {
        input.read(&c,sizeof(char));
	s += c;
    }
    return s;
}
Esempio n. 7
0
void readImageData( istream& is, cv::Mat_<cv::Vec3b>& cimg, cv::Mat_<cv::Vec3f>& points, cv::Mat_<float>& dimg)
{
    string ln;
    getline( is, ln);
    istringstream iss(ln);

    cv::Size imgSz;
    iss >> imgSz.height >> imgSz.width;
    cimg = cv::Mat_<cv::Vec3b>( imgSz);
    points = cv::Mat_<cv::Vec3f>( imgSz);
    dimg = cv::Mat_<float>( imgSz);

    const int sz = imgSz.width * imgSz.height;
    const int pxlChunk = 3*sizeof(float) + 3*sizeof(byte);
    const int totalBytes = sz * pxlChunk;
    char* buff = (char*)malloc( totalBytes);

    int readBytes = 0;
    while ( readBytes < totalBytes)
    {
        is.read( &buff[readBytes], totalBytes-readBytes);
        const int numBytesRead = is.gcount();
        if ( numBytesRead <= 0)
            break;
        readBytes += numBytesRead;
    }   // end while

    assert( readBytes == totalBytes);

    for ( int i = 0; i < sz; ++i)
    {
        int j = i * pxlChunk;   // Offset into read in buffer

        // Read in points (with respect to origin)
        cv::Vec3f p( *(float*)&buff[j], // X
                     *(float*)&buff[j+sizeof(float)], // Y
                     *(float*)&buff[j+2*sizeof(float)]);    // Z (depth)

        j += 3*sizeof(float);   // Skip to colour bytes
        cv::Vec3b c( (byte)buff[j], (byte)buff[j+1], (byte)buff[j+2]);

        const int row = i / imgSz.width;  // Integer division
        const int col = i % imgSz.width;

        cimg.at<cv::Vec3b>(row,col) = c;
        points.at<cv::Vec3f>(row,col) = p;
        dimg.at<float>(row,col) = p[2]; // Depth is just the Z value
    }   // end for

    free(buff);

    getline( is, ln);  // Read end of line
}   // end readImageData
Esempio n. 8
0
int FixedLengthBuffer::read(istream& stream){
	int recAddr = stream.tellg();
	stream.clear();
	this->clear();
	this->packing = 0; //FALSE
	stream.read(this->buffer, this->bufferSize);
	if(!stream.good()){
		stream.clear();
		return recAddr;
	}
	return recAddr;
}
Esempio n. 9
0
void VHP_RowInfo::readData(istream &in) {
    unsigned short n;
    in.read((char *)&n,sizeof(n));
    if (n != nbin) {
        if (nbin > 0) {
            delete [] pix;
            delete [] org;
            nbin = 0;
        }
    }
    if (n < 1) {
        return;
    }
    if (!nbin) {
        nbin = n;
        pix = new unsigned short [nbin+1];
        org = new unsigned char [nbin];
    }
    in.read((char *)pix,(nbin+1)*sizeof(unsigned short));
    in.read((char *)org,nbin*sizeof(unsigned char));
}
//--------------------------------------------------
bool ofBuffer::set(istream & stream){
	clear();
	if( stream.bad() ) return false;

	char aux_buffer[1024];
	std::streamsize size = 0;
	stream.read(aux_buffer, 1024);
	std::streamsize n = stream.gcount();
	while( n > 0 ){
		// we resize to size+1 initialized to 0 to have a 0 at the end for strings
		buffer.resize(size+n+1,0);
		memcpy(&(buffer[0])+size,aux_buffer,n);
		size += n;
		if( stream ){
			stream.read(aux_buffer, 1024);
			n = stream.gcount();
		}
		else n = 0;
	}
	return true;
}
Esempio n. 11
0
PWIZ_API_DECL string SHA1Calculator::hash(istream& is)
{
    CSHA1 sha1;
    is.clear();
    is.seekg(0);
    unsigned char buffer[65535];
    while (is && is.read(reinterpret_cast<char*>(buffer), 65535))
        sha1.Update(buffer, 65535u);
    sha1.Update(buffer, is.gcount());
    sha1.Final();
    return formatHash(sha1);
}
Esempio n. 12
0
 static bool unserialize(string &str,istream &input)
     {
         static int len;
         if (!Serialize::unserialize(len,input))
         {
             cerr << "Could not read the length of the string" << endl;
             return false;
         }
         str.resize(len);
         input.read(const_cast<char*>(str.data()),len);
         return true;
     };
Esempio n. 13
0
void Mach::ReadParams(istream &inpf, bool with_alloc)
{
  debug0("*** read params of type Mach\n");
  switch (Mach::fileid) {
    case file_header_version1: // read int but store ulong
      unsigned int itmp;
      inpf.read((char*) &itmp, sizeof(int)); nb_forw = (ulong) itmp;
      inpf.read((char*) &itmp, sizeof(int)); nb_backw = (ulong) itmp;
      debug2("V1 read int counters %lu/%lu\n",nb_forw,nb_backw);
      break;
    case file_header_version2: 
    case file_header_version3: 
    case file_header_version4: 
      inpf.read((char*) &nb_forw, sizeof(ulong));
      inpf.read((char*) &nb_backw, sizeof(ulong));
      debug2("V2 to V4 read ulong counters %lu/%lu\n",nb_forw,nb_backw);
      break;
    default:
      Error("internal error, fileid is unset");
  }
}
Esempio n. 14
0
void MidiEvent::ReadStandard(istream &stream) {
  switch (Type()) {
  case MidiEventType_NoteOff:
  case MidiEventType_NoteOn:
  case MidiEventType_Aftertouch:
  case MidiEventType_Controller:
  case MidiEventType_PitchWheel:
    stream.read(reinterpret_cast<char*>(&m_data1), sizeof(unsigned char));
    stream.read(reinterpret_cast<char*>(&m_data2), sizeof(unsigned char));
    break;

  case MidiEventType_ProgramChange:
  case MidiEventType_ChannelPressure:
    stream.read(reinterpret_cast<char*>(&m_data1), sizeof(unsigned char));
    m_data2 = 0;
    break;

  default:
    throw MidiError(MidiError_UnknownEventType);
  }
}
Esempio n. 15
0
DecisionTreePtr DecisionTree::readC5(istream& in, AttributeSpec* spec)
{
    int tag;
    in.read((char*)&tag, sizeof(int));
    if (memcmp((char *)&tag, "id=", 3) == 0)
    {
        in.seekg (0, ios::beg);
        return readC5Text(in, spec);
    }
    in.seekg(0, ios::beg);
    return readC5Bin(in, spec);
}
Esempio n. 16
0
void MatchIndex::Load(istream &ifs)
{
    size_t size;
    ifs.read(( char*)&size, sizeof(size));
    Context.resize(size);
    size_t len;
    for(size_t i=0; i<size; i++)
    {
        ifs.read(( char*)&len, sizeof(len));
        std::string str;
        str.resize(len);
        ifs.read(( char*)&str[0], len);
        Context[i]=UString(str,UString::UTF_8);
    }
    ifs.read(( char*)&size, sizeof(size));
    for(size_t i=0; i<size; i++)
    {
        size_t len;
        ifs.read(( char*)&len, sizeof(len));
        std::string str;
        str.resize(len);
        ifs.read(( char*)&str[0], len);
        PostingList ps;
        ifs>>ps;
        prefixVec.insert(make_pair(UString(str,UString::UTF_8), ps) );

    }
    build=true;
}
Esempio n. 17
0
int MessageProcessHelper::ProcessMessageStream( istream& istrm )
{
	PackageHajackStream hajack;
	int ret;
	unsigned have;
	z_stream strm;
	unsigned char in[CHUNK];
	unsigned char out[CHUNK];

	/* 初始化压缩状态 */
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	strm.avail_in = 0;
	strm.next_in = Z_NULL;
	ret = inflateInit(&strm);
	if (ret != Z_OK)
		return ret;

	/* 解压,直到流的结尾 */
	do {
		istrm.read((char*)in,CHUNK);
		strm.avail_in = istrm.gcount();
		if (strm.avail_in == 0)
			break;
		strm.next_in = in;

		do {
			strm.avail_out = CHUNK;
			strm.next_out = out;
			ret = inflate(&strm, Z_NO_FLUSH);
			switch (ret) {
			case Z_NEED_DICT:
				ret = Z_DATA_ERROR;     /* and fall through */
			case Z_DATA_ERROR:
			case Z_MEM_ERROR:
				(void)inflateEnd(&strm);
				return ret;
			}
			have = CHUNK - strm.avail_out;
			if(!hajack.WriteBlock((const char*)out,have,0))
			{
				(void)inflateEnd(&strm);
				return Z_ERRNO;
			}
		} while (strm.avail_out == 0);

	} while (ret != Z_STREAM_END);

	(void)inflateEnd(&strm);
	return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
Esempio n. 18
0
NetStream::STREAM_TYPE NetStream::classifyStream(istream& s)
{
	char buf[3];
	s.read(buf,3);
	STREAM_TYPE ret;
	if(strncmp(buf,"FLV",3)==0)
		ret=FLV_STREAM;
	else
		threadAbort();

	s.seekg(0);
	return ret;
}
Esempio n. 19
0
string ReadString( istream &in ) {
	unsigned int len = ReadUInt( in );
	string out;
	if ( len > 0x4000 )
	    throw runtime_error("String too long. Not a NIF file or unsupported format?");
	if ( len > 0 ) {
	    out.resize(len);
	    in.read( (char*)&out[0], len );
	    if (in.fail())
	      throw runtime_error("premature end of stream");
	}
	return out;
}
Esempio n. 20
0
NetStream::STREAM_TYPE NetStream::classifyStream(istream& s)
{
	char buf[3];
	s.read(buf,3);
	STREAM_TYPE ret;
	if(strncmp(buf,"FLV",3)==0)
		ret=FLV_STREAM;
	else
		throw ParseException("File signature not recognized");

	s.seekg(0);
	return ret;
}
Esempio n. 21
0
bool drwnDataRecord::read(istream& is)
{
    int rows = 0;
    int cols = 0;

    is.read((char *)&rows, sizeof(int));
    DRWN_ASSERT_MSG(!is.fail() && (rows >= 0), 
        (_owner ? _owner->name().c_str() : "<unknown>"));

    _structure.resize(rows);

    if (rows > 0) {
        is.read((char *)_structure.data(), rows * sizeof(int));
    }
    DRWN_ASSERT(!is.fail());

    is.read((char *)&rows, sizeof(int));
    is.read((char *)&cols, sizeof(int));
    DRWN_ASSERT(!is.fail() && (rows >= 0) && (cols >= 0));

    _data.resize(rows, cols);

    if (rows > 0) {
        is.read((char *)_data.data(), rows * cols * sizeof(double));
    }
    DRWN_ASSERT(!is.fail());

    is.read((char *)&rows, sizeof(int));
    DRWN_ASSERT(!is.fail() && (rows >= 0));

    _objective.resize(rows);
    if (rows > 0) {
        is.read((char *)_objective.data(), rows * sizeof(double));
    }

    is.read((char *)&rows, sizeof(int));
    is.read((char *)&cols, sizeof(int));
    DRWN_ASSERT(!is.fail() && (rows >= 0) && (cols >= 0));

    _gradient.resize(rows, cols);
    if (rows > 0) {
        is.read((char *)_gradient.data(), rows * cols * sizeof(double));
    }
    DRWN_ASSERT(!is.fail());

    _bDirty = false;
    return true;
}
Esempio n. 22
0
  void ezw_decoder::initial_decode(vector<unsigned char>& dest, istream& in, const ezw_header& header) {
    if (header.enc_type == HUFFMAN) {
      // --- Need to read in huffman buffer then decode to rle buffer. -- //
      vector<unsigned char> huff_buffer(header.enc_size);
      in.read((char*)&huff_buffer[0], header.enc_size);

      dest.resize(header.rle_size);
      Huffman_Uncompress(&huff_buffer[0], &dest[0], header.enc_size, header.rle_size);

    } else {
      dest.resize(header.rle_size);
      in.read((char*)&dest[0], header.rle_size);
    }

    vector<unsigned char> rle_buffer(header.ezw_size);
    rle_buffer.swap(dest);
    const size_t derle = RLE_Uncompress(&rle_buffer[0], &dest[0], header.rle_size);
      
    if (derle != header.ezw_size) {
      cerr << derle << "  !=  " << header.ezw_size << endl;
      exit(1);
    }
  }
Esempio n. 23
0
const char* LgScriptReader::read(State&, size_t *sz)
{
	if (extraline)
	{
		extraline = false;
		*sz = 1;
		return "\n";
	}
	if (infile->eof())
		return NULL;
	infile->read(buff, sizeof(buff));
	*sz = infile->gcount();
	return buff;
}
Esempio n. 24
0
bool DSA1Intro_Entry::read(istream& strm) {
    u8 length;
    char buf[13];
    length = read8(strm);
    if (length < 1 || length > 12) { // Eintrag überspringen
	strm.seekg(0x20-1, std::ios::cur);
	return false;
    }
    strm.read(buf, 12);
    buf[length] = '\0';
    name    = buf;
    length  = read8(strm);
    if (length < 1 || length > 12) { // Eintrag überspringen
	strm.seekg(0x20-14, std::ios::cur);
	return false;
    }
    strm.read(buf, 12);
    buf[length] = '\0';
    volname = buf;
    offset  = read32(strm);
    size    = read16(strm);
    return true;
}
Esempio n. 25
0
_NAME_BEGIN

bool
BMPHandler::doCanRead(istream& stream) const noexcept
{
	std::uint8_t hdr[2];

	if (stream.read((char*)hdr, sizeof(hdr)))
	{
		return hdr[0] == 'B' && hdr[1] == 'M';
	}

	return false;
}
Esempio n. 26
0
	string ReadString(istream& input)
	{
		int16_t len = ReadSwap<int16_t>(input);
		if( len == 0 )
			return string("");
		char *buf = new char[len+1];
		wchar_t *wbuf = new wchar_t[len+1];
		input.read(buf,len);
		buf[len] = '\0';
		mbstowcs( wbuf , buf , len+1 );
		wstring wstr(wbuf);
		delete[] wbuf;
		delete[] buf;
		return string(wstr.begin(),wstr.end() );
	}
Esempio n. 27
0
void 
readMaterial( istream &is, chunkSize size)
{
	TAB(1);
	DOUT(1) << "material : ";

	char *material = readString(is);

	DOUT(1) << '\'' << material << '\'';

	unsigned short number;
	is.read((char *) (void *) &number,2);

	DOUT(1) << ' ' << number << " faces." << endl;

	for (int n=0; n<number; n++)
	{
		unsigned short index;
		is.read((char *) (void *) &index,2);

		TAB(2);
		DOUT(2) << index << endl;
	}
}
Esempio n. 28
0
int VariableLengthBuffer::Read(istream & stream)
// write the number of bytes in the buffer field definitions
// the record length is represented by an unsigned short value
		{
	if(stream.eof())
		return -1;
	int recaddr = stream.tellg();
	Clear();
	unsigned short bufferSize;
	stream.read((char *) &bufferSize, sizeof(bufferSize));
	if(!stream.good()){
		stream.clear();
		return -1;
	}
	BufferSize = bufferSize;
	if(BufferSize > MaxBytes)
		return -1; // buffer overflow
	stream.read(Buffer, BufferSize);
	if(!stream.good()){
		stream.clear();
		return -1;
	}
	return recaddr;
}
Esempio n. 29
0
void LineBuffer::read(istream &stream) {
  while (true) {
    streamsize space = bufferSize - fill;

    stream.read(buffer + fill, space);
    streamsize bytes = stream.gcount();

    if (!bytes) break;

    fill += bytes;
    extractLines();

    if (bytes < space) break;
  }
}
Esempio n. 30
0
bool CanberraCnfDataSet::check(istream &f, string*)
{
    int acq_offset = 0;
    f.ignore(112);
    int pos = 112;
    char buf[48];
    while (!f.eof()) {
        f.read(buf, 48);
        if (f.gcount() != 48)
            return false;
        if ((buf[1] != 0x20 || buf[2] != 0x01) && buf[1] != 0 && buf[2] != 0)
            return false;
        pos += 48;
        if (buf[0] == 0) {
            acq_offset = from_le<uint32_t>(buf+10);
            break;
        }
    }
    if (acq_offset <= pos)
        return false;
    f.ignore(acq_offset - pos);
    f.read(buf, 48);
    return (!f.eof() && f.gcount() == 48 && buf[0] == 0 && buf[1] == 0x20);
}