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


C++ writeBlock函数代码示例

本文整理汇总了C++中writeBlock函数的典型用法代码示例。如果您正苦于以下问题:C++ writeBlock函数的具体用法?C++ writeBlock怎么用?C++ writeBlock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ftello

void PtexIncrWriter::writeMetaDataEdit()
{
    // init headers
    uint8_t edittype = et_editmetadata;
    uint32_t editsize;
    EditMetaDataHeader emdh;
    emdh.metadatazipsize = 0;
    emdh.metadatamemsize = 0;

    // record position and skip headers
    FilePos pos = ftello(_fp);
    writeBlank(_fp, sizeof(edittype) + sizeof(editsize) + sizeof(emdh));

    // write meta data
    for (int i = 0, n = _metadata.size(); i < n; i++) {
	MetaEntry& e = _metadata[i];
	emdh.metadatamemsize += writeMetaDataBlock(_fp, e);
    }
    // finish zip block
    emdh.metadatazipsize = writeZipBlock(_fp, 0, 0, /*finish*/ true);

    // update headers
    editsize = sizeof(emdh) + emdh.metadatazipsize;

    // rewind and write headers
    fseeko(_fp, pos, SEEK_SET);
    writeBlock(_fp, &edittype, sizeof(edittype));
    writeBlock(_fp, &editsize, sizeof(editsize));
    writeBlock(_fp, &emdh, sizeof(emdh));
    fseeko(_fp, 0, SEEK_END);
}
开发者ID:400notout,项目名称:oiio,代码行数:31,代码来源:PtexWriter.cpp

示例2: writeIndent

void Decompiler::writeIfControl(Common::WriteStream &out, const ControlStructure &control, size_t indent) {
	writeIndent(out, indent);

	const Variable *cond = control.ifCond->instructions.back()->variables[0];
	out.writeString("if (");
	out.writeString(formatVariableName(cond));
	out.writeString(") {\n");

	if (control.ifTrue)
		writeBlock(out, control.ifTrue, indent + 1);

	writeIndent(out, indent);
	out.writeString("}");

	if (control.ifElse) {
		out.writeString(" else {\n");
		writeBlock(out, control.ifElse, indent + 1);

		writeIndent(out, indent);
		out.writeString("}");
	}
	out.writeString("\n");

	if (control.ifNext)
		writeBlock(out, control.ifNext, indent);
}
开发者ID:xoreos,项目名称:xoreos-tools,代码行数:26,代码来源:decompiler.cpp

示例3: setNextBlock

/**
 * Menuliskan isi buffer ke filesystem
 * @param  position
 * @param  buffer
 * @param  size
 * @param  offset
 * @return
 */
int POI::writeBlock(Block position, const char *buffer, int size, int offset) {
	/* kalau sudah di END_BLOCK, return */
	if (position == END_BLOCK) {
		return 0;
	}
	/* kalau offset >= BLOCK_SIZE */
	if (offset >= BLOCK_SIZE) {
		/* kalau nextBlock tidak ada, alokasikan */
		if (nextBlock[position] == END_BLOCK) {
			setNextBlock(position, allocateBlock());
		}
		return writeBlock(nextBlock[position], buffer, size, offset - BLOCK_SIZE);
	}

	file.seekp(BLOCK_SIZE * DATA_POOL_OFFSET + position * BLOCK_SIZE + offset);
	int size_now = size;
	if (offset + size_now > BLOCK_SIZE) {
		size_now = BLOCK_SIZE - offset;
	}
	file.write(buffer, size_now);

	/* kalau size > block size, lanjutkan di nextBlock */
	if (offset + size > BLOCK_SIZE) {
		/* kalau nextBlock tidak ada, alokasikan */
		if (nextBlock[position] == END_BLOCK) {
			setNextBlock(position, allocateBlock());
		}
		return size_now + writeBlock(nextBlock[position], buffer + BLOCK_SIZE, offset + size - BLOCK_SIZE);
	}

	return size_now;
}
开发者ID:icalF,项目名称:PoisolFS,代码行数:40,代码来源:poi.cpp

示例4: putBytes

    void putBytes(const uchar* buf, int count)
    {
        uchar* data = (uchar*)buf;
        CV_Assert(m_f && data && m_current && count >= 0);
        if( m_current >= m_end )
            writeBlock();

        while( count )
        {
            int l = (int)(m_end - m_current);

            if (l > count)
                l = count;

            if( l > 0 )
            {
                memcpy(m_current, data, l);
                m_current += l;
                data += l;
                count -= l;
            }
            if( m_current >= m_end )
                writeBlock();
        }
    }
开发者ID:BKNio,项目名称:mjpeg,代码行数:25,代码来源:mjpegwriter.cpp

示例5: tfs_mkfs

int tfs_mkfs(char *filename, int nBytes){

	int i, diskNum;
	char* templateBlk = calloc(1, BLOCKSIZE);

	templateBlk[0] = 4;
	templateBlk[1] = 0x45;

	diskNum = openDisk(filename, nBytes);

	if(diskNum < 0)
		return ERR_MKDSK;

	for(i = 0; i < BLOCKSIZE; i++)
		writeBlock(diskNum, i, templateBlk);

	/* SUPER BLOCK */
	templateBlk[0] = 1;
	templateBlk[2] = 1;
	writeBlock(diskNum, 0, templateBlk);

        if(DEBUG)
            printf("Made File System with super block\n");

	free(templateBlk);
	close(diskNum);
	return 1;
}
开发者ID:bwong17,项目名称:CPE453-TinyFS,代码行数:28,代码来源:libTinyFS.c

示例6: calcTileRes

void PtexWriterBase::writeFaceData(FILE* fp, const void* data, int stride,
				   Res res, FaceDataHeader& fdh)
{
    // determine whether to break into tiles
    Res tileres = calcTileRes(res);
    int ntilesu = res.ntilesu(tileres);
    int ntilesv = res.ntilesv(tileres);
    int ntiles = ntilesu * ntilesv;
    if (ntiles == 1) {
	// write single block
	writeFaceBlock(fp, data, stride, res, fdh);
    } else {
	// write tiles to tilefp temp file
	rewind(_tilefp);

	// alloc tile header
	std::vector<FaceDataHeader> tileHeader(ntiles);
	int tileures = tileres.u();
	int tilevres = tileres.v();
	int tileustride = tileures*_pixelSize;
	int tilevstride = tilevres*stride;

	// output tiles
	FaceDataHeader* tdh = &tileHeader[0];
	int datasize = 0;
	const char* rowp = (const char*) data;
	const char* rowpend = rowp + ntilesv * tilevstride;
	for (; rowp != rowpend; rowp += tilevstride) {
	    const char* p = rowp;
	    const char* pend = p + ntilesu * tileustride;
	    for (; p != pend; tdh++, p += tileustride) {
		// determine if tile is constant
		if (PtexUtils::isConstant(p, stride, tileures, tilevres, _pixelSize))
		    writeConstFaceBlock(_tilefp, p, *tdh);
		else
		    writeFaceBlock(_tilefp, p, stride, tileres, *tdh);
		datasize += tdh->blocksize();
	    }
	}

	// output compressed tile header
	uint32_t tileheadersize = writeZipBlock(_tilefp, &tileHeader[0],
						int(sizeof(FaceDataHeader)*tileHeader.size()));


	// output tile data pre-header
	int totalsize = 0;
	totalsize += writeBlock(fp, &tileres, sizeof(Res));
	totalsize += writeBlock(fp, &tileheadersize, sizeof(tileheadersize));

	// copy compressed tile header from temp file
	totalsize += copyBlock(fp, _tilefp, datasize, tileheadersize);

	// copy tile data from temp file
	totalsize += copyBlock(fp, _tilefp, 0, datasize);

	fdh.set(totalsize, enc_tiled);
    }
}
开发者ID:400notout,项目名称:oiio,代码行数:59,代码来源:PtexWriter.cpp

示例7: paqFile

PaqDir *
paqFile(char *name, Dir *dir)
{
	int fd, n, nn, nb;
	vlong tot;
	uchar *block, *pointer;
	ulong offset;

	fd = open(name, OREAD);
	if(fd < 0) {
		warn("could not open file: %s: %r", name);
		return nil;
	}

	block = emallocz(blocksize);
	pointer = emallocz(blocksize);
	nb = 0;
	n = 0;
	tot = 0;
	for(;;) {
		nn = read(fd, block+n, blocksize-n);
		if(nn < 0) {
			warn("read failed: %s: %r", name);
			goto Err;
		}
		tot += nn;
		if(nn == 0) {	
			if(n == 0)
				break;	
			/* pad out last block */
			memset(block+n, 0, blocksize-n);
			nn = blocksize - n;
		}
		n += nn;
		if(n < blocksize)
			continue;
		if(nb >= blocksize/OffsetSize) {
			warn("file too big for blocksize: %s", name);
			goto Err;
		}
		offset = writeBlock(block, DataBlock);
		putl(pointer+nb*OffsetSize, offset);
		nb++;
		n = 0;
	}

	offset = writeBlock(pointer, PointerBlock);

	close(fd);
	free(pointer);
	free(block);
	dir->length = tot;
	return paqDirAlloc(dir, offset);
Err:
	close(fd);
	free(pointer);
	free(block);
	return nil;
}
开发者ID:grobe0ba,项目名称:plan9front,代码行数:59,代码来源:mkpaqfs.c

示例8: FreeMemoryBlock

const int MemBlockDevice::SaveFile(const std::string & data, FileHeader& file, int blocknr)
{
	for (int i = 0; i < file.nrofblocks; i++)
	{
		FreeMemoryBlock(file.blockPointers[i]);
	}
	if (file.nrofblocks > 0)
		file.blockPointers = 0;

	file.size = data.size();
	file.nrofblocks = (file.size / blocksize) + ((file.size % blocksize) ? 1 : 0);
	if(file.nrofblocks > 0)
		file.blockPointers = new int[file.nrofblocks];



	for (int i = 0; i < file.nrofblocks; i++)
	{
		file.blockPointers[i] = GetNextFreeBlock();
		if (file.blockPointers[i] == -1)
		{
			return -1;
		}
	}
	int err = writeBlock(blocknr, (char*)&file, sizeof(int)*4, 0 );
	if (err != 1)
	{
		return -1;
	}
	
	err = writeBlock(blocknr, file.name.c_str(), file.namesize, sizeof(int) * 4);
	if (err != 1)
	{
		return -1;
	}
	err = writeBlock(blocknr, (char*)file.blockPointers, sizeof(int)*file.nrofblocks, sizeof(int) * 4 + file.namesize);
	if (err != 1)
	{
		return -1;
	}
	int size = file.size;
	for (int i = 0; i < file.nrofblocks; i++)
	{
		int s = (size < blocksize) ? size%blocksize : blocksize;
		int err = writeBlock(file.blockPointers[i], (data.c_str() + i*blocksize), s, 0);
		if (err != 1)
		{
			return -1;
		}
		size -= blocksize;
	}

	return 1;
}
开发者ID:dastyk,项目名称:FileSystem,代码行数:54,代码来源:memblockdevice.cpp

示例9: testFunctionCallback

char testFunctionCallback(float seconds, float frequency)
{
  MMRESULT result;

  HWAVEOUT waveOut;
  result = waveOutOpen(&waveOut,
		       WAVE_MAPPER,
		       &waveFormat,
		       (DWORD_PTR)&waveOutCallback,
		       0,
		       CALLBACK_FUNCTION);
  if(result != MMSYSERR_NOERROR) {
    printf("waveOutOpen failed (result=%d)\n", result);
    return 1;
  }

  printf("[tid=%d] Opened Wave Mapper!\n", GetCurrentThreadId());
  fflush(stdout);
  
  waitForKey("to start rendering sound");

  DWORD sampleCount = seconds * waveFormat.nSamplesPerSec;
  LPSTR block1 = allocateBlock(sampleCount);
  LPSTR block2 = allocateBlock(sampleCount);
  fillSinWave(block1, frequency, sampleCount);
  fillSinWave(block2, frequency * 1.5, sampleCount);
  
  printf("Writing block (0x%p)...\n", block1);
  fflush(stdout);

  {
    WAVEHDR header1;
    WAVEHDR header2;
    
    ZeroMemory(&header1, sizeof(WAVEHDR));
    header1.dwBufferLength = sampleCount * waveFormat.nBlockAlign;
    header1.lpData = block1;
    
    writeBlock(waveOut, &header1);

    ZeroMemory(&header2, sizeof(WAVEHDR));
    header2.dwBufferLength = sampleCount * waveFormat.nBlockAlign;
    header2.lpData = block2;
    
    writeBlock(waveOut, &header2);
  }
  waitForKey("to close");

  waveOutClose(waveOut);

  return 0;
}
开发者ID:marler8997,项目名称:audio,代码行数:52,代码来源:samples.cpp

