当前位置: 首页>>代码示例>>C++>>正文


C++ ostream::seekp方法代码示例

本文整理汇总了C++中std::ostream::seekp方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::seekp方法的具体用法?C++ ostream::seekp怎么用?C++ ostream::seekp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ostream的用法示例。


在下文中一共展示了ostream::seekp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sizeof

void OSGA_Archive::IndexBlock::write(std::ostream& out)
{
    pos_type currentPos = ARCHIVE_POS( out.tellp() );

    if (_filePosition==pos_type(0))
    {
        OSG_INFO<<"OSGA_Archive::IndexBlock::write() setting _filePosition"<<std::endl;
        _filePosition = currentPos;
    }
    else
    {
         out.seekp( STREAM_POS( _filePosition ) );
    }
    OSG_INFO<<"OSGA_Archive::IndexBlock::write() to _filePosition"<< ARCHIVE_POS( out.tellp() )<<std::endl;

    out.write(reinterpret_cast<char*>(&_blockSize), sizeof(_blockSize));
    out.write(reinterpret_cast<char*>(&_filePositionNextIndexBlock), sizeof(_filePositionNextIndexBlock));
    out.write(reinterpret_cast<char*>(&_offsetOfNextAvailableSpace), sizeof(_offsetOfNextAvailableSpace));

    out.write(reinterpret_cast<char*>(_data),_blockSize);

    if( _filePosition < currentPos ) // move file ptr to the end of file
        out.seekp( STREAM_POS( currentPos ) );

    OSG_INFO<<"OSGA_Archive::IndexBlock::write() end"<<std::endl;
}
开发者ID:MORTAL2000,项目名称:OpenSceneGraph,代码行数:26,代码来源:OSGA_Archive.cpp

示例2: recursive_treewrite

	void recursive_treewrite(std::ostream &out, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *n, zsr::offset treestart)
	{
		static int nwritten = 0;
		logb(++nwritten);
		treesize nval = 0;
		if (n->m_children.count("") && n->m_children[""]->m_value) nval = n->m_children[""]->m_value->second.size();
		treesize nchild = 0;
		for (const std::pair<const std::string, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *> child : n->m_children) if (child.first != "" && child.second) nchild++; // TODO Probably a faster way?
		zsr::serialize(out, nchild);
		std::deque<zsr::offset> childpos{};
		for (const std::pair<const std::string, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *> child : n->m_children)
		{
			if (child.first == "" || ! child.second) continue;
			uint16_t namelen = child.first.size();
			zsr::serialize(out, namelen);
			out.write(&child.first[0], namelen);
			childpos.push_back(static_cast<zsr::offset>(out.tellp()));
			zsr::serialize(out, ptrfill);
		}
		zsr::serialize(out, nval);
		if (n->m_children.count("") && n->m_children[""]->m_value)
			for (const zsr::filecount &i : n->m_children[""]->m_value->second) zsr::serialize(out, i);
		for (const std::pair<const std::string, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *> child : n->m_children)
		{
			if (child.first == "" || ! child.second) continue;
			zsr::offset childstart = static_cast<zsr::offset>(out.tellp()) - treestart;
			out.seekp(childpos.front());
			zsr::serialize(out, childstart);
			out.seekp(0, std::ios_base::end);
			recursive_treewrite(out, child.second, treestart);
			childpos.pop_front();
		}
	}
开发者ID:showermat,项目名称:zsr-utils,代码行数:33,代码来源:search.cpp

示例3: saveToStream

void WorldRegion::saveToStream(std::ostream& regionData, std::ostream& chunkData)
{
	// Save the Pillars
	bio::gzip_compressor gzComp;
	bio::filtering_ostream gzOut;
	gzOut.push(gzComp);

	for (auto pillarIt = mPillars.begin(); pillarIt != mPillars.end(); ++pillarIt) {
		if ((*pillarIt != 0) && (*pillarIt)->isModified()) {
			std::ostringstream pillarData;
			gzOut.push(pillarData);
			(*pillarIt)->saveToStream(gzOut);
			gzOut.pop();

			uint32_t pillarDataSize = static_cast<uint32_t>(pillarData.str().size());
			uint32_t sectorOffset = findFreeRegionSectorOffset(*pillarIt, pillarDataSize);
			if (sectorOffset == 0) {
				throw std::exception("Couldn't find big enough free sector in RegionFile!");
			}

			uint32_t offset = getSectorFromOffset(sectorOffset) * RegionFileSectorSize;
			regionData.seekp(offset);
			regionData.write(pillarData.str().c_str(), pillarDataSize);
		}
	}

	// Save RegionFile Header
	regionData.seekp(0);
	regionData.write(reinterpret_cast<char*>(mPillarOffsets.data()), mPillarOffsets.size() * sizeof(mPillarOffsets[0]));

	// Now save the chunks
	saveChunksToStream(chunkData);
}
开发者ID:1am3r,项目名称:cubicplanets,代码行数:33,代码来源:WorldRegion.cpp

示例4:

	inline std::ostream::pos_type get_size(std::ostream& stream)
	{
		auto original_pos = stream.tellp();
		stream.seekp(0, std::ios::end);
		auto pos = stream.tellp();
		stream.seekp(original_pos);
		return pos;
	}
开发者ID:planaria,项目名称:kumori,代码行数:8,代码来源:stream_util.hpp

示例5: ShortWrite

/** Write data to a file section.
 *
 *   @param f       Output steam to which to write
 *   @param offset  Byte offset relative to start of this section
 *   @param bufsize Size of @p buf in bytes
 *   @param buf     Buffer of bytes to be written
 *
 *  @returns Returns the section-relative byte offset for the first byte beyond what would have been written if all bytes
 *  of the buffer were written.
 *
 *  The buffer is allowed to extend past the end of the section as long as the part that extends beyond is all zeros. The
 *  zeros will not be written to the output file.  Furthermore, any trailing zeros that extend beyond the end of the file will
 *  not be written (end-of-file is determined by SgAsmGenericFile::get_orig_size()) */
rose_addr_t
SgAsmGenericSection::write(std::ostream &f, rose_addr_t offset, size_t bufsize, const void *buf) const
{
    size_t nwrite, nzero;

    ROSE_ASSERT(this != NULL);

    /* Don't write past end of section */
    if (offset>=get_size()) {
        nwrite = 0;
        nzero  = bufsize;
    } else if (offset+bufsize<=get_size()) {
        nwrite = bufsize;
        nzero = 0;
    } else {
        nwrite = get_size() - offset;
        nzero = bufsize - nwrite;
    }

    /* Don't write past end of current EOF if we can help it. */
    f.seekp(0, std::ios::end);
    rose_addr_t filesize = f.tellp();
    while (nwrite>0 && 0==((const char*)buf)[nwrite-1] && get_offset()+offset+nwrite>filesize)
        --nwrite;

    /* Write bytes to file. This is a good place to set a break point if you're trying to figure out what section is writing
     * to a particular file address. For instance, if byte 0x7c is incorrect in the unparsed file you would set a conditional
     * breakpoint for o<=0x7c && o+nwrite>0x7c */
    ROSE_ASSERT(f);
    off_t o = get_offset() + offset;
    f.seekp(o);
    ROSE_ASSERT(f);
    f.write((const char*)buf, nwrite);
    ROSE_ASSERT(f);

    /* Check that truncated data is all zero and fail if it isn't */
    for (size_t i=nwrite; i<bufsize; i++) {
        if (((const char*)buf)[i]) {
            char mesg[1024];
            sprintf(mesg, "non-zero value truncated: buf[0x%zx]=0x%02x", i, ((const unsigned char*)buf)[i]);
            fprintf(stderr, "SgAsmGenericSection::write: error: %s", mesg);
            fprintf(stderr, " in [%d] \"%s\"\n", get_id(), get_name()->get_string(true).c_str());
            fprintf(stderr, "    section is at file offset 0x%08"PRIx64" (%"PRIu64"), size 0x%"PRIx64" (%"PRIu64") bytes\n", 
                    get_offset(), get_offset(), get_size(), get_size());
            fprintf(stderr, " write %" PRIuPTR " byte%s at section offset 0x%08"PRIx64"\n", bufsize, 1==bufsize?"":"s", offset);
            fprintf(stderr, "      ");
            HexdumpFormat hf;
            hf.prefix = "      ";
            hexdump(stderr, get_offset()+offset, (const unsigned char*)buf, bufsize, hf);
            fprintf(stderr, "\n");
            throw SgAsmGenericFile::ShortWrite(this, offset, bufsize, mesg);
        }
    }

    return offset+bufsize;
}
开发者ID:Sciumo,项目名称:rose,代码行数:69,代码来源:GenericSection.C

示例6: ShortWrite

/** Write data to a file section.
 *
 *   @param f       Output steam to which to write
 *   @param offset  Byte offset relative to start of this section
 *   @param bufsize Size of @p buf in bytes
 *   @param buf     Buffer of bytes to be written
 *
 *  @returns Returns the section-relative byte offset for the first byte beyond what would have been written if all bytes
 *  of the buffer were written.
 *
 *  The buffer is allowed to extend past the end of the section as long as the part that extends beyond is all zeros. The
 *  zeros will not be written to the output file.  Furthermore, any trailing zeros that extend beyond the end of the file will
 *  not be written (end-of-file is determined by SgAsmGenericFile::get_orig_size()) */
rose_addr_t
SgAsmGenericSection::write(std::ostream &f, rose_addr_t offset, size_t bufsize, const void *buf) const
{
    size_t nwrite;

    ROSE_ASSERT(this != NULL);

    /* Don't write past end of section */
    if (offset>=get_size()) {
        nwrite = 0;
    } else if (offset+bufsize<=get_size()) {
        nwrite = bufsize;
    } else {
        nwrite = get_size() - offset;
    }

    /* Don't write past end of current EOF if we can help it. */
    f.seekp(0, std::ios::end);
    rose_addr_t filesize = f.tellp();
    while (nwrite>0 && 0==((const char*)buf)[nwrite-1] && get_offset()+offset+nwrite>filesize)
        --nwrite;

    /* Write bytes to file. This is a good place to set a break point if you're trying to figure out what section is writing
     * to a particular file address. For instance, if byte 0x7c is incorrect in the unparsed file you would set a conditional
     * breakpoint for o<=0x7c && o+nwrite>0x7c */
    ROSE_ASSERT(f);
    off_t o = get_offset() + offset;
    f.seekp(o);
    ROSE_ASSERT(f);
    f.write((const char*)buf, nwrite);
    ROSE_ASSERT(f);

    /* Check that truncated data is all zero and fail if it isn't */
    for (size_t i=nwrite; i<bufsize; i++) {
        if (((const char*)buf)[i]) {
            char mesg[1024];
            sprintf(mesg, "non-zero value truncated: buf[0x%zx]=0x%02x", i, ((const unsigned char*)buf)[i]);
            mlog[ERROR] <<"SgAsmGenericSection::write: error: " <<mesg
                        <<" in [" <<get_id() <<"] \"" <<get_name()->get_string(true) <<"\"\n"
                        <<"    section is at file offset " <<StringUtility::addrToString(get_offset())
                        <<" size " <<StringUtility::plural(get_size(), "bytes") <<"\n"
                        <<"    write " <<StringUtility::plural(bufsize, "bytes")
                        <<" at section offset " <<StringUtility::addrToString(offset) <<"\n";
            HexdumpFormat hf;
            hf.prefix = "      ";
            hexdump(mlog[ERROR], get_offset()+offset, (const unsigned char*)buf, bufsize, hf);
            mlog[ERROR] <<"\n";
            throw SgAsmGenericFile::ShortWrite(this, offset, bufsize, mesg);
        }
    }

    return offset+bufsize;
}
开发者ID:GoblinInventor,项目名称:rose-develop,代码行数:66,代码来源:GenericSection.C

