Пример #1
0
// TODO: fix
boost::shared_ptr<Token> Tokenizer::peek(std::istream &is, SymbolTablePtr symbols) {
  std::streampos pos = is.tellg();
  boost::shared_ptr<Token> peek = next(is, symbols);
  is.seekg(pos);

  return peek;
}
Пример #2
0
boost::shared_ptr<Token> Tokenizer::next(std::istream &is, SymbolTablePtr symbols) {
  // Clear any whitespace until the next token. This works because no token
  // depends on _leading_ whitespace, as long as it is separated from the
  // previous token.
  while(std::isspace(is.peek())) is.get();

  // Now that we've cleared whitespace, may be at EOF.
  if(!is.good()) return NULL;

  for(size_t i = 0; i < TOKEN_PARSING_FUNCS_LENGTH; i++) {
    std::streampos pos = is.tellg();

    TokenParsingFunc f = TOKEN_PARSING_FUNCS[i];
    boost::shared_ptr<Token> token = f(is, symbols);

    if(token) {
      return token;
    } else {
      is.seekg(pos);
    }
  }

  std::cerr << "Tokenizer error!" << std::endl;
  exit(0);

  return NULL;
}
Пример #3
0
void OgreMeshDeserializer::determineEndianness(std::istream& stream)
{
    if (stream.tellg() != 0) {
        throw std::runtime_error(
            "Can only determine the endianness of the input stream if it "
                "is at the start");
    }

    std::uint16_t dest;
    // read header id manually (no conversion)
    stream.read(reinterpret_cast<char*>(&dest), sizeof(std::uint16_t));
    auto actually_read = stream.gcount();
    // skip back
    stream.seekg(0);
    if (actually_read != sizeof(std::uint16_t)) {
        // end of file?
        std::runtime_error("Couldn't read 16 bit header value from input stream.");
    }
    if (dest == HEADER_STREAM_ID) {
        m_flipEndian = false;
    } else if (dest == OTHER_ENDIAN_HEADER_STREAM_ID) {
        m_flipEndian = true;
    } else {
        std::runtime_error("Header chunk didn't match either endian: Corrupted stream?");
    }
}
Пример #4
0
    bool load(std::istream &in, Memory& mem, addr_t img_base) {
        if (virt_sz > 0) {
            addr_t sect_addr_va = img_base + virt_addr;
            int prot = get_prot(charac);
            mem.alloc_protect(sect_addr_va , virt_sz, prot | Memory::Write);
            //TODO check for file_sz > virt_sz (explained in spec)
            if (file_sz > 0) {
                std::istream::streampos pos_orig = in.tellg(); 
                if (pos_orig == std::istream::pos_type(std::istream::off_type(-1)))
                    return false;
                in.seekg(file_pos, std::ios_base::beg);
                // TODO is "bad()" the right thing to check?
                if (in.bad())
                    return false;
                char *sect_data = new char[file_sz];
                in.read(sect_data, file_sz);
                if (std::size_t(in.gcount()) < file_sz) {
                    delete[] sect_data;
                    return false;
                }
                // perhaps change "write" interface to accept const char * to
                // avoid this copying madness?
                mem.write(sect_addr_va, std::string(sect_data, file_sz));
                delete[] sect_data;
                if (!(prot & Memory::Write))
                    mem.alloc_protect(sect_addr_va, virt_sz, prot);
                in.seekg(pos_orig);
                if (in.bad())
                    return false;
            }
        }

        return true;
    }
Пример #5
0
        bool      archive::get_file(std::istream & stream_, const entry_p entry, file_p output) {
            uint32_t file_offset, bytes_read, use_size;

            std::streampos _save = stream_.tellg();
            file_offset = begin_data_offset + entry->offset;
          
            use_size = std::max(entry->size, entry->storage_size);
            output->data = new uint8_t[use_size];

            bytes_read = 0;
            stream_.seekg(file_offset, stream_.beg);
            while (bytes_read < use_size) {
                if (!stream_.read((char *)output->data + bytes_read, use_size - bytes_read)) {
                    delete[] output->data;
                    output->data = nullptr;
                    return false;
                }
                bytes_read += stream_.gcount();
            }
            
            
            output->size = use_size;
            output->entry = entry;

            stream_.seekg(_save, stream_.beg);

            return true;
        }
