mitab/mitab_tabfile.cpp
int TABFile::SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
                         TABFieldType *paeMapInfoNativeFieldTypes /* =NULL */)
{
    int           iField, numFields;
    OGRFieldDefn *poFieldDefn;
    TABFieldType eMapInfoType = TABFUnknown;
    int nStatus = 0;

    if (m_eAccessMode != TABWrite)
    {
        CPLError(CE_Failure, CPLE_NotSupported,
                 "SetFeatureDefn() can be used only with Write access.");
        return -1;
    }

    /*-----------------------------------------------------------------
     * Keep a reference to the OGRFeatureDefn... we'll have to take the
     * reference count into account when we are done with it.
     *----------------------------------------------------------------*/
    if (m_poDefn && m_poDefn->Dereference() == 0)
        delete m_poDefn;

    m_poDefn = poFeatureDefn;
    m_poDefn->Reference();

    /*-----------------------------------------------------------------
     * Pass field information to the .DAT file, after making sure that
     * it has been created and that it does not contain any field
     * definition yet.
     *----------------------------------------------------------------*/
    if (m_poDATFile== NULL || m_poDATFile->GetNumFields() > 0 )
    {
        CPLError(CE_Failure, CPLE_AssertionFailed,
                 "SetFeatureDefn() can be called only once in a newly "
                 "created dataset.");
        return -1;
    }

    numFields = poFeatureDefn->GetFieldCount();
    for(iField=0; nStatus==0 && iField < numFields; iField++)
    {
        poFieldDefn = m_poDefn->GetFieldDefn(iField);

        /*-------------------------------------------------------------
         * Make sure field name is valid... check for special chars, etc.
         *------------------------------------------------------------*/
        char *pszCleanName = TABCleanFieldName(poFieldDefn->GetNameRef());
        if (!EQUAL(pszCleanName, poFieldDefn->GetNameRef()))
            poFieldDefn->SetName(pszCleanName);
        CPLFree(pszCleanName);
        pszCleanName = NULL;

        if (paeMapInfoNativeFieldTypes)
        {
            eMapInfoType = paeMapInfoNativeFieldTypes[iField];
        }
        else
        {
            /*---------------------------------------------------------
             * Map OGRFieldTypes to MapInfo native types
             *--------------------------------------------------------*/
            switch(poFieldDefn->GetType())
            {
              case OFTInteger:
                eMapInfoType = TABFInteger;
                break;
              case OFTReal:
                eMapInfoType = TABFFloat;
                break;
              case OFTString:
              default:
                eMapInfoType = TABFChar;
            }
        }

        nStatus = m_poDATFile->AddField(poFieldDefn->GetNameRef(),
                                            eMapInfoType,
                                            poFieldDefn->GetWidth(),
                                            poFieldDefn->GetPrecision());
    }

    /*-----------------------------------------------------------------
     * Alloc the array to keep track of indexed fields (default=NOT indexed)
     *----------------------------------------------------------------*/
    m_panIndexNo = (int *)CPLCalloc(numFields, sizeof(int));

    return nStatus;
}
/**********************************************************************
 *                   TABFile::SetFeatureDefn()
 *
 * Pass a reference to the OGRFeatureDefn that will be used to create
 * features in this dataset.  This function should be called after
 * creating a new dataset, but before writing the first feature.
 * All features that will be written to this dataset must share this same
 * OGRFeatureDefn.
 *
 * A reference to the OGRFeatureDefn will be kept and will be used to
 * build the .DAT file, etc.
 *
 * Returns 0 on success, -1 on error.
 **********************************************************************/
:SetFeatureDefn()
Pass a reference to the OGRFeatureDefn that will be used to create
features in this dataset.  This function should be called after
creating a new dataset, but before writing the first feature.
All features that will be written to this dataset must share this same
OGRFeatureDefn.

A reference to the OGRFeatureDefn will be kept and will be used to
build the .DAT file, etc.

Returns 0 on success, -1 on error.
: SetFeatureDefn () Pass a reference to the OGRFeatureDefn that will be used to create features in this dataset . This function should be called after creating a new dataset but before writing the first feature . All features that will be written to this dataset must share this same OGRFeatureDefn . A reference to the OGRFeatureDefn will be kept and will be used to build the . DAT file etc . Returns 0 on success - 1 on error .
int TABFile::SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
                         TABFieldType *paeMapInfoNativeFieldTypes )
{
    int           iField, numFields;
    OGRFieldDefn *poFieldDefn;
    TABFieldType eMapInfoType = TABFUnknown;
    int nStatus = 0;
    if (m_eAccessMode != TABWrite)
    {
        CPLError(CE_Failure, CPLE_NotSupported,
                 "SetFeatureDefn() can be used only with Write access.");
        return -1;
    }
    if (m_poDefn && m_poDefn->Dereference() == 0)
        delete m_poDefn;
    m_poDefn = poFeatureDefn;
    m_poDefn->Reference();
    if (m_poDATFile== NULL || m_poDATFile->GetNumFields() > 0 )
    {
        CPLError(CE_Failure, CPLE_AssertionFailed,
                 "SetFeatureDefn() can be called only once in a newly "
                 "created dataset.");
        return -1;
    }
    numFields = poFeatureDefn->GetFieldCount();
    for(iField=0; nStatus==0 && iField < numFields; iField++)
    {
        poFieldDefn = m_poDefn->GetFieldDefn(iField);
        char *pszCleanName = TABCleanFieldName(poFieldDefn->GetNameRef());
        if (!EQUAL(pszCleanName, poFieldDefn->GetNameRef()))
            poFieldDefn->SetName(pszCleanName);
        CPLFree(pszCleanName);
        pszCleanName = NULL;
        if (paeMapInfoNativeFieldTypes)
        {
            eMapInfoType = paeMapInfoNativeFieldTypes[iField];
        }
        else
        {
            switch(poFieldDefn->GetType())
            {
              case OFTInteger:
                eMapInfoType = TABFInteger;
                break;
              case OFTReal:
                eMapInfoType = TABFFloat;
                break;
              case OFTString:
              default:
                eMapInfoType = TABFChar;
            }
        }
        nStatus = m_poDATFile->AddField(poFieldDefn->GetNameRef(),
                                            eMapInfoType,
                                            poFieldDefn->GetWidth(),
                                            poFieldDefn->GetPrecision());
    }
    m_panIndexNo = (int *)CPLCalloc(numFields, sizeof(int));
    return nStatus;
}
int TABFile :: SetFeatureDefn ( OGRFeatureDefn * poFeatureDefn , TABFieldType * paeMapInfoNativeFieldTypes ) { int iField , numFields ; OGRFieldDefn * poFieldDefn ; TABFieldType eMapInfoType = TABFUnknown ; int nStatus = 0 ; if ( m_eAccessMode != TABWrite ) { CPLError ( CE_Failure , CPLE_NotSupported , " " ) ; return -1 ; } if ( m_poDefn && m_poDefn -> Dereference ( ) == 0 ) delete m_poDefn ; m_poDefn = poFeatureDefn ; m_poDefn -> Reference ( ) ; if ( m_poDATFile == NULL || m_poDATFile -> GetNumFields ( ) > 0 ) { CPLError ( CE_Failure , CPLE_AssertionFailed , " " " " ) ; return -1 ; } numFields = poFeatureDefn -> GetFieldCount ( ) ; for ( iField = 0 ; nStatus == 0 && iField < numFields ; iField ++ ) { poFieldDefn = m_poDefn -> GetFieldDefn ( iField ) ; char * pszCleanName = TABCleanFieldName ( poFieldDefn -> GetNameRef ( ) ) ; if ( ! EQUAL ( pszCleanName , poFieldDefn -> GetNameRef ( ) ) ) poFieldDefn -> SetName ( pszCleanName ) ; CPLFree ( pszCleanName ) ; pszCleanName = NULL ; if ( paeMapInfoNativeFieldTypes ) { eMapInfoType = paeMapInfoNativeFieldTypes [ iField ] ; } else { switch ( poFieldDefn -> GetType ( ) ) { case OFTInteger : eMapInfoType = TABFInteger ; break ; case OFTReal : eMapInfoType = TABFFloat ; break ; case OFTString : default : eMapInfoType = TABFChar ; } } nStatus = m_poDATFile -> AddField ( poFieldDefn -> GetNameRef ( ) , eMapInfoType , poFieldDefn -> GetWidth ( ) , poFieldDefn -> GetPrecision ( ) ) ; } m_panIndexNo = ( int * ) CPLCalloc ( numFields , sizeof ( int ) ) ; return nStatus ; }
TABFile::SetFeatureDefn()
 Pass a reference to the OGRFeatureDefn that will be used to create
 features in this dataset.
TABFile :: SetFeatureDefn () Pass a reference to the OGRFeatureDefn that will be used to create features in this dataset .
/* =NULL */ /*-----------------------------------------------------------------
     * Keep a reference to the OGRFeatureDefn... we'll have to take the
     * reference count into account when we are done with it.
     *----------------------------------------------------------------*/ /*-----------------------------------------------------------------
     * Pass field information to the .DAT file, after making sure that
     * it has been created and that it does not contain any field
     * definition yet.
     *----------------------------------------------------------------*/ /*-------------------------------------------------------------
         * Make sure field name is valid... check for special chars, etc.
         *------------------------------------------------------------*/ /*---------------------------------------------------------
             * Map OGRFieldTypes to MapInfo native types
             *--------------------------------------------------------*/ /*-----------------------------------------------------------------
     * Alloc the array to keep track of indexed fields (default=NOT indexed)
     *----------------------------------------------------------------*/