示例7: SaveToStream

WError WMaterial::SaveToStream(WFile* file, std::ostream& outputStream) {
	if (!Valid())
		return WError(W_NOTVALID);

	VkDevice device = m_app->GetVulkanDevice();

	// write the UBO data
	uint tmp = m_uniformBuffers.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	for (uint i = 0; i < m_uniformBuffers.size(); i++) {
		UNIFORM_BUFFER_INFO* UBO = &m_uniformBuffers[i];
		outputStream.write((char*)&UBO->descriptor.range, sizeof(UBO->descriptor.range));
		void* data;
		VkResult vkRes = vkMapMemory(device, m_uniformBuffers[i].memory, 0, UBO->descriptor.range, 0, (void **)&data);
		if (vkRes)
			return WError(W_UNABLETOMAPBUFFER);
		outputStream.write((char*)data, UBO->descriptor.range);
		vkUnmapMemory(device, m_uniformBuffers[0].memory);
	}

	// write the texture data
	tmp = m_sampler_info.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	std::streampos texturesOffset = outputStream.tellp();
	for (uint i = 0; i < m_sampler_info.size(); i++) {
		SAMPLER_INFO* SI = &m_sampler_info[i];
		tmp = 0;
		outputStream.write((char*)&tmp, sizeof(tmp));
		outputStream.write((char*)&SI->sampler_info->binding_index, sizeof(SI->sampler_info->binding_index));
	}
	outputStream.write((char*)&tmp, sizeof(tmp)); // effect id
	_MarkFileEnd(file, outputStream.tellp());

	// save dependencies
	for (uint i = 0; i < m_sampler_info.size(); i++) {
		SAMPLER_INFO* SI = &m_sampler_info[i];
		if (SI->img) {
			WError err = file->SaveAsset(SI->img, &tmp);
			if (!err)
				return err;
			outputStream.seekp(texturesOffset + std::streamoff(i * (2 * sizeof(uint))));
			outputStream.write((char*)&tmp, sizeof(tmp));
		}
	}
	WError err = file->SaveAsset(m_effect, &tmp);
	if (!err)
		return err;
	outputStream.seekp(texturesOffset + std::streamoff(m_sampler_info.size() * (2 * sizeof(uint))));
	outputStream.write((char*)&tmp, sizeof(tmp));

	return WError(W_SUCCEEDED);
}
开发者ID:Hasan-Jawaheri,项目名称:Wasabi,代码行数:52,代码来源:WMaterial.cpp

示例8: SaveProgram

void VSTPresets::SaveProgram(std::ostream &f, CVstPlugin &plugin)
//---------------------------------------------------------------
{
	bool writeChunk = plugin.ProgramsAreChunks();
	ChunkHeader header;
	header.chunkMagic = cMagic;
	header.version = 1;
	header.fxID = plugin.GetUID();
	header.fxVersion = plugin.GetVersion();

	// Write unfinished header... We need to update the size once we're done writing.
	std::streamoff start = f.tellp();
	Write(header, f);

	const uint32 numParams = plugin.GetNumParameters();
	WriteBE(numParams, f);

	char name[MAX(kVstMaxProgNameLen + 1, 256)];
	plugin.Dispatch(effGetProgramName, 0, 0, name, 0);
	f.write(name, 28);

	if(writeChunk)
	{
		char *chunk = nullptr;
		uint32 chunkSize = mpt::saturate_cast<uint32>(plugin.Dispatch(effGetChunk, 1, 0, &chunk, 0));
		if(chunkSize && chunk)
		{
			WriteBE(chunkSize, f);
			f.write(chunk, chunkSize);
		} else
		{
			// The plugin returned no chunk! Gracefully go back and save parameters instead...
			writeChunk = false;
		}
	}
	if(!writeChunk)
	{
		for(uint32 p = 0; p < numParams; p++)
		{
			WriteBE(plugin.GetParameter(p), f);
		}
	}

	// Now we know the correct chunk size.
	std::streamoff end = f.tellp();
	header.byteSize = static_cast<VstInt32>(end - start - 8);
	header.fxMagic = writeChunk ? chunkPresetMagic : fMagic;
	header.ConvertEndianness();
	f.seekp(start);
	Write(header, f);
	f.seekp(end);
}
开发者ID:ksnydertn,项目名称:modplug,代码行数:52,代码来源:VstPresets.cpp

示例9: saveChunksToStream

void WorldRegion::saveChunksToStream(std::ostream& chunksDataStream)
{
	// Save the chunks
	bio::gzip_compressor gzComp;
	bio::filtering_ostream gzOut;
	gzOut.push(gzComp);
	std::vector<Chunk*> chunksToSave;
	
	for (auto pillarIt = mPillars.begin(); pillarIt != mPillars.end(); ++pillarIt) {
		
		if (*pillarIt == 0) {
			continue;
		}

		// Get all chunks to save from the pillar
		(*pillarIt)->getChunksToSave(chunksToSave);

		for (size_t numChunks = 0; numChunks < chunksToSave.size(); ++numChunks) {
			Chunk* curChunk = chunksToSave[numChunks];
			std::ostringstream chunkData;
			gzOut.push(chunkData);
			if (!curChunk->saveToStream(gzOut)) {
				// No data or error occured, skip chunk
				gzOut.pop();
				continue;
			}
			gzOut.pop();

			uint32_t chunkDataSize = static_cast<uint32_t>(chunkData.str().size());
			log << "Chunk x:" << (int) curChunk->mX << " y:" << (int) curChunk->mY << " z:" << (int) curChunk->mZ << " Size: " << (unsigned int) chunkDataSize << std::endl;
			uint32_t sectorOffset = findFreeChunkSectorOffset(curChunk, chunkDataSize);
			if (sectorOffset == 0) {
				throw std::exception("Couldn't find big enough free sector in ChunkFile!");
			}

			uint32_t offset = getSectorFromOffset(sectorOffset) * ChunkFileSectorSize;
			chunksDataStream.seekp(offset);
			chunksDataStream.write(chunkData.str().c_str(), chunkDataSize);
		}
		chunksToSave.clear();
	}


	// Save ChunkFile Header
	for (auto chunkIt = mChunkOffsets.begin(); chunkIt != mChunkOffsets.end(); ++chunkIt) {
		if (chunkIt->second > 0) {
			chunksDataStream.seekp(chunkIt->first * sizeof(chunkIt->second));
			chunksDataStream.write(reinterpret_cast<char*>(&chunkIt->second), sizeof(chunkIt->second));
		}
	}
}
开发者ID:1am3r,项目名称:cubicplanets,代码行数:51,代码来源:WorldRegion.cpp

示例10: write

void AVR::write(std::ostream& os, const AVRTexture& texture)
{
	os.write("TEXT", 4);
	auto sizePos = os.tellp();
	os.seekp(4, std::ios::cur);
	auto startPos = os.tellp();

	os.write(texture.mPath.c_str(), texture.mPath.length() + 1);

	auto endPos = os.tellp();
	uint32_t size = endPos - startPos;
	os.seekp(sizePos);
	os.write((char*) &size, 4);
	os.seekp(endPos);
}
开发者ID:MiKom,项目名称:vorticity,代码行数:15,代码来源:avrtexture.cpp

示例11: SaveToStream

WError WEffect::SaveToStream(WFile* file, std::ostream& outputStream) {
	if (!Valid())
		return WError(W_NOTVALID);

	uint tmp;

	outputStream.write((char*)&m_topology, sizeof(m_topology));
	outputStream.write((char*)&m_depthStencilState, sizeof(m_depthStencilState));
	outputStream.write((char*)&m_rasterizationState, sizeof(m_rasterizationState));
	tmp = m_blendStates.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	outputStream.write((char*)m_blendStates.data(), m_blendStates.size() * sizeof(VkPipelineColorBlendAttachmentState));
	tmp = m_shaders.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	std::streampos shaderIdsBegin = outputStream.tellp();
	for (uint i = 0; i < m_shaders.size(); i++) {
		tmp = 0;
		outputStream.write((char*)&tmp, sizeof(tmp));
	}
	_MarkFileEnd(file, outputStream.tellp());
	for (uint i = 0; i < m_shaders.size(); i++) {
		WError err = file->SaveAsset(m_shaders[i], &tmp);
		if (!err)
			return err;
		outputStream.seekp(shaderIdsBegin + std::streamoff(i * sizeof(uint)));
		outputStream.write((char*)&tmp, sizeof(tmp));
	}

	return WError(W_SUCCEEDED);
}
开发者ID:Hasan-Jawaheri,项目名称:Wasabi,代码行数:30,代码来源:WEffect.cpp

示例12: SaveFile

bool VSTPresets::SaveFile(std::ostream &f, CVstPlugin &plugin, bool bank)
//-----------------------------------------------------------------------
{
	if(!bank)
	{
		SaveProgram(f, plugin);
	} else
	{
		bool writeChunk = plugin.ProgramsAreChunks();
		ChunkHeader header;
		header.chunkMagic = cMagic;
		header.version = 2;
		header.fxID = plugin.GetUID();
		header.fxVersion = plugin.GetVersion();

		// Write unfinished header... We need to update the size once we're done writing.
		Write(header, f);

		uint32 numProgs = std::max(plugin.GetNumPrograms(), VstInt32(1)), curProg = plugin.GetCurrentProgram();
		WriteBE(numProgs, f);
		WriteBE(curProg, f);
		char reserved[124];
		MemsetZero(reserved);
		Write(reserved, f);

		if(writeChunk)
		{
			char *chunk = nullptr;
			uint32 chunkSize = mpt::saturate_cast<uint32>(plugin.Dispatch(effGetChunk, 0, 0, &chunk, 0));
			if(chunkSize && chunk)
			{
				WriteBE(chunkSize, f);
				f.write(chunk, chunkSize);
			} else
			{
				// The plugin returned no chunk! Gracefully go back and save parameters instead...
				writeChunk = false;
			}
		}
		if(!writeChunk)
		{
			for(uint32 p = 0; p < numProgs; p++)
			{
				plugin.SetCurrentProgram(p);
				SaveProgram(f, plugin);
			}
			plugin.SetCurrentProgram(curProg);
		}

		// Now we know the correct chunk size.
		std::streamoff end = f.tellp();
		header.byteSize = static_cast<VstInt32>(end - 8);
		header.fxMagic = writeChunk ? chunkBankMagic : bankMagic;
		header.ConvertEndianness();
		f.seekp(0);
		Write(header, f);
	}

	return true;
}
开发者ID:ksnydertn,项目名称:modplug,代码行数:60,代码来源:VstPresets.cpp

示例13: reset

void Display::reset(std::ostream& os) {
	pthread_mutex_lock(&Display::mutex);
	os.flush();
        os.clear();
        os.seekp(0);
	pthread_mutex_unlock(&Display::mutex);
}
开发者ID:ic-hep,项目名称:emi3,代码行数:7,代码来源:Display.cpp

示例14: advance

 inline void advance(size_t s) {
   if (out == NULL) {
     expand_buf(s);
     off += s;
   } else {
     out->seekp(s, std::ios_base::cur);
   }
 }
开发者ID:Bhushan1002,项目名称:SFrame,代码行数:8,代码来源:oarchive.hpp

示例15: save

    bool
    save( std::ostream& stream ) const
    {
        stream.seekp( 0 );
        stream.write( reinterpret_cast<const char*>( &header ), sizeof( header ) );

        return stream.good();
    }
开发者ID:SilentControl,项目名称:mangler,代码行数:8,代码来源:elfio_header.hpp


注:本文中的std::ostream::seekp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。