Пример #6
0
			static uint64_t getSparseCount(std::istream & CIS)
			{
				CIS.clear();
				CIS.seekg(0,std::ios::end);
				uint64_t const n = CIS.tellg() / (2*sizeof(uint64_t));
				return n;
			}
Пример #7
0
bool demo_csgo::parse_full(std::istream& is) {
    while(!this->case_demo_stop) {
        int64_t start_pos = is.tellg();

        memset(&this->current_cmdheader, 0, sizeof(demo_cmdheader));
        if(!demo_cmdheader_read(is, this->current_cmdheader)) {
            std::cerr << "demo_csgo::parse_full(): !demo_cmdheader_read(is, this->current_cmdheader)" << std::endl;
            return false;
        }

        bool success;
        switch(this->current_cmdheader.cmd) {
        case DEMO_SIGNON: success = handle_cmdheader<DEMO_SIGNON>(is, this->current_cmdheader); break;
        case DEMO_PACKET: success = handle_cmdheader<DEMO_PACKET>(is, this->current_cmdheader); break;
        case DEMO_SYNCTICK: success = handle_cmdheader<DEMO_SYNCTICK>(is, this->current_cmdheader); break;
        case DEMO_CONSOLECMD: success = handle_cmdheader<DEMO_CONSOLECMD>(is, this->current_cmdheader); break;
        case DEMO_USERCMD: success = handle_cmdheader<DEMO_USERCMD>(is, this->current_cmdheader); break;
        case DEMO_DATATABLES: success = handle_cmdheader<DEMO_DATATABLES>(is, this->current_cmdheader); break;
        case DEMO_STOP: success = handle_cmdheader<DEMO_STOP>(is, this->current_cmdheader); break;
        case DEMO_CUSTOMDATA: success = handle_cmdheader<DEMO_CUSTOMDATA>(is, this->current_cmdheader); break;
        case DEMO_STRINGTABLES: success = handle_cmdheader<DEMO_STRINGTABLES>(is, this->current_cmdheader); break;
        default:
            std::cerr << "demo_csgo::parse_full(): switch(this->current_cmdheader.cmd), default case, this->current_cmdheader.cmd=" << std::dec << (uint32_t)this->current_cmdheader.cmd << std::endl;
        }

        if(!success) {
            std::cerr << "demo_csgo::parse_full(): !success" << std::endl;
            return false;
        }
    }

    return true;
}
Пример #8
0
bool L3DS::Load(std::istream &is)
{
    // get length of file:
    is.seekg(0, std::ios::end);
    m_bufferSize = is.tellg();
    is.seekg(0, std::ios::beg);

    m_buffer = static_cast<unsigned char*>(calloc(m_bufferSize, 1));
    if (m_buffer == 0)
    {
        fprintf(stderr, "L3DS::LoadFile - not enough memory (malloc failed)");
        return false;
    }
    is.read(reinterpret_cast<char *>(m_buffer), m_bufferSize);
    if(is.gcount() != std::streamsize(m_bufferSize))
    {
        free(m_buffer);
        m_bufferSize = 0;
        fprintf(stderr, "L3DS::LoadFile - error reading from stream");
        return false;
    }

    Clear();
    bool res = Read3DS();
    free(m_buffer);
    m_buffer = 0;
    m_bufferSize = 0;
    return res;
}
Пример #9
0
			IndexEntry readEntry(std::istream & indexistr, uint64_t const entryid) const
			{
				uint64_t const entrybitpos = getEntryBitPos(entryid);
				uint64_t const entrybytepos = entrybitpos>>3;
				uint64_t const entrybitoff = entrybitpos - (entrybytepos<<3);

				// seek to index position
				indexistr.clear();
				indexistr.seekg(entrybytepos,std::ios::beg);
				if ( static_cast<int64_t>(indexistr.tellg()) != static_cast<int64_t>(entrybytepos) )
				{
					::libmaus2::exception::LibMausException se;
					se.getStream() << "Failed to seek to index position " << entrybytepos << " in file " << filename << " of size "
						<< ::libmaus2::util::GetFileSize::getFileSize(filename) << std::endl;
					se.finish();
					throw se;
				}
				::libmaus2::bitio::StreamBitInputStream SBIS(indexistr);

				SBIS.read(entrybitoff);

				uint64_t const pos = SBIS.read(posbits);
				uint64_t const kcnt = SBIS.read(kbits);
				uint64_t const vcnt = SBIS.read(vbits);

				return IndexEntry(pos,kcnt,vcnt);
			}
Пример #10
0
msdata::msdata(std::istream& in, size_t fsize) : loaded_( false )
{
    static_assert(sizeof( detail::msdata ) == msdata::block_size
                  , "struct 'msdata' not alinged to 256 octets, check declaration.");

    int16_t scan = 0;
    while ( ( fsize - in.tellg() ) >= block_size ) {
        //auto pos = in.tellg();
        auto d = std::make_shared< detail::msdata >();
        in.read( reinterpret_cast<char *>(d.get()), block_size );
        //const detail::msdata * pdata = d.get();
        if ( in.fail() )
            return;
        if ( (d->flags & 0x0f) != record_type_code ) 
            return;

        if ( scan == 0 ) // 1-orign value
            scan = d->scan;

        if ( scan != d->scan )
            return;

        data_.push_back( d );
    }
}
Пример #11
0
static void check_contents(std::istream& s)
{
    int c;
    
    c = s.get();
    BOOST_CHECK(c == 'R');
    
    c = s.get();
    BOOST_CHECK(c == 'e');
    
    s.seekg(-4, std::ios_base::end);

    std::streamoff e = s.tellg();
    BOOST_CHECK(e == 78);

    c = s.get();
    BOOST_CHECK(c == 'n');
    
    BOOST_CHECK(!s.eof());

    BOOST_CHECK(s.get() == '.');
    BOOST_CHECK(s.get() == '.');
    BOOST_CHECK(s.get() == '.');
    BOOST_CHECK(s.get() == -1);

    BOOST_CHECK(s.eof());

    return;
}
Пример #12
0
void BoWBinaryReaderPrivate::readSimpleToken(std::istream& file,
                BoWToken* token)
{

  LimaString lemma,inflectedForm;
  Misc::readUTF8StringField(file,lemma);
#ifdef DEBUG_LP
  BOWLOGINIT;
  LDEBUG << "BoWBinaryReader::readSimpleToken file at: " << file.tellg();
  LDEBUG << "BoWBinaryReader::readSimpleToken read lemma: " << lemma;
#endif
  Misc::readUTF8StringField(file,inflectedForm);
#ifdef DEBUG_LP
  LDEBUG << "BoWBinaryReader::readSimpleToken read infl: " << inflectedForm;
#endif
  LinguisticCode category;
  uint64_t position,length;
  category=static_cast<LinguisticCode>(Misc::readCodedInt(file));
  position=Misc::readCodedInt(file);
  length=Misc::readCodedInt(file);
  token->setLemma(lemma);
  token->setInflectedForm(inflectedForm);
  token->setCategory(category);
  token->setPosition(position);
  token->setLength(length);
}
Пример #13
0
// moves the read pointer to the first frame compatible with the stream; returns "false" if no such frame is found
bool MpegStream::findNextCompatFrame(std::istream& in, std::streampos posMax)
{
    streampos pos (in.tellg());
    NoteColl notes (10);
    for (;;)
    {
        try
        {
            pos = getNextStream(in, pos);
            if (pos > posMax)
            {
                return false;
            }

            in.seekg(pos);
            try
            {
                MpegFrameBase frm (notes, in);
                if (isCompatible(frm))
                {
                    in.seekg(pos);
                    return true;
                }
            }
            catch (const MpegFrameBase::NotMpegFrame&)
            {
            }
        }
        catch (const EndOfFile&)
        {
            return false;
        }
    }
}
Пример #14
0
void SceneFileHandlerBase::initReadProgress(std::istream &is)
{
    if(_readProgressFP == NULL)
        return;

    // get length of the stream.
    _progressData.is = &is;
    is.seekg(0, std::ios::end);
    _progressData.length = is.tellg();
    is.seekg(0, std::ios::beg);

    _readReady = false;

    if(_useProgressThread)
    {
        _progressData.thread =  Thread::find("OSG::FileIOReadProgressThread");

        if(_progressData.thread == NULL)
        {
            _progressData.thread =
                OSG::Thread::get("OSG::FileIOReadProgressThread", true);
        }

        if(_progressData.thread != NULL)
        {
            _progressData.thread->runFunction(readProgress, 0, NULL);
        }
        else
        {
            SWARNING << "Couldn't create read progress thread!" << std::endl;
        }
    }
}
Пример #15
0
void Vab::ReadVb( std::istream& aStream )
{

    //    aStream.setByteOrder( QDataStream::LittleEndian );
	aStream.seekg(0, aStream.end);
	int streamSize = aStream.tellg();
	aStream.seekg(0, aStream.beg);
    
	if (streamSize > 5120) // No exoddus vb is greater than 5kb
	{
		for (_Uint32t i = 0; i < iHeader->iNumVags; ++i)
		{
			AoVag* vag = new AoVag();
			aStream.read((char*)&vag->iSize, sizeof(vag->iSize));
			aStream.read((char*)&vag->iSampleRate, sizeof(vag->iSampleRate));
			vag->iSampleData.resize(vag->iSize);
			aStream.read((char*)vag->iSampleData.data(), vag->iSize);

			iAoVags.push_back(vag);
		}
	}
	else
	{
		for (unsigned int i = 0; i < iHeader->iNumVags; i++)
		{
			AEVh* vh = new AEVh(aStream);
			iOffs.push_back(vh);
		}
	}
}
Пример #16
0
chunk_ptr chunk::read_chunk(std::istream &is) throw(std::ios_base::failure)
{
	uint32_t id;
	be32 length;

	std::istream::pos_type chunk_start = is.tellg();
	is.read(reinterpret_cast<char*>(&id), sizeof(id));

	
	chunk_create_function ccf = &chunk::create_chunk;

	for(chunk_info_table_type::const_iterator cittci = get_table().begin();
	    cittci != get_table().end();
		cittci++)
	{
		if((*cittci)->m_id == id)
		{
			ccf = (*cittci)->m_create_function;

			break;
		}
	}
	chunk_ptr rv = ccf(id,chunk_start, is);

	return rv;
}
Пример #17
0
        virtual ReadResult readShader(std::istream& fin,const Options* options) const
        {
            // read source
            fin.seekg(0, std::ios::end);
            int length = fin.tellg();
            char *text = new char[length + 1];
            fin.seekg(0, std::ios::beg);
            fin.read(text, length);
            text[length] = '\0';
        
            // create shader
            osg::Shader* shader = new osg::Shader();
            shader->setShaderSource( text );

            // check options which can define the type of the shader program
            if (options)
            {
                if (options->getOptionString().find("fragment")!=std::string::npos) shader->setType(osg::Shader::FRAGMENT);
                if (options->getOptionString().find("vertex")!=std::string::npos) shader->setType(osg::Shader::VERTEX);
                if (options->getOptionString().find("geometry")!=std::string::npos) shader->setType(osg::Shader::GEOMETRY);
            }

            // cleanup
            delete [] text;

            // return valid shader
            return shader;
        }
