Example #1
0
bool Organism::State::Load (std::fstream &File) {
   int Count;

   File.read ((char *) &Count, sizeof (int));

   char *cname = new char [Count];
   File.read ((char *) cname, sizeof (char) * Count);

	Name = cname;

	delete [] cname;

   if (!File.good ())
      return false;

   return true;
}
Example #2
0
void ReadSector(char* buffer, size_t sec) {
    sec += partitionOffset;
    if (sec > partitionLength)
        return;

    f.seekg(sec * 512, std::ios::beg);
    f.read(buffer, 512);
}
Example #3
0
inline bool PBFParser::readBlob(std::fstream &stream, ParserThreadData *thread_data)
{
    if (stream.eof())
    {
        return false;
    }

    const int size = thread_data->PBFBlobHeader.datasize();
    if (size < 0 || size > MAX_BLOB_SIZE)
    {
        std::cerr << "[error] invalid Blob size:" << size << std::endl;
        return false;
    }

    char *data = new char[size];
    stream.read(data, sizeof(data[0]) * size);

    if (!thread_data->PBFBlob.ParseFromArray(data, size))
    {
        std::cerr << "[error] failed to parse blob" << std::endl;
        delete[] data;
        return false;
    }

    if (thread_data->PBFBlob.has_raw())
    {
        const std::string &data = thread_data->PBFBlob.raw();
        thread_data->charBuffer.clear();
        thread_data->charBuffer.resize(data.size());
        std::copy(data.begin(), data.end(), thread_data->charBuffer.begin());
    }
    else if (thread_data->PBFBlob.has_zlib_data())
    {
        if (!unpackZLIB(thread_data))
        {
            std::cerr << "[error] zlib data encountered that could not be unpacked" << std::endl;
            delete[] data;
            return false;
        }
    }
    else if (thread_data->PBFBlob.has_lzma_data())
    {
        if (!unpackLZMA(thread_data))
        {
            std::cerr << "[error] lzma data encountered that could not be unpacked" << std::endl;
        }
        delete[] data;
        return false;
    }
    else
    {
        std::cerr << "[error] Blob contains no data" << std::endl;
        delete[] data;
        return false;
    }
    delete[] data;
    return true;
}
Example #4
0
void
CBOLoader::_readIndexData (std::shared_ptr<nau::geometry::IndexData>& anIndexData, std::fstream &f) {

	unsigned int siz;
	unsigned int countFilledArrays;

	f.read(reinterpret_cast<char *> (&countFilledArrays), sizeof (countFilledArrays));

	f.read (reinterpret_cast<char *> (&siz), sizeof (siz));
	if (siz > 0) {
		std::shared_ptr<std::vector<unsigned int>> aNewVector = 
			std::shared_ptr<std::vector<unsigned int>>(new std::vector<unsigned int>(siz));

		f.read (reinterpret_cast<char *> (&(*aNewVector)[0]), siz * sizeof (unsigned int));

		anIndexData->setIndexData (aNewVector);
	}
}
Example #5
0
bool
StandardFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize )
{
    _fstream.read( (char*)buffer, size );
    if( _fstream.fail() )
        return true;
    nin = _fstream.gcount();
    return false;
}
Example #6
0
 unsigned readString(char* _str,unsigned _count) {
     if(size==0 || _str==0 || _count==0)
         return 0;
     char ch[1];
     unsigned i=0;
     for(i=0; i<_count && file.read(ch,sizeof(ch)); ++i) //读取文件中的内容
         sprintf(_str+2*i,"%02x",int(ch[0])+128);
     return i;
 }
