OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimIso8211.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copied from "gdal" project. See licence below.
3  *
4  * Project: ISO 8211 Access
5  * Purpose: Main declarations for ISO 8211.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 1999, Frank Warmerdam <warmerdam@pobox.com>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ******************************************************************************
29  * $Id: ossimIso8211.h 7238 2005-02-13 16:08:04Z dburken $
30  */
31 
32 #ifndef ossimIso8211_HEADER
33 #define ossimIso8211_HEADER
34 
35 #include <cstdio>
36 #include <cstdlib>
37 
38 
42 typedef enum {
47 } DDFDataType;
48 
49 /************************************************************************/
50 /* These should really be private to the library ... they are */
51 /* mostly conveniences. */
52 /************************************************************************/
53 
54 long ossimDDFScanInt( const char *pszString, int nMaxChars );
55 int ossimDDFScanVariable( const char * pszString,
56  int nMaxChars, int nDelimChar );
57 char *ossimDDFFetchVariable( const char *pszString, int nMaxChars,
58  int nDelimChar1, int nDelimChar2,
59  int *pnConsumedChars );
60 
61 #ifndef OSSIM_DDF_FIELD_TERMINATOR
62 # define OSSIM_DDF_FIELD_TERMINATOR 30
63 #endif
64 #ifndef OSSIM_DDF_UNIT_TERMINATOR
65 # define OSSIM_DDF_UNIT_TERMINATOR 31
66 #endif
67 
68 /************************************************************************/
69 /* Predeclarations */
70 /************************************************************************/
71 
72 class ossimDDFFieldDefn;
74 class ossimDDFRecord;
75 class ossimDDFField;
76 
77 /************************************************************************/
78 /* DDFModule */
79 /************************************************************************/
80 
89 {
90  public:
93 
94  int Open( const char * pszFilename, int bFailQuietly = false );
95  int Create( const char *pszFilename );
96  void Close();
97 
98  int Initialize( char chInterchangeLevel = '3',
99  char chLeaderIden = 'L',
100  char chCodeExtensionIndicator = 'E',
101  char chVersionNumber = '1',
102  char chAppIndicator = ' ',
103  const char *pszExtendedCharSet = " ! ",
104  int nSizeFieldLength = 3,
105  int nSizeFieldPos = 4,
106  int nSizeFieldTag = 4 );
107 
108  void Dump( FILE * fp );
109 
110  ossimDDFRecord *ReadRecord( void );
111  void Rewind( long nOffset = -1 );
112 
113  ossimDDFFieldDefn *FindFieldDefn( const char * );
114 
117  int GetFieldCount() { return nFieldDefnCount; }
119  void AddField( ossimDDFFieldDefn *poNewFDefn );
120 
121  // This is really just for internal use.
123  void AddCloneRecord( ossimDDFRecord * );
125 
126  // This is just for DDFRecord.
127  FILE *GetFP() { return fpDDF; }
128 
129  private:
130  FILE *fpDDF;
133 
140 
147 
148  // One DirEntry per field.
151 
153 
157 };
158 
159 /************************************************************************/
160 /* DDFFieldDefn */
161 /************************************************************************/
162 
164  typedef enum { dtc_char_string,
171 
180 {
181  public:
184 
185  int Create( const char *pszTag, const char *pszFieldName,
186  const char *pszDescription,
187  DDF_data_struct_code eDataStructCode,
188  DDF_data_type_code eDataTypeCode,
189  const char *pszFormat = NULL );
190  void AddSubfield( ossimDDFSubfieldDefn *poNewSFDefn,
191  int bDontAddToFormat = false );
192  void AddSubfield( const char *pszName, const char *pszFormat );
193  int GenerateDDREntry( char **ppachData, int *pnLength );
194 
195  int Initialize( ossimDDFModule * poModule, const char *pszTag,
196  int nSize, const char * pachRecord );
197 
198  void Dump( FILE * fp );
199 
203  const char *GetName() { return pszTag; }
204 
208  const char *GetDescription() { return _fieldName; }
209 
212 
214  ossimDDFSubfieldDefn *FindSubfieldDefn( const char * );
215 
223  int GetFixedWidth() { return nFixedWidth; }
224 
231 
232  static char *ExpandFormat( const char * );
233 
236 
237  char *GetDefaultValue( int *pnSize );
238 
239  private:
240 
241  static char *ExtractSubstring( const char * );
242 
244  char * pszTag;
245 
246  char * _fieldName;
247  char * _arrayDescr;
249 
251  int nFixedWidth; // zero if variable.
252 
253  int BuildSubfields();
254  int ApplyFormats();
255 
257 
259 
262 };
263 
264 /************************************************************************/
265 /* DDFSubfieldDefn */
266 /* */
267 /* Information from the DDR record for one subfield of a */
268 /* particular field. */
269 /************************************************************************/
270 
279 {
280 public:
281 
284 
285  void SetName( const char * pszName );
286 
288  const char *GetName() { return pszName; }
289 
291  const char *GetFormat() { return pszFormatString; }
292  int SetFormat( const char * pszFormat );
293 
302  DDFDataType GetType() { return eType; }
303 
304  double ExtractFloatData( const char *pachData, int nMaxBytes,
305  int * pnConsumedBytes );
306  int ExtractIntData( const char *pachData, int nMaxBytes,
307  int * pnConsumedBytes );
308  const char *ExtractStringData( const char *pachData, int nMaxBytes,
309  int * pnConsumedBytes );
310  int GetDataLength( const char *, int, int * );
311  void DumpData( const char *pachData, int nMaxBytes, FILE * fp );
312 
313  int FormatStringValue( char *pachData, int nBytesAvailable,
314  int *pnBytesUsed, const char *pszValue,
315  int nValueLength = -1 );
316 
317  int FormatIntValue( char *pachData, int nBytesAvailable,
318  int *pnBytesUsed, int nNewValue );
319 
320  int FormatFloatValue( char *pachData, int nBytesAvailable,
321  int *pnBytesUsed, double dfNewValue );
322 
324  int GetWidth() { return nFormatWidth; } // zero for variable.
325 
326  int GetDefaultValue( char *pachData, int nBytesAvailable,
327  int *pnBytesUsed );
328 
329  void Dump( FILE * fp );
330 
335 typedef enum {
337  UInt=1,
338  SInt=2,
343 
345 
346 
347 private:
348 
349  char *pszName; // a.k.a. subfield mnemonic
351 
354 
355 /* -------------------------------------------------------------------- */
356 /* bIsVariable determines whether we using the */
357 /* chFormatDelimeter (TRUE), or the fixed width (false). */
358 /* -------------------------------------------------------------------- */
360 
363 
364 /* -------------------------------------------------------------------- */
365 /* Fetched string cache. This is where we hold the values */
366 /* returned from ExtractStringData(). */
367 /* -------------------------------------------------------------------- */
369  char *pachBuffer;
370 };
371 
372 /************************************************************************/
373 /* DDFRecord */
374 /* */
375 /* Class that contains one DR record from a file. We read into */
376 /* the same record object repeatedly to ensure that repeated */
377 /* leaders can be easily preserved. */
378 /************************************************************************/
379 
386 {
387  public:
389  ~ossimDDFRecord();
390 
393 
394  void Dump( FILE * );
395 
397  int GetFieldCount() { return nFieldCount; }
398 
399  ossimDDFField *FindField( const char *, int = 0 );
400  ossimDDFField *GetField( int );
401 
402  int GetIntSubfield( const char *, int, const char *, int,
403  int * = NULL );
404  double GetFloatSubfield( const char *, int, const char *, int,
405  int * = NULL );
406  const char *GetStringSubfield( const char *, int, const char *, int,
407  int * = NULL );
408 
409  int SetIntSubfield( const char *pszField, int iFieldIndex,
410  const char *pszSubfield, int iSubfieldIndex,
411  int nValue );
412  int SetStringSubfield( const char *pszField, int iFieldIndex,
413  const char *pszSubfield, int iSubfieldIndex,
414  const char *pszValue, int nValueLength=-1 );
415  int SetFloatSubfield( const char *pszField, int iFieldIndex,
416  const char *pszSubfield, int iSubfieldIndex,
417  double dfNewValue );
418 
420  int GetDataSize() { return nDataSize; }
421 
427  const char *GetData() { return pachData; }
428 
434 
435  int ResizeField( ossimDDFField *poField, int nNewDataSize );
436  int DeleteField( ossimDDFField *poField );
438 
439  int CreateDefaultFieldInstance( ossimDDFField *poField, int iIndexWithinField );
440 
441  int SetFieldRaw( ossimDDFField *poField, int iIndexWithinField,
442  const char *pachRawData, int nRawDataSize );
443  int UpdateFieldRaw( ossimDDFField *poField, int iIndexWithinField,
444  int nStartOffset, int nOldSize,
445  const char *pachRawData, int nRawDataSize );
446 
447  int Write();
448 
449  // This is really just for the DDFModule class.
450  int Read();
451  void Clear();
452  int ResetDirectory();
453 
454  private:
455 
456  int ReadHeader();
457 
459 
461 
462  int nFieldOffset; // field data area, not dir entries.
463 
467 
468  int nDataSize; // Whole record except leader with header
469  char *pachData;
470 
473 
474  int bIsClone;
475 };
476 
477 /************************************************************************/
478 /* DDFField */
479 /* */
480 /* This object represents one field in a DDFRecord. */
481 /************************************************************************/
482 
493 {
494  public:
495  void Initialize( ossimDDFFieldDefn *, const char *pszData,
496  int nSize );
497 
498  void Dump( FILE * fp );
499 
500  const char *GetSubfieldData( ossimDDFSubfieldDefn *,
501  int * = NULL, int = 0 );
502 
503  const char *GetInstanceData( int nInstance, int *pnSize );
504 
509  const char *GetData() { return pachData; }
510 
512  int GetDataSize() { return nDataSize; }
513 
514  int GetRepeatCount();
515 
518 
519  private:
521 
523 
524  const char *pachData;
525 };
526 
527 #endif /* ifndef ossimIso8211_HEADER */
int GetDefaultValue(char *pachData, int nBytesAvailable, int *pnBytesUsed)
Get default data.
long nFirstRecordOffset
Definition: ossimIso8211.h:132
const char * GetName()
Get pointer to subfield name.
Definition: ossimIso8211.h:288
void Dump(FILE *)
Write out record contents to debugging file.
void Initialize(ossimDDFFieldDefn *, const char *pszData, int nSize)
int GetFieldCount()
Fetch the number of defined fields.
Definition: ossimIso8211.h:117
ossimDDFModule()
The constructor.
const char * ExtractStringData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a zero terminated string containing the data for this subfield.
void RemoveCloneRecord(ossimDDFRecord *)
static char * ExtractSubstring(const char *)
Information from the DDR defining one field.
Definition: ossimIso8211.h:179
int FormatFloatValue(char *pachData, int nBytesAvailable, int *pnBytesUsed, double dfNewValue)
Format float subfield value.
int GetDataSize()
Return the number of bytes in the data block returned by GetData().
Definition: ossimIso8211.h:512
double ExtractFloatData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a subfield value as a float.
const char * GetName()
Fetch a pointer to the field name (tag).
Definition: ossimIso8211.h:203
char * GetDefaultValue(int *pnSize)
Return default data for field instance.
ossimDDFModule * poModule
Definition: ossimIso8211.h:243
int Initialize(ossimDDFModule *poModule, const char *pszTag, int nSize, const char *pachRecord)
int Create(const char *pszFilename)
char * ossimDDFFetchVariable(const char *pszString, int nMaxChars, int nDelimChar1, int nDelimChar2, int *pnConsumedChars)
int FormatStringValue(char *pachData, int nBytesAvailable, int *pnBytesUsed, const char *pszValue, int nValueLength=-1)
Format string subfield value.
int GetDataSize()
Fetch size of records raw data (GetData()) in bytes.
Definition: ossimIso8211.h:420
int UpdateFieldRaw(ossimDDFField *poField, int iIndexWithinField, int nStartOffset, int nOldSize, const char *pachRawData, int nRawDataSize)
void Dump(FILE *fp)
Write out subfield definition info to debugging file.
ossimDDFSubfieldDefn ** papoSubfields
Definition: ossimIso8211.h:261
int GetFieldControlLength()
Definition: ossimIso8211.h:122
static char * ExpandFormat(const char *)
int GenerateDDREntry(char **ppachData, int *pnLength)
int ossimDDFScanVariable(const char *pszString, int nMaxChars, int nDelimChar)
ossimDDFField * FindField(const char *, int=0)
Find the named field within this record.
int SetStringSubfield(const char *pszField, int iFieldIndex, const char *pszSubfield, int iSubfieldIndex, const char *pszValue, int nValueLength=-1)
Set a string subfield in record.
ossimDDFRecord * Clone()
Make a copy of a record.
ossimDDFRecord * poRecord
Definition: ossimIso8211.h:152
int CreateDefaultFieldInstance(ossimDDFField *poField, int iIndexWithinField)
Initialize default instance.
int SetFloatSubfield(const char *pszField, int iFieldIndex, const char *pszSubfield, int iSubfieldIndex, double dfNewValue)
Set a float subfield in record.
void Dump(FILE *fp)
Write out module info to debugging file.
~ossimDDFModule()
The destructor.
const char * GetSubfieldData(ossimDDFSubfieldDefn *, int *=NULL, int=0)
Fetch raw data pointer for a particular subfield of this field.
ossimDDFFieldDefn * FindFieldDefn(const char *)
Fetch the definition of the named field.
ossimDDFRecord ** papoClones
Definition: ossimIso8211.h:156
ossimDDFField * GetField(int)
Fetch field object based on index.
int FormatIntValue(char *pachData, int nBytesAvailable, int *pnBytesUsed, int nNewValue)
Format int subfield value.
double GetFloatSubfield(const char *, int, const char *, int, int *=NULL)
Fetch value of a subfield as a float (double).
void AddSubfield(ossimDDFSubfieldDefn *poNewSFDefn, int bDontAddToFormat=false)
This object represents one field in a DDFRecord.
Definition: ossimIso8211.h:492
int DeleteField(ossimDDFField *poField)
Delete a field instance from a record.
ossimDDFRecord(ossimDDFModule *)
void Dump(FILE *fp)
Write out field definition info to debugging file.
ossimDDFField * paoFields
Definition: ossimIso8211.h:472
os2<< "> n<< " > nendobj n
int GetRepeatCount()
How many times do the subfields of this record repeat? This will always be one for non-repeating fie...
int Write()
Write record out to module.
int SetFieldRaw(ossimDDFField *poField, int iIndexWithinField, const char *pachRawData, int nRawDataSize)
Set the raw contents of a field instance.
ossimDDFFieldDefn ** papoFieldDefns
Definition: ossimIso8211.h:150
ossimDDFSubfieldDefn * FindSubfieldDefn(const char *)
Find a subfield definition by it&#39;s mnemonic tag.
const char * pachData
Definition: ossimIso8211.h:524
void SetName(const char *pszName)
ossimDDFField * AddField(ossimDDFFieldDefn *)
Add a new field to record.
const char * GetStringSubfield(const char *, int, const char *, int, int *=NULL)
Fetch value of a subfield as a string.
int ResizeField(ossimDDFField *poField, int nNewDataSize)
Alter field data size within record.
int GetFixedWidth()
Get the width of this field.
Definition: ossimIso8211.h:223
const char * GetData()
Return the pointer to the entire data block for this record.
Definition: ossimIso8211.h:509
ossimDDFModule * poModule
Definition: ossimIso8211.h:458
DDF_data_type_code
Definition: ossimIso8211.h:164
DDF_data_type_code _data_type_code
Definition: ossimIso8211.h:258
void Rewind(long nOffset=-1)
Return to first record.
const char * GetInstanceData(int nInstance, int *pnSize)
Get field instance data and size.
int SetIntSubfield(const char *pszField, int iFieldIndex, const char *pszSubfield, int iSubfieldIndex, int nValue)
Set an integer subfield in record.
int GetSubfieldCount()
Get the number of subfields.
Definition: ossimIso8211.h:211
void AddField(ossimDDFFieldDefn *poNewFDefn)
Add new field definition.
int GetFieldCount()
Get the number of DDFFields on this record.
Definition: ossimIso8211.h:397
void Dump(FILE *fp)
Write out field contents to debugging file.
int GetIntSubfield(const char *, int, const char *, int, int *=NULL)
Fetch value of a subfield as an integer.
ossimDDFFieldDefn * GetField(int)
Fetch a field definition by index.
DDF_data_struct_code _data_struct_code
Definition: ossimIso8211.h:256
ossimDDFFieldDefn * GetFieldDefn()
Fetch the corresponding DDFFieldDefn.
Definition: ossimIso8211.h:517
int ExtractIntData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a subfield value as an integer.
void Close()
Close an ISO 8211 file.
int Open(const char *pszFilename, int bFailQuietly=false)
Open a ISO 8211 (DDF) file for reading.
char _extendedCharSet[4]
Definition: ossimIso8211.h:139
The primary class for reading ISO 8211 files.
Definition: ossimIso8211.h:88
int GetDataLength(const char *, int, int *)
Scan for the end of variable length data.
DDFBinaryFormat eBinaryFormat
Definition: ossimIso8211.h:353
char _inlineCodeExtensionIndicator
Definition: ossimIso8211.h:135
ossimDDFRecord * ReadRecord(void)
Read one record from the file.
long ossimDDFScanInt(const char *pszString, int nMaxChars)
ossimDDFRecord * CloneOn(ossimDDFModule *)
Recreate a record referencing another module.
Contains instance data from one data record (DR).
Definition: ossimIso8211.h:385
DDFBinaryFormat
Binary format: this is the digit immediately following the B or b for binary formats.
Definition: ossimIso8211.h:335
int Create(const char *pszTag, const char *pszFieldName, const char *pszDescription, DDF_data_struct_code eDataStructCode, DDF_data_type_code eDataTypeCode, const char *pszFormat=NULL)
int GetWidth()
Get the subfield width (zero for variable).
Definition: ossimIso8211.h:324
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)
const char * GetFormat()
Get pointer to subfield format string.
Definition: ossimIso8211.h:291
void DumpData(const char *pachData, int nMaxBytes, FILE *fp)
Dump subfield value to debugging file.
DDF_data_struct_code
Definition: ossimIso8211.h:163
int SetFormat(const char *pszFormat)
char _interchangeLevel
Definition: ossimIso8211.h:134
DDFBinaryFormat GetBinaryFormat(void) const
Definition: ossimIso8211.h:344
void AddCloneRecord(ossimDDFRecord *)
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
const char * GetDescription()
Fetch a longer descriptio of this field.
Definition: ossimIso8211.h:208
const char * GetData()
Fetch the raw data for this record.
Definition: ossimIso8211.h:427
DDFDataType GetType()
Get the general type of the subfield.
Definition: ossimIso8211.h:302
void SetRepeatingFlag(int n)
this is just for an S-57 hack for swedish data
Definition: ossimIso8211.h:235
ossimDDFModule * GetModule()
Fetch the DDFModule with which this record is associated.
Definition: ossimIso8211.h:433
DDFDataType
General data type.
Definition: ossimIso8211.h:42
FILE * GetFP()
Definition: ossimIso8211.h:127