Пример #18
0
void ossimJ2kCodRecord::parseStream(std::istream& in)
{
   // Get the stream posistion.
   std::streamoff pos = in.tellg();

   // Note: Marker is not read.
   in.read((char*)&theLcod,      2);
   in.read((char*)&theScod,      1);
   in.read((char*)&theSGcod,     4);
   in.read((char*)&theSPcod,     4);

   if (ossim::byteOrder() == OSSIM_LITTLE_ENDIAN)
   {
      // Stored big endian, must swap.
      ossimEndian s;
      s.swap(theLcod);
      s.swap(theSGcod);
   }

   //---
   // Seek to next record.  This is needed because there are sometimes extra
   // bytes.
   //---
   in.seekg(pos + theLcod, std::ios_base::beg);
}
Пример #19
0
        bool      archive::get_file(std::istream & stream_, const entry_p entry_, file_p output) {
            std::streamoff file_offset, bytes_read;
            uint32_t use_size;

            std::streampos _save = stream_.tellg();
            file_offset = begin_data_offset + entry_->offset;
          
            
            
            stream_.seekg(file_offset, stream_.beg);
            if (entry_->compression == 'Cprs') {
                output->data = std::unique_ptr<uint8_t[]>(new uint8_t[entry_->size]);
                _lzss_decompress(stream_, entry_->size);
                memcpy(output->data.get(), this->_data.get(), entry_->size);
                use_size = entry_->size;
            }
            else {
                bytes_read = 0;
                use_size = entry_->storage_size;
                output->data = std::unique_ptr<uint8_t[]>(new uint8_t[use_size]);
                while (bytes_read < use_size) {
                    if (!stream_.read((char *)output->data.get() + bytes_read, use_size - bytes_read)) {
                        return false;
                    }
                    bytes_read += stream_.gcount();
                }
            }
            
            output->size = use_size;
            output->entry = entry_;

            stream_.seekg(_save, stream_.beg);

            return true;
        }