Example #7
0
void stex::Tri::restore(std::fstream & cp_file)
{
    uint nspecs = patchdef()->countSpecs();
    cp_file.read((char*)pPoolCount, sizeof(uint) * nspecs);
    cp_file.read((char*)pPoolFlags, sizeof(uint) * nspecs);

    KProcPVecCI e = pKProcs.end();
    for (KProcPVecCI i = pKProcs.begin(); i != e; ++i) (*i)->restore(cp_file);
}
Example #8
0
int Camera::ByteToInt(std::fstream& _file)
{
	char b[4];
	int temp = 0;

	_file.read( b, sizeof(int) );
	memcpy( &temp, b, sizeof(int) );

	return temp;
}
Example #9
0
bool OsFileImpl::Read( void* Data, size_t Size )
{
    if( !IsValid() )
    {
        return false;
    }
    mFile.read( ( char* )Data, Size );
    mPosition = mFile.tellg();
    return IsValid();
}
Example #10
0
void Camera::read(std::fstream& stream, int versionNumber)
{
	stream.read((char*)&fogColor, sizeof(fogColor));
	setFogColor(fogColor);
	stream.read((char*)&fogStrength, sizeof(fogStrength));
	setFogStrength(fogStrength);

	if (versionNumber >= 6)
	{
		stream.read((char*)&fogColor, sizeof(fogColor));
		setFogColor(fogColor);

		stream.read((char*)&zoom ,sizeof(zoom));

	}

	if (versionNumber >= 11)
		stream.read((char*)&sunStrength, sizeof(sunStrength));
}
Example #11
0
camPath Camera::ByteToCamPath(std::fstream& _file)
{
	char b[sizeof(camPath)];
	camPath cp;

	_file.read(b, sizeof(camPath));
	memcpy(&cp, b, sizeof(camPath));

	return cp;
}
Example #12
0
//ReadOffsetString
//  Reads in the next 4 bytes as an offset to a zero-terminated string value, then
//  allocates and fills in the provided string with that value.
void ReadOffsetString(std::fstream& f, char*& sz)
{
	int32_t i;
	char szBuffer[4];

	f.read(szBuffer, 4);
	if (*(int32_t*)szBuffer == 0)
		sz = NULL;
	else
	{
		f.seekg(*(int32_t*)szBuffer - 4, ios::cur);
		for (i = 0; f.get() != '\0'; ++i);
		f.seekg(-(i + 1), ios::cur);
		sz = new char[i + 1];
		f.read(sz, i);
		sz[i] = '\0';
	}
	f.seekg(4 - *(int32_t*)szBuffer - i, ios::cur);
}
Example #13
0
/* Creates the material from a scene file. */
FrostedGlass::FrostedGlass(std::fstream& file, std::vector<Distribution*>* distributions) : Material(file)
{
    /* Read the material definition from the scene file. */
    FrostedGlassDefinition definition;
    file.read((char*)&definition, sizeof(FrostedGlassDefinition));

    /* Get the appropriate distribution from the distribution vector. */
    this->refractiveIndex = distributions->at(definition.refractiveIndex);
    this->roughness = definition.roughness;
}
Example #14
0
void G3D::readVertices(std::fstream & fs, std::vector<float*> & vertexAttributes, const GeometryInfo & info)
{
	for (uint32_t i=0; i<info.attributeSemantics.size(); ++i) 
	{
		vertexAttributes.push_back(NULL);
		uint32_t attributeFloats = floats(info.attributeSemantics.at(i));
		vertexAttributes.at(i) = new float[info.numberVertices * attributeFloats];
		fs.read((char*)vertexAttributes.at(i), info.numberVertices * attributeFloats * sizeof(float));
	}
}
Example #15
0
int User::readUNPW(std::fstream &fin){
	auto fpos = fin.cur;
	fin.seekg(0, fin.beg);
	fin.read(username, sizeof(str));
	fin.read(password, sizeof(str));
	decode(username);
	decode(password);
	fin.seekg(fpos);
	return 0;
}
Example #16
0
UINT64 TargetPhrase::ReadAlignFromFile(std::fstream &fileTPColl)
{
  UINT64 bytesRead = 0;

  UINT64 numAlign;
  fileTPColl.read((char*) &numAlign, sizeof(UINT64));
  bytesRead += sizeof(UINT64);

  for (size_t ind = 0; ind < numAlign; ++ind) {
    AlignPair alignPair;
    fileTPColl.read((char*) &alignPair.first, sizeof(UINT64));
    fileTPColl.read((char*) &alignPair.second, sizeof(UINT64));
    m_align.push_back(alignPair);

    bytesRead += sizeof(UINT64) * 2;
  }

  return bytesRead;
}
Example #17
0
void load_terran() {
	terrain_stream.open("Data/Terrain.raw", std::ios::out | std::ios::binary | std::ios::in);
	if (terrain_stream.is_open()) {
		fprintf(stdout, "Terrain file open success\n");
	}
	else {
		fprintf(stderr, "Terrain file open fail\n");
	}
	terrain_stream.read((char*)terrain, MAP_SIZE * MAP_SIZE);
}
Example #18
0
/* Creates a primitive, from a scene file and a list of materials and lights. */
Primitive::Primitive(std::fstream& file, std::vector<Material*>* materials, std::vector<Light*>* lights)
{
    /* Read the primitive header from the scene file. */
    PrimitiveDefinition definition;
    file.read((char*)&definition, sizeof(PrimitiveDefinition));

    /* Set the appropriate materials and lights from the passed vectors. */
    this->material = (definition.material >= 0) ? materials->at(definition.material) : nullptr;
    this->light = (definition.light >= 0) ? lights->at(definition.light) : nullptr;
}
void GameLoaderC3Map::Impl::initCameraStartPos(std::fstream &f, CityPtr ioCity)
{
  unsigned short int i = 0;
  unsigned short int j = 0;
  f.seekg(kCamera, std::ios::beg);
  f.read((char*)&i, 2);
  f.read((char*)&j, 2);

  ioCity->setCameraPos( TilePos( i, j ) );
}
void AnimationComponent::read(std::fstream& stream, int levelVersion)
{
	//std::string spriteFilename;
	int size;
	//char buffer[64];
	sf::Vector2i _spriteSize;
	
	stream.read((char*)&size, sizeof(size));
	std::string filepath(size,'\0');
	stream.read(&filepath[0], sizeof(char) * size);

	
	//stream.read(buffer, size);
	stream.read((char*)&_spriteSize, sizeof(_spriteSize));


	setSpriteSheet(imageManager->getTexture(filepath), _spriteSize);

}
Example #21
0
size_t Word::ReadFromFile(std::fstream &file)
{
  const size_t memAlloc = sizeof(UINT64) + sizeof(char);
  char mem[sizeof(UINT64) + sizeof(char)];
  file.read(mem, memAlloc);

  size_t memUsed = ReadFromMemory(mem);
  CHECK(memAlloc == memUsed);

  return memAlloc;
}
Example #22
0
		void read(std::string &s) {
			char c[2];
			std::ostringstream stream;

			while (true) {
				m_stream.read(c, 1);
				if (c[0] == '\0') break;
				stream << c[0];
			}
			s = stream.str();
		}
Example #23
0
inline bool PBFParser::readPBFBlobHeader(std::fstream &stream, ParserThreadData *thread_data)
{
    int size(0);
    stream.read((char *)&size, sizeof(int));
    size = SwapEndian(size);
    if (stream.eof())
    {
        return false;
    }
    if (size > MAX_BLOB_HEADER_SIZE || size < 0)
    {
        return false;
    }
    char *data = new char[size];
    stream.read(data, size * sizeof(data[0]));

    bool dataSuccessfullyParsed = (thread_data->PBFBlobHeader).ParseFromArray(data, size);
    delete[] data;
    return dataSuccessfullyParsed;
}
Example #24
0
void C3Map::Impl::initClimate(std::fstream &f, PlayerCityPtr ioCity )
{
  // read climate
  unsigned int i = 0;
  f.seekg(kClimate, std::ios::beg);
  f.read((char*)&i, 1);

  ioCity->setOption( PlayerCity::climateType, i);

  Logger::warning( "C3MapLoader: climate type is %d", i );
}
Example #25
0
void copy_file(std::fstream& outf, std::fstream& inf)
{
    while (true) {
        char c;
        inf.read(&c, sizeof (c));
        if(inf.eof()) {
            break;
        }
        outf.write(&c, sizeof (c));
    }
}
	void ModelDeSerializer::ReadAsBytes(std::fstream& fileStream, uint_t size, std::string& data)
	{
		char* buffer = new char[size+1];
		buffer[size] = '\0';

		fileStream.read(buffer, size);

		data = std::string(buffer);

		delete buffer;
	}
