00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _ISO8211_H_INCLUDED
00031 #define _ISO8211_H_INCLUDED
00032
00033 #include "cpl_port.h"
00034 #include "cpl_vsi.h"
00035
00039 typedef enum {
00040 DDFInt,
00041 DDFFloat,
00042 DDFString,
00043 DDFBinaryString
00044 } DDFDataType;
00045
00046
00047
00048
00049
00050
00051 long CPL_ODLL DDFScanInt( const char *pszString, int nMaxChars );
00052 int CPL_ODLL DDFScanVariable( const char * pszString, int nMaxChars, int nDelimChar );
00053 char CPL_ODLL *DDFFetchVariable( const char *pszString, int nMaxChars,
00054 int nDelimChar1, int nDelimChar2,
00055 int *pnConsumedChars );
00056
00057 #define DDF_FIELD_TERMINATOR 30
00058 #define DDF_UNIT_TERMINATOR 31
00059
00060
00061
00062
00063
00064 class DDFFieldDefn;
00065 class DDFSubfieldDefn;
00066 class DDFRecord;
00067 class DDFField;
00068
00069
00070
00071
00072
00080 class CPL_ODLL DDFModule
00081 {
00082 public:
00083 DDFModule();
00084 ~DDFModule();
00085
00086 int Open( const char * pszFilename, int bFailQuietly = FALSE );
00087 int Create( const char *pszFilename );
00088 void Close();
00089
00090 int Initialize( char chInterchangeLevel = '3',
00091 char chLeaderIden = 'L',
00092 char chCodeExtensionIndicator = 'E',
00093 char chVersionNumber = '1',
00094 char chAppIndicator = ' ',
00095 const char *pszExtendedCharSet = " ! ",
00096 int nSizeFieldLength = 3,
00097 int nSizeFieldPos = 4,
00098 int nSizeFieldTag = 4 );
00099
00100 void Dump( FILE * fp );
00101
00102 DDFRecord *ReadRecord( void );
00103 void Rewind( long nOffset = -1 );
00104
00105 DDFFieldDefn *FindFieldDefn( const char * );
00106
00109 int GetFieldCount() { return nFieldDefnCount; }
00110 DDFFieldDefn *GetField(int);
00111 void AddField( DDFFieldDefn *poNewFDefn );
00112
00113
00114 int GetFieldControlLength() { return _fieldControlLength; }
00115 void AddCloneRecord( DDFRecord * );
00116 void RemoveCloneRecord( DDFRecord * );
00117
00118
00119 VSILFILE *GetFP() { return fpDDF; }
00120 int GetSizeFieldTag() const { return (int)_sizeFieldTag; }
00121
00122 private:
00123 VSILFILE *fpDDF;
00124 int bReadOnly;
00125 long nFirstRecordOffset;
00126
00127 char _interchangeLevel;
00128 char _inlineCodeExtensionIndicator;
00129 char _versionNumber;
00130 char _appIndicator;
00131 int _fieldControlLength;
00132 char _extendedCharSet[4];
00133
00134 long _recLength;
00135 char _leaderIden;
00136 long _fieldAreaStart;
00137 long _sizeFieldLength;
00138 long _sizeFieldPos;
00139 long _sizeFieldTag;
00140
00141
00142 int nFieldDefnCount;
00143 DDFFieldDefn **papoFieldDefns;
00144
00145 DDFRecord *poRecord;
00146
00147 int nCloneCount;
00148 int nMaxCloneCount;
00149 DDFRecord **papoClones;
00150 };
00151
00152
00153
00154
00155
00156 typedef enum { dsc_elementary, dsc_vector, dsc_array, dsc_concatenated } DDF_data_struct_code;
00157 typedef enum { dtc_char_string,
00158 dtc_implicit_point,
00159 dtc_explicit_point,
00160 dtc_explicit_point_scaled,
00161 dtc_char_bit_string,
00162 dtc_bit_string,
00163 dtc_mixed_data_type } DDF_data_type_code;
00164
00172 class CPL_ODLL DDFFieldDefn
00173 {
00174 public:
00175 DDFFieldDefn();
00176 ~DDFFieldDefn();
00177
00178 int Create( const char *pszTag, const char *pszFieldName,
00179 const char *pszDescription,
00180 DDF_data_struct_code eDataStructCode,
00181 DDF_data_type_code eDataTypeCode,
00182 const char *pszFormat = NULL );
00183 void AddSubfield( DDFSubfieldDefn *poNewSFDefn,
00184 int bDontAddToFormat = FALSE );
00185 void AddSubfield( const char *pszName, const char *pszFormat );
00186 int GenerateDDREntry( char **ppachData, int *pnLength );
00187
00188 int Initialize( DDFModule * poModule, const char *pszTag,
00189 int nSize, const char * pachRecord );
00190
00191 void Dump( FILE * fp );
00192
00196 const char *GetName() { return pszTag; }
00197
00201 const char *GetDescription() { return _fieldName; }
00202
00204 int GetSubfieldCount() { return nSubfieldCount; }
00205
00206 DDFSubfieldDefn *GetSubfield( int i );
00207 DDFSubfieldDefn *FindSubfieldDefn( const char * );
00208
00216 int GetFixedWidth() { return nFixedWidth; }
00217
00223 int IsRepeating() { return bRepeatingSubfields; }
00224
00225 static char *ExpandFormat( const char * );
00226
00228 void SetRepeatingFlag( int n ) { bRepeatingSubfields = n; }
00229
00230 char *GetDefaultValue( int *pnSize );
00231
00232 const char *GetArrayDescr() const { return _arrayDescr; }
00233 const char *GetFormatControls() const { return _formatControls; }
00234 DDF_data_struct_code GetDataStructCode() const { return _data_struct_code; }
00235 DDF_data_type_code GetDataTypeCode() const { return _data_type_code; }
00236
00237 private:
00238
00239 static char *ExtractSubstring( const char * );
00240
00241 DDFModule * poModule;
00242 char * pszTag;
00243
00244 char * _fieldName;
00245 char * _arrayDescr;
00246 char * _formatControls;
00247
00248 int bRepeatingSubfields;
00249 int nFixedWidth;
00250
00251 int BuildSubfields();
00252 int ApplyFormats();
00253
00254 DDF_data_struct_code _data_struct_code;
00255
00256 DDF_data_type_code _data_type_code;
00257
00258 int nSubfieldCount;
00259 DDFSubfieldDefn **papoSubfields;
00260 };
00261
00262
00263
00264
00265
00266
00267
00268
00276 class CPL_ODLL DDFSubfieldDefn
00277 {
00278 public:
00279
00280 DDFSubfieldDefn();
00281 ~DDFSubfieldDefn();
00282
00283 void SetName( const char * pszName );
00284
00286 const char *GetName() { return pszName; }
00287
00289 const char *GetFormat() { return pszFormatString; }
00290 int SetFormat( const char * pszFormat );
00291
00300 DDFDataType GetType() { return eType; }
00301
00302 double ExtractFloatData( const char *pachData, int nMaxBytes,
00303 int * pnConsumedBytes );
00304 int ExtractIntData( const char *pachData, int nMaxBytes,
00305 int * pnConsumedBytes );
00306 const char *ExtractStringData( const char *pachData, int nMaxBytes,
00307 int * pnConsumedBytes );
00308 int GetDataLength( const char *, int, int * );
00309 void DumpData( const char *pachData, int nMaxBytes, FILE * fp );
00310
00311 int FormatStringValue( char *pachData, int nBytesAvailable,
00312 int *pnBytesUsed, const char *pszValue,
00313 int nValueLength = -1 );
00314
00315 int FormatIntValue( char *pachData, int nBytesAvailable,
00316 int *pnBytesUsed, int nNewValue );
00317
00318 int FormatFloatValue( char *pachData, int nBytesAvailable,
00319 int *pnBytesUsed, double dfNewValue );
00320
00322 int GetWidth() { return nFormatWidth; }
00323
00324 int GetDefaultValue( char *pachData, int nBytesAvailable,
00325 int *pnBytesUsed );
00326
00327 void Dump( FILE * fp );
00328
00333 typedef enum {
00334 NotBinary=0,
00335 UInt=1,
00336 SInt=2,
00337 FPReal=3,
00338 FloatReal=4,
00339 FloatComplex=5
00340 } DDFBinaryFormat;
00341
00342 DDFBinaryFormat GetBinaryFormat(void) const { return eBinaryFormat; }
00343
00344
00345 private:
00346
00347 char *pszName;
00348 char *pszFormatString;
00349
00350 DDFDataType eType;
00351 DDFBinaryFormat eBinaryFormat;
00352
00353
00354
00355
00356
00357 int bIsVariable;
00358
00359 char chFormatDelimeter;
00360 int nFormatWidth;
00361
00362
00363
00364
00365
00366 int nMaxBufChars;
00367 char *pachBuffer;
00368 };
00369
00370
00371
00372
00373
00374
00375
00376
00377
00383 class CPL_ODLL DDFRecord
00384 {
00385 public:
00386 DDFRecord( DDFModule * );
00387 ~DDFRecord();
00388
00389 DDFRecord *Clone();
00390 DDFRecord *CloneOn( DDFModule * );
00391
00392 void Dump( FILE * );
00393
00395 int GetFieldCount() { return nFieldCount; }
00396
00397 DDFField *FindField( const char *, int = 0 );
00398 DDFField *GetField( int );
00399
00400 int GetIntSubfield( const char *, int, const char *, int,
00401 int * = NULL );
00402 double GetFloatSubfield( const char *, int, const char *, int,
00403 int * = NULL );
00404 const char *GetStringSubfield( const char *, int, const char *, int,
00405 int * = NULL );
00406
00407 int SetIntSubfield( const char *pszField, int iFieldIndex,
00408 const char *pszSubfield, int iSubfieldIndex,
00409 int nValue );
00410 int SetStringSubfield( const char *pszField, int iFieldIndex,
00411 const char *pszSubfield, int iSubfieldIndex,
00412 const char *pszValue, int nValueLength=-1 );
00413 int SetFloatSubfield( const char *pszField, int iFieldIndex,
00414 const char *pszSubfield, int iSubfieldIndex,
00415 double dfNewValue );
00416
00418 int GetDataSize() { return nDataSize; }
00419
00425 const char *GetData() { return pachData; }
00426
00431 DDFModule * GetModule() { return poModule; }
00432
00433 int ResizeField( DDFField *poField, int nNewDataSize );
00434 int DeleteField( DDFField *poField );
00435 DDFField* AddField( DDFFieldDefn * );
00436
00437 int CreateDefaultFieldInstance( DDFField *poField, int iIndexWithinField );
00438
00439 int SetFieldRaw( DDFField *poField, int iIndexWithinField,
00440 const char *pachRawData, int nRawDataSize );
00441 int UpdateFieldRaw( DDFField *poField, int iIndexWithinField,
00442 int nStartOffset, int nOldSize,
00443 const char *pachRawData, int nRawDataSize );
00444
00445 int Write();
00446
00447
00448 int Read();
00449 void Clear();
00450 int ResetDirectory();
00451
00452 private:
00453
00454 int ReadHeader();
00455
00456 DDFModule *poModule;
00457
00458 int nReuseHeader;
00459
00460 int nFieldOffset;
00461
00462 int _sizeFieldTag;
00463 int _sizeFieldPos;
00464 int _sizeFieldLength;
00465
00466 int nDataSize;
00467 char *pachData;
00468
00469 int nFieldCount;
00470 DDFField *paoFields;
00471
00472 int bIsClone;
00473 };
00474
00475
00476
00477
00478
00479
00480
00490 class CPL_ODLL DDFField
00491 {
00492 public:
00493 void Initialize( DDFFieldDefn *, const char *pszData,
00494 int nSize );
00495
00496 void Dump( FILE * fp );
00497
00498 const char *GetSubfieldData( DDFSubfieldDefn *,
00499 int * = NULL, int = 0 );
00500
00501 const char *GetInstanceData( int nInstance, int *pnSize );
00502
00507 const char *GetData() { return pachData; }
00508
00510 int GetDataSize() { return nDataSize; }
00511
00512 int GetRepeatCount();
00513
00515 DDFFieldDefn *GetFieldDefn() { return poDefn; }
00516
00517 private:
00518 DDFFieldDefn *poDefn;
00519
00520 int nDataSize;
00521
00522 const char *pachData;
00523 };
00524
00525
00526 #endif