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 int 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
00079 class CPL_ODLL DDFModule
00080 {
00081 public:
00082 DDFModule();
00083 ~DDFModule();
00084
00085 int Open( const char * pszFilename, int bFailQuietly = FALSE );
00086 int Create( const char *pszFilename );
00087 void Close();
00088
00089 int Initialize( char chInterchangeLevel = '3',
00090 char chLeaderIden = 'L',
00091 char chCodeExtensionIndicator = 'E',
00092 char chVersionNumber = '1',
00093 char chAppIndicator = ' ',
00094 const char *pszExtendedCharSet = " ! ",
00095 int nSizeFieldLength = 3,
00096 int nSizeFieldPos = 4,
00097 int nSizeFieldTag = 4 );
00098
00099 void Dump( FILE * fp );
00100
00101 DDFRecord *ReadRecord( void );
00102 void Rewind( long nOffset = -1 );
00103
00104 DDFFieldDefn *FindFieldDefn( const char * );
00105
00108 int GetFieldCount() { return nFieldDefnCount; }
00109 DDFFieldDefn *GetField(int);
00110 void AddField( DDFFieldDefn *poNewFDefn );
00111
00112
00113 int GetFieldControlLength() { return _fieldControlLength; }
00114 void AddCloneRecord( DDFRecord * );
00115 void RemoveCloneRecord( DDFRecord * );
00116
00117
00118 VSILFILE *GetFP() { return fpDDF; }
00119 int GetSizeFieldTag() const { return (int)_sizeFieldTag; }
00120
00121
00122 int GetSizeFieldPos() const { return _sizeFieldPos; }
00123 int GetSizeFieldLength() const { return _sizeFieldLength; }
00124 char GetInterchangeLevel() const { return _interchangeLevel; }
00125 char GetLeaderIden() const { return _leaderIden; }
00126 char GetCodeExtensionIndicator() const { return _inlineCodeExtensionIndicator; }
00127 char GetVersionNumber() const { return _versionNumber; }
00128 char GetAppIndicator() const { return _appIndicator; }
00129 const char* GetExtendedCharSet() const { return _extendedCharSet; }
00130 void SetFieldControlLength(int nVal) { _fieldControlLength = nVal; }
00131
00132
00133 private:
00134 VSILFILE *fpDDF;
00135 int bReadOnly;
00136 long nFirstRecordOffset;
00137
00138 char _interchangeLevel;
00139 char _inlineCodeExtensionIndicator;
00140 char _versionNumber;
00141 char _appIndicator;
00142 int _fieldControlLength;
00143 char _extendedCharSet[4];
00144
00145 int _recLength;
00146 char _leaderIden;
00147 int _fieldAreaStart;
00148 int _sizeFieldLength;
00149 int _sizeFieldPos;
00150 int _sizeFieldTag;
00151
00152
00153 int nFieldDefnCount;
00154 DDFFieldDefn **papoFieldDefns;
00155
00156 DDFRecord *poRecord;
00157
00158 int nCloneCount;
00159 int nMaxCloneCount;
00160 DDFRecord **papoClones;
00161 };
00162
00163
00164
00165
00166
00167 typedef enum { dsc_elementary, dsc_vector, dsc_array, dsc_concatenated } DDF_data_struct_code;
00168 typedef enum { dtc_char_string,
00169 dtc_implicit_point,
00170 dtc_explicit_point,
00171 dtc_explicit_point_scaled,
00172 dtc_char_bit_string,
00173 dtc_bit_string,
00174 dtc_mixed_data_type } DDF_data_type_code;
00175
00183 class CPL_ODLL DDFFieldDefn
00184 {
00185 public:
00186 DDFFieldDefn();
00187 ~DDFFieldDefn();
00188
00189 int Create( const char *pszTag, const char *pszFieldName,
00190 const char *pszDescription,
00191 DDF_data_struct_code eDataStructCode,
00192 DDF_data_type_code eDataTypeCode,
00193 const char *pszFormat = NULL );
00194 void AddSubfield( DDFSubfieldDefn *poNewSFDefn,
00195 int bDontAddToFormat = FALSE );
00196 void AddSubfield( const char *pszName, const char *pszFormat );
00197 int GenerateDDREntry( DDFModule * poModule, char **ppachData, int *pnLength );
00198
00199 int Initialize( DDFModule * poModule, const char *pszTag,
00200 int nSize, const char * pachRecord );
00201
00202 void Dump( FILE * fp );
00203
00207 const char *GetName() { return pszTag; }
00208
00212 const char *GetDescription() { return _fieldName; }
00213
00215 int GetSubfieldCount() { return nSubfieldCount; }
00216
00217 DDFSubfieldDefn *GetSubfield( int i );
00218 DDFSubfieldDefn *FindSubfieldDefn( const char * );
00219
00227 int GetFixedWidth() { return nFixedWidth; }
00228
00234 int IsRepeating() { return bRepeatingSubfields; }
00235
00236 static char *ExpandFormat( const char * );
00237
00239 void SetRepeatingFlag( int n ) { bRepeatingSubfields = n; }
00240
00241 char *GetDefaultValue( int *pnSize );
00242
00243 const char *GetArrayDescr() const { return _arrayDescr; }
00244 const char *GetFormatControls() const { return _formatControls; }
00245 DDF_data_struct_code GetDataStructCode() const { return _data_struct_code; }
00246 DDF_data_type_code GetDataTypeCode() const { return _data_type_code; }
00247
00248 void SetFormatControls(const char* pszVal);
00249
00250 private:
00251
00252 static char *ExtractSubstring( const char * );
00253
00254 DDFModule * poModule;
00255 char * pszTag;
00256
00257 char * _fieldName;
00258 char * _arrayDescr;
00259 char * _formatControls;
00260
00261 int bRepeatingSubfields;
00262 int nFixedWidth;
00263
00264 int BuildSubfields();
00265 int ApplyFormats();
00266
00267 DDF_data_struct_code _data_struct_code;
00268
00269 DDF_data_type_code _data_type_code;
00270
00271 int nSubfieldCount;
00272 DDFSubfieldDefn **papoSubfields;
00273 };
00274
00275
00276
00277
00278
00279
00280
00281
00289 class CPL_ODLL DDFSubfieldDefn
00290 {
00291 public:
00292
00293 DDFSubfieldDefn();
00294 ~DDFSubfieldDefn();
00295
00296 void SetName( const char * pszName );
00297
00299 const char *GetName() { return pszName; }
00300
00302 const char *GetFormat() { return pszFormatString; }
00303 int SetFormat( const char * pszFormat );
00304
00313 DDFDataType GetType() { return eType; }
00314
00315 double ExtractFloatData( const char *pachData, int nMaxBytes,
00316 int * pnConsumedBytes );
00317 int ExtractIntData( const char *pachData, int nMaxBytes,
00318 int * pnConsumedBytes );
00319 const char *ExtractStringData( const char *pachData, int nMaxBytes,
00320 int * pnConsumedBytes );
00321 int GetDataLength( const char *, int, int * );
00322 void DumpData( const char *pachData, int nMaxBytes, FILE * fp );
00323
00324 int FormatStringValue( char *pachData, int nBytesAvailable,
00325 int *pnBytesUsed, const char *pszValue,
00326 int nValueLength = -1 );
00327
00328 int FormatIntValue( char *pachData, int nBytesAvailable,
00329 int *pnBytesUsed, int nNewValue );
00330
00331 int FormatFloatValue( char *pachData, int nBytesAvailable,
00332 int *pnBytesUsed, double dfNewValue );
00333
00335 int GetWidth() { return nFormatWidth; }
00336
00337 int GetDefaultValue( char *pachData, int nBytesAvailable,
00338 int *pnBytesUsed );
00339
00340 void Dump( FILE * fp );
00341
00346 typedef enum {
00347 NotBinary=0,
00348 UInt=1,
00349 SInt=2,
00350 FPReal=3,
00351 FloatReal=4,
00352 FloatComplex=5
00353 } DDFBinaryFormat;
00354
00355 DDFBinaryFormat GetBinaryFormat(void) const { return eBinaryFormat; }
00356
00357
00358 private:
00359
00360 char *pszName;
00361 char *pszFormatString;
00362
00363 DDFDataType eType;
00364 DDFBinaryFormat eBinaryFormat;
00365
00366
00367
00368
00369
00370 int bIsVariable;
00371
00372 char chFormatDelimiter;
00373 int nFormatWidth;
00374
00375
00376
00377
00378
00379 int nMaxBufChars;
00380 char *pachBuffer;
00381 };
00382
00383
00384
00385
00386
00387
00388
00389
00390
00396 class CPL_ODLL DDFRecord
00397 {
00398 public:
00399 DDFRecord( DDFModule * );
00400 ~DDFRecord();
00401
00402 DDFRecord *Clone();
00403 DDFRecord *CloneOn( DDFModule * );
00404
00405 void Dump( FILE * );
00406
00408 int GetFieldCount() { return nFieldCount; }
00409
00410 DDFField *FindField( const char *, int = 0 );
00411 DDFField *GetField( int );
00412
00413 int GetIntSubfield( const char *, int, const char *, int,
00414 int * = NULL );
00415 double GetFloatSubfield( const char *, int, const char *, int,
00416 int * = NULL );
00417 const char *GetStringSubfield( const char *, int, const char *, int,
00418 int * = NULL );
00419
00420 int SetIntSubfield( const char *pszField, int iFieldIndex,
00421 const char *pszSubfield, int iSubfieldIndex,
00422 int nValue );
00423 int SetStringSubfield( const char *pszField, int iFieldIndex,
00424 const char *pszSubfield, int iSubfieldIndex,
00425 const char *pszValue, int nValueLength=-1 );
00426 int SetFloatSubfield( const char *pszField, int iFieldIndex,
00427 const char *pszSubfield, int iSubfieldIndex,
00428 double dfNewValue );
00429
00431 int GetDataSize() { return nDataSize; }
00432
00438 const char *GetData() { return pachData; }
00439
00444 DDFModule * GetModule() { return poModule; }
00445
00446 int ResizeField( DDFField *poField, int nNewDataSize );
00447 int DeleteField( DDFField *poField );
00448 DDFField* AddField( DDFFieldDefn * );
00449
00450 int CreateDefaultFieldInstance( DDFField *poField, int iIndexWithinField );
00451
00452 int SetFieldRaw( DDFField *poField, int iIndexWithinField,
00453 const char *pachRawData, int nRawDataSize );
00454 int UpdateFieldRaw( DDFField *poField, int iIndexWithinField,
00455 int nStartOffset, int nOldSize,
00456 const char *pachRawData, int nRawDataSize );
00457
00458 int Write();
00459
00460
00461 int GetReuseHeader() const { return nReuseHeader; }
00462 int GetSizeFieldTag() const { return _sizeFieldTag; }
00463 int GetSizeFieldPos() const { return _sizeFieldPos; }
00464 int GetSizeFieldLength() const { return _sizeFieldLength; }
00465
00466 void SetSizeFieldTag(int nVal) { _sizeFieldTag = nVal; }
00467 void SetSizeFieldPos(int nVal) { _sizeFieldPos = nVal; }
00468 void SetSizeFieldLength(int nVal) { _sizeFieldLength = nVal; }
00469
00470
00471 int Read();
00472 void Clear();
00473 int ResetDirectory();
00474 void RemoveIsCloneFlag() { bIsClone = FALSE; }
00475
00476 private:
00477
00478 int ReadHeader();
00479
00480 DDFModule *poModule;
00481
00482 int nReuseHeader;
00483
00484 int nFieldOffset;
00485
00486 int _sizeFieldTag;
00487 int _sizeFieldPos;
00488 int _sizeFieldLength;
00489
00490 int nDataSize;
00491 char *pachData;
00492
00493 int nFieldCount;
00494 DDFField *paoFields;
00495
00496 int bIsClone;
00497 };
00498
00499
00500
00501
00502
00503
00504
00514 class CPL_ODLL DDFField
00515 {
00516 public:
00517 void Initialize( DDFFieldDefn *, const char *pszData,
00518 int nSize );
00519
00520 void Dump( FILE * fp );
00521
00522 const char *GetSubfieldData( DDFSubfieldDefn *,
00523 int * = NULL, int = 0 );
00524
00525 const char *GetInstanceData( int nInstance, int *pnSize );
00526
00531 const char *GetData() { return pachData; }
00532
00534 int GetDataSize() { return nDataSize; }
00535
00536 int GetRepeatCount();
00537
00539 DDFFieldDefn *GetFieldDefn() { return poDefn; }
00540
00541 private:
00542 DDFFieldDefn *poDefn;
00543
00544 int nDataSize;
00545
00546 const char *pachData;
00547 };
00548
00549
00550 #endif