Example #27
0
bool MixHeader::readKeySource(std::fstream& fh)
{
    if(!fh.is_open()) return false;

    fh.seekg(0, std::ios::beg);
    //read first 4 bytes, determine if we have keysource mix or not.
    char flagbuff[4];
    fh.read(flagbuff, 4);
    int32_t flags = *reinterpret_cast<int32_t*>(flagbuff);

    if(flags != mix_encrypted && flags != mix_encrypted + mix_checksum) {
        std::cout << "key_source not suitable." << std::endl;
        return false;
    }

    fh.read(m_keysource, 80);
    get_blowfish_key(reinterpret_cast<uint8_t*>(m_keysource),
                     reinterpret_cast<uint8_t*>(m_key));
    return true;
}
Example #28
0
	void Database::_WriteBlock(Item towrite, uint64_t blockpos) {
		backing.seekg(blockpos);
		backing.seekp(blockpos);
		uint64_t blkhdrs[4];
		if (backing.eof()) {
			blkhdrs[0] = 0;
			blkhdrs[1] = towrite.itemsize;
			blkhdrs[2] = towrite.itemsize;
			blkhdrs[3] = towrite.itemsize + (sizeof(uint64_t)*4) + 1;
			backing.write(0, 1);
			backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
			backing.write(towrite.item, towrite.itemsize);
			backing.flush();
		} else {
			_GetLock(blockpos, true);
			backing.read((char*)blkhdrs, sizeof(uint64_t)*4);
			if (towrite.itemsize + 1 + (sizeof(uint64_t)*4) <= blkhdrs[3]) {
				//Block large enough or non-existent block
				backing.write(0, 1);
				blkhdrs[0] = 0;
				blkhdrs[1] = towrite.itemsize;
				blkhdrs[2] = towrite.itemsize;
				//Keep blkhdrs[3]
				backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
				backing.write(towrite.item, towrite.itemsize);
				backing.flush();
				_ReleaseLock(blockpos, true);
			} else {
				//Have to continue to a new block, allocate or reuse
				std::streampos currentpos = backing.tellp();
				backing.seekp(0, std::ios::end);
				std::streampos endpos = backing.tellp();
				backing.seekp(currentpos, std::ios::beg);
				blkhdrs[0] = (uint64_t) endpos;

				//Keep blkhdrs[1]
				blkhdrs[2] = towrite.itemsize;
				//Keep blkhdrs[3]

				uint64_t blockcancontain = blkhdrs[3] - ((sizeof(uint64_t)*4) + 1);
				backing.write(0, 1);
				backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
				backing.write(towrite.item, blockcancontain);
				backing.flush();
				_ReleaseLock(blockpos, true);

				//Continue to next block!
				Item process;
				process.itemsize = towrite.itemsize-blockcancontain;
				process.item = towrite.item+blockcancontain;
				_WriteBlock(process, blockpos);
			}
		}
	}
Example #29
0
void Transaction::Load(std::fstream &stream, int version)
{
	m_Date.Load(stream, version);
	LoadString(m_Description, stream);
	LoadString(m_Payee, stream);
	LoadString(m_Category, stream);
	m_Amount.Load(stream, version);
	
	stream.read((char *) &m_Type, sizeof(unsigned char));
	
	unsigned char cBitset = 0;
	stream.read((char *) &cBitset, sizeof(unsigned char));
	
	std::bitset<8> localset(static_cast<unsigned long>(cBitset));
		
	m_Cleared = localset[0];
	m_Split = localset[1];
	
	if (version > 3)
	{
		m_Reconciled = localset[2];
		m_Flagged = localset[3];
		m_HasFITID = localset[4];
		
		if (m_HasFITID)
		{
			LoadString(m_FITID, stream);
		}
	}
	
	unsigned char numSplits = 0;	
	stream.read((char *) &numSplits, sizeof(unsigned char));
		
	for (int i = 0; i < numSplits; i++)
	{
		SplitTransaction tempSplit;
		tempSplit.Load(stream, version);
		
		m_aSplits.push_back(tempSplit);
	}
}
Example #30
0
size_t Word::ReadFromFile(std::fstream &file, size_t numFactors)
{
	size_t memAlloc = numFactors * sizeof(UINT64) + sizeof(char);
	char *mem = (char*) malloc(memAlloc);
	file.read(mem, memAlloc);
	
	size_t memUsed = ReadFromMemory(mem, numFactors);
	assert(memAlloc == memUsed);
	free(mem);
	
	return memUsed;
}