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

📄 ddfrecord.cpp

📁 开源的电子海图程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
}/************************************************************************//*                              GetField()                              *//************************************************************************//** * Fetch field object based on index. * * @param i The index of the field to fetch.  Between 0 and GetFieldCount()-1. * * @return A DDFField pointer, or NULL if the index is out of range. */DDFField *DDFRecord::GetField( int i ){    if( i < 0 || i >= nFieldCount )        return NULL;    else        return paoFields + i;}/************************************************************************//*                           GetIntSubfield()                           *//************************************************************************//** * Fetch value of a subfield as an integer.  This is a convenience * function for fetching a subfield of a field within this record. * * @param pszField The name of the field containing the subfield. * @param iFieldIndex The instance of this field within the record.  Use * zero for the first instance of this field. * @param pszSubfield The name of the subfield within the selected field. * @param iSubfieldIndex The instance of this subfield within the record. * Use zero for the first instance. * @param pnSuccess Pointer to an int which will be set to TRUE if the fetch * succeeds, or FALSE if it fails.  Use NULL if you don't want to check * success. * @return The value of the subfield, or zero if it failed for some reason. */int DDFRecord::GetIntSubfield( const char * pszField, int iFieldIndex,                               const char * pszSubfield, int iSubfieldIndex,                               int * pnSuccess ){    DDFField    *poField;    int         nDummyErr;    if( pnSuccess == NULL )        pnSuccess = &nDummyErr;    *pnSuccess = FALSE;            /* -------------------------------------------------------------------- *//*      Fetch the field. If this fails, return zero.                    *//* -------------------------------------------------------------------- */    poField = FindField( pszField, iFieldIndex );    if( poField == NULL )        return 0;/* -------------------------------------------------------------------- *//*      Get the subfield definition                                     *//* -------------------------------------------------------------------- */    DDFSubfieldDefn     *poSFDefn;    poSFDefn = poField->GetFieldDefn()->FindSubfieldDefn( pszSubfield );    if( poSFDefn == NULL )        return 0;/* -------------------------------------------------------------------- *//*      Get a pointer to the data.                                      *//* -------------------------------------------------------------------- */    int         nBytesRemaining;        const char *pachData = poField->GetSubfieldData(poSFDefn,                                                    &nBytesRemaining,                                                    iSubfieldIndex);/* -------------------------------------------------------------------- *//*      Return the extracted value.                                     *//* -------------------------------------------------------------------- */    *pnSuccess = TRUE;    return( poSFDefn->ExtractIntData( pachData, nBytesRemaining, NULL ) );}/************************************************************************//*                          GetFloatSubfield()                          *//************************************************************************//** * Fetch value of a subfield as a float (double).  This is a convenience * function for fetching a subfield of a field within this record. * * @param pszField The name of the field containing the subfield. * @param iFieldIndex The instance of this field within the record.  Use * zero for the first instance of this field. * @param pszSubfield The name of the subfield within the selected field. * @param iSubfieldIndex The instance of this subfield within the record. * Use zero for the first instance. * @param pnSuccess Pointer to an int which will be set to TRUE if the fetch * succeeds, or FALSE if it fails.  Use NULL if you don't want to check * success. * @return The value of the subfield, or zero if it failed for some reason. */double DDFRecord::GetFloatSubfield( const char * pszField, int iFieldIndex,                                 const char * pszSubfield, int iSubfieldIndex,                                    int * pnSuccess ){    DDFField    *poField;    int         nDummyErr;    if( pnSuccess == NULL )        pnSuccess = &nDummyErr;    *pnSuccess = FALSE;            /* -------------------------------------------------------------------- *//*      Fetch the field. If this fails, return zero.                    *//* -------------------------------------------------------------------- */    poField = FindField( pszField, iFieldIndex );    if( poField == NULL )        return 0;/* -------------------------------------------------------------------- *//*      Get the subfield definition                                     *//* -------------------------------------------------------------------- */    DDFSubfieldDefn     *poSFDefn;    poSFDefn = poField->GetFieldDefn()->FindSubfieldDefn( pszSubfield );    if( poSFDefn == NULL )        return 0;/* -------------------------------------------------------------------- *//*      Get a pointer to the data.                                      *//* -------------------------------------------------------------------- */    int         nBytesRemaining;        const char *pachData = poField->GetSubfieldData(poSFDefn,                                                    &nBytesRemaining,                                                    iSubfieldIndex);/* -------------------------------------------------------------------- *//*      Return the extracted value.                                     *//* -------------------------------------------------------------------- */    *pnSuccess = TRUE;    return( poSFDefn->ExtractFloatData( pachData, nBytesRemaining, NULL ) );}/************************************************************************//*                         GetStringSubfield()                          *//************************************************************************//** * Fetch value of a subfield as a string.  This is a convenience * function for fetching a subfield of a field within this record. * * @param pszField The name of the field containing the subfield. * @param iFieldIndex The instance of this field within the record.  Use * zero for the first instance of this field. * @param pszSubfield The name of the subfield within the selected field. * @param iSubfieldIndex The instance of this subfield within the record. * Use zero for the first instance. * @param pnSuccess Pointer to an int which will be set to TRUE if the fetch * succeeds, or FALSE if it fails.  Use NULL if you don't want to check * success. * @return The value of the subfield, or NULL if it failed for some reason. * The returned pointer is to internal data and should not be modified or * freed by the application. */const char *DDFRecord::GetStringSubfield( const char * pszField, int iFieldIndex,                              const char * pszSubfield, int iSubfieldIndex,                              int * pnSuccess ){    DDFField    *poField;    int         nDummyErr;    if( pnSuccess == NULL )        pnSuccess = &nDummyErr;    *pnSuccess = FALSE;            /* -------------------------------------------------------------------- *//*      Fetch the field. If this fails, return zero.                    *//* -------------------------------------------------------------------- */    poField = FindField( pszField, iFieldIndex );    if( poField == NULL )        return NULL;/* -------------------------------------------------------------------- *//*      Get the subfield definition                                     *//* -------------------------------------------------------------------- */    DDFSubfieldDefn     *poSFDefn;    poSFDefn = poField->GetFieldDefn()->FindSubfieldDefn( pszSubfield );    if( poSFDefn == NULL )        return NULL;/* -------------------------------------------------------------------- *//*      Get a pointer to the data.                                      *//* -------------------------------------------------------------------- */    int         nBytesRemaining;        const char *pachData = poField->GetSubfieldData(poSFDefn,                                                    &nBytesRemaining,                                                    iSubfieldIndex);/* -------------------------------------------------------------------- *//*      Return the extracted value.                                     *//* -------------------------------------------------------------------- */    *pnSuccess = TRUE;    return( poSFDefn->ExtractStringData( pachData, nBytesRemaining, NULL ) );}/************************************************************************//*                               Clone()                                *//************************************************************************//** * Make a copy of a record. * * This method is used to make a copy of a record that will become (mostly) * the properly of application.  However, it is automatically destroyed if * the DDFModule it was created relative to is destroyed, as it's field * and subfield definitions relate to that DDFModule.  However, it does * persist even when the record returned by DDFModule::ReadRecord() is * invalidated, such as when reading a new record.  This allows an application * to cache whole DDFRecords. * * @return A new copy of the DDFRecord.  This can be delete'd by the * application when no longer needed, otherwise it will be cleaned up when * the DDFModule it relates to is destroyed or closed. */DDFRecord * DDFRecord::Clone(){    DDFRecord   *poNR;    poNR = new DDFRecord( poModule );    poNR->nReuseHeader = FALSE;    poNR->nFieldOffset = nFieldOffset;        poNR->nDataSize = nDataSize;    poNR->pachData = (char *) CPLMalloc(nDataSize);    memcpy( poNR->pachData, pachData, nDataSize );        poNR->nFieldCount = nFieldCount;    poNR->paoFields = new DDFField[nFieldCount];    for( int i = 0; i < nFieldCount; i++ )    {        int     nOffset;        nOffset = (paoFields[i].GetData() - pachData);        poNR->paoFields[i].Initialize( paoFields[i].GetFieldDefn(),                                       poNR->pachData + nOffset,                                       paoFields[i].GetDataSize() );    }        poNR->bIsClone = TRUE;    poModule->AddCloneRecord( poNR );    return poNR;}/************************************************************************//*                              CloneOn()                               *//************************************************************************//** * Recreate a record referencing another module. * * Works similarly to the DDFRecord::Clone() method, but creates the * new record with reference to a different DDFModule.  All DDFFieldDefn * references are transcribed onto the new module based on field names. * If any fields don't have a similarly named field on the target module * the operation will fail.  No validation of field types and properties * is done, but this operation is intended only to be used between  * modules with matching definitions of all affected fields.  * * The new record will be managed as a clone by the target module in * a manner similar to regular clones.  * * @param poTargetModule the module on which the record copy should be * created. * * @return NULL on failure or a pointer to the cloned record. */DDFRecord *DDFRecord::CloneOn( DDFModule *poTargetModule ){/* -------------------------------------------------------------------- *//*      Verify that all fields have a corresponding field definition    *//*      on the target module.                                           *//* -------------------------------------------------------------------- */    int         i;    for( i = 0; i < nFieldCount; i++ )    {        DDFFieldDefn    *poDefn = paoFields[i].GetFieldDefn();        if( poTargetModule->FindFieldDefn( poDefn->GetName() ) == NULL )            return NULL;    }/* -------------------------------------------------------------------- *//*      Create a clone.                                                 *//* -------------------------------------------------------------------- */    DDFRecord   *poClone;    poClone = Clone();/* -------------------------------------------------------------------- *//*      Update all internal information to reference other module.      *//* -------------------------------------------------------------------- */    for( i = 0; i < nFieldCount; i++ )    {        DDFField        *poField = poClone->paoFields+i;        DDFFieldDefn    *poDefn;        poDefn = poTargetModule->FindFieldDefn(             poField->GetFieldDefn()->GetName() );        

⌨️ 快捷键说明

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