29 char *entryData = (
char *) pData;
31 for( i = nBytes/2-1; i >= 0; i-- )
35 byTemp = entryData[i];
36 entryData[i] = entryData[nBytes-i-1];
37 entryData[nBytes-i-1] = byTemp;
83 char *pszDictionary = (
char *)malloc(nDictMax);
90 if( nDictSize >= nDictMax-1 )
92 nDictMax = nDictSize * 2 + 100;
93 pszDictionary = (
char *) realloc(pszDictionary, nDictMax );
96 if( fread( pszDictionary + nDictSize, 1, 1, hHFA->
fp ) < 1
97 || pszDictionary[nDictSize] ==
'\0' 98 || (nDictSize > 2 && pszDictionary[nDictSize-2] ==
',' 99 && pszDictionary[nDictSize-1] ==
'.') )
105 pszDictionary[nDictSize] =
'\0';
107 return( pszDictionary );
117 if (m_auxInfo != NULL)
147 FILE *fp = fopen(file.
c_str(),
"r");
156 fread( header, 16, 1, fp);
158 char* tmpHeader =
const_cast<char*
>(header);
159 if(strcmp(tmpHeader,
"EHFA_HEADER_TAG") != 0)
172 fseek( fp, nHeaderPos, SEEK_SET );
174 fread( &(m_auxInfo->nVersion),
sizeof(
ossim_int32), 1, fp );
176 fread( header, 4, 1, fp );
178 fread( &(m_auxInfo->nRootPos),
sizeof(
ossim_int32), 1, fp );
180 fread( &(m_auxInfo->nEntryHeaderLength),
sizeof(
ossim_int16), 1, fp );
181 fread( &(m_auxInfo->nDictionaryPos),
sizeof(
ossim_int32), 1, fp );
183 fseek( fp, 0, SEEK_END );
186 m_auxInfo->m_Root =
new ossimAuxEntry( m_auxInfo, m_auxInfo->nRootPos, NULL, NULL );
188 m_auxInfo->dictionaryData = ossimAuxGetDictionary(m_auxInfo);
192 while( node != NULL )
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)
201 if( projEntry == NULL )
204 for( childEntry = node->
getChild(); childEntry != NULL && projEntry == NULL; childEntry = childEntry->
getNext() )
207 projEntry = childEntry;
211 const char* proj = NULL;
212 const char* units = NULL;
229 const char* datumStr = NULL;
234 if (datumStr != NULL)
255 dictionaryData = NULL;
266 if (m_Dictionary != NULL)
272 if (dictionaryData != NULL)
274 delete[] dictionaryData;
287 m_auxInfo = auxInfoIn;
298 nDataPos = nDataSize = 0;
299 nNextPos = nChildPos = 0;
301 entryNodeName[0] = entryType[0] =
'\0';
305 if( fseek( m_auxInfo->fp, nFilePos, SEEK_SET ) == -1
306 || fread( anEntryNums,
sizeof(
ossim_uint32), 6, m_auxInfo->fp ) < 1 )
311 nNextPos = anEntryNums[0];
312 nChildPos = anEntryNums[3];
313 nDataPos = anEntryNums[4];
314 nDataSize = anEntryNums[5];
316 if( fread( entryNodeName, 1, 64, m_auxInfo->fp ) < 1
317 || fread( entryType, 1, 32, m_auxInfo->fp ) < 1 )
324 if( entryData != NULL )
336 if( m_Child != NULL )
345 memset( entryNodeName,
'\0', 64 );
346 strncpy( entryNodeName, nodeName, 64 );
351 if( m_Child == NULL && nChildPos != 0 )
353 m_Child =
new ossimAuxEntry( m_auxInfo, nChildPos,
this, NULL );
361 if( m_Next == NULL && nNextPos != 0 )
367 past != NULL && past->
nFilePos != nNextPos;
376 m_Next =
new ossimAuxEntry(m_auxInfo, nNextPos, m_Parent,
this );
384 if( entryData != NULL || nDataSize == 0 )
389 entryData = (
char*) malloc(nDataSize);
390 if (entryData == NULL)
395 if(fseek(m_auxInfo->fp, nDataPos, SEEK_SET ) < 0 )
400 if( fread( entryData, 1, nDataSize, m_auxInfo->fp ) < 1 )
405 m_Type = m_auxInfo->m_Dictionary->findType( entryType );
418 name[nNameLen] !=
'.' 419 && name[nNameLen] !=
'\0' 420 && name[nNameLen] !=
':';
424 for( entry = getChild(); entry != NULL; entry = entry->
getNext() )
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 )
433 if( name[nNameLen] ==
'.' )
450 char chReqType,
void *reqReturn )
454 if( strchr(auxFieldPath,
':') != NULL )
456 entry = getNamedChild( auxFieldPath );
460 auxFieldPath = strchr(auxFieldPath,
':') + 1;
465 if( entryData == NULL )
475 return (m_Type->extractInstValue( auxFieldPath,
476 entryData, nDataPos, nDataSize,
477 chReqType, reqReturn ));
484 if( !getFieldValue( auxFieldPath,
'i', &nIntValue ) )
498 if( !getFieldValue( auxFieldPath,
's', &result ) )
520 itemObjectType = NULL;
521 m_auxItemObjectType = NULL;
529 if (itemObjectType != NULL)
531 delete[] itemObjectType;
535 if (enumNames != NULL)
541 if (fieldName != NULL)
549 char* entryData,
ossim_uint32 nDataOffset,
int nDataSize,
550 char chReqType,
void *reqReturn )
553 int nInstItemCount = getInstCount( entryData, nDataSize );
555 if( nIndexValue < 0 || nIndexValue >= nInstItemCount )
557 if( chItemType ==
'b' && nIndexValue >= -3 && nIndexValue < 0 )
563 if( chPointer !=
'\0' )
567 memcpy( &nOffset, entryData+4, 4 );
575 if( (chItemType ==
'c' || chItemType ==
'C') && chReqType ==
's' )
577 *((
char **)reqReturn) = entryData;
578 return( entryData != NULL );
586 if( chPointer ==
'\0' )
588 else if( chItemType ==
'b' )
595 memcpy( &nRows, entryData+8, 4 );
597 memcpy( &nColumns, entryData+12, 4 );
600 return nRows * nColumns;
609 memcpy( &nCount, entryData, 4 );
618 if( itemObjectType != NULL )
620 m_auxItemObjectType = auxDict->
findType( itemObjectType );
623 if( chPointer ==
'p' )
627 else if( m_auxItemObjectType != NULL )
630 if( m_auxItemObjectType->nBytes == -1 )
636 nBytes = m_auxItemObjectType->nBytes * nItemCount;
639 if( chPointer ==
'*' && nBytes != -1 )
646 nBytes = auxDict->
getItemSize( chItemType ) * nItemCount;
653 nItemCount = atoi(fieldInput);
655 while( *fieldInput !=
'\0' && *fieldInput !=
':' )
660 if( *fieldInput ==
'\0' )
667 if( *fieldInput ==
'p' || *fieldInput ==
'*' )
668 chPointer = *(fieldInput++);
670 if( *fieldInput ==
'\0' )
673 chItemType = *(fieldInput++);
675 if( chItemType ==
'o' )
677 for( i = 0; fieldInput[i] !=
'\0' && fieldInput[i] !=
','; i++ ) {}
679 itemObjectType = (
char *) malloc(i+1);
680 strncpy( itemObjectType, fieldInput, i );
681 itemObjectType[i] =
'\0';
686 if( chItemType ==
'x' && *fieldInput ==
'{' )
692 while( nBraceDepth > 0 && *fieldInput !=
'\0' )
694 if( *fieldInput ==
'{' )
696 else if( *fieldInput ==
'}' )
705 for( i = 0; fieldInput[i] !=
'\0' && fieldInput[i] !=
','; i++ ) {}
707 itemObjectType = (
char *) malloc(i+1);
708 strncpy( itemObjectType, fieldInput, i );
709 itemObjectType[i] =
'\0';
714 if( chItemType ==
'e' )
716 int nEnumCount = atoi(fieldInput);
719 fieldInput = strchr(fieldInput,
':');
720 if( fieldInput == NULL )
725 enumNames = (
char **) calloc(
sizeof(
char *), nEnumCount+1);
727 for( iEnum = 0; iEnum < nEnumCount; iEnum++ )
731 for( i = 0; fieldInput[i] !=
'\0' && fieldInput[i] !=
','; i++ ) {}
733 if( fieldInput[i] !=
',' )
736 pszToken = (
char *) malloc(i+1);
737 strncpy( pszToken, fieldInput, i );
740 enumNames[iEnum] = pszToken;
746 for( i = 0; fieldInput[i] !=
'\0' && fieldInput[i] !=
','; i++ ) {}
748 fieldName = (
char *) malloc(i+1);
749 strncpy( fieldName, fieldInput, i );
754 return( fieldInput );
766 if( chPointer !=
'\0' )
768 memcpy( &nCount, entryData, 4 );
777 if( chItemType ==
'b' && nCount != 0 )
782 memcpy( &nRows, entryData, 4 );
784 memcpy( &nColumns, entryData+4, 4 );
786 memcpy( &nBaseItemType, entryData+8, 2 );
794 else if( m_auxItemObjectType == NULL )
802 for( i = 0; i < nCount; i++ )
807 m_auxItemObjectType->getInstBytes( entryData,
808 nDataSize - nInstBytes );
809 nInstBytes += nThisBytes;
810 entryData += nThisBytes;
814 return( nInstBytes );
830 for(
int i = 0; i < nFields; i++ )
832 delete m_auxFields[i];
836 if (auxTypeName != NULL)
838 delete[] auxTypeName;
846 if( *typeInput !=
'{' )
848 while( *typeInput !=
'{' && *typeInput !=
'\0' )
851 if( *typeInput ==
'\0' )
857 while( typeInput != NULL && *typeInput !=
'}' )
861 typeInput = newField->
initialize( typeInput );
862 if( typeInput != NULL )
864 m_auxFields = (
ossimAuxField **)realloc(m_auxFields,
sizeof(
void*) * (nFields+1) );
865 m_auxFields[nFields++] = newField;
873 if( typeInput == NULL )
880 for( i = 0; typeInput[i] !=
'\0' && typeInput[i] !=
','; i++ ) {}
882 auxTypeName = (
char *) malloc(i+1);
883 strncpy( auxTypeName, typeInput, i );
884 auxTypeName[i] =
'\0';
898 for( i = 0; i < nFields; i++ )
900 m_auxFields[i]->completeDefn( auxDict );
901 if( m_auxFields[i]->nBytes < 0 || nBytes == -1 )
907 nBytes += m_auxFields[i]->nBytes;
913 char *entryData,
ossim_uint32 nDataOffset,
int nDataSize,
914 char chReqType,
void *reqReturn )
917 int nArrayIndex = 0, nNameLen, iField, nByteOffset;
918 const char *remainder;
920 const char *firstArray = strchr(auxFieldPath,
'[');
921 const char *firstDot = strchr(auxFieldPath,
'.');
923 if( firstArray != NULL
925 || firstDot > firstArray) )
927 const char *theEnd = firstArray;
929 nArrayIndex = atoi(theEnd+1);
930 nNameLen = theEnd - auxFieldPath;
932 remainder = strchr(auxFieldPath,
'.');
933 if( remainder != NULL )
938 else if( firstDot != NULL )
940 const char *theEnd = firstDot;
942 nNameLen = theEnd - auxFieldPath;
944 remainder = theEnd + 1;
948 nNameLen = (int)strlen(auxFieldPath);
954 for( iField = 0; iField < nFields && nByteOffset < nDataSize; iField++ )
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' )
967 m_auxFields[iField]->getInstBytes( entryData + nByteOffset,
968 nDataSize - nByteOffset );
971 if( iField == nFields || nByteOffset >= nDataSize )
977 return( m_auxFields[iField]->
978 extractInstValue( remainder, nArrayIndex,
979 entryData + nByteOffset,
980 nDataOffset + nByteOffset,
981 nDataSize - nByteOffset,
982 chReqType, reqReturn ) );
996 for( iField = 0; iField < nFields && nTotal < nDataSize; iField++ )
1001 nDataSize - nTotal );
1003 entryData += nInstBytes;
1004 nTotal += nInstBytes;
1014 static const char *defDefn[] = {
1016 "{0:pcproName,1:*oEprj_Coordinate,upperLeftCenter,1:*oEprj_Coordinate,lowerRightCenter,1:*oEprj_Size,pixelSize,0:pcunits,}Eprj_MapInfo",
1028 while( auxDictStr != NULL && *auxDictStr !=
'.' )
1031 auxDictStr = newType->
initialize( auxDictStr );
1033 if( auxDictStr != NULL )
1043 for( i = 0; defDefn[i] != NULL; i += 2 )
1045 if( findType( defDefn[i] ) == NULL )
1055 for( i = 0; i < nTypes; i++ )
1057 m_auxTypes[i]->completeDefn(
this );
1063 for(
int i = 0; i < nTypes; i++ )
1065 delete m_auxTypes[i];
1073 if( nTypes == nTypesMax )
1075 nTypesMax = nTypes * 2 + 10;
1077 sizeof(
void*) * nTypesMax );
1080 m_auxTypes[nTypes++] = type;
1088 for( i = 0; i < nTypes; i++ )
1090 if( strcmp(name, m_auxTypes[i]->auxTypeName) == 0 )
1092 return( m_auxTypes[i] );
void completeDefn(ossimAuxDictionary *auxDict)
const char * getStringField(const char *auxFieldPath)
bool isAuxFile(const ossimFilename &file)
.aux file
int getInstCount(char *entryData, int nDataSize)
void addType(ossimAuxType *type)
const char * initialize(const char *typeInput)
bool open(const ossimFilename &file)
the file for reading
void setName(const char *nodeName)
ossim_int16 getIntField(const char *auxFieldPath)
ossimAuxType * findType(const char *name)
int getInstBytes(char *entryData, int nDataSize)
ossimAuxEntry * getNext()
ossimAuxEntry * getChild()
unsigned int ossim_uint32
virtual ~ossimAuxFileHandler()
ossimAuxDictionary(const char *auxDictStr)
static ossimString downcase(const ossimString &aString)
int extractInstValue(const char *auxField, int nIndexValue, char *entryData, ossim_uint32 nDataOffset, int nDataSize, char chReqType, void *reqReturn)
ossim_uint32 nDictionaryPos
void ossimAuxStandardFile(int nBytes, void *pData)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
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)
ossimAuxEntry(ossimAuxInfo *auxInfoIn, ossim_uint32 nPos, ossimAuxEntry *parentIn, ossimAuxEntry *prevIn)
int getFieldValue(const char *auxFieldPath, char chReqType, void *reqReturn)
void completeDefn(ossimAuxDictionary *auxDict)
unsigned char ossim_uint8
ossimAuxEntry * getNamedChild(const char *name)
int getInstBytes(char *entryData, int nDataSize)