PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ DBFReadAttribute()

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

Definition at line 1017 of file dbfopen.c.

1020 {
1021  unsigned char *pabyRec;
1022  void *pReturnField = SHPLIB_NULLPTR;
1023 
1024 /* -------------------------------------------------------------------- */
1025 /* Verify selection. */
1026 /* -------------------------------------------------------------------- */
1027  if( hEntity < 0 || hEntity >= psDBF->nRecords )
1028  return SHPLIB_NULLPTR;
1029 
1030  if( iField < 0 || iField >= psDBF->nFields )
1031  return SHPLIB_NULLPTR;
1032 
1033 /* -------------------------------------------------------------------- */
1034 /* Have we read the record? */
1035 /* -------------------------------------------------------------------- */
1036  if( !DBFLoadRecord( psDBF, hEntity ) )
1037  return SHPLIB_NULLPTR;
1038 
1039  pabyRec = REINTERPRET_CAST(unsigned char *, psDBF->pszCurrentRecord);
1040 
1041 /* -------------------------------------------------------------------- */
1042 /* Ensure we have room to extract the target field. */
1043 /* -------------------------------------------------------------------- */
1044  if( psDBF->panFieldSize[iField] >= psDBF->nWorkFieldLength )
1045  {
1046  psDBF->nWorkFieldLength = psDBF->panFieldSize[iField] + 100;
1047  if( psDBF->pszWorkField == SHPLIB_NULLPTR )
1048  psDBF->pszWorkField = STATIC_CAST(char *, malloc(psDBF->nWorkFieldLength));
1049  else
1050  psDBF->pszWorkField = STATIC_CAST(char *, realloc(psDBF->pszWorkField,
1051  psDBF->nWorkFieldLength));
1052  }
1053 
1054 /* -------------------------------------------------------------------- */
1055 /* Extract the requested field. */
1056 /* -------------------------------------------------------------------- */
1057  memcpy( psDBF->pszWorkField,
1058  REINTERPRET_CAST(const char *, pabyRec) + psDBF->panFieldOffset[iField],
1059  psDBF->panFieldSize[iField] );
1060  psDBF->pszWorkField[psDBF->panFieldSize[iField]] = '\0';
1061 
1062  pReturnField = psDBF->pszWorkField;
1063 
1064 /* -------------------------------------------------------------------- */
1065 /* Decode the field. */
1066 /* -------------------------------------------------------------------- */
1067  if( chReqType == 'I' )
1068  {
1069  psDBF->fieldValue.nIntField = atoi(psDBF->pszWorkField);
1070 
1071  pReturnField = &(psDBF->fieldValue.nIntField);
1072  }
1073  else if( chReqType == 'N' )
1074  {
1075  psDBF->fieldValue.dfDoubleField = psDBF->sHooks.Atof(psDBF->pszWorkField);
1076 
1077  pReturnField = &(psDBF->fieldValue.dfDoubleField);
1078  }
1079 
1080 /* -------------------------------------------------------------------- */
1081 /* Should we trim white space off the string attribute value? */
1082 /* -------------------------------------------------------------------- */
1083 #ifdef TRIM_DBF_WHITESPACE
1084  else
1085  {
1086  char *pchSrc, *pchDst;
1087 
1088  pchDst = pchSrc = psDBF->pszWorkField;
1089  while( *pchSrc == ' ' )
1090  pchSrc++;
1091 
1092  while( *pchSrc != '\0' )
1093  *(pchDst++) = *(pchSrc++);
1094  *pchDst = '\0';
1095 
1096  while( pchDst != psDBF->pszWorkField && *(--pchDst) == ' ' )
1097  *pchDst = '\0';
1098  }
1099 #endif
1100 
1101  return pReturnField;
1102 }
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
union DBFInfo::@5 fieldValue
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
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: