OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAuxFileHandler.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: SPADAC Inc
9 // Adaptd from the GDAL package hfadataset.cpp
10 // Description: This class provides some simple utilities for aux file.
11 //
12 //********************************************************************
13 // $Id: ossimAuxFileHandler.cpp 2644 2011-05-26 15:20:11Z oscar.kramer $
14 
15 #include <cstdio>
16 #include <cstdlib>
17 #include <iostream>
18 
20 
23 using namespace std;
24 
25 void ossimAuxStandardFile( int nBytes, void * pData )
26 
27 {
28  int i;
29  char *entryData = (char *) pData;
30 
31  for( i = nBytes/2-1; i >= 0; i-- )
32  {
33  ossim_uint8 byTemp;
34 
35  byTemp = entryData[i];
36  entryData[i] = entryData[nBytes-i-1];
37  entryData[nBytes-i-1] = byTemp;
38  }
39 }
40 
41 int ossimAuxGetDataTypeBits( int nDataType )
42 
43 {
44  switch( nDataType )
45  {
46  case EPT_u1:
47  return 1;
48 
49  case EPT_u2:
50  return 2;
51 
52  case EPT_u4:
53  return 4;
54 
55  case EPT_u8:
56  case EPT_s8:
57  return 8;
58 
59  case EPT_u16:
60  case EPT_s16:
61  return 16;
62 
63  case EPT_u32:
64  case EPT_s32:
65  case EPT_f32:
66  return 32;
67 
68  case EPT_f64:
69  case EPT_c64:
70  return 64;
71 
72  case EPT_c128:
73  return 128;
74  }
75 
76  return 0;
77 }
78 
79 static char * ossimAuxGetDictionary(ossimAuxInfo* hHFA)
80 
81 {
82  int nDictMax = 100;
83  char *pszDictionary = (char *)malloc(nDictMax);
84  int nDictSize = 0;
85 
86  fseek(hHFA->fp, hHFA->nDictionaryPos, SEEK_SET );
87 
88  while( true )
89  {
90  if( nDictSize >= nDictMax-1 )
91  {
92  nDictMax = nDictSize * 2 + 100;
93  pszDictionary = (char *) realloc(pszDictionary, nDictMax );
94  }
95 
96  if( fread( pszDictionary + nDictSize, 1, 1, hHFA->fp ) < 1
97  || pszDictionary[nDictSize] == '\0'
98  || (nDictSize > 2 && pszDictionary[nDictSize-2] == ','
99  && pszDictionary[nDictSize-1] == '.') )
100  break;
101 
102  nDictSize++;
103  }
104 
105  pszDictionary[nDictSize] = '\0';
106 
107  return( pszDictionary );
108 }
109 
111 {
112  m_auxInfo = NULL;
113 }
114 
116 {
117  if (m_auxInfo != NULL)
118  {
119  delete m_auxInfo;
120  m_auxInfo = 0;
121  }
122 }
123 
125 {
126  bool result = false;
127 
128  if ( file.exists() )
129  {
130  ossimString ext = file.ext();
131  ext.downcase();
132  if (ext == "aux")
133  {
134  result = true;
135  }
136  else
137  {
138  result = false;
139  }
140  }
141 
142  return result;
143 }
144 
146 {
147  FILE *fp = fopen(file.c_str(), "r");
148  char header[16];
149  ossim_uint32 nHeaderPos;
150 
151  if( fp == NULL )
152  {
153  return false;
154  }
155 
156  fread( header, 16, 1, fp);
157 
158  char* tmpHeader = const_cast<char*>(header);
159  if(strcmp(tmpHeader,"EHFA_HEADER_TAG") != 0)
160  {
161  fclose( fp );
162  return false;
163  }
164 
165  //Create the ossimAuxInfo
166  m_auxInfo = new ossimAuxInfo();
167  m_auxInfo->fp = fp;
168 
169  //Where is the header?
170  fread( &nHeaderPos, sizeof(ossim_int32), 1, fp );
171 
172  fseek( fp, nHeaderPos, SEEK_SET );
173 
174  fread( &(m_auxInfo->nVersion), sizeof(ossim_int32), 1, fp );
175 
176  fread( header, 4, 1, fp ); /* skip freeList */
177 
178  fread( &(m_auxInfo->nRootPos), sizeof(ossim_int32), 1, fp );
179 
180  fread( &(m_auxInfo->nEntryHeaderLength), sizeof(ossim_int16), 1, fp );
181  fread( &(m_auxInfo->nDictionaryPos), sizeof(ossim_int32), 1, fp );
182 
183  fseek( fp, 0, SEEK_END );
184  m_auxInfo->nEndOfFile = (ossim_int32) ftell(fp);
185 
186  m_auxInfo->m_Root = new ossimAuxEntry( m_auxInfo, m_auxInfo->nRootPos, NULL, NULL );
187 
188  m_auxInfo->dictionaryData = ossimAuxGetDictionary(m_auxInfo);
189  m_auxInfo->m_Dictionary = new ossimAuxDictionary( m_auxInfo->dictionaryData );
190 
191  ossimAuxEntry *node = m_auxInfo->m_Root->getChild();
192  while( node != NULL )
193  {
194  std::string typeStr = node->getType();
195  size_t typeLen = typeStr.length();
196  std::string str = "Eimg_Layer";
197  size_t strLen = str.length();
198  if( typeLen == strLen)
199  {
200  ossimAuxEntry* projEntry = node->getNamedChild("Map_Info");
201  if( projEntry == NULL )
202  {
203  ossimAuxEntry* childEntry;
204  for( childEntry = node->getChild(); childEntry != NULL && projEntry == NULL; childEntry = childEntry->getNext() )
205  {
206  if (ossimString(childEntry->getType()) == "Eprj_MapInfo")
207  projEntry = childEntry;
208  }
209  }
210 
211  const char* proj = NULL;
212  const char* units = NULL;
213  if (projEntry)
214  {
215  proj = projEntry->getStringField("proName");
216  units = projEntry->getStringField("units");
217  }
218 
219  if (proj != NULL)
220  {
221  m_projName = ossimString(proj);
222  }
223  if (units != NULL)
224  {
225  m_unitsType = ossimString(proj);
226  }
227 
228  ossimAuxEntry* datumEntry = node->getNamedChild( "Projection.Datum" );
229  const char* datumStr = NULL;
230  if (datumEntry)
231  {
232  datumStr = datumEntry->getStringField("datumname");
233  }
234  if (datumStr != NULL)
235  {
236  m_datumName = ossimString(datumStr);;
237  }
238  break;
239  }
240  node = node->getNext();
241  }
242 
243  fclose(fp);
244  return true;
245 }
246 
247 /************************************************************************/
248 /* ossimAuxInfo() */
249 /************************************************************************/
251 {
252  fp = NULL;
253  m_Root = NULL;
254  m_Dictionary = NULL;
255  dictionaryData = NULL;
256 }
257 
259 {
260  if (m_Root != NULL)
261  {
262  delete m_Root;
263  m_Root = 0;
264  }
265 
266  if (m_Dictionary != NULL)
267  {
268  delete m_Dictionary;
269  m_Dictionary = 0;
270  }
271 
272  if (dictionaryData != NULL)
273  {
274  delete[] dictionaryData;
275  dictionaryData = 0;
276  }
277 }
278 
279 /************************************************************************/
280 /* ossimAuxEntry() */
281 /************************************************************************/
282 
284  ossimAuxEntry * parentIn, ossimAuxEntry * prevIn)
285 
286 {
287  m_auxInfo = auxInfoIn;
288 
289  nFilePos = nPos;
290 
291  m_Parent = parentIn;
292  m_Prev = prevIn;
293 
294  m_Next = NULL;
295  m_Child = NULL;
296  entryData = NULL;
297 
298  nDataPos = nDataSize = 0;
299  nNextPos = nChildPos = 0;
300 
301  entryNodeName[0] = entryType[0] = '\0';
302 
303  ossim_int32 anEntryNums[6];
304 
305  if( fseek( m_auxInfo->fp, nFilePos, SEEK_SET ) == -1
306  || fread( anEntryNums, sizeof(ossim_uint32), 6, m_auxInfo->fp ) < 1 )
307  {
308  return;
309  }
310 
311  nNextPos = anEntryNums[0];
312  nChildPos = anEntryNums[3];
313  nDataPos = anEntryNums[4];
314  nDataSize = anEntryNums[5];
315 
316  if( fread( entryNodeName, 1, 64, m_auxInfo->fp ) < 1
317  || fread( entryType, 1, 32, m_auxInfo->fp ) < 1 )
318  {
319  return;
320  }
321 }
323 {
324  if( entryData != NULL )
325  {
326  delete entryData;
327  entryData = 0;
328  }
329 
330  if( m_Next != NULL )
331  {
332  delete m_Next;
333  m_Next = 0;
334  }
335 
336  if( m_Child != NULL )
337  {
338  delete m_Child;
339  m_Child = 0;
340  }
341 }
342 
343 void ossimAuxEntry::setName( const char *nodeName )
344 {
345  memset( entryNodeName, '\0', 64 );
346  strncpy( entryNodeName, nodeName, 64 );
347 }
348 
350 {
351  if( m_Child == NULL && nChildPos != 0 )
352  {
353  m_Child = new ossimAuxEntry( m_auxInfo, nChildPos, this, NULL );
354  }
355 
356  return( m_Child );
357 }
358 
360 {
361  if( m_Next == NULL && nNextPos != 0 )
362  {
363  // Check if we have a loop on the next node in this sibling chain.
364  ossimAuxEntry *past;
365 
366  for( past = this;
367  past != NULL && past->nFilePos != nNextPos;
368  past = past->m_Prev ) {}
369 
370  if( past != NULL )
371  {
372  nNextPos = 0;
373  return NULL;
374  }
375 
376  m_Next = new ossimAuxEntry(m_auxInfo, nNextPos, m_Parent, this );
377  }
378 
379  return( m_Next );
380 }
381 
383 {
384  if( entryData != NULL || nDataSize == 0 )
385  {
386  return;
387  }
388 
389  entryData = (char*) malloc(nDataSize);
390  if (entryData == NULL)
391  {
392  return;
393  }
394 
395  if(fseek(m_auxInfo->fp, nDataPos, SEEK_SET ) < 0 )
396  {
397  return;
398  }
399 
400  if( fread( entryData, 1, nDataSize, m_auxInfo->fp ) < 1 )
401  {
402  return;
403  }
404 
405  m_Type = m_auxInfo->m_Dictionary->findType( entryType );
406  if(m_Type == NULL)
407  {
408  return;
409  }
410 }
411 
413 {
414  int nNameLen;
415  ossimAuxEntry *entry;
416 
417  for( nNameLen = 0;
418  name[nNameLen] != '.'
419  && name[nNameLen] != '\0'
420  && name[nNameLen] != ':';
421  nNameLen++ ) {}
422 
423 
424  for( entry = getChild(); entry != NULL; entry = entry->getNext() )
425  {
426  std::string tmpEntryName = const_cast<char*>(entry->getName());
427  tmpEntryName = tmpEntryName.substr(0, nNameLen);
428  std::string tmpName = const_cast<char*>(name);
429  tmpName = tmpName.substr(0, nNameLen);
430  if( strcmp(tmpEntryName.c_str(),tmpName.c_str()) == 0
431  && (int) strlen(entry->getName()) == nNameLen )
432  {
433  if( name[nNameLen] == '.' )
434  {
435  ossimAuxEntry *result;
436 
437  result = entry->getNamedChild( name+nNameLen+1 );
438  if( result != NULL )
439  return result;
440  }
441  else
442  return entry;
443  }
444  }
445 
446  return NULL;
447 }
448 
449 int ossimAuxEntry::getFieldValue( const char * auxFieldPath,
450  char chReqType, void *reqReturn )
451 {
452  ossimAuxEntry *entry = this;
453 
454  if( strchr(auxFieldPath,':') != NULL )
455  {
456  entry = getNamedChild( auxFieldPath );
457  if( entry == NULL )
458  return false;
459 
460  auxFieldPath = strchr(auxFieldPath,':') + 1;
461  }
462 
463  loadData();
464 
465  if( entryData == NULL )
466  {
467  return false;
468  }
469 
470  if( m_Type == NULL )
471  {
472  return false;
473  }
474 
475  return (m_Type->extractInstValue( auxFieldPath,
476  entryData, nDataPos, nDataSize,
477  chReqType, reqReturn ));
478 }
479 
480 ossim_int16 ossimAuxEntry::getIntField(const char* auxFieldPath)
481 {
482  ossim_int16 nIntValue;
483 
484  if( !getFieldValue( auxFieldPath, 'i', &nIntValue ) )
485  {
486  return 0;
487  }
488  else
489  {
490  return nIntValue;
491  }
492 }
493 
494 const char* ossimAuxEntry::getStringField( const char* auxFieldPath)
495 {
496  char *result = NULL;
497 
498  if( !getFieldValue( auxFieldPath, 's', &result ) )
499  {
500  return NULL;
501  }
502  else
503  {
504  return result;
505  }
506 }
507 
508 /************************************************************************/
509 /* ossimAuxField() */
510 /************************************************************************/
511 
513 {
514  nBytes = 0;
515 
516  nItemCount = 0;
517  chPointer = '\0';
518  chItemType = '\0';
519 
520  itemObjectType = NULL;
521  m_auxItemObjectType = NULL;
522 
523  enumNames = NULL;
524  fieldName = NULL;
525 }
526 
528 {
529  if (itemObjectType != NULL)
530  {
531  delete[] itemObjectType;
532  itemObjectType = 0;
533  }
534 
535  if (enumNames != NULL)
536  {
537  delete[] enumNames;
538  enumNames = 0;
539  }
540 
541  if (fieldName != NULL)
542  {
543  delete[] fieldName;
544  fieldName = 0;
545  }
546 }
547 
548 int ossimAuxField::extractInstValue( const char* /* auxField */, int nIndexValue,
549  char* entryData, ossim_uint32 nDataOffset, int nDataSize,
550  char chReqType, void *reqReturn )
551 
552 {
553  int nInstItemCount = getInstCount( entryData, nDataSize );
554 
555  if( nIndexValue < 0 || nIndexValue >= nInstItemCount )
556  {
557  if( chItemType == 'b' && nIndexValue >= -3 && nIndexValue < 0 )
558  /* ok - special index values */;
559  else
560  return false;
561  }
562 
563  if( chPointer != '\0' )
564  {
565  ossim_uint32 nOffset;
566 
567  memcpy( &nOffset, entryData+4, 4 );
568 
569  entryData += 8;
570 
571  nDataOffset += 8;
572  nDataSize -= 8;
573  }
574 
575  if( (chItemType == 'c' || chItemType == 'C') && chReqType == 's' )
576  {
577  *((char **)reqReturn) = entryData;
578  return( entryData != NULL );
579  }
580 
581  return false;
582 }
583 
584 int ossimAuxField::getInstCount( char * entryData, int nDataSize )
585 {
586  if( chPointer == '\0' )
587  return nItemCount;
588  else if( chItemType == 'b' )
589  {
590  ossim_int32 nRows, nColumns;
591 
592  if( nDataSize < 20 )
593  return 0;
594 
595  memcpy( &nRows, entryData+8, 4 );
596  ossimAuxStandardFile( 4, &nRows );
597  memcpy( &nColumns, entryData+12, 4 );
598  ossimAuxStandardFile( 4, &nColumns );
599 
600  return nRows * nColumns;
601  }
602  else
603  {
604  ossim_int32 nCount;
605 
606  if( nDataSize < 4 )
607  return 0;
608 
609  memcpy( &nCount, entryData, 4 );
610  ossimAuxStandardFile( 4, &nCount );
611  return nCount;
612  }
613 }
614 
616 
617 {
618  if( itemObjectType != NULL )
619  {
620  m_auxItemObjectType = auxDict->findType( itemObjectType );
621  }
622 
623  if( chPointer == 'p' )
624  {
625  nBytes = -1; /* we can't know the instance size */
626  }
627  else if( m_auxItemObjectType != NULL )
628  {
629  m_auxItemObjectType->completeDefn( auxDict );
630  if( m_auxItemObjectType->nBytes == -1 )
631  {
632  nBytes = -1;
633  }
634  else
635  {
636  nBytes = m_auxItemObjectType->nBytes * nItemCount;
637  }
638 
639  if( chPointer == '*' && nBytes != -1 )
640  {
641  nBytes += 8; /* count, and offset */
642  }
643  }
644  else
645  {
646  nBytes = auxDict->getItemSize( chItemType ) * nItemCount;
647  }
648 }
649 
650 const char *ossimAuxField::initialize( const char * fieldInput )
651 {
652  int i;
653  nItemCount = atoi(fieldInput);
654 
655  while( *fieldInput != '\0' && *fieldInput != ':' )
656  {
657  fieldInput++;
658  }
659 
660  if( *fieldInput == '\0' )
661  {
662  return NULL;
663  }
664 
665  fieldInput++;
666 
667  if( *fieldInput == 'p' || *fieldInput == '*' )
668  chPointer = *(fieldInput++);
669 
670  if( *fieldInput == '\0' )
671  return NULL;
672 
673  chItemType = *(fieldInput++);
674 
675  if( chItemType == 'o' )
676  {
677  for( i = 0; fieldInput[i] != '\0' && fieldInput[i] != ','; i++ ) {}
678 
679  itemObjectType = (char *) malloc(i+1);
680  strncpy( itemObjectType, fieldInput, i );
681  itemObjectType[i] = '\0';
682 
683  fieldInput += i+1;
684  }
685 
686  if( chItemType == 'x' && *fieldInput == '{' )
687  {
688  int nBraceDepth = 1;
689  fieldInput++;
690 
691  // Skip past the definition.
692  while( nBraceDepth > 0 && *fieldInput != '\0' )
693  {
694  if( *fieldInput == '{' )
695  nBraceDepth++;
696  else if( *fieldInput == '}' )
697  nBraceDepth--;
698 
699  fieldInput++;
700  }
701 
702  chItemType = 'o';
703 
704  // find the comma terminating the type name.
705  for( i = 0; fieldInput[i] != '\0' && fieldInput[i] != ','; i++ ) {}
706 
707  itemObjectType = (char *) malloc(i+1);
708  strncpy( itemObjectType, fieldInput, i );
709  itemObjectType[i] = '\0';
710 
711  fieldInput += i+1;
712  }
713 
714  if( chItemType == 'e' )
715  {
716  int nEnumCount = atoi(fieldInput);
717  int iEnum;
718 
719  fieldInput = strchr(fieldInput,':');
720  if( fieldInput == NULL )
721  return NULL;
722 
723  fieldInput++;
724 
725  enumNames = (char **) calloc(sizeof(char *), nEnumCount+1);
726 
727  for( iEnum = 0; iEnum < nEnumCount; iEnum++ )
728  {
729  char *pszToken;
730 
731  for( i = 0; fieldInput[i] != '\0' && fieldInput[i] != ','; i++ ) {}
732 
733  if( fieldInput[i] != ',' )
734  return NULL;
735 
736  pszToken = (char *) malloc(i+1);
737  strncpy( pszToken, fieldInput, i );
738  pszToken[i] = '\0';
739 
740  enumNames[iEnum] = pszToken;
741 
742  fieldInput += i+1;
743  }
744  }
745 
746  for( i = 0; fieldInput[i] != '\0' && fieldInput[i] != ','; i++ ) {}
747 
748  fieldName = (char *) malloc(i+1);
749  strncpy( fieldName, fieldInput, i );
750  fieldName[i] = '\0';
751 
752  fieldInput += i+1;
753 
754  return( fieldInput );
755 }
756 
757 int ossimAuxField::getInstBytes( char *entryData, int nDataSize )
758 
759 {
760  int nCount;
761  int nInstBytes = 0;
762 
763  if( nBytes > -1 )
764  return nBytes;
765 
766  if( chPointer != '\0' )
767  {
768  memcpy( &nCount, entryData, 4 );
769  ossimAuxStandardFile( 4, &nCount );
770 
771  entryData += 8;
772  nInstBytes += 8;
773  }
774  else
775  nCount = 1;
776 
777  if( chItemType == 'b' && nCount != 0 ) // BASEDATA
778  {
779  ossim_int32 nRows, nColumns;
780  ossim_int16 nBaseItemType;
781 
782  memcpy( &nRows, entryData, 4 );
783  ossimAuxStandardFile( 4, &nRows );
784  memcpy( &nColumns, entryData+4, 4 );
785  ossimAuxStandardFile( 4, &nColumns );
786  memcpy( &nBaseItemType, entryData+8, 2 );
787  ossimAuxStandardFile( 2, &nBaseItemType );
788 
789  nInstBytes += 12;
790 
791  nInstBytes +=
792  ((ossimAuxGetDataTypeBits(nBaseItemType) + 7) / 8) * nRows * nColumns;
793  }
794  else if( m_auxItemObjectType == NULL )
795  {
796  nInstBytes += nCount * ossimAuxDictionary::getItemSize(chItemType);
797  }
798  else
799  {
800  int i;
801 
802  for( i = 0; i < nCount; i++ )
803  {
804  int nThisBytes;
805 
806  nThisBytes =
807  m_auxItemObjectType->getInstBytes( entryData,
808  nDataSize - nInstBytes );
809  nInstBytes += nThisBytes;
810  entryData += nThisBytes;
811  }
812  }
813 
814  return( nInstBytes );
815 }
816 
817 /************************************************************************/
818 /* ossimAuxType() */
819 /************************************************************************/
821 {
822  nBytes = 0;
823  nFields = 0;
824  m_auxFields = NULL;
825  auxTypeName = NULL;
826 }
827 
829 {
830  for(int i = 0; i < nFields; i++ )
831  {
832  delete m_auxFields[i];
833  m_auxFields[i] = 0;
834  }
835 
836  if (auxTypeName != NULL)
837  {
838  delete[] auxTypeName;
839  auxTypeName = 0;
840  }
841 }
842 
843 const char* ossimAuxType::initialize( const char * typeInput )
844 {
845  int i;
846  if( *typeInput != '{' )
847  {
848  while( *typeInput != '{' && *typeInput != '\0' )
849  typeInput++;
850 
851  if( *typeInput == '\0' )
852  return NULL;
853  }
854 
855  typeInput++;
856 
857  while( typeInput != NULL && *typeInput != '}' )
858  {
859  ossimAuxField *newField = new ossimAuxField();
860 
861  typeInput = newField->initialize( typeInput );
862  if( typeInput != NULL )
863  {
864  m_auxFields = (ossimAuxField **)realloc(m_auxFields, sizeof(void*) * (nFields+1) );
865  m_auxFields[nFields++] = newField;
866  }
867  else
868  {
869  delete newField;
870  }
871  }
872 
873  if( typeInput == NULL )
874  {
875  return NULL;
876  }
877 
878  typeInput++; /* skip `}' */
879 
880  for( i = 0; typeInput[i] != '\0' && typeInput[i] != ','; i++ ) {}
881 
882  auxTypeName = (char *) malloc(i+1);
883  strncpy( auxTypeName, typeInput, i );
884  auxTypeName[i] = '\0';
885 
886  typeInput += i+1;
887 
888  return( typeInput );
889 }
890 
892 {
893  int i;
894 
895  if( nBytes != 0 )
896  return;
897 
898  for( i = 0; i < nFields; i++ )
899  {
900  m_auxFields[i]->completeDefn( auxDict );
901  if( m_auxFields[i]->nBytes < 0 || nBytes == -1 )
902  {
903  nBytes = -1;
904  }
905  else
906  {
907  nBytes += m_auxFields[i]->nBytes;
908  }
909  }
910 }
911 
912 int ossimAuxType::extractInstValue( const char * auxFieldPath,
913  char *entryData, ossim_uint32 nDataOffset, int nDataSize,
914  char chReqType, void *reqReturn )
915 
916 {
917  int nArrayIndex = 0, nNameLen, iField, nByteOffset;
918  const char *remainder;
919 
920  const char *firstArray = strchr(auxFieldPath,'[');
921  const char *firstDot = strchr(auxFieldPath,'.');
922 
923  if( firstArray != NULL
924  && (firstDot == NULL
925  || firstDot > firstArray) )
926  {
927  const char *theEnd = firstArray;
928 
929  nArrayIndex = atoi(theEnd+1);
930  nNameLen = theEnd - auxFieldPath;
931 
932  remainder = strchr(auxFieldPath,'.');
933  if( remainder != NULL )
934  {
935  remainder++;
936  }
937  }
938  else if( firstDot != NULL )
939  {
940  const char *theEnd = firstDot;
941 
942  nNameLen = theEnd - auxFieldPath;
943 
944  remainder = theEnd + 1;
945  }
946  else
947  {
948  nNameLen = (int)strlen(auxFieldPath);
949  remainder = NULL;
950  }
951 
952  //Find this field within this type, if possible.
953  nByteOffset = 0;
954  for( iField = 0; iField < nFields && nByteOffset < nDataSize; iField++ )
955  {
956  std::string tmpFieldPath = const_cast<char*>(auxFieldPath);
957  tmpFieldPath = tmpFieldPath.substr(0, nNameLen);
958  std::string tmpFieldName = const_cast<char*>(m_auxFields[iField]->fieldName);
959  tmpFieldName = tmpFieldName.substr(0, nNameLen);
960  if( strcmp(tmpFieldPath.c_str(),tmpFieldName.c_str()) == 0
961  && m_auxFields[iField]->fieldName[nNameLen] == '\0' )
962  {
963  break;
964  }
965 
966  nByteOffset +=
967  m_auxFields[iField]->getInstBytes( entryData + nByteOffset,
968  nDataSize - nByteOffset );
969  }
970 
971  if( iField == nFields || nByteOffset >= nDataSize )
972  {
973  return false;
974  }
975 
976  //Extract this field value, and return.
977  return( m_auxFields[iField]->
978  extractInstValue( remainder, nArrayIndex,
979  entryData + nByteOffset,
980  nDataOffset + nByteOffset,
981  nDataSize - nByteOffset,
982  chReqType, reqReturn ) );
983 }
984 
985 int ossimAuxType::getInstBytes( char* entryData, int nDataSize )
986 {
987  if( nBytes >= 0 )
988  {
989  return( nBytes );
990  }
991  else
992  {
993  int nTotal = 0;
994  int iField;
995 
996  for( iField = 0; iField < nFields && nTotal < nDataSize; iField++ )
997  {
998  ossimAuxField *poField = m_auxFields[iField];
999 
1000  int nInstBytes = poField->getInstBytes( entryData,
1001  nDataSize - nTotal );
1002 
1003  entryData += nInstBytes;
1004  nTotal += nInstBytes;
1005  }
1006 
1007  return( nTotal );
1008  }
1009 }
1010 
1011 /************************************************************************/
1012 /* ossimAuxDictionary() */
1013 /************************************************************************/
1014 static const char *defDefn[] = {
1015  "Eprj_MapInfo",
1016  "{0:pcproName,1:*oEprj_Coordinate,upperLeftCenter,1:*oEprj_Coordinate,lowerRightCenter,1:*oEprj_Size,pixelSize,0:pcunits,}Eprj_MapInfo",
1017  NULL,
1018  NULL };
1019 
1021 {
1022  int i;
1023  nTypes = 0;
1024  nTypesMax = 0;
1025  m_auxTypes = NULL;
1026 
1027  //Read all the types.
1028  while( auxDictStr != NULL && *auxDictStr != '.' )
1029  {
1030  ossimAuxType* newType = new ossimAuxType();
1031  auxDictStr = newType->initialize( auxDictStr );
1032 
1033  if( auxDictStr != NULL )
1034  {
1035  addType( newType );
1036  }
1037  else
1038  {
1039  delete newType;
1040  }
1041  }
1042 
1043  for( i = 0; defDefn[i] != NULL; i += 2 )
1044  {
1045  if( findType( defDefn[i] ) == NULL )
1046  {
1047  ossimAuxType *newType = new ossimAuxType();
1048 
1049  newType->initialize( defDefn[i+1] );
1050  addType( newType );
1051  }
1052  }
1053 
1054  //Complete the definitions.
1055  for( i = 0; i < nTypes; i++ )
1056  {
1057  m_auxTypes[i]->completeDefn( this );
1058  }
1059 }
1060 
1062 {
1063  for(int i = 0; i < nTypes; i++ )
1064  {
1065  delete m_auxTypes[i];
1066  m_auxTypes[i] = 0;
1067  }
1068 }
1069 
1071 
1072 {
1073  if( nTypes == nTypesMax )
1074  {
1075  nTypesMax = nTypes * 2 + 10;
1076  m_auxTypes = (ossimAuxType **) realloc( m_auxTypes,
1077  sizeof(void*) * nTypesMax );
1078  }
1079 
1080  m_auxTypes[nTypes++] = type;
1081 }
1082 
1084 
1085 {
1086  int i;
1087 
1088  for( i = 0; i < nTypes; i++ )
1089  {
1090  if( strcmp(name, m_auxTypes[i]->auxTypeName) == 0 )
1091  {
1092  return( m_auxTypes[i] );
1093  }
1094  }
1095 
1096  return NULL;
1097 }
1098 
1100 
1101 {
1102  switch( chType )
1103  {
1104  case '1':
1105  case '2':
1106  case '4':
1107  case 'c':
1108  case 'C':
1109  return 1;
1110 
1111  case 'e':
1112  case 's':
1113  case 'S':
1114  return 2;
1115 
1116  case 't':
1117  case 'l':
1118  case 'L':
1119  case 'f':
1120  return 4;
1121 
1122  case 'd':
1123  case 'm':
1124  return 8;
1125 
1126  case 'M':
1127  return 16;
1128 
1129  case 'b':
1130  return -1;
1131 
1132  case 'o':
1133  case 'x':
1134  return 0;
1135  }
1136 
1137  return 0;
1138 }
void completeDefn(ossimAuxDictionary *auxDict)
const char * getStringField(const char *auxFieldPath)
bool isAuxFile(const ossimFilename &file)
.aux file
int getInstCount(char *entryData, int nDataSize)
#define EPT_u1
void addType(ossimAuxType *type)
#define EPT_u2
#define EPT_s16
const char * initialize(const char *typeInput)
bool open(const ossimFilename &file)
the file for reading
void setName(const char *nodeName)
#define EPT_f32
ossim_int16 getIntField(const char *auxFieldPath)
ossimAuxType * findType(const char *name)
int getInstBytes(char *entryData, int nDataSize)
ossimAuxEntry * getNext()
ossimAuxEntry * getChild()
bool exists() const
const char * getType()
#define EPT_c128
#define EPT_u8
unsigned int ossim_uint32
ossimAuxDictionary(const char *auxDictStr)
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
#define EPT_u16
ossim_uint32 nFilePos
int extractInstValue(const char *auxField, int nIndexValue, char *entryData, ossim_uint32 nDataOffset, int nDataSize, char chReqType, void *reqReturn)
ossim_uint32 nDictionaryPos
#define EPT_c64
short ossim_int16
#define EPT_f64
void ossimAuxStandardFile(int nBytes, void *pData)
ossimAuxEntry * m_Prev
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
static int getItemSize(char chType)
int extractInstValue(const char *auxField, char *entryData, ossim_uint32 nDataOffset, int nDataSize, char chReqType, void *reqReturn)
int ossimAuxGetDataTypeBits(int nDataType)
const char * initialize(const char *fieldInput)
#define EPT_u4
ossimString ext() const
ossimAuxEntry(ossimAuxInfo *auxInfoIn, ossim_uint32 nPos, ossimAuxEntry *parentIn, ossimAuxEntry *prevIn)
int getFieldValue(const char *auxFieldPath, char chReqType, void *reqReturn)
void completeDefn(ossimAuxDictionary *auxDict)
const char * getName()
#define EPT_s32
#define EPT_s8
unsigned char ossim_uint8
ossimAuxEntry * getNamedChild(const char *name)
int getInstBytes(char *entryData, int nDataSize)
int ossim_int32
#define EPT_u32