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

This object represents one field in a DDFRecord. More...

#include <ossimIso8211.h>

Public Member Functions

void Initialize (ossimDDFFieldDefn *, const char *pszData, int nSize)
 
void Dump (FILE *fp)
 Write out field contents to debugging file. More...
 
const char * GetSubfieldData (ossimDDFSubfieldDefn *, int *=NULL, int=0)
 Fetch raw data pointer for a particular subfield of this field. More...
 
const char * GetInstanceData (int nInstance, int *pnSize)
 Get field instance data and size. More...
 
const char * GetData ()
 Return the pointer to the entire data block for this record. More...
 
int GetDataSize ()
 Return the number of bytes in the data block returned by GetData(). More...
 
int GetRepeatCount ()
 How many times do the subfields of this record repeat? This
will always be one for non-repeating fields. More...
 
ossimDDFFieldDefnGetFieldDefn ()
 Fetch the corresponding DDFFieldDefn. More...
 

Private Attributes

ossimDDFFieldDefnpoDefn
 
int nDataSize
 
const char * pachData
 

Detailed Description

This object represents one field in a DDFRecord.

This models an instance of the fields data, rather than it's data definition which is handled by the DDFFieldDefn class. Note that a DDFField doesn't have DDFSubfield children as you would expect. To extract subfield values use GetSubfieldData() to find the right data pointer and then use ExtractIntData(), ExtractFloatData() or ExtractStringData().

Definition at line 492 of file ossimIso8211.h.

Member Function Documentation

◆ Dump()

void ossimDDFField::Dump ( FILE *  fp)

Write out field contents to debugging file.

A variety of information about this field, and all it's subfields is written to the given debugging file handle. Note that field definition information (ala DDFFieldDefn) isn't written.

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

Definition at line 71 of file ossimDdffield.cpp.

References ossimDDFSubfieldDefn::DumpData(), ossimDDFSubfieldDefn::GetDataLength(), ossimDDFFieldDefn::GetName(), GetRepeatCount(), ossimDDFFieldDefn::GetSubfield(), ossimDDFFieldDefn::GetSubfieldCount(), min, nDataSize, pachData, and poDefn.

Referenced by ossimDDFRecord::Dump().

73 {
74  int nMaxRepeat = 8;
75 
76  if( getenv("DDF_MAXDUMP") != NULL )
77  nMaxRepeat = atoi(getenv("DDF_MAXDUMP"));
78 
79  fprintf( fp, " DDFField:\n" );
80  fprintf( fp, " Tag = `%s'\n", poDefn->GetName() );
81  fprintf( fp, " DataSize = %d\n", nDataSize );
82 
83  fprintf( fp, " Data = `" );
84  for( int i = 0; i < std::min(nDataSize,40); i++ )
85  {
86  if( pachData[i] < 32 || pachData[i] > 126 )
87  fprintf( fp, "\\%02X", ((unsigned char *) pachData)[i] );
88  else
89  fprintf( fp, "%c", pachData[i] );
90  }
91 
92  if( nDataSize > 40 )
93  fprintf( fp, "..." );
94  fprintf( fp, "'\n" );
95 
96 /* -------------------------------------------------------------------- */
97 /* dump the data of the subfields. */
98 /* -------------------------------------------------------------------- */
99  int iOffset = 0, nLoopCount;
100 
101  for( nLoopCount = 0; nLoopCount < GetRepeatCount(); nLoopCount++ )
102  {
103  if( nLoopCount > nMaxRepeat )
104  {
105  fprintf( fp, " ...\n" );
106  break;
107  }
108 
109  for( int i = 0; i < poDefn->GetSubfieldCount(); i++ )
110  {
111  int nBytesConsumed;
112 
113  poDefn->GetSubfield(i)->DumpData( pachData + iOffset,
114  nDataSize - iOffset, fp );
115 
116  poDefn->GetSubfield(i)->GetDataLength( pachData + iOffset,
117  nDataSize - iOffset,
118  &nBytesConsumed );
119 
120  iOffset += nBytesConsumed;
121  }
122  }
123 }
const char * GetName()
Fetch a pointer to the field name (tag).
Definition: ossimIso8211.h:203
int GetRepeatCount()
How many times do the subfields of this record repeat? This will always be one for non-repeating fie...
const char * pachData
Definition: ossimIso8211.h:524
int GetSubfieldCount()
Get the number of subfields.
Definition: ossimIso8211.h:211
int GetDataLength(const char *, int, int *)
Scan for the end of variable length data.
void DumpData(const char *pachData, int nMaxBytes, FILE *fp)
Dump subfield value to debugging file.
ossimDDFSubfieldDefn * GetSubfield(int i)
Fetch a subfield by index.
ossimDDFFieldDefn * poDefn
Definition: ossimIso8211.h:520
#define min(a, b)
Definition: auxiliary.h:75