示例10: format

void format(char * device)
{
	FILE *floppy;
	unsigned int totalBlocks,FsBegin, fsBlockSize, index; 
	int blockNumber;
	UnusedBlock lastFreeBlock;
	DirectoryBlock rootDirectory;
	SuperBlock superBlock;
	
	floppy = fopen(device, "rw+");
	if(floppy==0){
		printf("floppy.img not found\n");
		return;
	}

	fseek(floppy, 0, SEEK_END);
	totalBlocks = ftell(floppy)/BLOCKSIZE;

	fseek(floppy, BLOCKSIZE*FsStart,SEEK_SET);

	FsBegin = ftell(floppy)/BLOCKSIZE;

	fsBlockSize = totalBlocks - FsBegin;
	index = FsBegin - 1;

	
	superBlock.magicNumber = MAGICNUMBER;
	superBlock.totalBlocksInDisk = totalBlocks; 
	superBlock.totalFreeBlocks = superBlock.totalBlocksInDisk  - 3;
	superBlock.firstFreeBlock = 3;
	superBlock.lastFreeBlock = superBlock.totalBlocksInDisk -1;
	
	
	for(blockNumber = superBlock.firstFreeBlock; blockNumber < superBlock.lastFreeBlock;blockNumber++)
	{
		UnusedBlock freeBlock;
		freeBlock.nextFreeBlock = blockNumber + 1;
		writeBlock(floppy, blockNumber, &freeBlock);
	}
	
	lastFreeBlock.nextFreeBlock=0;
	writeBlock(floppy, superBlock.lastFreeBlock, &lastFreeBlock);
	
	
	rootDirectory = createEmptyDirectory();
    writeBlock(floppy, ROOTBLOCK, &rootDirectory);
    
	writeBlock(floppy, SUPERBLOCK,&superBlock);
}
开发者ID:rogerpaz1116,项目名称:ProyectoSO2,代码行数:49,代码来源:formatFS.c

示例11: debug

void
VirtualComponent::saveToBuffer(uint8_t **buffer)
{
    uint8_t *old = *buffer;

    debug(3, "    Saving internal state (%d bytes) ...\n", VirtualComponent::stateSize());

    // Save internal state of sub components
    if (subComponents != NULL) {
        for (unsigned i = 0; subComponents[i] != NULL; i++)
            subComponents[i]->saveToBuffer(buffer);
    }
    
    // Save own internal state
    void *data; size_t size; int flags;
    for (unsigned i = 0; snapshotItems != NULL && snapshotItems[i].data != NULL; i++) {
        
        data  = snapshotItems[i].data;
        flags = snapshotItems[i].flags & 0x0F;
        size  = snapshotItems[i].size;

        if (flags == 0) { // Auto detect size
            
            switch (snapshotItems[i].size) {
                case 1:  write8(buffer, *(uint8_t *)data); break;
                case 2:  write16(buffer, *(uint16_t *)data); break;
                case 4:  write32(buffer, *(uint32_t *)data); break;
                case 8:  write64(buffer, *(uint64_t *)data); break;
                default: writeBlock(buffer, (uint8_t *)data, size);
            }
            
        } else { // Format is specified manually
            
            switch (flags) {
                case BYTE_FORMAT: writeBlock(buffer, (uint8_t *)data, size); break;
                case WORD_FORMAT: writeBlock16(buffer, (uint16_t *)data, size); break;
                case DOUBLE_WORD_FORMAT: writeBlock32(buffer, (uint32_t *)data, size); break;
                case QUAD_WORD_FORMAT: writeBlock64(buffer, (uint64_t *)data, size); break;
                default: assert(0);
            }
        }
    }
    
    if (*buffer - old != VirtualComponent::stateSize()) {
        panic("saveToBuffer: Snapshot size is wrong.");
        assert(false);
    }
}
开发者ID:jedivind,项目名称:VirtualC64-Core,代码行数:48,代码来源:VirtualComponent.cpp

示例12: do_tagging

void chunkArchive::writeString(const char *s)
{
	do_tagging(CHUNK_STRING);
	unsigned long size = strlen(s) + 1;
	writeLong(size);
	writeBlock((const char *) s, size);
}
开发者ID:itadinanta,项目名称:emufxtool,代码行数:7,代码来源:chunkfile.C

示例13: alloca

int PtexWriterBase::writeZipBlock(FILE* fp, const void* data, int size, bool finish)
{
    if (!_ok) return 0;
    void* buff = alloca(BlockSize);
    _zstream.next_in = (Bytef*)data;
    _zstream.avail_in = size;

    while (1) {
	_zstream.next_out = (Bytef*)buff;
	_zstream.avail_out = BlockSize;
	int zresult = deflate(&_zstream, finish ? Z_FINISH : Z_NO_FLUSH);
	int size = BlockSize - _zstream.avail_out;
	if (size > 0) writeBlock(fp, buff, size);
	if (zresult == Z_STREAM_END) break;
	if (zresult != Z_OK) {
	    setError("PtexWriter error: data compression internal error");
	    break;
	}
	if (!finish && _zstream.avail_out != 0)
	    // waiting for more input
	    break;
    }

    if (!finish) return 0;

    int total = _zstream.total_out;
    deflateReset(&_zstream);
    return total;
}
开发者ID:400notout,项目名称:oiio,代码行数:29,代码来源:PtexWriter.cpp

示例14: FIFO

//FIFO
void FIFO(BM_BufferPool *const bm, Structure_Details *node)  
{
  int i=0;
  int prev = n%buffpg_size;
  sd = (Structure_Details *) bm->mgmtData;
  while(i<buffpg_size) // checks if the page size is greater than 0
  {
    if(sd[prev].fixedcount == 0) 
	  {
      if(sd[prev].dirtyPage == 1) // checks if dirtypage is present and writes it to the disk
	    {
        openPageFile (bm->pageFile, &fh);
        writeBlock (sd[prev].pagenum, &fh, sd[prev].data);
        writeIO++;
	    }
    	 sd[prev].data = node->data;
    	 sd[prev].pagenum = node->pagenum;
    	 sd[prev].dirtyPage = node->dirtyPage;
    	 sd[prev].fixedcount = node->fixedcount;
    	 break;
	  }
	  else
	  {
       prev++;
	     if(prev%buffpg_size == 0)
       prev=0;
	  }
    i++;
  }
}
开发者ID:VTHIRUMOORTHY,项目名称:Database,代码行数:31,代码来源:buffer_mgr.c

示例15: while

void Buffer::closeFile(string& dbName, string& fileName, int fileType){
	FileInfo* tempFile = fileHead->firstFile;
	FileInfo* oldFile = NULL;

	while (tempFile){
		if ((tempFile->fileName == fileName) && (tempFile->type == fileType)){
			BlockInfo* tempBlock = tempFile->firstBlock;
			BlockInfo* oldBlock = NULL;
			while (tempBlock){
				oldBlock = tempBlock;
				tempBlock = tempBlock->next;
				if (oldBlock->dirtyBit)
					writeBlock(dbName, oldBlock);
				fileHead->fileNum--;
				//delete oldBlock;		//在哪分配就在哪释放
			}
			if (oldFile)
				oldFile->next = tempFile->next;
			else
				fileHead->firstFile = tempFile->next;
			delete tempFile;
			fileHead->fileNum--;
			break;
		}
		else{
			oldFile = tempFile;
			tempFile = tempFile->next;
		}
	}
}
开发者ID:DBMiniSQL,项目名称:MiniSQL,代码行数:30,代码来源:Buffer.cpp


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