From 7cbc22fae4179a7dc380fb5c0673d09eb280a159 Mon Sep 17 00:00:00 2001 From: dsandersoremutah Date: Thu, 20 Jul 2006 14:53:19 +0000 Subject: [PATCH] Enhancements and improvements to the field ID table inside of records. git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@685 0109f412-320b-0410-ab79-c3e0c5ffbbe6 --- flaim/src/flaim.h | 28 +++++++-- flaim/src/fqeval.cpp | 14 ++--- flaim/src/frec.cpp | 124 ++++++++++++++++++++++++++++++-------- flaim/util/basic_test.cpp | 9 +-- 4 files changed, 135 insertions(+), 40 deletions(-) diff --git a/flaim/src/flaim.h b/flaim/src/flaim.h index c46192b..a1e2727 100644 --- a/flaim/src/flaim.h +++ b/flaim/src/flaim.h @@ -4585,13 +4585,33 @@ /// Find a level one field ID in a record. void * findLevelOneField( - FLMUINT uiFieldID, ///< Field number of field to be found. - FLMBOOL bFindInclusive ///< OK to find next field after uiFieldID? + FLMUINT uiFieldID, ///< Field number of field to be found. + FLMBOOL bFindInclusive, ///< OK to find next field after uiFieldID? + FLMUINT * puiFieldPos ///< Field position in field ID table is returned here. ); - /// Find a level one field ID in a record. + /// Determine if the level one field at the specified position in the field ID table + /// matches the passed in field ID.\ If so, return that field pointer. + void * getLevelOneField( + FLMUINT uiFieldId, ///< Field id to be matched. + FLMUINT uiLevelOnePosition ///< Level one field position to be checked. + ); + + /// Get the next level one field after the position specified.\ Make sure + /// that the next field has the same field ID as the current field. void * nextLevelOneField( - void * pvLastLevelOneField ///< Last level one field that was found. + FLMUINT * puiFieldPos, ///< Current level one field position.\ Returns + ///< the next level one field position. + FLMBOOL bFieldIdsMustMatch ///< Specifies whether the field ID of the next + ///< field in the field ID table must match the + ///< field ID of the current field position. + ); + + /// Get the field ID of the field that is in the specified position in the + /// field ID table. + FLMUINT getLevelOneFieldId( + FLMUINT uiLevelOnePosition ///< Level one field position whose field ID is to + ///< be returned. ); void * locateFieldByPosition( diff --git a/flaim/src/fqeval.cpp b/flaim/src/fqeval.cpp index 04df549..c7010a4 100644 --- a/flaim/src/fqeval.cpp +++ b/flaim/src/fqeval.cpp @@ -775,8 +775,8 @@ FSTATIC RCODE flmCurGetAtomFromRec( { RCODE rc = FERR_OK; FQATOM * pTmpResult = NULL; - void * pvField; - void * pvLastLevelOneField = NULL; + void * pvField = NULL; + FLMUINT uiLastLevelOneFieldPos = 0; FLMUINT * puiFldPath; FLMUINT uiCurrFieldPath[ GED_MAXLVLNUM + 1]; FLMUINT uiFieldLevel; @@ -851,14 +851,14 @@ FSTATIC RCODE flmCurGetAtomFromRec( if (bUseFieldIdLookupTable) { - if ((pvLastLevelOneField = - pRecord->findLevelOneField( uiLevelOneFieldId, FALSE)) == NULL) + if ((pvField = + pRecord->findLevelOneField( uiLevelOneFieldId, FALSE, + &uiLastLevelOneFieldPos)) == NULL) { goto Exit; } uiCurrFieldPath [0] = puiPToCPath [0]; - pvField = pvLastLevelOneField; uiFieldLevel = 1; } } @@ -1030,8 +1030,8 @@ FSTATIC RCODE flmCurGetAtomFromRec( if (bUseFieldIdLookupTable && uiFieldLevel == 1) { - pvLastLevelOneField = pvField = pRecord->nextLevelOneField( - pvLastLevelOneField); + pvField = pRecord->nextLevelOneField( + &uiLastLevelOneFieldPos, TRUE); } break; diff --git a/flaim/src/frec.cpp b/flaim/src/frec.cpp index 0728d7f..379c0b4 100644 --- a/flaim/src/frec.cpp +++ b/flaim/src/frec.cpp @@ -5370,23 +5370,23 @@ Exit: Desc: Find a level one field in the record. ******************************************************************************/ void * FlmRecord::findLevelOneField( - FLMUINT uiFieldId, - FLMBOOL bFindInclusive) + FLMUINT uiFieldId, + FLMBOOL bFindInclusive, + FLMUINT * puiFieldPos) { - FLMUINT uiInsertPos; FIELD_ID * pFieldId; void * pvField = NULL; if (m_pucFieldIdTable) { - if ((pFieldId = findFieldId( (FLMUINT16)uiFieldId, 0, &uiInsertPos)) != NULL) + if ((pFieldId = findFieldId( (FLMUINT16)uiFieldId, 0, puiFieldPos)) != NULL) { pvField = (void *)((FLMUINT)pFieldId->ui32FieldOffset); } else if (bFindInclusive && - uiInsertPos < getFieldIdTableItemCount( m_pucFieldIdTable)) + *puiFieldPos < getFieldIdTableItemCount( m_pucFieldIdTable)) { - pFieldId = getFieldIdTable( m_pucFieldIdTable) + uiInsertPos; + pFieldId = getFieldIdTable( m_pucFieldIdTable) + *puiFieldPos; pvField = (void *)((FLMUINT)pFieldId->ui32FieldOffset); } } @@ -5397,37 +5397,76 @@ void * FlmRecord::findLevelOneField( return( pvField); } +/****************************************************************************** +Desc: Determine if a particular level one field matches the specified field ID + If so, return the field pointer. +******************************************************************************/ +void * FlmRecord::getLevelOneField( + FLMUINT uiFieldId, + FLMUINT uiLevelOnePosition) +{ + void * pvField = NULL; + + if (m_pucFieldIdTable) + { + FIELD_ID * pFieldId; + + if (m_uiFlags & RCA_NEED_TO_SORT_FIELD_ID_TABLE) + { + sortFieldIdTable(); + } + + // See if there is a next field in the array. + + if (uiLevelOnePosition < getFieldIdTableItemCount( m_pucFieldIdTable)) + { + pFieldId = getFieldIdTable( m_pucFieldIdTable) + uiLevelOnePosition; + if (uiFieldId == (FLMUINT)(pFieldId->ui16FieldId)) + { + pvField = (void *)((FLMUINT)pFieldId->ui32FieldOffset); + } + } + } + else + { + flmAssert( m_uiFlags & RCA_FIELD_ID_TABLE_ENABLED); + } + return( pvField); +} + /****************************************************************************** Desc: Find a level one field in the record. ******************************************************************************/ void * FlmRecord::nextLevelOneField( - void * pvLastLevelOneField) + FLMUINT * puiCurrLevelOnePosition, + FLMBOOL bFieldIdsMustMatch) { - FLMUINT16 ui16FieldId = (FLMUINT16)getFieldID( pvLastLevelOneField); - FIELDLINK ui32FieldOffset = (FIELDLINK)((FLMUINT)pvLastLevelOneField); - FLMUINT uiInsertPos; - FIELD_ID * pFieldId; void * pvField = NULL; if (m_pucFieldIdTable) { - if ((pFieldId = findFieldId( ui16FieldId, ui32FieldOffset, - &uiInsertPos)) != NULL) + FLMUINT uiNextPos = *puiCurrLevelOnePosition + 1; + FIELD_ID * pFieldId; + + if (m_uiFlags & RCA_NEED_TO_SORT_FIELD_ID_TABLE) + { + sortFieldIdTable(); + } + + // See if there is a next field in the array. + + if (uiNextPos < getFieldIdTableItemCount( m_pucFieldIdTable)) { - // See if there is a next field in the array. - - if (uiInsertPos + 1 < getFieldIdTableItemCount( m_pucFieldIdTable)) + // See if the next field in the array has the same field ID as + // the current one. + + pFieldId = getFieldIdTable( m_pucFieldIdTable) + uiNextPos; + if (!bFieldIdsMustMatch || + pFieldId->ui16FieldId == (pFieldId - 1)->ui16FieldId) { - - // See if the next field in the array has the same field ID as - // the one we're looking for. - - pFieldId = getFieldIdTable( m_pucFieldIdTable) + uiInsertPos + 1; - if (pFieldId->ui16FieldId == ui16FieldId) - { - pvField = (void *)((FLMUINT)pFieldId->ui32FieldOffset); - } + pvField = (void *)((FLMUINT)pFieldId->ui32FieldOffset); + *puiCurrLevelOnePosition = uiNextPos; } } } @@ -5438,6 +5477,41 @@ void * FlmRecord::nextLevelOneField( return( pvField); } +/****************************************************************************** +Desc: Get the field ID of a level one field at the specified position. +******************************************************************************/ +FLMUINT FlmRecord::getLevelOneFieldId( + FLMUINT uiLevelOnePosition) +{ + FLMUINT uiFieldId = 0; + + if (m_pucFieldIdTable) + { + FIELD_ID * pFieldId; + + if (m_uiFlags & RCA_NEED_TO_SORT_FIELD_ID_TABLE) + { + sortFieldIdTable(); + } + + // See if there is a next field in the array. + + if (uiLevelOnePosition < getFieldIdTableItemCount( m_pucFieldIdTable)) + { + + // Return the field ID for the position. + + pFieldId = getFieldIdTable( m_pucFieldIdTable) + uiLevelOnePosition; + uiFieldId = (FLMUINT)(pFieldId->ui16FieldId); + } + } + else + { + flmAssert( m_uiFlags & RCA_FIELD_ID_TABLE_ENABLED); + } + return( uiFieldId); +} + /****************************************************************************** Desc: Create the field ID table, if not already created. ******************************************************************************/ diff --git a/flaim/util/basic_test.cpp b/flaim/util/basic_test.cpp index cd41341..dd80fee 100644 --- a/flaim/util/basic_test.cpp +++ b/flaim/util/basic_test.cpp @@ -2194,6 +2194,7 @@ RCODE IFlmTestImpl::sortedFieldsTest( FLMBOOL bTransActive = FALSE; char szFieldName [100]; FLMUINT uiFieldId; + FLMUINT uiFieldPos = 0; FLMUINT uiTmp; FLMUINT uiCount; FLMUINT uiLoop1; @@ -2370,7 +2371,7 @@ RCODE IFlmTestImpl::sortedFieldsTest( for (uiFieldId = 1000; uiFieldId <= 1600; uiFieldId += 2) { - pvDataField = pDataRec->findLevelOneField( uiFieldId, TRUE); + pvDataField = pDataRec->findLevelOneField( uiFieldId, TRUE, &uiFieldPos); if (!pvDataField) { rc = RC_SET( FERR_FAILURE); @@ -2411,7 +2412,7 @@ RCODE IFlmTestImpl::sortedFieldsTest( uiCount = 1; for (;;) { - pvDataField = pDataRec->nextLevelOneField( pvDataField); + pvDataField = pDataRec->nextLevelOneField( &uiFieldPos, TRUE); if (!pvDataField) { if (uiCount != 3) @@ -2485,7 +2486,7 @@ RCODE IFlmTestImpl::sortedFieldsTest( for (uiCount = 1; uiCount <= 3; uiCount++) { - pvDataField = pCopyRec->findLevelOneField( uiFieldId, FALSE); + pvDataField = pCopyRec->findLevelOneField( uiFieldId, FALSE, &uiFieldPos); if (!pvDataField) { rc = RC_SET( FERR_FAILURE); @@ -2531,7 +2532,7 @@ RCODE IFlmTestImpl::sortedFieldsTest( // All instances should be gone now. - pvDataField = pCopyRec->findLevelOneField( uiFieldId, FALSE); + pvDataField = pCopyRec->findLevelOneField( uiFieldId, FALSE, &uiFieldPos); if (pvDataField) { rc = RC_SET( FERR_FAILURE);