◆ GetData()

const char* ossimDDFField::GetData ( )
inline

Return the pointer to the entire data block for this record.

This is an internal copy, and shouldn't be freed by the application.

Definition at line 509 of file ossimIso8211.h.

References pachData.

Referenced by ossimDDFRecord::Clone(), ossimDDFRecord::CloneOn(), GetInstanceData(), ossimAdrgHeader::parse(), ossimDDFRecord::ResetDirectory(), ossimDDFRecord::ResizeField(), ossimDDFRecord::SetFieldRaw(), and ossimDDFRecord::UpdateFieldRaw().

509 { return pachData; }
const char * pachData
Definition: ossimIso8211.h:524

◆ GetDataSize()

int ossimDDFField::GetDataSize ( )
inline

◆ GetFieldDefn()

ossimDDFFieldDefn* ossimDDFField::GetFieldDefn ( )
inline

◆ GetInstanceData()

const char * ossimDDFField::GetInstanceData ( int  nInstance,
int *  pnInstanceSize 
)

Get field instance data and size.

The returned data pointer and size values are suitable for use with DDFRecord::SetFieldRaw().

Parameters
nInstancea value from 0 to GetRepeatCount()-1.
pnInstanceSizea location to put the size (in bytes) of the field instance data returned. This size will include the unit terminator (if any), but not the field terminator. This size pointer may be NULL if not needed.
Returns
the data pointer, or NULL on error.

Definition at line 280 of file ossimDdffield.cpp.

References GetData(), ossimDDFSubfieldDefn::GetDataLength(), GetDataSize(), GetRepeatCount(), ossimDDFFieldDefn::GetSubfield(), ossimDDFFieldDefn::GetSubfieldCount(), GetSubfieldData(), and poDefn.

Referenced by ossimDDFRecord::SetFieldRaw(), ossimDDFRecord::SetFloatSubfield(), ossimDDFRecord::SetIntSubfield(), ossimDDFRecord::SetStringSubfield(), and ossimDDFRecord::UpdateFieldRaw().

283 {
284  int nRepeatCount = GetRepeatCount();
285  const char *pachWrkData;
286 
287  if( nInstance < 0 || nInstance >= nRepeatCount )
288  return NULL;
289 
290 /* -------------------------------------------------------------------- */
291 /* Special case for fields without subfields (like "0001"). We */
292 /* don't currently handle repeating simple fields. */
293 /* -------------------------------------------------------------------- */
294  if( poDefn->GetSubfieldCount() == 0 )
295  {
296  pachWrkData = GetData();
297  if( pnInstanceSize != 0 )
298  *pnInstanceSize = GetDataSize();
299  return pachWrkData;
300  }
301 
302 /* -------------------------------------------------------------------- */
303 /* Get a pointer to the start of the existing data for this */
304 /* iteration of the field. */
305 /* -------------------------------------------------------------------- */
306  int nBytesRemaining1=0, nBytesRemaining2=0;
307  ossimDDFSubfieldDefn *poFirstSubfield;
308 
309  poFirstSubfield = poDefn->GetSubfield(0);
310 
311  pachWrkData = GetSubfieldData(poFirstSubfield, &nBytesRemaining1,
312  nInstance);
313 
314 /* -------------------------------------------------------------------- */
315 /* Figure out the size of the entire field instance, including */
316 /* unit terminators, but not any trailing field terminator. */
317 /* -------------------------------------------------------------------- */
318  if( pnInstanceSize != NULL )
319  {
320  ossimDDFSubfieldDefn *poLastSubfield;
321  int nLastSubfieldWidth;
322  const char *pachLastData;
323 
324  poLastSubfield = poDefn->GetSubfield(poDefn->GetSubfieldCount()-1);
325 
326  pachLastData = GetSubfieldData( poLastSubfield, &nBytesRemaining2,
327  nInstance );
328  poLastSubfield->GetDataLength( pachLastData, nBytesRemaining2,
329  &nLastSubfieldWidth );
330 
331  *pnInstanceSize =
332  nBytesRemaining1 - (nBytesRemaining2 - nLastSubfieldWidth);
333  }
334 
335  return pachWrkData;
336 }
int GetDataSize()
Return the number of bytes in the data block returned by GetData().
Definition: ossimIso8211.h:512
const char * GetSubfieldData(ossimDDFSubfieldDefn *, int *=NULL, int=0)
Fetch raw data pointer for a particular subfield of this field.
int GetRepeatCount()
How many times do the subfields of this record repeat? This will always be one for non-repeating fie...
const char * GetData()
Return the pointer to the entire data block for this record.
Definition: ossimIso8211.h:509
int GetSubfieldCount()
Get the number of subfields.
Definition: ossimIso8211.h:211
int GetDataLength(const char *, int, int *)
Scan for the end of variable length data.
ossimDDFSubfieldDefn * GetSubfield(int i)
Fetch a subfield by index.
Information from the DDR record describing one subfield of a DDFFieldDefn.
Definition: ossimIso8211.h:278
ossimDDFFieldDefn * poDefn
Definition: ossimIso8211.h:520

◆ GetRepeatCount()

int ossimDDFField::GetRepeatCount ( )

How many times do the subfields of this record repeat? This
will always be one for non-repeating fields.

Returns
The number of times that the subfields of this record occur in this record. This will be one for non-repeating fields.
See also
8211view example program for demonstation of handling repeated fields properly.

Definition at line 209 of file ossimDdffield.cpp.

References ossimDDFSubfieldDefn::GetDataLength(), ossimDDFFieldDefn::GetFixedWidth(), ossimDDFFieldDefn::GetSubfield(), ossimDDFFieldDefn::GetSubfieldCount(), ossimDDFSubfieldDefn::GetWidth(), ossimDDFFieldDefn::IsRepeating(), nDataSize, pachData, and poDefn.

Referenced by Dump(), GetInstanceData(), ossimDDFRecord::SetFieldRaw(), and ossimDDFRecord::UpdateFieldRaw().

211 {
212  if( !poDefn->IsRepeating() )
213  return 1;
214 
215 /* -------------------------------------------------------------------- */
216 /* The occurance count depends on how many copies of this */
217 /* field's list of subfields can fit into the data space. */
218 /* -------------------------------------------------------------------- */
219  if( poDefn->GetFixedWidth() )
220  {
221  return nDataSize / poDefn->GetFixedWidth();
222  }
223 
224 /* -------------------------------------------------------------------- */
225 /* Note that it may be legal to have repeating variable width */
226 /* subfields, but I don't have any samples, so I ignore it for */
227 /* now. */
228 /* */
229 /* The file data/cape_royal_AZ_DEM/1183XREF.DDF has a repeating */
230 /* variable length field, but the count is one, so it isn't */
231 /* much value for testing. */
232 /* -------------------------------------------------------------------- */
233  int iOffset = 0, iRepeatCount = 1;
234 
235  while( true )
236  {
237  for( int iSF = 0; iSF < poDefn->GetSubfieldCount(); iSF++ )
238  {
239  int nBytesConsumed;
240  ossimDDFSubfieldDefn * poThisSFDefn = poDefn->GetSubfield( iSF );
241 
242  if( poThisSFDefn->GetWidth() > nDataSize - iOffset )
243  nBytesConsumed = poThisSFDefn->GetWidth();
244  else
245  poThisSFDefn->GetDataLength( pachData+iOffset,
246  nDataSize - iOffset,
247  &nBytesConsumed);
248 
249  iOffset += nBytesConsumed;
250  if( iOffset > nDataSize )
251  return iRepeatCount - 1;
252  }
253 
254  if( iOffset > nDataSize - 2 )
255  return iRepeatCount;
256 
257  iRepeatCount++;
258  }
259 }
const char * pachData
Definition: ossimIso8211.h:524
int GetFixedWidth()
Get the width of this field.
Definition: ossimIso8211.h:223
int GetSubfieldCount()
Get the number of subfields.
Definition: ossimIso8211.h:211
int GetDataLength(const char *, int, int *)
Scan for the end of variable length data.
int GetWidth()
Get the subfield width (zero for variable).
Definition: ossimIso8211.h:324
int IsRepeating()
Fetch repeating flag.
Definition: ossimIso8211.h:230
ossimDDFSubfieldDefn * GetSubfield(int i)
Fetch a subfield by index.
Information from the DDR record describing one subfield of a DDFFieldDefn.
Definition: ossimIso8211.h:278
ossimDDFFieldDefn * poDefn
Definition: ossimIso8211.h:520

◆ GetSubfieldData()

const char * ossimDDFField::GetSubfieldData ( ossimDDFSubfieldDefn poSFDefn,
int *  pnMaxBytes = NULL,
int  iSubfieldIndex = 0 
)

Fetch raw data pointer for a particular subfield of this field.

The passed DDFSubfieldDefn (poSFDefn) should be acquired from the DDFFieldDefn corresponding with this field. This is normally done once before reading any records. This method involves a series of calls to DDFSubfield::GetDataLength() in order to track through the DDFField data to that belonging to the requested subfield. This can be relatively expensive.

Parameters
poSFDefnThe definition of the subfield for which the raw data pointer is desired.
pnMaxBytesThe maximum number of bytes that can be accessed from the returned data pointer is placed in this int, unless it is NULL.
iSubfieldIndexThe instance of this subfield to fetch. Use zero (the default) for the first instance.
Returns
A pointer into the DDFField's data that belongs to the subfield. This returned pointer is invalidated by the next record read (DDFRecord::ReadRecord()) and the returned pointer should not be freed by the application.

Definition at line 152 of file ossimDdffield.cpp.

References ossimDDFSubfieldDefn::GetDataLength(), ossimDDFFieldDefn::GetFixedWidth(), ossimDDFFieldDefn::GetSubfield(), ossimDDFFieldDefn::GetSubfieldCount(), nDataSize, pachData, and poDefn.

Referenced by ossimDDFRecord::GetFloatSubfield(), GetInstanceData(), ossimDDFRecord::GetIntSubfield(), ossimDDFRecord::GetStringSubfield(), ossimAdrgHeader::parse(), ossimDDFRecord::SetFloatSubfield(), ossimDDFRecord::SetIntSubfield(), and ossimDDFRecord::SetStringSubfield().

155 {
156  int iOffset = 0;
157 
158  if( poSFDefn == NULL )
159  return NULL;
160 
161  if( iSubfieldIndex > 0 && poDefn->GetFixedWidth() > 0 )
162  {
163  iOffset = poDefn->GetFixedWidth() * iSubfieldIndex;
164  iSubfieldIndex = 0;
165  }
166 
167  while( iSubfieldIndex >= 0 )
168  {
169  for( int iSF = 0; iSF < poDefn->GetSubfieldCount(); iSF++ )
170  {
171  int nBytesConsumed;
172  ossimDDFSubfieldDefn * poThisSFDefn = poDefn->GetSubfield( iSF );
173 
174  if( poThisSFDefn == poSFDefn && iSubfieldIndex == 0 )
175  {
176  if( pnMaxBytes != NULL )
177  *pnMaxBytes = nDataSize - iOffset;
178 
179  return pachData + iOffset;
180  }
181 
182  poThisSFDefn->GetDataLength( pachData+iOffset, nDataSize - iOffset,
183  &nBytesConsumed);
184  iOffset += nBytesConsumed;
185  }
186 
187  iSubfieldIndex--;
188  }
189 
190  // We didn't find our target subfield or instance!
191  return NULL;
192 }
const char * pachData
Definition: ossimIso8211.h:524
int GetFixedWidth()
Get the width of this field.
Definition: ossimIso8211.h:223
int GetSubfieldCount()
Get the number of subfields.
Definition: ossimIso8211.h:211
int GetDataLength(const char *, int, int *)
Scan for the end of variable length data.
ossimDDFSubfieldDefn * GetSubfield(int i)
Fetch a subfield by index.
Information from the DDR record describing one subfield of a DDFFieldDefn.
Definition: ossimIso8211.h:278
ossimDDFFieldDefn * poDefn
Definition: ossimIso8211.h:520

◆ Initialize()

void ossimDDFField::Initialize ( ossimDDFFieldDefn poDefnIn,
const char *  pszData,
int  nSize 
)

Definition at line 48 of file ossimDdffield.cpp.

References nDataSize, pachData, and poDefn.

Referenced by ossimDDFRecord::AddField(), ossimDDFRecord::Clone(), ossimDDFRecord::CloneOn(), ossimDDFRecord::ResetDirectory(), and ossimDDFRecord::ResizeField().

51 {
52  pachData = pachDataIn;
53  nDataSize = nDataSizeIn;
54  poDefn = poDefnIn;
55 }
const char * pachData
Definition: ossimIso8211.h:524
ossimDDFFieldDefn * poDefn
Definition: ossimIso8211.h:520

Member Data Documentation

◆ nDataSize

int ossimDDFField::nDataSize
private

Definition at line 522 of file ossimIso8211.h.

Referenced by Dump(), GetDataSize(), GetRepeatCount(), GetSubfieldData(), and Initialize().

◆ pachData

const char* ossimDDFField::pachData
private

Definition at line 524 of file ossimIso8211.h.

Referenced by Dump(), GetData(), GetRepeatCount(), GetSubfieldData(), and Initialize().

◆ poDefn

ossimDDFFieldDefn* ossimDDFField::poDefn
private

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