rspfErrorCode rspfRpfAttributeSectionSubheader::parseStream(istream& in,
                                                              rspfByteOrder byteOrder)
{
   theAttributeSectionSubheaderStart = 0;
   theAttributeSectionSubheaderEnd = 0;
   if(in)
   {
      theAttributeSectionSubheaderStart = in.tellg();
      in.read((char*)&theNumberOfAttributeOffsetRecords, 2);
      in.read((char*)&theNumberOfExplicitArealCoverageRecords, 2);
      in.read((char*)&theAttributeOffsetTableOffset, 4);
      in.read((char*)&theAttribteOffsetRecordLength, 2);
      rspfEndian anEndian;

      if(anEndian.getSystemEndianType() != byteOrder)
      {
         anEndian.swap(theNumberOfAttributeOffsetRecords);
         anEndian.swap(theNumberOfExplicitArealCoverageRecords);
         anEndian.swap(theAttributeOffsetTableOffset);
         anEndian.swap(theAttribteOffsetRecordLength);
      }
      theAttributeSectionSubheaderEnd = in.tellg();
   }
   else
   {
      return rspfErrorCodes::RSPF_ERROR;
   }
   
   return rspfErrorCodes::RSPF_OK;
}
Esempio n. 2
0
int FixedFieldBuffer::ReadHeader(istream & stream){
    char *str = new char[headerStrSize+1];
    int numFields, *fieldSize;
    int result = FixedLengthBuffer::ReadHeader(stream);
    if(!result) return -1;

    //read header string.    
    stream.read(str, headerStrSize);
    if(!stream.good()) return -1;

    if(strncmp(str, headerStr, headerStrSize)!=0) return -1;

    stream.read((char*)&numFields, sizeof(numFields));
    if(!stream) return -1;

    for(int i=0; i<numFields; i++)
        stream.read((char*)&fieldSize[i], sizeof(fieldSize[i]));

    if(Initialized){
        if(numFields!=NumFields) return -1;
        for(int j=0; j<numFields; j++)
            if(fieldSize[j]!=FieldSize[j]) return -1;
        return stream.tellg();
    }
    Init(numFields, fieldSize);
    return stream.tellg();
}
Esempio n. 3
0
static size_t getStreamSize(istream& stream) {
    auto startPosition = stream.tellg();
    stream.seekg(0, ios_base::end);
    auto fileSize = static_cast<size_t>(stream.tellg());
    stream.seekg(startPosition);
    return fileSize;
}
Esempio n. 4
0
string parser::preprocess_input(istream &stream)
{
    streampos start = stream.tellg();
    stream.seekg(0, ios::end);
    streampos end = stream.tellg();
    size_t file_size = end - start;
    stream.seekg(start, ios::beg);
    char bom_test[3];
    static const char * BOM = "\xEF\xBB\xBF";
    stream.read(bom_test, 3u);
    if (strncmp(bom_test, BOM, 3u) == 0) {
        // Matched BOM, keep stream position to prevent its reading
        file_size -= 3u;
    }
    else {
        // Seek stream back
        stream.seekg(start, ios::beg);
    }
    char * buffer = new char[file_size + 1];
    stream.read(buffer, file_size);
    buffer[file_size] = '\0';
    string s0(buffer);
    delete[] buffer;
    string s1 = fix_corrupted_data(s0);
    return s1;
}
Esempio n. 5
0
void
readsection(HeaderInfo &rwh, uint32 build, uint32 level, istream &rw)
{
	for(uint32 i = 0; i < level; i++)
		cout << "  ";
	string name = getChunkName(rwh.type);
	cout << name << " (" << hex << rwh.length << " bytes @ 0x" <<
	  hex << rw.tellg()-(streampos)12 << "/0x" << hex << rw.tellg() <<
	  ") - [0x" << hex << rwh.type << "] " << rwh.build << endl;

	streampos end = rw.tellg() + (streampos)rwh.length;

	while(rw.tellg() < end){
		HeaderInfo newrwh;
		newrwh.read(rw);

		if(newrwh.build == build){
			readsection(newrwh, build, level+1, rw);

			/* Native Data PLG has the wrong length */
			if(rwh.type == 0x510)
				rw.seekg(end, ios::beg);
		}else{
			streampos sp = rw.tellg()+(streampos)rwh.length;
			sp -= 12;
			rw.seekg(sp, ios::beg);
			break;
		}
	}
}
Esempio n. 6
0
ScriptDataTag::ScriptDataTag(istream& s):VideoTag(s)
{
	unsigned int start=s.tellg();
	tiny_string methodName;

	//Specs talks about an arbitrary number of stuff, actually just a string and an array are expected
	UI8 Type;
	s >> Type;
	if(Type!=2)
		throw ParseException("Unexpected type in FLV");

	ScriptDataString String(s);
	methodName=String.getString();
	//cout << methodName << endl;

	s >> Type;
	if(Type!=8)
		throw ParseException("Unexpected type in FLV");

	ScriptECMAArray ecmaArray(s);
	frameRate=ecmaArray.frameRate;
	//Compute totalLen
	unsigned int end=s.tellg();
	totalLen=(end-start)+11;
}
rspfErrorCode rspfRpfImageDisplayParameterSubheader::parseStream(istream& in,
                                                         rspfByteOrder byteOrder)
{
   clearFields();
   if(in)
   {
      theStartOffset = in.tellg();
      in.read((char*)&theNumberOfImageRows, 4);
      in.read((char*)&theNumberOfImageCodesPerRow, 4);
      in.read((char*)&theImageCodeBitLength, 1);
      theEndOffset = in.tellg();

      rspfEndian anEndian;
      if(anEndian.getSystemEndianType() != byteOrder)
      {
         anEndian.swap(theNumberOfImageRows);
         anEndian.swap(theNumberOfImageCodesPerRow);
      }
   }
   else
   {
      return rspfErrorCodes::RSPF_ERROR;
   }
   
   return rspfErrorCodes::RSPF_OK;
}
Esempio n. 8
0
size_t get_fsize(istream& is)
{
    size_t fsize = is.tellg();
    is.seekg(0, std::ios::end);
    fsize = size_t(is.tellg()) - fsize;
    is.seekg(0, std::ios::beg);
    return fsize;
}
bool SceneLoader::doCamera(istream &str, string &name)
{
    if (!getName(str, "camera", name))
        return false;

    SceneGroup *n = new SceneGroup();
    groups[name] = n;
    n->_name = name;

    n->_camera = new ParametricCamera();


    do {
        int state = findOpenOrClosedParen(str);
        if (state == ERROR) {
            SetCameraDefaults(n);
            return false;
        } else if (state == CLOSED) {
            SetCameraDefaults(n);
            return true;
        }
        else if (state == OPEN)
        {
            string cmd;
            vector<ParametricValue*> values;
            string sides = "lrbtnf";
            int side = 0;
            if (readCommand(str, cmd)) {
                if (cmd == "perspective") {
                    if (getValues(str, values) < 1) {
                        *err << "Perspective with no parameters at ";
                        errLine(str.tellg());
                    } else {
                        cleanAfter(values, 1);
                        n->_camera->_perspective = values[0];
                    }
                }
                else if (cmd.size() == 1 && (side = (int)sides.find(cmd)) != string::npos) {
                    if (getValues(str, values) < 1) {
                        *err << "l with no parameters at ";
                        errLine(str.tellg());
                    } else {
                        cleanAfter(values, 1);
                        n->_camera->_frustum[side] = values[0];
                    }
                }
                else
                {
                    *err << "Error: command " << cmd << " not recognized at ";
                    errLine(str.tellg());
                }
                findCloseParen(str);
            }
        }
    } while (true);
}
Esempio n. 10
0
std::streampos Data::_getStreamSize(istream &stream) {
  auto current_pos = stream.tellg();

  //Retrieve length
  stream.seekg(0, stream.end);
  auto endpos = stream.tellg();

  //Restore old position
  stream.seekg(current_pos, stream.beg);

  return endpos - current_pos;
}
Esempio n. 11
0
bool SceneLoader::doSphere(istream &str, string &name)
{
    if (!getName(str, "sphere", name))
        return false;

    SceneGroup *n = new SceneGroup();
    groups[name] = n;
    n->_name = name;

    n->_sphere = new ParametricSphere();

    do {
        int state = findOpenOrClosedParen(str);
        if (state == ERROR) {
            SetSphereDefaults(n);
            return false;
        } else if (state == CLOSED) {
            SetSphereDefaults(n);
            return true;
        } else if (state == OPEN)
        {
            string cmd;
            vector<ParametricValue*> values;
            if (readCommand(str, cmd)) {
                if (cmd == "radius") {
                    if (getValues(str, values) < 1) {
                        *err << "Type with no parameters at ";
                        errLine(str.tellg());
                    } else {
                        cleanAfter(values, 1);
                        n->_sphere->_radius = values[0];
                    }
                } else if (cmd == "material") {
                    string matName = getString(str);
                    if (matName.empty()) {
                        *err << "No material name after material command at ";
                        errLine(str.tellg());
                    } else if (materials[matName] == NULL) {
                        *err << "Unknown material " << matName << " referenced at ";
                        errLine(str.tellg());
                    } else {
                        n->_sphere->_material = materials[matName];
                    }
                } else {
                    *err << "Error: command " << cmd << " not recognized at ";
                    errLine(str.tellg());
                }
                findCloseParen(str);
            }
        }
    } while (true);
}
Esempio n. 12
0
// no obj includes in as5; they come back in as6
bool SceneLoader::doInclude(istream &str, string& name)
{
    if (!getName(str, "include", name))
        return false;

    SceneGroup *n = new SceneGroup();
    groups[name] = n;
    n->_name = name;

    string file = getQuoted(str);
    n->_mesh = new OBJTriangleMesh(file);

    do {
        int state = findOpenOrClosedParen(str);
        if (state == ERROR) {
            if (n->_meshMaterial == NULL) {
                n->_meshMaterial = new ParametricMaterial();
                SetMaterialDefaults(n->_meshMaterial);
            }
            return false;
        } else if (state == CLOSED) {
            if (n->_meshMaterial == NULL) {
                n->_meshMaterial = new ParametricMaterial();
                SetMaterialDefaults(n->_meshMaterial);
            }
            return true;
        } else if (state == OPEN) {
            string cmd;
            if (readCommand(str, cmd)) {
                if (cmd == "material") {
                    string matName = getString(str);
                    if (matName.empty()) {
                        *err << "No material name after material command at ";
                        errLine(str.tellg());
                    } else if (materials[matName] == NULL) {
                        *err << "Unknown material " << matName << " referenced at ";
                        errLine(str.tellg());
                    } else {
                        n->_meshMaterial = materials[matName];
                    }
                } else {
                    *err << "Error: command " << cmd << " not recognized at ";
                    errLine(str.tellg());
                }
                findCloseParen(str);
            }
        }
    } while (true);
}
Esempio n. 13
0
void CL_TimeOfDay::FromStream (istream& s)
{
    CL_String rep;
    char c;
    long count = 0;
    char fill_char = s.fill ();
    
    while (s.get (c) && c == fill_char);
    if (!s.good() || s.eof()) {
        _numSecs = 0;
        return;
    }
    do {
        if (isalnum (c) || c == ':') {
            rep.Append (c);
            count++;
        }
        else
            break;
    } while (s.get (c));

    long n = ParseAndConvert (rep);
    if (n > 0) {
        if (!s.eof())
            s.putback (c);
        _numSecs = n;
    }
    else {
        s.seekg (s.tellg() - count, istream::cur);
        _numSecs = 0;
    }
}
Esempio n. 14
0
bool DSA1Intro::read(istream& strm) {
    header_size = 20;
    file_size   = filesize(strm);
    count       = read16(strm);
    // TODO: Was bedeutet der Rest des Headers?
    strm.seekg(0x20);
    while(strm.tellg() < file_size) {
	DSA1Intro_Entry* entry = new DSA1Intro_Entry;
	if (!entry->read(strm)) {
	    entry->name    = "DUMMY";
	    entry->size    = 0;
	    entry->volname = "DUMMY";
	    entry->offset  = 0;
	    entries.push_back(entry);
	    //delete entry;
	} else {
	    // Nach Duplikaten suchen und diese entfernen
	    /*for (u32 j=0; j<entries.size(); j++) {
		if (entry->name == entries[j]->name) {
		    delete entry;
		    entry = 0;
		    break;
		}
		}*/
	    if (entry == 0) continue;
	    else entries.push_back(entry);
	}
    }
    //assert(count == entries.size());
    return true;
 }
Esempio n. 15
0
int
Patch::read_stream(istream &is, vector<string> &leftover)
{
   leftover.clear();
   // Number of faces in this patch
   int num_faces;
   is >> num_faces;

   bool debug = Config::get_var_bool("DEBUG_PATCH_READ_STREAM",false);
   if (debug)
      err_msg("\n********\nPatch::read_stream: %d faces to read", num_faces);

   if (num_faces > 0) {

      if (debug)
         err_msg("Patch::read_stream: reading %d faces from file", num_faces);

      // for each face...
      int face;
      for (int f = 0; f < num_faces; f++) {
         is >> face;
         if (face < _mesh->nfaces()) {
            add(_mesh->bf(face));
         } else {
            cerr << "Patch::read_stream - face " << face << " > "
               << _mesh->nfaces()
               << ", at byte " << is.tellg() << endl;
         }
      }
   } else {
      if (debug)
Esempio n. 16
0
bool SceneLoader::getName(istream &str, string type, string &name)
{
    name = getString(str);
    if (name.empty()) {
        *err << "Couldn't read " << type << " name at "; errLine(str.tellg());
        return false;
    }

    if (groups[name] != NULL)
    {
        *err << "Illegal re-use of name \"" << name << "\" at "; errLine(str.tellg());
        return false;
    }

    return true;
}
Esempio n. 17
0
vector< vector< double > > loadMatrix(istream &file) {
    vector< vector< double > > toReturn;
    int pos;
    string s;
    int matrix_width = 0;
    while(getline(file,s))
    {
        //Ignores files with a #
        size_t found = s.find("#");
        if(found!=string::npos)
            continue;
        vector< double > vd;
        stringstream ss(s);
        double d;
        while(!ss.fail()) {
            ss >> d;
            if(!ss.fail()) {
                vd.push_back(d);
            }
        }
        if(matrix_width==0)
            matrix_width = vd.size();
        if(vd.size() == matrix_width) {
            toReturn.push_back(vd);
        } else {
            // Return before the string that has been read
            file.seekg(pos);
            break;
        }
        pos = file.tellg();
    }
    return toReturn;
}
Esempio n. 18
0
/* Reads a whole file/stream: somewhat inelegant */
string read_whole_stream(istream& in) {
	in.seekg(0, ios::end);
	string buf(in.tellg(), '$');
	in.seekg(0, ios::beg);
	in.read(&buf[0], buf.size());
	return buf;
}
Esempio n. 19
0
bool Point3Dot::load(istream &in){
  coords.resize(3);
  int start = in.tellg();
  for(int i = 0; i < 3; i++){
    in >> coords[i];
    if(in.fail()){
      in.clear();
      in.seekg(start+1); //????????? Why that one
      return false;
    }
  }
  in >> theta;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  in >> phi;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  int typeInt;
  in >> typeInt;
  type = (Type)typeInt;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  return true;
}
Esempio n. 20
0
bool SceneLoader::doG(istream &str, string &name)
{
    name = getString(str);
    if (name.empty()) {
        *err << "Couldn't read group name at ";
        errLine(str.tellg());
        return false;
    }

    if (groups[name] != NULL)
    {
        *err << "Illegal re-use of group name \"" << name << "\" at ";
        curPos(*err,str.tellg());
        *err << endl;
        return false;
    }

    SceneGroup *n = new SceneGroup();
    groups[name] = n;
    n->_name = name;

    do {
        int state = findOpenOrClosedParen(str);
        if (state == ERROR)
            return false;
        else if (state == CLOSED)
            return true;
        else if (state == OPEN)
        {
            string cmd;
            if (readCommand(str, cmd)) {
                if (cmd != "I")
                {
                    *err << "Command other than I from G at ";
                    curPos(*err,str.tellg());
                    *err << endl;
                }
                string iname;
                SceneInstance *newNode;
                if ((newNode = doI(str,iname)) != NULL) {
                    n->_children.push_back( newNode );
                }
                findCloseParen(str);
            }
        }
    } while (true);
}
Esempio n. 21
0
void seekToFirstTree(istream &inputFile)
{
    if (DEBUG_OUTPUT >= 3){
        cout << "seekToFirstTree called." << endl;
    }
    string fileInputUpper;
    getline(inputFile,fileInputUpper);
    if (inputFile.bad()) {
        cout << "Can not read file given to seekToFirstTree." << endl;
        exit (0);
    }
    transform(fileInputUpper.begin(), fileInputUpper.end(),fileInputUpper.begin(), ::toupper);
    while (!( fileInputUpper.find("TREE") != string::npos && fileInputUpper.find("=") != string::npos))
    {
        if (DEBUG_OUTPUT >= 3){
            cout << fileInputUpper.substr(0,40) << endl;
        }
        getline(inputFile,fileInputUpper);
        if (inputFile.bad()) {
            cout << "Can not read file given to seekToFirstTree." << endl;
            exit (0);
        }
        transform(fileInputUpper.begin(), fileInputUpper.end(),fileInputUpper.begin(), ::toupper);
    }
    if (DEBUG_OUTPUT >= 3){
        cout << fileInputUpper.substr(0,40) << endl;
        cout << "inputFile.tellg(): "   << inputFile.tellg() << endl;
        cout << "inputFile.bad(): "     << inputFile.bad() << endl;
        cout << "inputFile.good(): "    << inputFile.good() << endl;
        cout << "inputFile.eof(): "     << inputFile.eof() << endl;
        cout << "inputFile.rdstate(): " << inputFile.rdstate() << endl;
    }
    // Something is happening to Peter's computer here!
    int curPosition = inputFile.tellg();
    // This might be causing problems to seek negative int from cur position
    // inputFile.seekg(-(fileInputUpper.size()+1),ios_base::cur);
    inputFile.seekg( curPosition - ((fileInputUpper.size()+1)), ios_base::beg);
    if (DEBUG_OUTPUT >= 3){
        cout << "inputFile.tellg(): " << inputFile.tellg() << endl;
        cout << "inputFile.bad(): " << inputFile.bad() << endl;
        cout << "inputFile.good(): " << inputFile.good() << endl;
        cout << "inputFile.eof(): " << inputFile.eof() << endl;
        cout << "inputFile.rdstate(): " << inputFile.rdstate() << endl;
        cout << "seekToFirstTree done." << endl;
    }
}
JSize
JTellg
	(
	istream& stream
	)
{
	return stream.tellg();
}
Esempio n. 23
0
bool SceneLoader::doSurface(istream &str, string& name) {
  name = getString(str);
  if (name.empty()) {
    *err << "Couldn't read surface name at "; errLine(str.tellg());
    return false;
  }

  if (_savedColors[name] != NULL) {
    *err << "Illegal re-use of surface name \"" << name << "\" at ";
    curPos(*err,str.tellg());
    *err << endl;
    return false;
  }

  do {
    int state = findOpenOrClosedParen(str);
    if (state == ERROR)
      return false;
    else if (state == CLOSED)
      return true;
    else if (state == OPEN) {
      string cmd;
      vector<ParametricValue*> values;
      if (readCommand(str, cmd)) {
	if (cmd == "rgb") {
	  int numv = getValues(str, values);
	  if (numv < 3) {
	    *err << "rgb with not enough args at "; errLine(str.tellg());
	  } else {
	    cleanAfter(values, 3);
	    Color *c = new Color();
	    for (int i = 0; i < 3; i++) {
	      c->_color[i] = values[i];
	    }
	    _savedColors[name] = c;
	  }
	} else if (cmd == "bitmap") {
	  // something with loading textures
	  string file = getQuoted(str);
	  _savedTextures[name] = file;
	}
	findCloseParen(str);
      }
    }
  } while (true);
}
Esempio n. 24
0
int IOBuffer::DRead(istream & stream, int recref)
// read specified record
		{
	stream.seekg(recref, ios::beg);
	if(stream.tellg() != recref)
		return -1;
	return Read(stream);
}
Esempio n. 25
0
CppSeqFile::Reader::Reader(istream& in, long start, long length) :
  _in(in), _dis(in)
{
  _start = start;
  if (length >= 0)
  {
    _end = start + length;
  }
  else
  {
    long p = in.tellg();
    in.seekg(0, ios_base::end);
    _end = in.tellg();
    in.seekg(p, ios_base::beg);
  }
  _init();
}
Esempio n. 26
0
void NifStream( IndexString & val, istream& in, const NifInfo & info ) {
	if (info.version >= VER_20_1_0_3) {
		std::streampos pos = in.tellg();

		ToIndexString(ReadUInt(in), hdrInfo::getInfo(in), val);
	} else {
		val = ReadString( in );
	}
}
Esempio n. 27
0
//------------------------------------------------------------------------------
unsigned eatBlankLines (istream& is, char* line, unsigned bufferSize) {
   char* pos;
   int lineStart(is.tellg());
   unsigned lines(0);
   while (true) {
      is.getline(line, bufferSize);
      pos = line;
      eatws(pos);
      if (*pos != 0 or !is.good()) {
         break;
      }
      lineStart = is.tellg();
      ++lines;
   }
   // what happens if we reach the end of the file?
   is.seekg(lineStart);
   return lines;
}
Esempio n. 28
0
    BinaryReader(istream &is): buffer(nullptr), size(0), pos(0) {
        is.seekg (0, ios::end);
        size = is.tellg();
        is.seekg (0, ios::beg);

        buffer = new char[size];
        is.read(buffer, size);
        is.seekg(0, ios::beg);
    }
Esempio n. 29
0
VideoDataTag::VideoDataTag(istream& s):VideoTag(s),_isHeader(false),packetData(NULL)
{
	unsigned int start=s.tellg();
	UI8 typeAndCodec;
	s >> typeAndCodec;

	frameType=(typeAndCodec>>4);
	codecId=(typeAndCodec&0xf);

	if(frameType!=1 && frameType!=2)
		throw ParseException("Unexpected frameType in FLV");

	assert_and_throw(codecId==7);

	//AVCVideoPacket
	UI8 packetType;
	s >> packetType;
	switch(packetType)
	{
		case 0: //Sequence header
			_isHeader=true;
			break;
		case 1: //NALU
			break;
		default:
			throw UnsupportedException("Unexpected packet type in FLV");
	}

	SI24 CompositionTime;
	s >> CompositionTime;
	assert_and_throw(CompositionTime==0); //TODO: what are composition times

	//Compute lenght of raw data
	packetLen=dataSize-5;
	int ret=posix_memalign((void**)&packetData, 16, packetLen+16); //Ensure no overrun happens when doing aligned reads
	assert(ret==0);

	s.read((char*)packetData,packetLen);
	memset(packetData+packetLen,0,16);

	//Compute totalLen
	unsigned int end=s.tellg();
	totalLen=(end-start)+11;
}
Esempio n. 30
0
FrFILETYPE FrFileType(istream &in)
{
   char buf[BUFFER_SIZE] ;
   long pos = in.tellg() ;
   in.seekg(0) ;
   (void)in.read(buf,sizeof(buf)) ;
   FrFILETYPE type = check_type(buf,in.gcount()) ;
   in.seekg(pos) ;
   return type ;
}