PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ DBFReadAttribute()

static void* DBFReadAttribute ( DBFHandle  psDBF,
int  hEntity,
int  iField,
char  chReqType 
)
static

Definition at line 1008 of file dbfopen.c.

1011 {
1012  unsigned char *pabyRec;
1013  void *pReturnField = SHPLIB_NULLPTR;
1014 
1015 /* -------------------------------------------------------------------- */
1016 /* Verify selection. */
1017 /* -------------------------------------------------------------------- */
1018  if( hEntity < 0 || hEntity >= psDBF->nRecords )
1019  return SHPLIB_NULLPTR;
1020 
1021  if( iField < 0 || iField >= psDBF->nFields )
1022  return SHPLIB_NULLPTR;
1023 
1024 /* -------------------------------------------------------------------- */
1025 /* Have we read the record? */
1026 /* -------------------------------------------------------------------- */
1027  if( !DBFLoadRecord( psDBF, hEntity ) )
1028  return SHPLIB_NULLPTR;
1029 
1030  pabyRec = REINTERPRET_CAST(unsigned char *, psDBF->pszCurrentRecord);
1031 
1032 /* -------------------------------------------------------------------- */
1033 /* Ensure we have room to extract the target field. */
1034 /* -------------------------------------------------------------------- */
1035  if( psDBF->panFieldSize[iField] >= psDBF->nWorkFieldLength )
1036  {
1037  psDBF->nWorkFieldLength = psDBF->panFieldSize[iField] + 100;
1038  if( psDBF->pszWorkField == SHPLIB_NULLPTR )
1039  psDBF->pszWorkField = STATIC_CAST(char *, malloc(psDBF->nWorkFieldLength));
1040  else
1041  psDBF->pszWorkField = STATIC_CAST(char *, realloc(psDBF->pszWorkField,
1042  psDBF->nWorkFieldLength));
1043  }
1044 
1045 /* -------------------------------------------------------------------- */
1046 /* Extract the requested field. */
1047 /* -------------------------------------------------------------------- */
1048  memcpy( psDBF->pszWorkField,
1049  REINTERPRET_CAST(const char *, pabyRec) + psDBF->panFieldOffset[iField],
1050  psDBF->panFieldSize[iField] );
1051  psDBF->pszWorkField[psDBF->panFieldSize[iField]] = '\0';
1052 
1053  pReturnField = psDBF->pszWorkField;
1054 
1055 /* -------------------------------------------------------------------- */
1056 /* Decode the field. */
1057 /* -------------------------------------------------------------------- */
1058  if( chReqType == 'I' )
1059  {
1060  psDBF->fieldValue.nIntField = atoi(psDBF->pszWorkField);
1061 
1062  pReturnField = &(psDBF->fieldValue.nIntField);
1063  }
1064  else if( chReqType == 'N' )
1065  {
1066  psDBF->fieldValue.dfDoubleField = psDBF->sHooks.Atof(psDBF->pszWorkField);
1067 
1068  pReturnField = &(psDBF->fieldValue.dfDoubleField);
1069  }
1070 
1071 /* -------------------------------------------------------------------- */
1072 /* Should we trim white space off the string attribute value? */
1073 /* -------------------------------------------------------------------- */
1074 #ifdef TRIM_DBF_WHITESPACE
1075  else
1076  {
1077  char *pchSrc, *pchDst;
1078 
1079  pchDst = pchSrc = psDBF->pszWorkField;
1080  while( *pchSrc == ' ' )
1081  pchSrc++;
1082 
1083  while( *pchSrc != '\0' )
1084  *(pchDst++) = *(pchSrc++);
1085  *pchDst = '\0';
1086 
1087  while( pchDst != psDBF->pszWorkField && *(--pchDst) == ' ' )
1088  *pchDst = '\0';
1089  }
1090 #endif
1091 
1092  return pReturnField;
1093 }
static int DBFLoadRecord(DBFHandle psDBF, int iRecord)
Definition: dbfopen.c:257
#define STATIC_CAST(type, x)
Definition: dbfopen.c:96
#define REINTERPRET_CAST(type, x)
Definition: dbfopen.c:97
#define SHPLIB_NULLPTR
Definition: dbfopen.c:99
void * malloc(YYSIZE_T)
int * panFieldOffset
Definition: shapefil.h:601
int nFields
Definition: shapefil.h:600
int * panFieldSize
Definition: shapefil.h:602
char * pszCurrentRecord
Definition: shapefil.h:610
int nWorkFieldLength
Definition: shapefil.h:612
SAHooks sHooks
Definition: shapefil.h:590
int nRecords
Definition: shapefil.h:594
char * pszWorkField
Definition: shapefil.h:613
union DBFInfo::@4 fieldValue
double dfDoubleField
Definition: shapefil.h:620
int nIntField
Definition: shapefil.h:621
double(* Atof)(const char *str)
Definition: shapefil.h:300

References SAHooks::Atof, DBFLoadRecord(), DBFInfo::dfDoubleField, DBFInfo::fieldValue, malloc(), DBFInfo::nFields, DBFInfo::nIntField, DBFInfo::nRecords, DBFInfo::nWorkFieldLength, DBFInfo::panFieldOffset, DBFInfo::panFieldSize, DBFInfo::pszCurrentRecord, DBFInfo::pszWorkField, REINTERPRET_CAST, DBFInfo::sHooks, SHPLIB_NULLPTR, and STATIC_CAST.

Referenced by DBFReadDoubleAttribute(), DBFReadIntegerAttribute(), DBFReadLogicalAttribute(), and DBFReadStringAttribute().

Here is the call graph for this function:
Here is the caller graph for this function: