📄 mitab_maptoolblock.cpp
字号:
int nFileOffset /* = 0*/){ /*----------------------------------------------------------------- * Start with the default initialisation *----------------------------------------------------------------*/ if ( TABRawBinBlock::InitNewBlock(fpSrc, nBlockSize, nFileOffset) != 0) return -1; /*----------------------------------------------------------------- * And then set default values for the block header. *----------------------------------------------------------------*/ m_nNextToolBlock = 0; m_numDataBytes = 0; GotoByteInBlock(0x000); if (m_eAccess != TABRead) { WriteInt16(TABMAP_TOOL_BLOCK); // Block type code WriteInt16(0); // num. bytes used, excluding header WriteInt32(0); // Pointer to next tool block } if (CPLGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABMAPToolBlock::SetNextToolBlock() * * Set the address (offset from beginning of file) of the drawing tool block * that follows the current one. **********************************************************************/void TABMAPToolBlock::SetNextToolBlock(GInt32 nNextToolBlockAddress){ m_nNextToolBlock = nNextToolBlockAddress;}/********************************************************************** * TABMAPToolBlock::SetMAPBlockManagerRef() * * Pass a reference to the block manager object for the file this * block belongs to. The block manager will be used by this object * when it needs to automatically allocate a new block. **********************************************************************/void TABMAPToolBlock::SetMAPBlockManagerRef(TABBinBlockManager *poBlockMgr){ m_poBlockManagerRef = poBlockMgr;};/********************************************************************** * TABMAPToolBlock::ReadBytes() * * Cover function for TABRawBinBlock::ReadBytes() that will automagically * load the next coordinate block in the chain before reading the * requested bytes if we are at the end of the current block and if * m_nNextToolBlock is a valid block. * * Then the control is passed to TABRawBinBlock::ReadBytes() to finish the * work: * Copy the number of bytes from the data block's internal buffer to * the user's buffer pointed by pabyDstBuf. * * Passing pabyDstBuf = NULL will only move the read pointer by the * specified number of bytes as if the copy had happened... but it * won't crash. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/int TABMAPToolBlock::ReadBytes(int numBytes, GByte *pabyDstBuf){ int nStatus; if (m_pabyBuf && m_nCurPos >= (m_numDataBytes+MAP_TOOL_HEADER_SIZE) && m_nNextToolBlock > 0) { if ( (nStatus=GotoByteInFile(m_nNextToolBlock)) != 0) { // Failed.... an error has already been reported. return nStatus; } GotoByteInBlock(MAP_TOOL_HEADER_SIZE); // Move pointer past header m_numBlocksInChain++; } return TABRawBinBlock::ReadBytes(numBytes, pabyDstBuf);}/********************************************************************** * TABMAPToolBlock::WriteBytes() * * Cover function for TABRawBinBlock::WriteBytes() that will automagically * CommitToFile() the current block and create a new one if we are at * the end of the current block. * * Then the control is passed to TABRawBinBlock::WriteBytes() to finish the * work. * * Passing pabySrcBuf = NULL will only move the write pointer by the * specified number of bytes as if the copy had happened... but it * won't crash. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/int TABMAPToolBlock::WriteBytes(int nBytesToWrite, GByte *pabySrcBuf){ if (m_eAccess == TABWrite && m_poBlockManagerRef && (m_nBlockSize - m_nCurPos) < nBytesToWrite) { int nNewBlockOffset = m_poBlockManagerRef->AllocNewBlock(); SetNextToolBlock(nNewBlockOffset); if (CommitToFile() != 0 || InitNewBlock(m_fp, 512, nNewBlockOffset) != 0) { // An error message should have already been reported. return -1; } m_numBlocksInChain ++; } return TABRawBinBlock::WriteBytes(nBytesToWrite, pabySrcBuf);}/********************************************************************** * TABMAPToolBlock::CheckAvailableSpace() * * Check if an object of the specified type can fit in * current block. If it can't fit then force committing current block * and allocating a new one. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/int TABMAPToolBlock::CheckAvailableSpace(int nToolType){ int nBytesToWrite = 0; switch(nToolType) { case TABMAP_TOOL_PEN: nBytesToWrite = 11; break; case TABMAP_TOOL_BRUSH: nBytesToWrite = 13; break; case TABMAP_TOOL_FONT: nBytesToWrite = 37; break; case TABMAP_TOOL_SYMBOL: nBytesToWrite = 13; break; default: CPLAssert(FALSE); } if (GetNumUnusedBytes() < nBytesToWrite) { int nNewBlockOffset = m_poBlockManagerRef->AllocNewBlock(); SetNextToolBlock(nNewBlockOffset); if (CommitToFile() != 0 || InitNewBlock(m_fp, 512, nNewBlockOffset) != 0) { // An error message should have already been reported. return -1; } m_numBlocksInChain ++; } return 0;}/********************************************************************** * TABMAPToolBlock::Dump() * * Dump block contents... available only in DEBUG mode. **********************************************************************/#ifdef DEBUGvoid TABMAPToolBlock::Dump(FILE *fpOut /*=NULL*/){ if (fpOut == NULL) fpOut = stdout; fprintf(fpOut, "----- TABMAPToolBlock::Dump() -----\n"); if (m_pabyBuf == NULL) { fprintf(fpOut, "Block has not been initialized yet."); } else { fprintf(fpOut,"Coordinate Block (type %d) at offset %d.\n", m_nBlockType, m_nFileOffset); fprintf(fpOut," m_numDataBytes = %d\n", m_numDataBytes); fprintf(fpOut," m_nNextToolBlock = %d\n", m_nNextToolBlock); } fflush(fpOut);}#endif // DEBUG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -