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

The primary class for reading ISO 8211 files. More...

#include <ossimIso8211.h>

Public Member Functions

 ossimDDFModule ()
 The constructor. More...
 
 ~ossimDDFModule ()
 The destructor. More...
 
int Open (const char *pszFilename, int bFailQuietly=false)
 Open a ISO 8211 (DDF) file for reading. More...
 
int Create (const char *pszFilename)
 
void Close ()
 Close an ISO 8211 file. More...
 
int Initialize (char chInterchangeLevel='3', char chLeaderIden='L', char chCodeExtensionIndicator='E', char chVersionNumber='1', char chAppIndicator=' ', const char *pszExtendedCharSet=" ! ", int nSizeFieldLength=3, int nSizeFieldPos=4, int nSizeFieldTag=4)
 
void Dump (FILE *fp)
 Write out module info to debugging file. More...
 
ossimDDFRecordReadRecord (void)
 Read one record from the file. More...
 
void Rewind (long nOffset=-1)
 Return to first record. More...
 
ossimDDFFieldDefnFindFieldDefn (const char *)
 Fetch the definition of the named field. More...
 
int GetFieldCount ()
 Fetch the number of defined fields. More...
 
ossimDDFFieldDefnGetField (int)
 Fetch a field definition by index. More...
 
void AddField (ossimDDFFieldDefn *poNewFDefn)
 Add new field definition. More...
 
int GetFieldControlLength ()
 
void AddCloneRecord (ossimDDFRecord *)
 
void RemoveCloneRecord (ossimDDFRecord *)
 
FILE * GetFP ()
 

Private Attributes

FILE * fpDDF
 
int bReadOnly
 
long nFirstRecordOffset
 
char _interchangeLevel
 
char _inlineCodeExtensionIndicator
 
char _versionNumber
 
char _appIndicator
 
int _fieldControlLength
 
char _extendedCharSet [4]
 
long _recLength
 
char _leaderIden
 
long _fieldAreaStart
 
long _sizeFieldLength
 
long _sizeFieldPos
 
long _sizeFieldTag
 
int nFieldDefnCount
 
ossimDDFFieldDefn ** papoFieldDefns
 
ossimDDFRecordpoRecord
 
int nCloneCount
 
int nMaxCloneCount
 
ossimDDFRecord ** papoClones
 

Detailed Description

The primary class for reading ISO 8211 files.

This class contains all the information read from the DDR record, and is used to read records from the file.

Definition at line 88 of file ossimIso8211.h.

Constructor & Destructor Documentation

◆ ossimDDFModule()

ossimDDFModule::ossimDDFModule ( )

The constructor.

Definition at line 46 of file ossimDdfmodule.cpp.

References _appIndicator, _extendedCharSet, _fieldAreaStart, _fieldControlLength, _inlineCodeExtensionIndicator, _interchangeLevel, _leaderIden, _recLength, _sizeFieldLength, _sizeFieldPos, _sizeFieldTag, _versionNumber, bReadOnly, fpDDF, nCloneCount, nFieldDefnCount, nMaxCloneCount, papoClones, papoFieldDefns, and poRecord.

48 {
49  nFieldDefnCount = 0;
50  papoFieldDefns = NULL;
51  poRecord = NULL;
52 
53  papoClones = NULL;
55 
56  fpDDF = NULL;
57  bReadOnly = true;
58 
59  _interchangeLevel = '\0';
61  _versionNumber = '\0';
62  _appIndicator = '\0';
63  _fieldControlLength = '\0';
64  strcpy( _extendedCharSet, " ! " );
65 
66  _recLength = 0;
67  _leaderIden = 'L';
68  _fieldAreaStart = 0;
69  _sizeFieldLength = 0;
70  _sizeFieldPos = 0;
71  _sizeFieldTag = 0;
72 }
ossimDDFRecord * poRecord
Definition: ossimIso8211.h:152
ossimDDFRecord ** papoClones
Definition: ossimIso8211.h:156
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150
char _extendedCharSet[4]
Definition: ossimIso8211.h:139
char _inlineCodeExtensionIndicator
Definition: ossimIso8211.h:135
char _interchangeLevel
Definition: ossimIso8211.h:134

◆ ~ossimDDFModule()

ossimDDFModule::~ossimDDFModule ( )

The destructor.

Definition at line 82 of file ossimDdfmodule.cpp.

References Close().

84 {
85  Close();
86 }
void Close()
Close an ISO 8211 file.

Member Function Documentation

◆ AddCloneRecord()

void ossimDDFModule::AddCloneRecord ( ossimDDFRecord poRecord)

Definition at line 647 of file ossimDdfmodule.cpp.

References nCloneCount, nMaxCloneCount, ossimCPLRealloc(), papoClones, and poRecord.

Referenced by ossimDDFRecord::Clone(), and ossimDDFRecord::CloneOn().

649 {
650 /* -------------------------------------------------------------------- */
651 /* Do we need to grow the container array? */
652 /* -------------------------------------------------------------------- */
653  if( nCloneCount == nMaxCloneCount )
654  {
655  nMaxCloneCount = nCloneCount*2 + 20;
657  nMaxCloneCount * sizeof(void*));
658  }
659 
660 /* -------------------------------------------------------------------- */
661 /* Add to the list. */
662 /* -------------------------------------------------------------------- */
664 }
ossimDDFRecord * poRecord
Definition: ossimIso8211.h:152
ossimDDFRecord ** papoClones
Definition: ossimIso8211.h:156
Contains instance data from one data record (DR).
Definition: ossimIso8211.h:385
OSSIMDLLEXPORT void * ossimCPLRealloc(void *pData, size_t nNewSize)

◆ AddField()

void ossimDDFModule::AddField ( ossimDDFFieldDefn poNewFDefn)

Add new field definition.

Field definitions may only be added to DDFModules being used for writing, not those being used for reading. Ownership of the DDFFieldDefn object is taken by the DDFModule.

Parameters
poNewFDefndefinition to be added to the module.

Definition at line 611 of file ossimDdfmodule.cpp.

References nFieldDefnCount, ossimCPLRealloc(), and papoFieldDefns.

613 {
614  nFieldDefnCount++;
617  papoFieldDefns[nFieldDefnCount-1] = poNewFDefn;
618 }
Information from the DDR defining one field.
Definition: ossimIso8211.h:179
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150
OSSIMDLLEXPORT void * ossimCPLRealloc(void *pData, size_t nNewSize)

◆ Close()

void ossimDDFModule::Close ( )

Close an ISO 8211 file.

Definition at line 99 of file ossimDdfmodule.cpp.

References fpDDF, nCloneCount, nFieldDefnCount, nMaxCloneCount, papoClones, papoFieldDefns, and poRecord.

Referenced by ossimAdrgHeader::parse(), and ~ossimDDFModule().

101 {
102 /* -------------------------------------------------------------------- */
103 /* Close the file. */
104 /* -------------------------------------------------------------------- */
105  if( fpDDF != NULL )
106  {
107  fclose( fpDDF );
108  fpDDF = NULL;
109  }
110 
111 /* -------------------------------------------------------------------- */
112 /* Cleanup the working record. */
113 /* -------------------------------------------------------------------- */
114  if( poRecord != NULL )
115  {
116  delete poRecord;
117  poRecord = NULL;
118  }
119 
120 /* -------------------------------------------------------------------- */
121 /* Cleanup the clones. Deleting them will cause a callback to */
122 /* remove them from the list. */
123 /* -------------------------------------------------------------------- */
124  while( nCloneCount > 0 )
125  delete papoClones[0];
126 
127  nMaxCloneCount = 0;
128  free( papoClones );
129  papoClones = NULL;
130 
131 /* -------------------------------------------------------------------- */
132 /* Cleanup the field definitions. */
133 /* -------------------------------------------------------------------- */
134  int i;
135 
136  for( i = 0; i < nFieldDefnCount; i++ )
137  delete papoFieldDefns[i];
138  free( papoFieldDefns );
139  papoFieldDefns = NULL;
140  nFieldDefnCount = 0;
141 }
ossimDDFRecord * poRecord
Definition: ossimIso8211.h:152
ossimDDFRecord ** papoClones
Definition: ossimIso8211.h:156
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150

◆ Create()

int ossimDDFModule::Create ( const char *  pszFilename)

Definition at line 381 of file ossimDdfmodule.cpp.

References _appIndicator, _extendedCharSet, _fieldAreaStart, _fieldControlLength, _inlineCodeExtensionIndicator, _interchangeLevel, _leaderIden, _recLength, _sizeFieldLength, _sizeFieldPos, _sizeFieldTag, _versionNumber, bReadOnly, fpDDF, ossimDDFFieldDefn::GenerateDDREntry(), nFieldDefnCount, OSSIM_DDF_FIELD_TERMINATOR, ossimNotify(), ossimNotifyLevel_WARN, and papoFieldDefns.

383 {
384  // CPLAssert( fpDDF == NULL );
385 
386 /* -------------------------------------------------------------------- */
387 /* Create the file on disk. */
388 /* -------------------------------------------------------------------- */
389  fpDDF = fopen( pszFilename, "wb+" );
390  if( fpDDF == NULL )
391  {
393  << "Failed to create file %s, check path and permissions."
394  << pszFilename << std::endl;
395  return false;
396  }
397 
398  bReadOnly = false;
399 
400 /* -------------------------------------------------------------------- */
401 /* Prepare all the field definition information. */
402 /* -------------------------------------------------------------------- */
403  int iField;
404 
406  _recLength = 24
408  + 1;
409 
411 
412  for( iField=0; iField < nFieldDefnCount; iField++ )
413  {
414  int nLength;
415 
416  papoFieldDefns[iField]->GenerateDDREntry( NULL, &nLength );
417  _recLength += nLength;
418  }
419 
420 /* -------------------------------------------------------------------- */
421 /* Setup 24 byte leader. */
422 /* -------------------------------------------------------------------- */
423  char achLeader[25];
424 
425  sprintf( achLeader+0, "%05d", (int) _recLength );
426  achLeader[5] = _interchangeLevel;
427  achLeader[6] = _leaderIden;
428  achLeader[7] = _inlineCodeExtensionIndicator;
429  achLeader[8] = _versionNumber;
430  achLeader[9] = _appIndicator;
431  sprintf( achLeader+10, "%02d", (int) _fieldControlLength );
432  sprintf( achLeader+12, "%05d", (int) _fieldAreaStart );
433  strncpy( achLeader+17, _extendedCharSet, 3 );
434  sprintf( achLeader+20, "%1d", (int) _sizeFieldLength );
435  sprintf( achLeader+21, "%1d", (int) _sizeFieldPos );
436  achLeader[22] = '0';
437  sprintf( achLeader+23, "%1d", (int) _sizeFieldTag );
438  fwrite( achLeader, 24, 1, fpDDF );
439 
440 /* -------------------------------------------------------------------- */
441 /* Write out directory entries. */
442 /* -------------------------------------------------------------------- */
443  int nOffset = 0;
444  for( iField=0; iField < nFieldDefnCount; iField++ )
445  {
446  char achDirEntry[12];
447  int nLength;
448 
449  papoFieldDefns[iField]->GenerateDDREntry( NULL, &nLength );
450 
451  strcpy( achDirEntry, papoFieldDefns[iField]->GetName() );
452  sprintf( achDirEntry + _sizeFieldTag, "%03d", nLength );
453  sprintf( achDirEntry + _sizeFieldTag + _sizeFieldLength,
454  "%04d", nOffset );
455  nOffset += nLength;
456 
457  fwrite( achDirEntry, 11, 1, fpDDF );
458  }
459 
460  char chUT = OSSIM_DDF_FIELD_TERMINATOR;
461  fwrite( &chUT, 1, 1, fpDDF );
462 
463 /* -------------------------------------------------------------------- */
464 /* Write out the field descriptions themselves. */
465 /* -------------------------------------------------------------------- */
466  for( iField=0; iField < nFieldDefnCount; iField++ )
467  {
468  char *pachData;
469  int nLength;
470 
471  papoFieldDefns[iField]->GenerateDDREntry( &pachData, &nLength );
472  fwrite( pachData, nLength, 1, fpDDF );
473  free( pachData );
474  }
475 
476  return true;
477 }
int GenerateDDREntry(char **ppachData, int *pnLength)
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150
char _extendedCharSet[4]
Definition: ossimIso8211.h:139
char _inlineCodeExtensionIndicator
Definition: ossimIso8211.h:135
char _interchangeLevel
Definition: ossimIso8211.h:134
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
#define OSSIM_DDF_FIELD_TERMINATOR
Definition: ossimIso8211.h:62

◆ Dump()

void ossimDDFModule::Dump ( FILE *  fp)

Write out module info to debugging file.

A variety of information about the module is written to the debugging file. This includes all the field and subfield definitions read from the header.

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

Definition at line 493 of file ossimDdfmodule.cpp.

References _appIndicator, _extendedCharSet, _fieldAreaStart, _fieldControlLength, _inlineCodeExtensionIndicator, _interchangeLevel, _leaderIden, _recLength, _sizeFieldLength, _sizeFieldPos, _sizeFieldTag, _versionNumber, ossimDDFFieldDefn::Dump(), nFieldDefnCount, and papoFieldDefns.

495 {
496  fprintf( fp, "DDFModule:\n" );
497  fprintf( fp, " _recLength = %ld\n", _recLength );
498  fprintf( fp, " _interchangeLevel = %c\n", _interchangeLevel );
499  fprintf( fp, " _leaderIden = %c\n", _leaderIden );
500  fprintf( fp, " _inlineCodeExtensionIndicator = %c\n",
502  fprintf( fp, " _versionNumber = %c\n", _versionNumber );
503  fprintf( fp, " _appIndicator = %c\n", _appIndicator );
504  fprintf( fp, " _extendedCharSet = `%s'\n", _extendedCharSet );
505  fprintf( fp, " _fieldControlLength = %d\n", _fieldControlLength );
506  fprintf( fp, " _fieldAreaStart = %ld\n", _fieldAreaStart );
507  fprintf( fp, " _sizeFieldLength = %ld\n", _sizeFieldLength );
508  fprintf( fp, " _sizeFieldPos = %ld\n", _sizeFieldPos );
509  fprintf( fp, " _sizeFieldTag = %ld\n", _sizeFieldTag );
510 
511  for( int i = 0; i < nFieldDefnCount; i++ )
512  {
513  papoFieldDefns[i]->Dump( fp );
514  }
515 }
void Dump(FILE *fp)
Write out field definition info to debugging file.
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150
char _extendedCharSet[4]
Definition: ossimIso8211.h:139
char _inlineCodeExtensionIndicator
Definition: ossimIso8211.h:135
char _interchangeLevel
Definition: ossimIso8211.h:134

◆ FindFieldDefn()

ossimDDFFieldDefn * ossimDDFModule::FindFieldDefn ( const char *  pszFieldName)

Fetch the definition of the named field.

This function will scan the DDFFieldDefn's on this module, to find one with the indicated field name.

Parameters
pszFieldNameThe name of the field to search for. The comparison is case insensitive.
Returns
A pointer to the request DDFFieldDefn object is returned, or NULL if none matching the name are found. The return object remains owned by the DDFModule, and should not be deleted by application code.

Definition at line 535 of file ossimDdfmodule.cpp.

References ossimDDFFieldDefn::GetName(), nFieldDefnCount, and papoFieldDefns.

Referenced by ossimDDFRecord::CloneOn().

537 {
538  int i;
539 
540 /* -------------------------------------------------------------------- */
541 /* This pass tries to reduce the cost of comparing strings by */
542 /* first checking the first character, and by using strcmp() */
543 /* -------------------------------------------------------------------- */
544  for( i = 0; i < nFieldDefnCount; i++ )
545  {
546  const char *pszThisName = papoFieldDefns[i]->GetName();
547 
548  if( *pszThisName == *pszFieldName
549  && strcmp( pszFieldName+1, pszThisName+1) == 0 )
550  return papoFieldDefns[i];
551  }
552 
553 /* -------------------------------------------------------------------- */
554 /* Now do a more general check. Application code may not */
555 /* always use the correct name case. */
556 /* -------------------------------------------------------------------- */
557  for( i = 0; i < nFieldDefnCount; i++ )
558  {
560  if( s == pszFieldName )
561  return papoFieldDefns[i];
562  }
563 
564  return NULL;
565 }
const char * GetName()
Fetch a pointer to the field name (tag).
Definition: ossimIso8211.h:203
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150

◆ GetField()

ossimDDFFieldDefn * ossimDDFModule::GetField ( int  i)

Fetch a field definition by index.

Parameters
i(from 0 to GetFieldCount() - 1.
Returns
the returned field pointer or NULL if the index is out of range.

Definition at line 631 of file ossimDdfmodule.cpp.

References nFieldDefnCount, and papoFieldDefns.

633 {
634  if( i < 0 || i >= nFieldDefnCount )
635  return NULL;
636  else
637  return papoFieldDefns[i];
638 }
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150

◆ GetFieldControlLength()

int ossimDDFModule::GetFieldControlLength ( )
inline

Definition at line 122 of file ossimIso8211.h.

References _fieldControlLength.

Referenced by ossimDDFFieldDefn::Initialize().

122 { return _fieldControlLength; }

◆ GetFieldCount()

int ossimDDFModule::GetFieldCount ( )
inline

Fetch the number of defined fields.

Definition at line 117 of file ossimIso8211.h.

References nFieldDefnCount.

117 { return nFieldDefnCount; }

◆ GetFP()

FILE* ossimDDFModule::GetFP ( )
inline

Definition at line 127 of file ossimIso8211.h.

References fpDDF.

Referenced by ossimDDFRecord::Read().

127 { return fpDDF; }

◆ Initialize()

int ossimDDFModule::Initialize ( char  chInterchangeLevel = '3',
char  chLeaderIden = 'L',
char  chCodeExtensionIndicator = 'E',
char  chVersionNumber = '1',
char  chAppIndicator = ' ',
const char *  pszExtendedCharSet = " ! ",
int  nSizeFieldLength = 3,
int  nSizeFieldPos = 4,
int  nSizeFieldTag = 4 
)

Definition at line 353 of file ossimDdfmodule.cpp.

References _appIndicator, _extendedCharSet, _inlineCodeExtensionIndicator, _interchangeLevel, _leaderIden, _sizeFieldLength, _sizeFieldPos, _sizeFieldTag, and _versionNumber.

363 {
364  _interchangeLevel = chInterchangeLevel;
365  _leaderIden = chLeaderIden;
366  _inlineCodeExtensionIndicator = chCodeExtensionIndicator;
367  _versionNumber = chVersionNumber;
368  _appIndicator = chAppIndicator;
369  strcpy( _extendedCharSet, pszExtendedCharSet );
370  _sizeFieldLength = nSizeFieldLength;
371  _sizeFieldPos = nSizeFieldPos;
372  _sizeFieldTag = nSizeFieldTag;
373 
374  return true;
375 }
char _extendedCharSet[4]
Definition: ossimIso8211.h:139
char _inlineCodeExtensionIndicator
Definition: ossimIso8211.h:135
char _interchangeLevel
Definition: ossimIso8211.h:134

◆ Open()

int ossimDDFModule::Open ( const char *  pszFilename,
int  bFailQuietly = false 
)

Open a ISO 8211 (DDF) file for reading.

If the open succeeds the data descriptive record (DDR) will have been read, and all the field and subfield definitions will be available.

Parameters
pszFilenameThe name of the file to open.
bFailQuietlyIf false a CPL Error is issued for non-8211 files, otherwise quietly return NULL.
Returns
false if the open fails or true if it succeeds. Errors messages are issued internally with CPLError().

Definition at line 164 of file ossimDdfmodule.cpp.

Referenced by ossimAdrgHeader::parse().

166 {
167  static const size_t nLeaderSize = 24;
168 
169 /* -------------------------------------------------------------------- */
170 /* Close the existing file if there is one. */
171 /* -------------------------------------------------------------------- */
172  if( fpDDF != NULL )
173  Close();
174 
175  // Check for empty filename.
176  if (!pszFilename)
177  {
178  return false;
179  }
180 
181 /* -------------------------------------------------------------------- */
182 /* Open the file. */
183 /* -------------------------------------------------------------------- */
184  fpDDF = fopen( pszFilename, "rb" );
185 
186  if( fpDDF == NULL )
187  {
188  if( !bFailQuietly )
190  << "Unable to open DDF file `%s'."
191  << pszFilename << std::endl;
192  return false;
193  }
194 
195 /* -------------------------------------------------------------------- */
196 /* Read the 24 byte leader. */
197 /* -------------------------------------------------------------------- */
198  char achLeader[nLeaderSize];
199 
200  if( fread( achLeader, 1, nLeaderSize, fpDDF ) != nLeaderSize )
201  {
202  fclose( fpDDF );
203  fpDDF = NULL;
204 
205  if( !bFailQuietly )
207  << "Leader is short on DDF file `%s'."
208  << pszFilename << std::endl;
209 
210  return false;
211  }
212 
213 /* -------------------------------------------------------------------- */
214 /* Verify that this appears to be a valid DDF file. */
215 /* -------------------------------------------------------------------- */
216  int i, bValid = true;
217 
218  for( i = 0; i < (int)nLeaderSize; i++ )
219  {
220  if( achLeader[i] < 32 || achLeader[i] > 126 )
221  bValid = false;
222  }
223 
224  if( achLeader[5] != '1' && achLeader[5] != '2' && achLeader[5] != '3' )
225  bValid = false;
226 
227  if( achLeader[6] != 'L' )
228  bValid = false;
229  if( achLeader[8] != '1' && achLeader[8] != ' ' )
230  bValid = false;
231 
232 /* -------------------------------------------------------------------- */
233 /* Extract information from leader. */
234 /* -------------------------------------------------------------------- */
235 
236  if( bValid )
237  {
238  _recLength = ossimDDFScanInt( achLeader+0, 5 );
239  _interchangeLevel = achLeader[5];
240  _leaderIden = achLeader[6];
241  _inlineCodeExtensionIndicator = achLeader[7];
242  _versionNumber = achLeader[8];
243  _appIndicator = achLeader[9];
244  _fieldControlLength = ossimDDFScanInt(achLeader+10,2);
245  _fieldAreaStart = ossimDDFScanInt(achLeader+12,5);
246  _extendedCharSet[0] = achLeader[17];
247  _extendedCharSet[1] = achLeader[18];
248  _extendedCharSet[2] = achLeader[19];
249  _extendedCharSet[3] = '\0';
250  _sizeFieldLength = ossimDDFScanInt(achLeader+20,1);
251  _sizeFieldPos = ossimDDFScanInt(achLeader+21,1);
252  _sizeFieldTag = ossimDDFScanInt(achLeader+23,1);
253 
254  if( _recLength < 12 || _fieldControlLength == 0
255  || _fieldAreaStart < 24 || _sizeFieldLength == 0
256  || _sizeFieldPos == 0 || _sizeFieldTag == 0 )
257  {
258  bValid = false;
259  }
260  }
261 
262 /* -------------------------------------------------------------------- */
263 /* If the header is invalid, then clean up, report the error */
264 /* and return. */
265 /* -------------------------------------------------------------------- */
266  if( !bValid )
267  {
268  fclose( fpDDF );
269  fpDDF = NULL;
270 
271  if( !bFailQuietly )
273  << "File `%s' does not appear to have\n"
274  << "a valid ISO 8211 header.\n"
275  << pszFilename << std::endl;
276  return false;
277  }
278 
279 /* -------------------------------------------------------------------- */
280 /* Read the whole record info memory. */
281 /* -------------------------------------------------------------------- */
282  char *pachRecord;
283 
284  pachRecord = (char *) malloc(_recLength);
285  memcpy( pachRecord, achLeader, nLeaderSize );
286 
287  if( fread( pachRecord+nLeaderSize, 1, _recLength-nLeaderSize, fpDDF )
288  != _recLength - nLeaderSize )
289  {
290  if( !bFailQuietly )
292  << "Header record is short on DDF file `%s'."
293  << pszFilename << std::endl;
294 
295  return false;
296  }
297 
298 /* -------------------------------------------------------------------- */
299 /* First make a pass counting the directory entries. */
300 /* -------------------------------------------------------------------- */
301  int nFieldEntryWidth, nFDCount = 0;
302 
303  nFieldEntryWidth = _sizeFieldLength + _sizeFieldPos + _sizeFieldTag;
304 
305  for( i = nLeaderSize; i < _recLength; i += nFieldEntryWidth )
306  {
307  if( pachRecord[i] == OSSIM_DDF_FIELD_TERMINATOR )
308  break;
309 
310  nFDCount++;
311  }
312 
313 /* -------------------------------------------------------------------- */
314 /* Allocate, and read field definitions. */
315 /* -------------------------------------------------------------------- */
316  for( i = 0; i < nFDCount; i++ )
317  {
318  char szTag[128];
319  int nEntryOffset = nLeaderSize + i*nFieldEntryWidth;
320  int nFieldLength, nFieldPos;
321  ossimDDFFieldDefn *poFDefn;
322 
323  strncpy( szTag, pachRecord+nEntryOffset, _sizeFieldTag );
324  szTag[_sizeFieldTag] = '\0';
325 
326  nEntryOffset += _sizeFieldTag;
327  nFieldLength = ossimDDFScanInt( pachRecord+nEntryOffset, _sizeFieldLength );
328 
329  nEntryOffset += _sizeFieldLength;
330  nFieldPos = ossimDDFScanInt( pachRecord+nEntryOffset, _sizeFieldPos );
331 
332  poFDefn = new ossimDDFFieldDefn();
333  poFDefn->Initialize( this, szTag, nFieldLength,
334  pachRecord+_fieldAreaStart+nFieldPos );
335  AddField( poFDefn );
336  }
337 
338  free( pachRecord );
339 
340 /* -------------------------------------------------------------------- */
341 /* Record the current file offset, the beginning of the first */
342 /* data record. */
343 /* -------------------------------------------------------------------- */
344  nFirstRecordOffset = ftell( fpDDF );
345 
346  return true;
347 }
long nFirstRecordOffset
Definition: ossimIso8211.h:132
Information from the DDR defining one field.
Definition: ossimIso8211.h:179
int Initialize(ossimDDFModule *poModule, const char *pszTag, int nSize, const char *pachRecord)
void AddField(ossimDDFFieldDefn *poNewFDefn)
Add new field definition.
void Close()
Close an ISO 8211 file.
char _extendedCharSet[4]
Definition: ossimIso8211.h:139
char _inlineCodeExtensionIndicator
Definition: ossimIso8211.h:135
long ossimDDFScanInt(const char *pszString, int nMaxChars)
char _interchangeLevel
Definition: ossimIso8211.h:134
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
#define OSSIM_DDF_FIELD_TERMINATOR
Definition: ossimIso8211.h:62

◆ ReadRecord()

ossimDDFRecord * ossimDDFModule::ReadRecord ( void  )

Read one record from the file.

Returns
A pointer to a DDFRecord object is returned, or NULL if a read error, or end of file occurs. The returned record is owned by the module, and should not be deleted by the application. The record is only valid untill the next ReadRecord() at which point it is overwritten.

Definition at line 585 of file ossimDdfmodule.cpp.

References poRecord, and ossimDDFRecord::Read().

Referenced by ossimAdrgHeader::parse().

587 {
588  if( poRecord == NULL )
589  poRecord = new ossimDDFRecord( this );
590 
591  if( poRecord->Read() )
592  return poRecord;
593  else
594  return NULL;
595 }
ossimDDFRecord * poRecord
Definition: ossimIso8211.h:152
Contains instance data from one data record (DR).
Definition: ossimIso8211.h:385

◆ RemoveCloneRecord()

void ossimDDFModule::RemoveCloneRecord ( ossimDDFRecord poRecord)

Definition at line 670 of file ossimDdfmodule.cpp.

References nCloneCount, papoClones, and poRecord.

Referenced by ossimDDFRecord::CloneOn(), and ossimDDFRecord::~ossimDDFRecord().

672 {
673  int i;
674 
675  for( i = 0; i < nCloneCount; i++ )
676  {
677  if( papoClones[i] == poRecord )
678  {
680  nCloneCount--;
681  return;
682  }
683  }
684 
685  // CPLAssert( false );
686 }
ossimDDFRecord * poRecord
Definition: ossimIso8211.h:152
ossimDDFRecord ** papoClones
Definition: ossimIso8211.h:156

◆ Rewind()

void ossimDDFModule::Rewind ( long  nOffset = -1)

Return to first record.

The next call to ReadRecord() will read the first data record in the file.

Parameters
nOffsetthe offset in the file to return to. By default this is -1, a special value indicating that reading should return to the first data record. Otherwise it is an absolute byte offset in the file.

Definition at line 702 of file ossimDdfmodule.cpp.

References ossimDDFRecord::Clear(), fpDDF, nFirstRecordOffset, and poRecord.

704 {
705  if( nOffset == -1 )
706  nOffset = nFirstRecordOffset;
707 
708  if( fpDDF == NULL )
709  return;
710 
711  fseek( fpDDF, nOffset, SEEK_SET );
712 
713  if( nOffset == nFirstRecordOffset && poRecord != NULL )
714  poRecord->Clear();
715 
716 }
long nFirstRecordOffset
Definition: ossimIso8211.h:132
ossimDDFRecord * poRecord
Definition: ossimIso8211.h:152

Member Data Documentation

◆ _appIndicator

char ossimDDFModule::_appIndicator
private

Definition at line 137 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _extendedCharSet

char ossimDDFModule::_extendedCharSet[4]
private

Definition at line 139 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _fieldAreaStart

long ossimDDFModule::_fieldAreaStart
private

Definition at line 143 of file ossimIso8211.h.

Referenced by Create(), Dump(), and ossimDDFModule().

◆ _fieldControlLength

int ossimDDFModule::_fieldControlLength
private

Definition at line 138 of file ossimIso8211.h.

Referenced by Create(), Dump(), GetFieldControlLength(), and ossimDDFModule().

◆ _inlineCodeExtensionIndicator

char ossimDDFModule::_inlineCodeExtensionIndicator
private

Definition at line 135 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _interchangeLevel

char ossimDDFModule::_interchangeLevel
private

Definition at line 134 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _leaderIden

char ossimDDFModule::_leaderIden
private

Definition at line 142 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _recLength

long ossimDDFModule::_recLength
private

Definition at line 141 of file ossimIso8211.h.

Referenced by Create(), Dump(), and ossimDDFModule().

◆ _sizeFieldLength

long ossimDDFModule::_sizeFieldLength
private

Definition at line 144 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _sizeFieldPos

long ossimDDFModule::_sizeFieldPos
private

Definition at line 145 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _sizeFieldTag

long ossimDDFModule::_sizeFieldTag
private

Definition at line 146 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ _versionNumber

char ossimDDFModule::_versionNumber
private

Definition at line 136 of file ossimIso8211.h.

Referenced by Create(), Dump(), Initialize(), and ossimDDFModule().

◆ bReadOnly

int ossimDDFModule::bReadOnly
private

Definition at line 131 of file ossimIso8211.h.

Referenced by Create(), and ossimDDFModule().

◆ fpDDF

FILE* ossimDDFModule::fpDDF
private

Definition at line 130 of file ossimIso8211.h.

Referenced by Close(), Create(), GetFP(), ossimDDFModule(), and Rewind().

◆ nCloneCount

int ossimDDFModule::nCloneCount
private

Definition at line 154 of file ossimIso8211.h.

Referenced by AddCloneRecord(), Close(), ossimDDFModule(), and RemoveCloneRecord().

◆ nFieldDefnCount

int ossimDDFModule::nFieldDefnCount
private

◆ nFirstRecordOffset

long ossimDDFModule::nFirstRecordOffset
private

Definition at line 132 of file ossimIso8211.h.

Referenced by Rewind().

◆ nMaxCloneCount

int ossimDDFModule::nMaxCloneCount
private

Definition at line 155 of file ossimIso8211.h.

Referenced by AddCloneRecord(), Close(), and ossimDDFModule().

◆ papoClones

ossimDDFRecord** ossimDDFModule::papoClones
private

Definition at line 156 of file ossimIso8211.h.

Referenced by AddCloneRecord(), Close(), ossimDDFModule(), and RemoveCloneRecord().

◆ papoFieldDefns

ossimDDFFieldDefn** ossimDDFModule::papoFieldDefns
private

Definition at line 150 of file ossimIso8211.h.

Referenced by AddField(), Close(), Create(), Dump(), FindFieldDefn(), GetField(), and ossimDDFModule().

◆ poRecord

ossimDDFRecord* ossimDDFModule::poRecord
private

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