예제 #1
0
void SkillLevelEvent::save( std::iostream& ios )
{

    Event::save(ios);

    // Save bonus
    ios.write( (char*) &bonus, sizeof( bonus ) );

    // Save skill
    ios.write( (char*) &skill, sizeof( skill ) );
}
예제 #2
0
파일: ammo.cpp 프로젝트: anylonen/abura-tan
void Ammo::toFile( std::iostream& outFile )
{

    // Write Item base information:
    Item::toFile( outFile );

    // Write char form
    outFile.write( (char*) &form, sizeof(form) );

    // Write bool fired
    outFile.write( (char*) &fired, sizeof(fired) );

}
예제 #3
0
void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
{
    out.clear(std::ios::goodbit);
    if(m_hasSearchPath) {
        std::string fullPath = resolvePath(fileName);
        PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
        if(!file) {
            out.clear(std::ios::failbit);
            stdext::throw_exception(stdext::format("failed to load file '%s': %s", fullPath.c_str(), PHYSFS_getLastError()));
        } else {
            int fileSize = PHYSFS_fileLength(file);
            if(fileSize > 0) {
                std::vector<char> buffer(fileSize);
                PHYSFS_read(file, (void*)&buffer[0], 1, fileSize);
                out.write(&buffer[0], fileSize);
            } else
                out.clear(std::ios::eofbit);
            PHYSFS_close(file);
            out.seekg(0, std::ios::beg);
        }
    } else {
        std::ifstream fin(fileName);
        if(!fin) {
            out.clear(std::ios::failbit);
            stdext::throw_exception(stdext::format("failed to load file '%s': %s", fileName.c_str(), PHYSFS_getLastError()));
        } else {
            out << fin.rdbuf();
        }
    }
}
예제 #4
0
void Fluid::toFile( std::iostream& outFile )
{

    // Write Item base information:
    Item::toFile( outFile );

    // Write materialClass f_material
    outFile.write( (char*) &f_material, sizeof(f_material) );

}
예제 #5
0
void readExactly(size_t toread, std::iostream& result)
{
  size_t hasread = 0;
  while(toread > hasread && std::cin.good()) {
    char a[1];
    std::cin.read(a,1);
    result.write(a,1);
    hasread++;
  }
}
예제 #6
0
void ActionEvent::save( std::iostream& ios )
{

    Event::save(ios);

    // Save target
    ios << target;

    // Save actor
    ios.write( (char*) &action, sizeof( action ) );
}
예제 #7
0
void FilePiece::print(int64_t from, int64_t to, std::iostream &outStream)
{
	if (fileData)
	{
		const int64_t BUFFSIZE = 8192;
		int64_t targetLength;
		uint8_t buffer[BUFFSIZE];
		for (int64_t i = from; i <= to; i += targetLength)
		{
			targetLength = MIN(BUFFSIZE, to - i + 1);
			cs.read(buffer, i, targetLength);
			outStream.write((const char *)buffer, targetLength);
		}
	}
	else
	{
		if (signature == SIG_CDFH || signature == SIG_DD)
		{
			FilePiece* fileDataPiece = (FilePiece*)extraBuffer;

			if (fileDataPiece->cs.reachedOffset < (fileDataPiece->length - 1))
			{
				uint8_t tmp;
				fileDataPiece->cs.read(&tmp, fileDataPiece->length - 1, 1);
			}

			if (fileDataPiece->cs.reachedOffset < (int64_t)(fileDataPiece->length - 1)) //safety measure: insufficient crc
				abort();
			if (signature == SIG_CDFH)
				((CDFH*)buffer)->CRC32 = fileDataPiece->cs.crc.GetCRC32();
			else if (signature == SIG_DD)
				((DD*)buffer)->CRC32 = fileDataPiece->cs.crc.GetCRC32();
		}
		outStream.write((const char *)buffer + from, to - from + 1);
	}
}
예제 #8
0
bool test_seekable_in_chunks(std::iostream& io)
{
    int i;  // old 'for' scope workaround.

    // Test seeking with ios::cur
    for (i = 0; i < data_reps; ++i) {
        io.write(narrow_data(), chunk_size);
        io.seekp(-chunk_size, BOOST_IOS::cur);
        char buf[chunk_size];
        io.read(buf, chunk_size);
        if (strncmp(buf, narrow_data(), chunk_size) != 0)
            return false;
        io.seekp(-chunk_size, BOOST_IOS::cur);
        io.write(narrow_data(), chunk_size);
    }

    // Test seeking with ios::beg
    std::streamoff off = 0;
    io.seekp(0, BOOST_IOS::beg);
    for (i = 0; i < data_reps; ++i, off += chunk_size) {
        io.write(narrow_data(), chunk_size);
        io.seekp(off, BOOST_IOS::beg);
        char buf[chunk_size];
        io.read(buf, chunk_size);
        if (strncmp(buf, narrow_data(), chunk_size) != 0)
            return false;
        io.seekp(off, BOOST_IOS::beg);
        io.write(narrow_data(), chunk_size);
    }
    
    // Test seeking with ios::end
    io.seekp(0, BOOST_IOS::end);
    off = io.tellp();
    io.seekp(-off, BOOST_IOS::end);
    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
        io.write(narrow_data(), chunk_size);
        io.seekp(-off, BOOST_IOS::end);
        char buf[chunk_size];
        io.read(buf, chunk_size);
        if (strncmp(buf, narrow_data(), chunk_size) != 0)
            return false;
        io.seekp(-off, BOOST_IOS::end);
        io.write(narrow_data(), chunk_size);
    }
    return true;
}
예제 #9
0
void Event::save( std::iostream& ios )
{

    ios.write( (char*) &time, sizeof(time) );
}