OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Private Attributes | List of all members
ossimDDFSubfieldDefn Class Reference

Information from the DDR record describing one subfield of a DDFFieldDefn. More...

#include <ossimIso8211.h>

Public Types

enum  DDFBinaryFormat {
  NotBinary =0, UInt =1, SInt =2, FPReal =3,
  FloatReal =4, FloatComplex =5
}
 Binary format: this is the digit immediately following the B or b for binary formats. More...
 

Public Member Functions

 ossimDDFSubfieldDefn ()
 
 ~ossimDDFSubfieldDefn ()
 
void SetName (const char *pszName)
 
const char * GetName ()
 Get pointer to subfield name. More...
 
const char * GetFormat ()
 Get pointer to subfield format string. More...
 
int SetFormat (const char *pszFormat)
 
DDFDataType GetType ()
 Get the general type of the subfield. More...
 
double ExtractFloatData (const char *pachData, int nMaxBytes, int *pnConsumedBytes)
 Extract a subfield value as a float. More...
 
int ExtractIntData (const char *pachData, int nMaxBytes, int *pnConsumedBytes)
 Extract a subfield value as an integer. More...
 
const char * ExtractStringData (const char *pachData, int nMaxBytes, int *pnConsumedBytes)
 Extract a zero terminated string containing the data for this subfield. More...
 
int GetDataLength (const char *, int, int *)
 Scan for the end of variable length data. More...
 
void DumpData (const char *pachData, int nMaxBytes, FILE *fp)
 Dump subfield value to debugging file. More...
 
int FormatStringValue (char *pachData, int nBytesAvailable, int *pnBytesUsed, const char *pszValue, int nValueLength=-1)
 Format string subfield value. More...
 
int FormatIntValue (char *pachData, int nBytesAvailable, int *pnBytesUsed, int nNewValue)
 Format int subfield value. More...
 
int FormatFloatValue (char *pachData, int nBytesAvailable, int *pnBytesUsed, double dfNewValue)
 Format float subfield value. More...
 
int GetWidth ()
 Get the subfield width (zero for variable). More...
 
int GetDefaultValue (char *pachData, int nBytesAvailable, int *pnBytesUsed)
 Get default data. More...
 
void Dump (FILE *fp)
 Write out subfield definition info to debugging file. More...
 
DDFBinaryFormat GetBinaryFormat (void) const
 

Private Attributes

char * pszName
 
char * pszFormatString
 
DDFDataType eType
 
DDFBinaryFormat eBinaryFormat
 
int bIsVariable
 
char chFormatDelimeter
 
int nFormatWidth
 
int nMaxBufChars
 
char * pachBuffer
 

Detailed Description

Information from the DDR record describing one subfield of a DDFFieldDefn.

All subfields of a field will occur in each occurance of that field (as a DDFField) in a DDFRecord. Subfield's actually contain formatted data (as instances within a record).

Definition at line 278 of file ossimIso8211.h.

Member Enumeration Documentation

◆ DDFBinaryFormat

Binary format: this is the digit immediately following the B or b for binary formats.

Enumerator
NotBinary 
UInt 
SInt 
FPReal 
FloatReal 
FloatComplex 

Definition at line 335 of file ossimIso8211.h.

335  {
336  NotBinary=0,
337  UInt=1,
338  SInt=2,
339  FPReal=3,
340  FloatReal=4,
341  FloatComplex=5
DDFBinaryFormat
Binary format: this is the digit immediately following the B or b for binary formats.
Definition: ossimIso8211.h:335

Constructor & Destructor Documentation

◆ ossimDDFSubfieldDefn()

ossimDDFSubfieldDefn::ossimDDFSubfieldDefn ( )

◆ ~ossimDDFSubfieldDefn()

ossimDDFSubfieldDefn::~ossimDDFSubfieldDefn ( )

Definition at line 62 of file ossimDdfsubfielddefn.cpp.

References pachBuffer, pszFormatString, and pszName.

64 {
65  free( pszName );
66  free( pszFormatString );
67  free( pachBuffer );
68 }

Member Function Documentation

◆ Dump()

void ossimDDFSubfieldDefn::Dump ( FILE *  fp)

Write out subfield definition info to debugging file.

A variety of information about this field definition is written to the give debugging file handle.

Parameters
fpThe standard io file handle to write to. ie. stderr

Definition at line 199 of file ossimDdfsubfielddefn.cpp.

References pszFormatString, and pszName.

201 {
202  fprintf( fp, " DDFSubfieldDefn:\n" );
203  fprintf( fp, " Label = `%s'\n", pszName );
204  fprintf( fp, " FormatString = `%s'\n", pszFormatString );
205 }

◆ DumpData()

void ossimDDFSubfieldDefn::DumpData ( const char *  pachData,
int  nMaxBytes,
FILE *  fp 
)

Dump subfield value to debugging file.

Parameters
pachDataPointer to data for this subfield.
nMaxBytesMaximum number of bytes available in pachData.
fpFile to write report to.

Definition at line 689 of file ossimDdfsubfielddefn.cpp.

References DDFBinaryString, DDFFloat, DDFInt, eType, ExtractFloatData(), ExtractIntData(), ExtractStringData(), min, and pszName.

Referenced by ossimDDFField::Dump().

692 {
693  if( eType == DDFFloat )
694  fprintf( fp, " Subfield `%s' = %f\n",
695  pszName,
696  ExtractFloatData( pachData, nMaxBytes, NULL ) );
697  else if( eType == DDFInt )
698  fprintf( fp, " Subfield `%s' = %d\n",
699  pszName,
700  ExtractIntData( pachData, nMaxBytes, NULL ) );
701  else if( eType == DDFBinaryString )
702  {
703  int nBytes, i;
704  ossim_uint8 *pabyBString = (ossim_uint8 *) ExtractStringData( pachData, nMaxBytes, &nBytes );
705 
706  fprintf( fp, " Subfield `%s' = 0x", pszName );
707  for( i = 0; i < std::min(nBytes,24); i++ )
708  fprintf( fp, "%02X", pabyBString[i] );
709 
710  if( nBytes > 24 )
711  fprintf( fp, "%s", "..." );
712 
713  fprintf( fp, "\n" );
714  }
715  else
716  fprintf( fp, " Subfield `%s' = `%s'\n",
717  pszName,
718  ExtractStringData( pachData, nMaxBytes, NULL ) );
719 }
const char * ExtractStringData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a zero terminated string containing the data for this subfield.
double ExtractFloatData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a subfield value as a float.
int ExtractIntData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a subfield value as an integer.
unsigned char ossim_uint8
#define min(a, b)
Definition: auxiliary.h:75

◆ ExtractFloatData()

double ossimDDFSubfieldDefn::ExtractFloatData ( const char *  pachSourceData,
int  nMaxBytes,
int *  pnConsumedBytes 
)

Extract a subfield value as a float.

Given a pointer to the data for this subfield (from within a DDFRecord) this method will return the floating point data for this subfield. The number of bytes consumed as part of this field can also be fetched. This method may be called for any type of subfield, and will return zero if the subfield is not numeric.

Parameters
pachSourceDataThe pointer to the raw data for this field. This may have come from DDFRecord::GetData(), taking into account skip factors over previous subfields data.
nMaxBytesThe maximum number of bytes that are accessable after pachSourceData.
pnConsumedBytesPointer to an integer into which the number of bytes consumed by this field should be written. May be NULL to ignore. This is used as a skip factor to increment pachSourceData to point to the next subfields data.
Returns
The subfield's numeric value (or zero if it isn't numeric).
See also
ExtractIntData(), ExtractStringData()

Definition at line 394 of file ossimDdfsubfielddefn.cpp.

References eBinaryFormat, ExtractStringData(), FloatComplex, FloatReal, FPReal, nFormatWidth, NotBinary, pszFormatString, SInt, and UInt.

Referenced by DumpData(), and ossimDDFRecord::GetFloatSubfield().

397 {
398  switch( pszFormatString[0] )
399  {
400  case 'A':
401  case 'I':
402  case 'R':
403  case 'S':
404  case 'C':
405  return atof(ExtractStringData(pachSourceData, nMaxBytes,
406  pnConsumedBytes));
407 
408  case 'B':
409  case 'b':
410  {
411  unsigned char abyData[8];
412 
413  // CPLAssert( nFormatWidth <= nMaxBytes );
414  if( pnConsumedBytes != NULL )
415  *pnConsumedBytes = nFormatWidth;
416 
417  // Byte swap the data if it isn't in machine native format.
418  // In any event we copy it into our buffer to ensure it is
419  // word aligned.
420 #ifdef CPL_LSB
421  if( pszFormatString[0] == 'B' )
422 #else
423  if( pszFormatString[0] == 'b' )
424 #endif
425  {
426  for( int i = 0; i < nFormatWidth; i++ )
427  abyData[nFormatWidth-i-1] = pachSourceData[i];
428  }
429  else
430  {
431  memcpy( abyData, pachSourceData, nFormatWidth );
432  }
433 
434  // Interpret the bytes of data.
435  switch( eBinaryFormat )
436  {
437  case UInt:
438  if( nFormatWidth == 1 )
439  {
440  return( abyData[0] );
441  }
442  else if( nFormatWidth == 2 )
443  {
444  ossim_uint16* ptr = (ossim_uint16*) abyData;
445  return *ptr;
446  }
447  else if( nFormatWidth == 4 )
448  {
449  ossim_uint32* ptr = (ossim_uint32*) abyData;
450  return *ptr;
451  }
452  else
453  {
454  // CPLAssert( false );
455  return 0.0;
456  }
457 
458  case SInt:
459  if( nFormatWidth == 1 )
460  {
461  signed char* ptr = (signed char*) abyData;
462  return *ptr;
463  }
464  else if( nFormatWidth == 2 )
465  {
466  ossim_int16* ptr = (ossim_int16*) abyData;
467  return *ptr;
468  }
469  else if( nFormatWidth == 4 )
470  {
471  ossim_int32* ptr = (ossim_int32*) abyData;
472  return *ptr;
473  }
474  else
475  {
476  // CPLAssert( false );
477  return 0.0;
478  }
479 
480  case FloatReal:
481  if( nFormatWidth == 4 )
482  {
483  float* ptr = (float*) abyData;
484  return *ptr;
485  }
486  else if( nFormatWidth == 8 )
487  {
488  double* ptr = (double*) abyData;
489  return *ptr;
490  }
491  else
492  {
493  // CPLAssert( false );
494  return 0.0;
495  }
496 
497  case NotBinary:
498  case FPReal:
499  case FloatComplex:
500  // CPLAssert( false );
501  return 0.0;
502  }
503  break;
504  // end of 'b'/'B' case.
505  }
506 
507  default:
508  // CPLAssert( false );
509  return 0.0;
510  }
511 
512  // CPLAssert( false );
513  return 0.0;
514 }
const char * ExtractStringData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a zero terminated string containing the data for this subfield.
unsigned short ossim_uint16
unsigned int ossim_uint32
short ossim_int16
DDFBinaryFormat eBinaryFormat
Definition: ossimIso8211.h:353
int ossim_int32

◆ ExtractIntData()

int ossimDDFSubfieldDefn::ExtractIntData ( const char *  pachSourceData,
int  nMaxBytes,
int *  pnConsumedBytes 
)

Extract a subfield value as an integer.

Given a pointer to the data for this subfield (from within a DDFRecord) this method will return the int data for this subfield. The number of bytes consumed as part of this field can also be fetched. This method may be called for any type of subfield, and will return zero if the subfield is not numeric.

Parameters
pachSourceDataThe pointer to the raw data for this field. This may have come from DDFRecord::GetData(), taking into account skip factors over previous subfields data.
nMaxBytesThe maximum number of bytes that are accessable after pachSourceData.
pnConsumedBytesPointer to an integer into which the number of bytes consumed by this field should be written. May be NULL to ignore. This is used as a skip factor to increment pachSourceData to point to the next subfields data.
Returns
The subfield's numeric value (or zero if it isn't numeric).
See also
ExtractFloatData(), ExtractStringData()

Definition at line 544 of file ossimDdfsubfielddefn.cpp.

References eBinaryFormat, ExtractStringData(), FloatComplex, FloatReal, FPReal, nFormatWidth, NotBinary, ossimNotify(), ossimNotifyLevel_WARN, pszFormatString, pszName, SInt, and UInt.

Referenced by DumpData(), and ossimDDFRecord::GetIntSubfield().