Пример #20
0
void GaussianFCHKParser::getGeometry(std::istream& is) {
  //atomic numbers
  vector<int> atomic_number(NumberOfAtoms);
  vector<double> q(NumberOfAtoms);

  //read atomic numbers
  search(is, "Atomic numbers");//search for Atomic numbers
  getValues(is,atomic_number.begin(),atomic_number.end());

  streampos pivot= is.tellg();
  //read effective nuclear charges
  search(is, "Nuclear");//search for Nuclear
  getValues(is,q.begin(),q.end());

  is.seekg(pivot);//rewind it
  search(is,"coordinates");
  vector<double> pos(NumberOfAtoms*OHMMS_DIM);
  getValues(is,pos.begin(),pos.end());

  SpeciesSet& species(IonSystem.getSpeciesSet());
  for(int i=0, ii=0; i<NumberOfAtoms; i++) {
    IonSystem.R[i][0]=pos[ii++]; 
    IonSystem.R[i][1]=pos[ii++]; 
    IonSystem.R[i][2]=pos[ii++];
    GroupName[i]=IonName[atomic_number[i]];
    int speciesID = species.addSpecies(GroupName[i]);
    IonSystem.GroupID[i]=speciesID;
    species(AtomicNumberIndex,speciesID)=atomic_number[i];
    species(IonChargeIndex,speciesID)=q[i];
  }
}
Пример #21
0
/*----------------------------------------------------------------------------*/
void Extractor::exec(std::istream &bitstream)
{
    Decoder::State decoder{PictureOutput::Disabled};
    CmdQueue cmdQueue;
    SNUQueue snuQueue;
    SNUQueue cvs;
    size_t cvsSizeInBytes = 0;

    while(!bitstream.eof())
    {
        const auto p = bitstream.tellg();
        auto snuPayload = parse(bitstream);

        /* parse only */
        {
            /* use "const L-value &" as payload (no ownership transfer) */
            snuQueue.push(makeHandle<SNU>(snuPayload));

            decoder.exec(CmdId::ParseSNU, snuQueue);
        }

        const NalUnitType nut =
            *toNalUnit(*decoder.snu).getSubtree<NUH>()->get<NUH::NalUnitType>();

        /* release all resources consumed by decoder while parsing current SNU */
        destruct(decoder.snu);

        if(isIDR(nut) || isBLA(nut) || isCRA(nut))
        {
            std::unique_lock<std::mutex> lock(m_mutex);

            m_queue.push({cvsSizeInBytes, std::move(cvs)});
            m_queueSizeInBytes += cvsSizeInBytes;
            cvsSizeInBytes = 0;
            m_popCond.notify_one();

            if(State::StopReq == m_state)
            {
                bitstream.seekg(p);
                break;
            }

            while(m_queueSizeInBytes > m_queueMaxSizeInBytes)
            {
                m_pushCond.wait(lock);
            }
        }

        cvsSizeInBytes += snuPayload.size();
        /* use "R-value &" as payload (ownership transfer) */
        cvs.push(makeHandle<SNU>(std::move(snuPayload)));
    }

    {
        std::unique_lock<std::mutex> lock(m_mutex);

        m_state = State::Stopped;
        m_popCond.notify_one();
    }
}
Пример #22
0
Field::Field(std::istream& file) :
		lambdaCache(), stoneCache() {
	char* file_buf;
	int file_size;

	file.seekg(0, std::ios::end);
	file_size = file.tellg();
	if (file_size == 0) {
		LOGERROR("Can't load map : file is empty");
		throw FieldParseException();
	}
	if (file_size == -1) {
		LOGERROR("Can't load map : no file specified");
		throw FieldParseException();
	}

	file_buf = new char[file_size + 1];
	file.seekg(0, std::ios::beg);
	file.read(file_buf, file_size);
	file_buf[file_size] = '\0';

	try {
		init(file_buf);
	} catch (const FieldParseException& e) {
		LOGERROR("Can't load map: map is incorrect");
		delete[] file_buf;
		throw e;
	}
	delete[] file_buf;
	LOGINFO("Map loaded");
}
Пример #23
0
Gdx2DPixmap::Gdx2DPixmap (std::istream& in, int requestedFormat)
        :
        pixData(0)
        ,width(0)
        ,height(0)
        ,format(0)
{

    char* nativeBuffer = (char*) malloc(1024);
    int bufSize = 1024;

    int readBytes = 0;

    while (!in.eof()) {
        in.read(nativeBuffer, 1024);
        readBytes += in.tellg();
        while (readBytes >= bufSize) {
            nativeBuffer = (char*) realloc(nativeBuffer, bufSize * 2);
            bufSize *= 2;
        }
    }

    pixData = load((unsigned char*)nativeBuffer, 0, readBytes, requestedFormat);

    width = pixData->width;
    height = pixData->height;
    format = pixData->format;

    free(nativeBuffer);

    if (pixData == NULL) {
        throw std::runtime_error("couldn't load pixmap");

    }
}
Пример #24
0
AudioDataTag::AudioDataTag(std::istream& s):VideoTag(s),_isHeader(false)
{
	unsigned int start=s.tellg();
	BitStream bs(s);
	SoundFormat=(FLV_AUDIO_CODEC)(int)UB(4,bs);
	switch(UB(2,bs))
	{
		case 0:
			SoundRate=5500;
			break;
		case 1:
			SoundRate=11000;
			break;
		case 2:
			SoundRate=22000;
			break;
		case 3:
			SoundRate=44000;
			break;
	}
	is16bit=UB(1,bs);
	isStereo=UB(1,bs);

	uint32_t headerConsumed=1;
	//Special handling for AAC data
	if(SoundFormat==AAC)
	{
		UI8 t;
		s >> t;
		_isHeader=(t==0);
		headerConsumed++;
	}
Пример #25
0
 std::streamoff skip_whitespace(std::istream& in, char& c)
 {
   std::streamoff pos = in.tellg();
   while (! in.eof() && (std::isspace(c) || c == '\n'))
     c = getchar(in);
   return pos;
 }
void ossimNitfTagInformation::parseStream(std::istream &in)
{
   if(in)
   {
      theTagOffset = in.tellg();
      in.read(theTagName, 6);
      in.read(theTagLength, 5);
      theTagDataOffset = in.tellg();

      theTagData = ossimNitfTagFactoryRegistry::instance()->create(getTagName());

      if (theTagData.valid())
      {
         if (theTagData->getClassName() == "ossimNitfUnknownTag")
         {
            // Unknown tag doesn't know his tag name yet.
            theTagData->setTagName( getTagName() );
         }

         //---
         // Tags with dynamic tag length construct with 0 length.
         // Set if 0.
         //---
         if ( theTagData->getTagLength() == 0 )
         {
            theTagData->setTagLength( getTagLength() );
         }
         // Sanity check fixed length in code with length from CEL field:
         else if ( theTagData->getTagLength() != getTagLength() )
         {
            ossimNotify(ossimNotifyLevel_WARN)
               << "ossimNitfTagInformation::parseStream WARNING!"
               << "\nCEL field length does not match fixed tag length for tag: "
               << theTagData->getTagName().c_str()
               << "\nCEL: " << getTagLength()
               << "\nTag: " << theTagData->getTagLength()
               << std::endl;
         }
                               
         theTagData->parseStream(in);
      }
      else
      {
         theTagData = (ossimNitfRegisteredTag*)NULL;
      }
   }
}
Пример #27
0
unsigned int extractDataSet(std::istream & sourceFile, DataSet & oneDataSet) {
	extractDataSetMeta(sourceFile, oneDataSet.setColumnsMetadata());

	// Calculate the width of the rows' data.
	int sumOfColumnSizes = 0; // Represents the total bytewidth of the fixed-width rows.
	std::vector<ColumnMetadata>::const_iterator oneCM;
	oneCM = oneDataSet.getColumnsMetadata().begin();
	std::vector<ColumnMetadata>::const_iterator metaDataEnd;
	metaDataEnd = oneDataSet.getColumnsMetadata().end();
	std::cout << "\t\tColumns and widths: \n";
	for (; oneCM < metaDataEnd; oneCM++) {
		int columnSize = oneCM->getColumnSize();
		sumOfColumnSizes += columnSize;
		std::cout << "\t\t\t";
		std::wcout << oneCM->getColumnName();
		std::cout << " (";
		std::cout << columnSize;
		std::cout << ")\n";
	}

	unsigned int thisSetRowCount = extractUint(sourceFile);
	std::cout << "\t\tNumber of rows: " << thisSetRowCount << "\n";
	oneDataSet.setRowCount(thisSetRowCount);

	// Extract the data set's rows. The DataSet class' buffer is
	// one-dimensional, so the reserve size should be the row
	// count by the sum of the column widths.
	unsigned long long byteCount = thisSetRowCount*sumOfColumnSizes;
	oneDataSet.setFlattenedDataElementsReserve(byteCount);

	// TODO: Implement a more OOP-based allocation.
	unsigned char * buff;
	if (byteCount > 0) {
		buff = new unsigned char[byteCount];
		sourceFile.read((char*)buff, byteCount);
		oneDataSet.setFlattenedDataElements(buff, &buff[byteCount]);
		delete [] buff;
	}

	// Done: Figure out why the bytewidth is SOMETIMES out-of-sync.
	//
	//       By the newest Command Console Generic Data File Format documentation:
	//
	//       "When [the current data set] is the last data set in the data
	//        group the value shall be 1 byte past the end of the data set. This
	//        way the size of the data set may be determined."
	//
	//       Therefore, the null byte is part of the spec.
	unsigned int currentPos = (unsigned int)sourceFile.tellg();
	unsigned int nextDataSetPos = oneDataSet.getNextDataSetPos();
	if (currentPos != nextDataSetPos) {
		if (nextDataSetPos - currentPos > 1) {
			// TODO: define and throw an exception.
		}
		sourceFile.seekg(nextDataSetPos);
	}

	return thisSetRowCount;
}
Пример #28
0
size_t getFileSize(std::istream& stream)
{
    stream.seekg(0, std::ios::end);
    size_t length = stream.tellg();
    stream.seekg(0, std::ios::beg);

    return length;
}
Пример #29
0
 void load(std::istream& ifs)
 {
     ifs.seekg(0, std::ios::end);
     auto length = ifs.tellg();
     ifs.seekg(0, std::ios::beg);
     m_text.resize(length);
     ifs.read(&m_text[0], length);
 }
Пример #30
0
	bool BinaryFile::Load(std::istream& stream, Buffer& buffer)
	{
		stream.seekg(0, std::ios_base::end);
		std::streamoff size = stream.tellg();
		stream.seekg(0, std::ios_base::beg);
		buffer.SetSize((int)size);
		stream.read(reinterpret_cast<char*>(buffer.StartPointer()), size);
		return true;
	}