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

📄 s57classregistrar.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        {            CPLAssert( FALSE );            continue;        }                iAttr = atoi(papszTokens[0]);        if( iAttr < 0 || iAttr >= nAttrMax            || papszAttrNames[iAttr] != NULL )        {            CPLAssert( FALSE );            continue;        }                papszAttrNames[iAttr] = CPLStrdup(papszTokens[1]);        papszAttrAcronym[iAttr] = CPLStrdup(papszTokens[2]);        pachAttrType[iAttr] = papszTokens[3][0];        pachAttrClass[iAttr] = papszTokens[4][0];        CSLDestroy( papszTokens );    }    if( fp != NULL )        VSIFClose( fp );    /* -------------------------------------------------------------------- *//*      Build unsorted index of attributes.                             *//* -------------------------------------------------------------------- */    nAttrCount = 0;    for( iAttr = 0; iAttr < nAttrMax; iAttr++ )    {        if( papszAttrAcronym[iAttr] != NULL )            panAttrIndex[nAttrCount++] = iAttr;    }/* -------------------------------------------------------------------- *//*      Sort index by acronym.                                          *//* -------------------------------------------------------------------- */    int         bModified;    do    {        bModified = FALSE;        for( iAttr = 0; iAttr < nAttrCount-1; iAttr++ )        {            if( strcmp(papszAttrAcronym[panAttrIndex[iAttr]],                       papszAttrAcronym[panAttrIndex[iAttr+1]]) > 0 )            {                int     nTemp;                nTemp = panAttrIndex[iAttr];                panAttrIndex[iAttr] = panAttrIndex[iAttr+1];                panAttrIndex[iAttr+1] = nTemp;                bModified = TRUE;            }        }    } while( bModified );        return TRUE;}/************************************************************************//*                         SelectClassByIndex()                         *//************************************************************************/int S57ClassRegistrar::SelectClassByIndex( int nNewIndex ){    if( nNewIndex < 0 || nNewIndex >= nClasses )        return FALSE;/* -------------------------------------------------------------------- *//*      Do we have our cache of class information field lists?          *//* -------------------------------------------------------------------- */    if( papapszClassesFields == NULL )    {        papapszClassesFields = (char ***) CPLCalloc(sizeof(void*),nClasses);    }/* -------------------------------------------------------------------- *//*      Has this info been parsed yet?                                  *//* -------------------------------------------------------------------- */    if( papapszClassesFields[nNewIndex] == NULL )        papapszClassesFields[nNewIndex] =             CSLTokenizeStringComplex( papszClassesInfo[nNewIndex],                                      ",", TRUE, TRUE );    papszCurrentFields = papapszClassesFields[nNewIndex];    iCurrentClass = nNewIndex;    return TRUE;}/************************************************************************//*                             SelectClass()                            *//************************************************************************/int S57ClassRegistrar::SelectClass( int nOBJL ){    for( int i = 0; i < nClasses; i++ )    {        if( atoi(papszClassesInfo[i]) == nOBJL )            return SelectClassByIndex( i );    }    return FALSE;}/************************************************************************//*                            SelectClass()                             *//************************************************************************/int S57ClassRegistrar::SelectClass( const char *pszAcronym ){    for( int i = 0; i < nClasses; i++ )    {        if( !SelectClassByIndex( i ) )            continue;        if( EQUAL(GetAcronym(),pszAcronym) )            return TRUE;    }    return FALSE;}/************************************************************************//*                              GetOBJL()                               *//************************************************************************/int S57ClassRegistrar::GetOBJL(){    if( iCurrentClass >= 0 )        return atoi(papszClassesInfo[iCurrentClass]);    else        return -1;}/************************************************************************//*                           GetDescription()                           *//************************************************************************/const char * S57ClassRegistrar::GetDescription(){    if( iCurrentClass >= 0 && papszCurrentFields[0] != NULL )        return papszCurrentFields[1];    else        return NULL;}/************************************************************************//*                             GetAcronym()                             *//************************************************************************/const char * S57ClassRegistrar::GetAcronym(){    if( iCurrentClass >= 0         && papszCurrentFields[0] != NULL         && papszCurrentFields[1] != NULL )        return papszCurrentFields[2];    else        return NULL;}/************************************************************************//*                          GetAttributeList()                          *//*                                                                      *//*      The passed string can be "a", "b", "c" or NULL for all.  The    *//*      returned list remained owned by this object, not the caller.    *//************************************************************************/char **S57ClassRegistrar::GetAttributeList( const char * pszType ){    if( iCurrentClass < 0 )        return NULL;        CSLDestroy( papszTempResult );    papszTempResult = NULL;        for( int iColumn = 3; iColumn < 6; iColumn++ )    {        if( pszType != NULL && iColumn == 3 && !EQUAL(pszType,"a") )            continue;                if( pszType != NULL && iColumn == 4 && !EQUAL(pszType,"b") )            continue;                if( pszType != NULL && iColumn == 5 && !EQUAL(pszType,"c") )            continue;        char    **papszTokens;        papszTokens =            CSLTokenizeStringComplex( papszCurrentFields[iColumn], ";",                                      TRUE, FALSE );        papszTempResult = CSLInsertStrings( papszTempResult, -1,                                            papszTokens );        CSLDestroy( papszTokens );    }    return papszTempResult;}/************************************************************************//*                            GetClassCode()                            *//************************************************************************/char S57ClassRegistrar::GetClassCode(){    if( iCurrentClass >= 0        && papszCurrentFields[0] != NULL        && papszCurrentFields[1] != NULL        && papszCurrentFields[2] != NULL        && papszCurrentFields[3] != NULL        && papszCurrentFields[4] != NULL        && papszCurrentFields[5] != NULL         && papszCurrentFields[6] != NULL )        return papszCurrentFields[6][0];    else        return '\0';}/************************************************************************//*                           GetPrimitives()                            *//************************************************************************/char **S57ClassRegistrar::GetPrimitives(){    if( iCurrentClass >= 0        && CSLCount(papszCurrentFields) > 7 )    {        CSLDestroy( papszTempResult );        papszTempResult =             CSLTokenizeStringComplex( papszCurrentFields[7], ";",                                      TRUE, FALSE );        return papszTempResult;    }    else        return NULL;}/************************************************************************//*                         FindAttrByAcronym()                          *//************************************************************************/int     S57ClassRegistrar::FindAttrByAcronym( const char * pszName ){    int         iStart, iEnd, iCandidate;    iStart = 0;    iEnd = nAttrCount-1;    while( iStart <= iEnd )    {        int     nCompareValue;                iCandidate = (iStart + iEnd)/2;        nCompareValue =            strcmp( pszName, papszAttrAcronym[panAttrIndex[iCandidate]] );        if( nCompareValue < 0 )        {            iEnd = iCandidate-1;        }        else if( nCompareValue > 0 )        {            iStart = iCandidate+1;        }        else            return panAttrIndex[iCandidate];    }    return -1;}

⌨️ 快捷键说明

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