⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mitab_maptoolblock.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/********************************************************************** * $Id: mitab_maptoolblock.cpp,v 1.6 2004/06/30 20:29:04 dmorissette Exp $ * * Name:     mitab_maptoollock.cpp * Project:  MapInfo TAB Read/Write library * Language: C++ * Purpose:  Implementation of the TABMAPToolBlock class used to handle *           reading/writing of the .MAP files' drawing tool blocks * Author:   Daniel Morissette, dmorissette@dmsolutions.ca * ********************************************************************** * Copyright (c) 1999, 2000, Daniel Morissette * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: *  * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  * DEALINGS IN THE SOFTWARE. ********************************************************************** * * $Log: mitab_maptoolblock.cpp,v $ * Revision 1.6  2004/06/30 20:29:04  dmorissette * Fixed refs to old address danmo@videotron.ca * * Revision 1.5  2000/11/15 04:13:50  daniel * Fixed writing of TABMAPToolBlock to allocate a new block when full * * Revision 1.4  2000/02/28 17:03:30  daniel * Changed TABMAPBlockManager to TABBinBlockManager * * Revision 1.3  2000/01/15 22:30:44  daniel * Switch to MIT/X-Consortium OpenSource license * * Revision 1.2  1999/09/26 14:59:37  daniel * Implemented write support * * Revision 1.1  1999/09/16 02:39:17  daniel * Completed read support for most feature types * **********************************************************************/#include "mitab.h"/*===================================================================== *                      class TABMAPToolBlock *====================================================================*/#define MAP_TOOL_HEADER_SIZE   8/********************************************************************** *                   TABMAPToolBlock::TABMAPToolBlock() * * Constructor. **********************************************************************/TABMAPToolBlock::TABMAPToolBlock(TABAccess eAccessMode /*= TABRead*/):    TABRawBinBlock(eAccessMode, TRUE){    m_nNextToolBlock = m_numDataBytes = 0;    m_numBlocksInChain = 1;  // Current block counts as 1     m_poBlockManagerRef = NULL;}/********************************************************************** *                   TABMAPToolBlock::~TABMAPToolBlock() * * Destructor. **********************************************************************/TABMAPToolBlock::~TABMAPToolBlock(){   }/********************************************************************** *                   TABMAPToolBlock::EndOfChain() * * Return TRUE if we reached the end of the last block in the chain * TABMAPToolBlocks, or FALSE if there is still data to be read from  * this chain. **********************************************************************/GBool TABMAPToolBlock::EndOfChain(){   if (m_pabyBuf &&        (m_nCurPos < (m_numDataBytes+MAP_TOOL_HEADER_SIZE) ||         m_nNextToolBlock > 0 ) )   {       return FALSE;  // There is still data to be read.   }   return TRUE;}/********************************************************************** *                   TABMAPToolBlock::InitBlockFromData() * * Perform some initialization on the block after its binary data has * been set or changed (or loaded from a file). * * Returns 0 if succesful or -1 if an error happened, in which case  * CPLError() will have been called. **********************************************************************/int     TABMAPToolBlock::InitBlockFromData(GByte *pabyBuf, int nSize,                                          GBool bMakeCopy /* = TRUE */,                                         FILE *fpSrc /* = NULL */,                                          int nOffset /* = 0 */){    int nStatus;    /*-----------------------------------------------------------------     * First of all, we must call the base class' InitBlockFromData()     *----------------------------------------------------------------*/    nStatus = TABRawBinBlock::InitBlockFromData(pabyBuf, nSize, bMakeCopy,                                            fpSrc, nOffset);    if (nStatus != 0)           return nStatus;    /*-----------------------------------------------------------------     * Validate block type     *----------------------------------------------------------------*/    if (m_nBlockType != TABMAP_TOOL_BLOCK)    {        CPLError(CE_Failure, CPLE_FileIO,                 "InitBlockFromData(): Invalid Block Type: got %d expected %d",                 m_nBlockType, TABMAP_TOOL_BLOCK);        CPLFree(m_pabyBuf);        m_pabyBuf = NULL;        return -1;    }    /*-----------------------------------------------------------------     * Init member variables     *----------------------------------------------------------------*/    GotoByteInBlock(0x002);    m_numDataBytes = ReadInt16();       /* Excluding 8 bytes header */    m_nNextToolBlock = ReadInt32();    /*-----------------------------------------------------------------     * The read ptr is now located at the beginning of the data part.     *----------------------------------------------------------------*/    GotoByteInBlock(MAP_TOOL_HEADER_SIZE);    return 0;}/********************************************************************** *                   TABMAPToolBlock::CommitToFile() * * Commit the current state of the binary block to the file to which  * it has been previously attached. * * This method makes sure all values are properly set in the map object * block header and then calls TABRawBinBlock::CommitToFile() to do * the actual writing to disk. * * Returns 0 if succesful or -1 if an error happened, in which case  * CPLError() will have been called. **********************************************************************/int     TABMAPToolBlock::CommitToFile(){    int nStatus = 0;    if ( m_pabyBuf == NULL )    {        CPLError(CE_Failure, CPLE_AssertionFailed,                  "CommitToFile(): Block has not been initialized yet!");        return -1;    }    /*-----------------------------------------------------------------     * Make sure 8 bytes block header is up to date.     *----------------------------------------------------------------*/    GotoByteInBlock(0x000);    WriteInt16(TABMAP_TOOL_BLOCK);    // Block type code    WriteInt16(m_nSizeUsed - MAP_TOOL_HEADER_SIZE); // num. bytes used    WriteInt32(m_nNextToolBlock);    nStatus = CPLGetLastErrorNo();    /*-----------------------------------------------------------------     * OK, call the base class to write the block to disk.     *----------------------------------------------------------------*/    if (nStatus == 0)        nStatus = TABRawBinBlock::CommitToFile();    return nStatus;}/********************************************************************** *                   TABMAPToolBlock::InitNewBlock() * * Initialize a newly created block so that it knows to which file it * is attached, its block size, etc . and then perform any specific  * initialization for this block type, including writing a default  * block header, etc. and leave the block ready to receive data. * * This is an alternative to calling ReadFromFile() or InitBlockFromData() * that puts the block in a stable state without loading any initial * data in it. * * Returns 0 if succesful or -1 if an error happened, in which case  * CPLError() will have been called. **********************************************************************/int     TABMAPToolBlock::InitNewBlock(FILE *fpSrc, int nBlockSize, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -