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

📄 ddffielddefn.cpp

📁 国际海图标准S-57格式数据读取源码VC
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "StdAfx.h"
#include "iso8211.h"#include "CplString.h"#include <ctype.h>/************************************************************************//*                            DDFFieldDefn()                            *//************************************************************************/DDFFieldDefn::DDFFieldDefn(){    poModule = NULL;    pszTag = NULL;    _fieldName = NULL;    _arrayDescr = NULL;    _formatControls = NULL;    nSubfieldCount = 0;    papoSubfields = NULL;    bRepeatingSubfields = FALSE;    nFixedWidth = 0;}/************************************************************************//*                           ~DDFFieldDefn()                            *//************************************************************************/DDFFieldDefn::~DDFFieldDefn(){    int   i;    CPLFree( pszTag );    CPLFree( _fieldName );    CPLFree( _arrayDescr );    CPLFree( _formatControls );    for( i = 0; i < nSubfieldCount; i++ )        delete papoSubfields[i];    CPLFree( papoSubfields );}/************************************************************************//*                            AddSubfield()                             *//************************************************************************/void DDFFieldDefn::AddSubfield( const char *pszName,                                 const char *pszFormat ){    DDFSubfieldDefn *poSFDefn = new DDFSubfieldDefn;    poSFDefn->SetName( pszName );    poSFDefn->SetFormat( pszFormat );    AddSubfield( poSFDefn );}/************************************************************************//*                            AddSubfield()                             *//************************************************************************/void DDFFieldDefn::AddSubfield( DDFSubfieldDefn *poNewSFDefn,                                int bDontAddToFormat ){    nSubfieldCount++;    papoSubfields = (DDFSubfieldDefn ** )        CPLRealloc( papoSubfields, sizeof(void*) * nSubfieldCount );    papoSubfields[nSubfieldCount-1] = poNewSFDefn;        if( bDontAddToFormat )        return;/* -------------------------------------------------------------------- *//*      Add this format to the format list.  We don't bother            *//*      aggregating formats here.                                       *//* -------------------------------------------------------------------- */    if( _formatControls == NULL || strlen(_formatControls) == 0 )    {        CPLFree( _formatControls );        _formatControls = CPLStrdup( "()" );    }        int nOldLen = strlen(_formatControls);        char *pszNewFormatControls = (char *)         CPLMalloc(nOldLen+3+strlen(poNewSFDefn->GetFormat()));        strcpy( pszNewFormatControls, _formatControls );    pszNewFormatControls[nOldLen-1] = '\0';    if( pszNewFormatControls[nOldLen-2] != '(' )        strcat( pszNewFormatControls, "," );        strcat( pszNewFormatControls, poNewSFDefn->GetFormat() );    strcat( pszNewFormatControls, ")" );        CPLFree( _formatControls );    _formatControls = pszNewFormatControls;/* -------------------------------------------------------------------- *//*      Add the subfield name to the list.                              *//* -------------------------------------------------------------------- */    if( _arrayDescr == NULL )        _arrayDescr = CPLStrdup("");    _arrayDescr = (char *)         CPLRealloc(_arrayDescr,                    strlen(_arrayDescr)+strlen(poNewSFDefn->GetName())+2);    if( strlen(_arrayDescr) > 0 )        strcat( _arrayDescr, "!" );    strcat( _arrayDescr, poNewSFDefn->GetName() );}/************************************************************************//*                               Create()                               *//*                                                                      *//*      Initialize a new field defn from application input, instead     *//*      of from an existing file.                                       *//************************************************************************/int DDFFieldDefn::Create( const char *pszTag, const char *pszFieldName,                           const char *pszDescription,                           DDF_data_struct_code eDataStructCode,                          DDF_data_type_code   eDataTypeCode,                          const char *pszFormat ){    CPLAssert( this->pszTag == NULL );    poModule = NULL;    this->pszTag = CPLStrdup( pszTag );    _fieldName = CPLStrdup( pszFieldName );    _arrayDescr = CPLStrdup( pszDescription );    _formatControls = CPLStrdup( "" );        _data_struct_code = eDataStructCode;    _data_type_code = eDataTypeCode;    if( pszFormat != NULL )        _formatControls = CPLStrdup( pszFormat );    if( pszDescription != NULL && *pszDescription == '*' )        bRepeatingSubfields = TRUE;    return TRUE;}/************************************************************************//*                          GenerateDDREntry()                          *//************************************************************************/int DDFFieldDefn::GenerateDDREntry( char **ppachData,                                     int *pnLength ){    *pnLength = 9 + strlen(_fieldName) + 1         + strlen(_arrayDescr) + 1        + strlen(_formatControls) + 1;    if( strlen(_formatControls) == 0 )        *pnLength -= 1;    if( ppachData == NULL )        return TRUE;    *ppachData = (char *) CPLMalloc( *pnLength+1 );        if( _data_struct_code == dsc_elementary )        (*ppachData)[0] = '0';    else if( _data_struct_code == dsc_vector )        (*ppachData)[0] = '1';    else if( _data_struct_code == dsc_array )        (*ppachData)[0] = '2';    else if( _data_struct_code == dsc_concatenated )        (*ppachData)[0] = '3';        if( _data_type_code == dtc_char_string )        (*ppachData)[1] = '0';    else if( _data_type_code == dtc_implicit_point )        (*ppachData)[1] = '1';    else if( _data_type_code == dtc_explicit_point )        (*ppachData)[1] = '2';    else if( _data_type_code == dtc_explicit_point_scaled )        (*ppachData)[1] = '3';    else if( _data_type_code == dtc_char_bit_string )        (*ppachData)[1] = '4';    else if( _data_type_code == dtc_bit_string )        (*ppachData)[1] = '5';    else if( _data_type_code == dtc_mixed_data_type )        (*ppachData)[1] = '6';    (*ppachData)[2] = '0';    (*ppachData)[3] = '0';    (*ppachData)[4] = ';';    (*ppachData)[5] = '&';    (*ppachData)[6] = ' ';    (*ppachData)[7] = ' ';    (*ppachData)[8] = ' ';    sprintf( *ppachData + 9, "%s%c%s",              _fieldName, DDF_UNIT_TERMINATOR, _arrayDescr );    if( strlen(_formatControls) > 0 )        sprintf( *ppachData + strlen(*ppachData), "%c%s",                 DDF_UNIT_TERMINATOR, _formatControls );    sprintf( *ppachData + strlen(*ppachData), "%c", DDF_FIELD_TERMINATOR );    return TRUE;}/************************************************************************//*                             Initialize()                             *//*                                                                      *//*      Initialize the field definition from the information in the     *//*      DDR record.  This is called by DDFModule::Open().               *//************************************************************************/int DDFFieldDefn::Initialize( DDFModule * poModuleIn,                              const char * pszTagIn,                               int nFieldEntrySize,                              const char * pachFieldArea ){    int         iFDOffset = poModuleIn->GetFieldControlLength();    int         nCharsConsumed;    poModule = poModuleIn;        pszTag = CPLStrdup( pszTagIn );/* -------------------------------------------------------------------- *//*      Set the data struct and type codes.                             *//* -------------------------------------------------------------------- */    switch( pachFieldArea[0] )    {      case '0':        _data_struct_code = dsc_elementary;        break;      case '1':        _data_struct_code = dsc_vector;        break;      case '2':        _data_struct_code = dsc_array;        break;      case '3':        _data_struct_code = dsc_concatenated;        break;      default:        CPLError( CE_Failure, CPLE_AppDefined,                   "Unrecognised data_struct_code value %c.\n"                  "Field %s initialization incorrect.\n",                  pachFieldArea[0], pszTag );        _data_struct_code = dsc_elementary;    }    switch( pachFieldArea[1] )    {      case '0':        _data_type_code = dtc_char_string;        break;              case '1':        _data_type_code = dtc_implicit_point;        break;              case '2':        _data_type_code = dtc_explicit_point;        break;              case '3':        _data_type_code = dtc_explicit_point_scaled;        break;              case '4':        _data_type_code = dtc_char_bit_string;        break;              case '5':        _data_type_code = dtc_bit_string;        break;              case '6':        _data_type_code = dtc_mixed_data_type;        break;      default:        CPLError( CE_Failure, CPLE_AppDefined,                   "Unrecognised data_type_code value %c.\n"                  "Field %s initialization incorrect.\n",                  pachFieldArea[1], pszTag );        _data_type_code = dtc_char_string;    }    /* -------------------------------------------------------------------- *//*      Capture the field name, description (sub field names), and      *//*      format statements.                                              *//* -------------------------------------------------------------------- */    _fieldName =        DDFFetchVariable( pachFieldArea + iFDOffset,                          nFieldEntrySize - iFDOffset,                          DDF_UNIT_TERMINATOR, DDF_FIELD_TERMINATOR,                          &nCharsConsumed );    iFDOffset += nCharsConsumed;        _arrayDescr =        DDFFetchVariable( pachFieldArea + iFDOffset,                          nFieldEntrySize - iFDOffset,                          DDF_UNIT_TERMINATOR, DDF_FIELD_TERMINATOR,                           &nCharsConsumed );    iFDOffset += nCharsConsumed;        _formatControls =        DDFFetchVariable( pachFieldArea + iFDOffset,                          nFieldEntrySize - iFDOffset,                          DDF_UNIT_TERMINATOR, DDF_FIELD_TERMINATOR,                           &nCharsConsumed );    /* -------------------------------------------------------------------- *//*      Parse the subfield info.                                        *//* -------------------------------------------------------------------- */    if( _data_struct_code != dsc_elementary )    {        if( !BuildSubfields() )            return FALSE;        if( !ApplyFormats() )            return FALSE;    }        return TRUE;}/************************************************************************//*                                Dump()                                *//************************************************************************//** * Write out field definition info to debugging file. * * A variety of information about this field definition, and all it's * subfields is written to the give debugging file handle. * * @param fp The standard io file handle to write to.  ie. stderr */void DDFFieldDefn::Dump( FILE * fp ){    const char  *pszValue = "";        fprintf( fp, "  DDFFieldDefn:\n" );    fprintf( fp, "      Tag = `%s'\n", pszTag );    fprintf( fp, "      _fieldName = `%s'\n", _fieldName );    fprintf( fp, "      _arrayDescr = `%s'\n", _arrayDescr );    fprintf( fp, "      _formatControls = `%s'\n", _formatControls );    switch( _data_struct_code )    {      case dsc_elementary:        pszValue = "elementary";        break;              case dsc_vector:        pszValue = "vector";        break;              case dsc_array:        pszValue = "array";        break;              case dsc_concatenated:        pszValue = "concatenated";        break;              default:        CPLAssert( FALSE );        pszValue = "(unknown)";    }    fprintf( fp, "      _data_struct_code = %s\n", pszValue );    switch( _data_type_code )    {      case dtc_char_string:        pszValue = "char_string";        break;              case dtc_implicit_point:        pszValue = "implicit_point";        break;              case dtc_explicit_point:        pszValue = "explicit_point";        break;              case dtc_explicit_point_scaled:        pszValue = "explicit_point_scaled";        break;              case dtc_char_bit_string:        pszValue = "char_bit_string";        break;              case dtc_bit_string:        pszValue = "bit_string";        break;

⌨️ 快捷键说明

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