547 {
548  switch( pszFormatString[0] )
549  {
550  case 'A':
551  case 'I':
552  case 'R':
553  case 'S':
554  case 'C':
555  return atoi(ExtractStringData(pachSourceData, nMaxBytes,
556  pnConsumedBytes));
557 
558  case 'B':
559  case 'b':
560  {
561  unsigned char abyData[8];
562 
563  if( nFormatWidth > nMaxBytes )
564  {
566  << "Attempt to extract int subfield %s with format %s\n"
567  << "failed as only %d bytes available. Using zero."
568  << pszName << pszFormatString << nMaxBytes << std::endl;
569  return 0;
570  }
571 
572  if( pnConsumedBytes != NULL )
573  *pnConsumedBytes = nFormatWidth;
574 
575  // Byte swap the data if it isn't in machine native format.
576  // In any event we copy it into our buffer to ensure it is
577  // word aligned.
578 #ifdef CPL_LSB
579  if( pszFormatString[0] == 'B' )
580 #else
581  if( pszFormatString[0] == 'b' )
582 #endif
583  {
584  for( int i = 0; i < nFormatWidth; i++ )
585  abyData[nFormatWidth-i-1] = pachSourceData[i];
586  }
587  else
588  {
589  memcpy( abyData, pachSourceData, nFormatWidth );
590  }
591 
592  // Interpret the bytes of data.
593  switch( eBinaryFormat )
594  {
595  case UInt:
596  if( nFormatWidth == 4 )
597  {
598  ossim_uint32* ptr = (ossim_uint32*) abyData;
599  return *ptr;
600  }
601  else if( nFormatWidth == 1 )
602  {
603  return( abyData[0] );
604  }
605  else if( nFormatWidth == 2 )
606  {
607  ossim_uint16* ptr = (ossim_uint16*)abyData;
608  return *ptr;
609  }
610  else
611  {
612  // CPLAssert( false );
613  return 0;
614  }
615 
616  case SInt:
617  if( nFormatWidth == 4 )
618  {
619  ossim_int32* ptr = (ossim_int32 *) abyData;
620  return *ptr;
621  }
622  else if( nFormatWidth == 1 )
623  {
624  signed char* ptr = (signed char *) abyData;
625  return *ptr;
626  }
627  else if( nFormatWidth == 2 )
628  {
629  ossim_int16* ptr = (ossim_int16 *) abyData;
630  return *ptr;
631  }
632  else
633  {
634  // CPLAssert( false );
635  return 0;
636  }
637 
638  case FloatReal:
639  if( nFormatWidth == 4 )
640  {
641  float* ptr = (float *) abyData;
642  return (int) *ptr;
643  }
644  else if( nFormatWidth == 8 )
645  {
646  double* ptr = (double *) abyData;
647  return (int) *ptr;
648  }
649  else
650  {
651  // CPLAssert( false );
652  return 0;
653  }
654 
655  case NotBinary:
656  case FPReal:
657  case FloatComplex:
658  // CPLAssert( false );
659  return 0;
660  }
661  break;
662  // end of 'b'/'B' case.
663  }
664 
665  default:
666  // CPLAssert( false );
667  return 0;
668  }
669 
670  // CPLAssert( false );
671  return 0;
672 }
const char * ExtractStringData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a zero terminated string containing the data for this subfield.
unsigned short ossim_uint16
unsigned int ossim_uint32
short ossim_int16
DDFBinaryFormat eBinaryFormat
Definition: ossimIso8211.h:353
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32

◆ ExtractStringData()

const char * ossimDDFSubfieldDefn::ExtractStringData ( const char *  pachSourceData,
int  nMaxBytes,
int *  pnConsumedBytes 
)

Extract a zero terminated string containing the data for this subfield.

Given a pointer to the data for this subfield (from within a DDFRecord) this method will return the data for this subfield. The number of bytes consumed as part of this field can also be fetched. This number may be one longer than the string length if there is a terminator character used.

This function will return the raw binary data of a subfield for types other than DDFString, including data past zero chars. This is the standard way of extracting DDFBinaryString subfields for instance.

Parameters
pachSourceDataThe pointer to the raw data for this field. This may have come from DDFRecord::GetData(), taking into account skip factors over previous subfields data.
nMaxBytesThe maximum number of bytes that are accessable after pachSourceData.
pnConsumedBytesPointer to an integer into which the number of bytes consumed by this field should be written. May be NULL to ignore. This is used as a skip factor to increment pachSourceData to point to the next subfields data.
Returns
A pointer to a buffer containing the data for this field. The returned pointer is to an internal buffer which is invalidated on the next ExtractStringData() call on this DDFSubfieldDefn(). It should not be freed by the application.
See also
ExtractIntData(), ExtractFloatData()

Definition at line 338 of file ossimDdfsubfielddefn.cpp.

References GetDataLength(), nMaxBufChars, and pachBuffer.

Referenced by DumpData(), ExtractFloatData(), ExtractIntData(), ossimDDFRecord::GetStringSubfield(), and ossimAdrgHeader::parse().

341 {
342  int nLength = GetDataLength( pachSourceData, nMaxBytes,
343  pnConsumedBytes );
344 
345 /* -------------------------------------------------------------------- */
346 /* Do we need to grow the buffer. */
347 /* -------------------------------------------------------------------- */
348  if( nMaxBufChars < nLength+1 )
349  {
350  free( pachBuffer );
351 
352  nMaxBufChars = nLength+1;
353  pachBuffer = (char *) malloc(nMaxBufChars);
354  }
355 
356 /* -------------------------------------------------------------------- */
357 /* Copy the data to the buffer. We use memcpy() so that it */
358 /* will work for binary data. */
359 /* -------------------------------------------------------------------- */
360  memcpy( pachBuffer, pachSourceData, nLength );
361  pachBuffer[nLength] = '\0';
362 
363  return pachBuffer;
364 }
int GetDataLength(const char *, int, int *)
Scan for the end of variable length data.

◆ FormatFloatValue()

int ossimDDFSubfieldDefn::FormatFloatValue ( char *  pachData,
int  nBytesAvailable,
int *  pnBytesUsed,
double  dfNewValue 
)

Format float subfield value.

Returns a buffer with the passed in float value reformatted in a way suitable for storage in a DDFField for this subfield.

Definition at line 946 of file ossimDdfsubfielddefn.cpp.

References bIsVariable, GetBinaryFormat(), nFormatWidth, NotBinary, and OSSIM_DDF_UNIT_TERMINATOR.

Referenced by ossimDDFRecord::SetFloatSubfield().

949 {
950  int nSize;
951  char szWork[120];
952 
953  sprintf( szWork, "%.16g", dfNewValue );
954 
955  if( bIsVariable )
956  {
957  nSize = (int)strlen(szWork) + 1;
958  }
959  else
960  {
961  nSize = nFormatWidth;
962 
963  if( GetBinaryFormat() == NotBinary && (int) strlen(szWork) > nSize )
964  return false;
965  }
966 
967  if( pnBytesUsed != NULL )
968  *pnBytesUsed = nSize;
969 
970  if( pachData == NULL )
971  return true;
972 
973  if( nBytesAvailable < nSize )
974  return false;
975 
976  if( bIsVariable )
977  {
978  strncpy( pachData, szWork, nSize-1 );
979  pachData[nSize-1] = OSSIM_DDF_UNIT_TERMINATOR;
980  }
981  else
982  {
983  if( GetBinaryFormat() == NotBinary )
984  {
985  memset( pachData, '0', nSize );
986  strncpy( pachData + nSize - strlen(szWork), szWork,
987  strlen(szWork) );
988  }
989  else
990  {
991  // CPLAssert( false );
992  /* implement me */
993  }
994  }
995 
996  return true;
997 }
#define OSSIM_DDF_UNIT_TERMINATOR
Definition: ossimIso8211.h:65
DDFBinaryFormat GetBinaryFormat(void) const
Definition: ossimIso8211.h:344

◆ FormatIntValue()

int ossimDDFSubfieldDefn::FormatIntValue ( char *  pachData,
int  nBytesAvailable,
int *  pnBytesUsed,
int  nNewValue 
)

Format int subfield value.

Returns a buffer with the passed in int value reformatted in a way suitable for storage in a DDFField for this subfield.

Definition at line 857 of file ossimDdfsubfielddefn.cpp.

References bIsVariable, FloatReal, GetBinaryFormat(), nFormatWidth, NotBinary, OSSIM_DDF_UNIT_TERMINATOR, pszFormatString, SInt, and UInt.

Referenced by ossimDDFRecord::SetIntSubfield().

860 {
861  int nSize;
862  char szWork[30];
863 
864  sprintf( szWork, "%d", nNewValue );
865 
866  if( bIsVariable )
867  {
868  nSize = (int)strlen(szWork) + 1;
869  }
870  else
871  {
872  nSize = nFormatWidth;
873 
874  if( GetBinaryFormat() == NotBinary && (int) strlen(szWork) > nSize )
875  return false;
876  }
877 
878  if( pnBytesUsed != NULL )
879  *pnBytesUsed = nSize;
880 
881  if( pachData == NULL )
882  return true;
883 
884  if( nBytesAvailable < nSize )
885  return false;
886 
887  if( bIsVariable )
888  {
889  strncpy( pachData, szWork, nSize-1 );
890  pachData[nSize-1] = OSSIM_DDF_UNIT_TERMINATOR;
891  }
892  else
893  {
894  ossim_uint32 nMask = 0xff;
895  int i;
896 
897  switch( GetBinaryFormat() )
898  {
899  case NotBinary:
900  memset( pachData, '0', nSize );
901  strncpy( pachData + nSize - strlen(szWork), szWork,
902  strlen(szWork) );
903  break;
904 
905  case UInt:
906  case SInt:
907  for( i = 0; i < nFormatWidth; i++ )
908  {
909  int iOut;
910 
911  // big endian required?
912  if( pszFormatString[0] == 'B' )
913  iOut = nFormatWidth - i - 1;
914  else
915  iOut = i;
916 
917  pachData[iOut] = (nNewValue & nMask) >> (i*8);
918  nMask *= 256;
919  }
920  break;
921 
922  case FloatReal:
923  // CPLAssert( false );
924  break;
925 
926  default:
927  // CPLAssert( false );
928  break;
929  }
930  }
931 
932  return true;
933 }
unsigned int ossim_uint32
#define OSSIM_DDF_UNIT_TERMINATOR
Definition: ossimIso8211.h:65
DDFBinaryFormat GetBinaryFormat(void) const
Definition: ossimIso8211.h:344

◆ FormatStringValue()

int ossimDDFSubfieldDefn::FormatStringValue ( char *  pachData,
int  nBytesAvailable,
int *  pnBytesUsed,
const char *  pszValue,
int  nValueLength = -1 
)

Format string subfield value.

Returns a buffer with the passed in string value reformatted in a way suitable for storage in a DDFField for this subfield.

Definition at line 795 of file ossimDdfsubfielddefn.cpp.

References bIsVariable, GetBinaryFormat(), min, nFormatWidth, NotBinary, and OSSIM_DDF_UNIT_TERMINATOR.

Referenced by ossimDDFRecord::SetStringSubfield().

800 {
801  int nSize;
802 
803  if( nValueLength == -1 )
804  nValueLength = (int)strlen(pszValue);
805 
806  if( bIsVariable )
807  {
808  nSize = nValueLength + 1;
809  }
810  else
811  {
812  nSize = nFormatWidth;
813  }
814 
815  if( pnBytesUsed != NULL )
816  *pnBytesUsed = nSize;
817 
818  if( pachData == NULL )
819  return true;
820 
821  if( nBytesAvailable < nSize )
822  return false;
823 
824  if( bIsVariable )
825  {
826  strncpy( pachData, pszValue, nSize-1 );
827  pachData[nSize-1] = OSSIM_DDF_UNIT_TERMINATOR;
828  }
829  else
830  {
831  if( GetBinaryFormat() == NotBinary )
832  {
833  memset( pachData, ' ', nSize );
834  memcpy( pachData, pszValue, std::min(nValueLength,nSize) );
835  }
836  else
837  {
838  memset( pachData, 0, nSize );
839  memcpy( pachData, pszValue, std::min(nValueLength,nSize) );
840  }
841  }
842 
843  return true;
844 }
#define OSSIM_DDF_UNIT_TERMINATOR
Definition: ossimIso8211.h:65
DDFBinaryFormat GetBinaryFormat(void) const
Definition: ossimIso8211.h:344
#define min(a, b)
Definition: auxiliary.h:75

◆ GetBinaryFormat()

DDFBinaryFormat ossimDDFSubfieldDefn::GetBinaryFormat ( void  ) const
inline

Definition at line 344 of file ossimIso8211.h.

References eBinaryFormat.

Referenced by FormatFloatValue(), FormatIntValue(), FormatStringValue(), and GetDefaultValue().

344 { return eBinaryFormat; }
DDFBinaryFormat eBinaryFormat
Definition: ossimIso8211.h:353

◆ GetDataLength()

int ossimDDFSubfieldDefn::GetDataLength ( const char *  pachSourceData,
int  nMaxBytes,
int *  pnConsumedBytes 
)

Scan for the end of variable length data.

Given a pointer to the data for this subfield (from within a DDFRecord) this method will return the number of bytes which are data for this subfield. The number of bytes consumed as part of this field can also be fetched. This number may be one longer than the length if there is a terminator character used.

This method is mainly for internal use, or for applications which want the raw binary data to interpret themselves. Otherwise use one of ExtractStringData(), ExtractIntData() or ExtractFloatData().

Parameters
pachSourceDataThe pointer to the raw data for this field. This may have come from DDFRecord::GetData(), taking into account skip factors over previous subfields data.
nMaxBytesThe maximum number of bytes that are accessable after pachSourceData.
pnConsumedBytesPointer to an integer into which the number of bytes consumed by this field should be written. May be NULL to ignore.
Returns
The number of bytes at pachSourceData which are actual data for this record (not including unit, or field terminator).

Definition at line 237 of file ossimDdfsubfielddefn.cpp.

References bIsVariable, chFormatDelimeter, nFormatWidth, OSSIM_DDF_FIELD_TERMINATOR, ossimNotify(), ossimNotifyLevel_WARN, pszFormatString, and pszName.

Referenced by ossimDDFField::Dump(), ExtractStringData(), ossimDDFField::GetInstanceData(), ossimDDFField::GetRepeatCount(), ossimDDFField::GetSubfieldData(), ossimDDFRecord::SetFloatSubfield(), ossimDDFRecord::SetIntSubfield(), and ossimDDFRecord::SetStringSubfield().

240 {
241  if( !bIsVariable )
242  {
243  if( nFormatWidth > nMaxBytes )
244  {
246  << "Only %d bytes available for subfield %s with\n"
247  << "format string %s ... returning shortened data."
248  << nMaxBytes << pszName << pszFormatString << std::endl;
249 
250  if( pnConsumedBytes != NULL )
251  *pnConsumedBytes = nMaxBytes;
252 
253  return nMaxBytes;
254  }
255  else
256  {
257  if( pnConsumedBytes != NULL )
258  *pnConsumedBytes = nFormatWidth;
259 
260  return nFormatWidth;
261  }
262  }
263  else
264  {
265  int nLength = 0;
266  int bCheckFieldTerminator = true;
267 
268  /* We only check for the field terminator because of some buggy
269  * datasets with missing format terminators. However, we have found
270  * the field terminator is a legal character within the fields of
271  * some extended datasets (such as JP34NC94.000). So we don't check
272  * for the field terminator if the field appears to be multi-byte
273  * which we established by the first character being out of the
274  * ASCII printable range (32-127).
275  */
276 
277  if( pachSourceData[0] < 32 || pachSourceData[0] >= 127 )
278  bCheckFieldTerminator = false;
279 
280  while( nLength < nMaxBytes
281  && pachSourceData[nLength] != chFormatDelimeter )
282  {
283  if( bCheckFieldTerminator
284  && pachSourceData[nLength] == OSSIM_DDF_FIELD_TERMINATOR )
285  break;
286 
287  nLength++;
288  }
289 
290  if( pnConsumedBytes != NULL )
291  {
292  if( nMaxBytes == 0 )
293  *pnConsumedBytes = nLength;
294  else
295  *pnConsumedBytes = nLength+1;
296  }
297 
298  return nLength;
299  }
300 }
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
#define OSSIM_DDF_FIELD_TERMINATOR
Definition: ossimIso8211.h:62

◆ GetDefaultValue()

int ossimDDFSubfieldDefn::GetDefaultValue ( char *  pachData,
int  nBytesAvailable,
int *  pnBytesUsed 
)

Get default data.

Returns the default subfield data contents for this subfield definition. For variable length numbers this will normally be "0<unit-terminator>". For variable length strings it will be "<unit-terminator>". For fixed length numbers it is zero filled. For fixed length strings it is space filled. For binary numbers it is binary zero filled.

Parameters
pachDatathe buffer into which the returned default will be placed. May be NULL if just querying default size.
nBytesAvailablethe size of pachData in bytes.
pnBytesUsedwill receive the size of the subfield default data in bytes.
Returns
true on success or false on failure or if the passed buffer is too small to hold the default.

Definition at line 744 of file ossimDdfsubfielddefn.cpp.

References bIsVariable, DDFFloat, DDFInt, GetBinaryFormat(), GetType(), nFormatWidth, NotBinary, and OSSIM_DDF_UNIT_TERMINATOR.

747 {
748  int nDefaultSize;
749 
750  if( !bIsVariable )
751  nDefaultSize = nFormatWidth;
752  else
753  nDefaultSize = 1;
754 
755  if( pnBytesUsed != NULL )
756  *pnBytesUsed = nDefaultSize;
757 
758  if( pachData == NULL )
759  return true;
760 
761  if( nBytesAvailable < nDefaultSize )
762  return false;
763 
764  if( bIsVariable )
765  {
766  pachData[0] = OSSIM_DDF_UNIT_TERMINATOR;
767  }
768  else
769  {
770  if( GetBinaryFormat() == NotBinary )
771  {
772  if( GetType() == DDFInt || GetType() == DDFFloat )
773  memset( pachData, 0, nDefaultSize );
774  else
775  memset( pachData, ' ', nDefaultSize );
776  }
777  else
778  memset( pachData, 0, nDefaultSize );
779  }
780 
781  return true;
782 }
#define OSSIM_DDF_UNIT_TERMINATOR
Definition: ossimIso8211.h:65
DDFBinaryFormat GetBinaryFormat(void) const
Definition: ossimIso8211.h:344
DDFDataType GetType()
Get the general type of the subfield.
Definition: ossimIso8211.h:302

◆ GetFormat()

const char* ossimDDFSubfieldDefn::GetFormat ( )
inline

Get pointer to subfield format string.

Definition at line 291 of file ossimIso8211.h.

References pszFormatString.

Referenced by ossimDDFFieldDefn::AddSubfield().

291 { return pszFormatString; }

◆ GetName()

const char* ossimDDFSubfieldDefn::GetName ( )
inline

Get pointer to subfield name.

Definition at line 288 of file ossimIso8211.h.

References pszName.

Referenced by ossimDDFFieldDefn::AddSubfield(), and ossimDDFFieldDefn::FindSubfieldDefn().

288 { return pszName; }

◆ GetType()

DDFDataType ossimDDFSubfieldDefn::GetType ( )
inline

Get the general type of the subfield.

This can be used to determine which of ExtractFloatData(), ExtractIntData() or ExtractStringData() should be used.

Returns
The subfield type. One of DDFInt, DDFFloat, DDFString or DDFBinaryString.

Definition at line 302 of file ossimIso8211.h.

References eType.

Referenced by GetDefaultValue().

302 { return eType; }

◆ GetWidth()

int ossimDDFSubfieldDefn::GetWidth ( )
inline

Get the subfield width (zero for variable).

Definition at line 324 of file ossimIso8211.h.

References nFormatWidth.

Referenced by ossimDDFFieldDefn::ApplyFormats(), and ossimDDFField::GetRepeatCount().

324 { return nFormatWidth; } // zero for variable.

◆ SetFormat()

int ossimDDFSubfieldDefn::SetFormat ( const char *  pszFormat)

Definition at line 98 of file ossimDdfsubfielddefn.cpp.

References bIsVariable, DDFBinaryString, DDFFloat, DDFInt, DDFString, eBinaryFormat, eType, nFormatWidth, ossimNotify(), ossimNotifyLevel_WARN, pszFormatString, SInt, and UInt.

Referenced by ossimDDFFieldDefn::AddSubfield().

100 {
101  free( pszFormatString );
102  pszFormatString = strdup( pszFormat );
103 
104 /* -------------------------------------------------------------------- */
105 /* These values will likely be used. */
106 /* -------------------------------------------------------------------- */
107  if( pszFormatString[1] == '(' )
108  {
109  nFormatWidth = atoi(pszFormatString+2);
110  bIsVariable = nFormatWidth == 0;
111  }
112  else
113  bIsVariable = true;
114 
115 /* -------------------------------------------------------------------- */
116 /* Interpret the format string. */
117 /* -------------------------------------------------------------------- */
118  switch( pszFormatString[0] )
119  {
120  case 'A':
121  case 'C': // It isn't clear to me how this is different than 'A'
122  eType = DDFString;
123  break;
124 
125  case 'R':
126  eType = DDFFloat;
127  break;
128 
129  case 'I':
130  case 'S':
131  eType = DDFInt;
132  break;
133 
134  case 'B':
135  case 'b':
136  // Is the width expressed in bits? (is it a bitstring)
137  bIsVariable = false;
138  if( pszFormatString[1] == '(' )
139  {
140  // CPLAssert( atoi(pszFormatString+2) % 8 == 0 );
141 
142  nFormatWidth = atoi(pszFormatString+2) / 8;
143  eBinaryFormat = SInt; // good default, works for SDTS.
144 
145  if( nFormatWidth < 5 )
146  eType = DDFInt;
147  else
149  }
150 
151  // or do we have a binary type indicator? (is it binary)
152  else
153  {
155  nFormatWidth = atoi(pszFormatString+2);
156 
157  if( eBinaryFormat == SInt || eBinaryFormat == UInt )
158  eType = DDFInt;
159  else
160  eType = DDFFloat;
161  }
162  break;
163 
164  case 'X':
165  // 'X' is extra space, and shouldn't be directly assigned to a
166  // subfield ... I haven't encountered it in use yet though.
168  << "Format type of `%c' not supported.\n"
169  << pszFormatString[0] << std::endl;
170 
171  // CPLAssert( false );
172  return false;
173 
174  default:
176  << "Format type of `%c' not recognised.\n"
177  << pszFormatString[0] << std::endl;
178 
179  // CPLAssert( false );
180  return false;
181  }
182 
183  return true;
184 }
DDFBinaryFormat eBinaryFormat
Definition: ossimIso8211.h:353
DDFBinaryFormat
Binary format: this is the digit immediately following the B or b for binary formats.
Definition: ossimIso8211.h:335
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ SetName()

void ossimDDFSubfieldDefn::SetName ( const char *  pszName)

Definition at line 74 of file ossimDdfsubfielddefn.cpp.

References pszName.

Referenced by ossimDDFFieldDefn::AddSubfield(), and ossimDDFFieldDefn::BuildSubfields().

76 {
77  int i;
78 
79  free( pszName );
80 
81  pszName = strdup( pszNewName );
82 
83  for( i = (int)strlen(pszName)-1; i > 0 && pszName[i] == ' '; i-- )
84  pszName[i] = '\0';
85 }

Member Data Documentation

◆ bIsVariable

int ossimDDFSubfieldDefn::bIsVariable
private

◆ chFormatDelimeter

char ossimDDFSubfieldDefn::chFormatDelimeter
private

Definition at line 361 of file ossimIso8211.h.

Referenced by GetDataLength(), and ossimDDFSubfieldDefn().

◆ eBinaryFormat

DDFBinaryFormat ossimDDFSubfieldDefn::eBinaryFormat
private

◆ eType

DDFDataType ossimDDFSubfieldDefn::eType
private

Definition at line 352 of file ossimIso8211.h.

Referenced by DumpData(), GetType(), ossimDDFSubfieldDefn(), and SetFormat().

◆ nFormatWidth

int ossimDDFSubfieldDefn::nFormatWidth
private

◆ nMaxBufChars

int ossimDDFSubfieldDefn::nMaxBufChars
private

Definition at line 368 of file ossimIso8211.h.

Referenced by ExtractStringData(), and ossimDDFSubfieldDefn().

◆ pachBuffer

char* ossimDDFSubfieldDefn::pachBuffer
private

Definition at line 369 of file ossimIso8211.h.

Referenced by ExtractStringData(), ossimDDFSubfieldDefn(), and ~ossimDDFSubfieldDefn().

◆ pszFormatString

char* ossimDDFSubfieldDefn::pszFormatString
private

◆ pszName

char* ossimDDFSubfieldDefn::pszName
private

The documentation for this class was generated from the following files: