metadataengine/client/src/mdeobjectdef.cpp
branchRCL_3
changeset 3 6752808b2036
parent 1 acef663c1218
child 6 646a02f170b9
equal deleted inserted replaced
2:b73a2e62868f 3:6752808b2036
    57     iPropertyDefs.ReserveL( propertyCount );
    57     iPropertyDefs.ReserveL( propertyCount );
    58     for ( TUint32 i = 0; i < propertyCount; ++i )
    58     for ( TUint32 i = 0; i < propertyCount; ++i )
    59         {
    59         {
    60 		aSchemaBuffer.PositionL( propertyOffset + i * sizeof(TMdCPropertyDef) );
    60 		aSchemaBuffer.PositionL( propertyOffset + i * sizeof(TMdCPropertyDef) );
    61 		const TMdCPropertyDef& propertyDef = TMdCPropertyDef::GetFromBufferL(aSchemaBuffer);
    61 		const TMdCPropertyDef& propertyDef = TMdCPropertyDef::GetFromBufferL(aSchemaBuffer);
    62 		CMdEPropertyDef* propertyDefImpl = CMdEPropertyDef::NewL( propertyDef, aSchemaBuffer, *this );
    62 		
    63 		iPropertyDefs.InsertInOrder( propertyDefImpl, TLinearOrder<CMdEPropertyDef>(CMdEObjectDef::CompareProperties) );
    63 		CMdEPropertyDef* defImpl = CMdEPropertyDef::NewL( propertyDef, aSchemaBuffer, *this );
       
    64 		iPropertyDefs.InsertInOrder(defImpl, TLinearOrder<CMdEPropertyDef>(CMdEObjectDef::CompareProperties)); 
    64         }
    65         }
    65     }
    66     }
    66 
    67 
    67 CMdEObjectDef::~CMdEObjectDef()
    68 CMdEObjectDef::~CMdEObjectDef()
    68     {
    69     {
   155     return NULL;
   156     return NULL;
   156     }
   157     }
   157 
   158 
   158 CMdEPropertyDef* CMdEObjectDef::GetPropertyDefL(TDefId aId, CMdEObjectDef* aChild)
   159 CMdEPropertyDef* CMdEObjectDef::GetPropertyDefL(TDefId aId, CMdEObjectDef* aChild)
   159     {
   160     {
   160     const TInt i = iPropertyDefs.FindInOrder(aId, CMdEObjectDef::CompareProperties );
   161     const TInt count = iPropertyDefs.Count();
       
   162 
       
   163     TInt low( 0 );
       
   164     TInt high( count );
       
   165     TBool linearSearchRequired( EFalse );
   161     
   166     
   162     if (i >= 0 && i < iPropertyDefs.Count() && iPropertyDefs[i] )
   167     while( low < high )
   163         {
   168         {
   164         return iPropertyDefs[i];
   169         TInt mid( (low+high)>>1 );
       
   170         
       
   171         if( !iPropertyDefs[mid] )
       
   172             {
       
   173             linearSearchRequired = ETrue;
       
   174             break;
       
   175             }
       
   176         
       
   177         TInt compare( aId - iPropertyDefs[mid]->Id() );
       
   178         if( compare == 0 )
       
   179             {
       
   180             return iPropertyDefs[mid];
       
   181             }
       
   182         else if( compare > 0 )
       
   183             {
       
   184             low = mid + 1;
       
   185             }
       
   186         else
       
   187             {
       
   188             high = mid;
       
   189             }
       
   190         }
       
   191   
       
   192     if( linearSearchRequired )
       
   193         {
       
   194         for ( TInt i = 0; i < count; ++i )
       
   195             {
       
   196             CMdEPropertyDef* propDef = iPropertyDefs[i];
       
   197         
       
   198             if( propDef && propDef->Id() == aId )
       
   199                 {
       
   200                 return propDef;
       
   201                 }
       
   202             }
   165         }
   203         }
   166 
   204 
   167     CMdEObjectDef* parent = ParentL();
   205     CMdEObjectDef* parent = ParentL();
   168     if ( parent ) 
   206     if ( parent ) 
   169         {
   207         {
   187 	    }
   225 	    }
   188 
   226 
   189 	return iPropertyDefs[aIndex];
   227 	return iPropertyDefs[aIndex];
   190 	}
   228 	}
   191 
   229 
   192 TInt CMdEObjectDef::CompareProperties( const CMdEPropertyDef& aFirst, const CMdEPropertyDef& aSecond )
   230 TInt CMdEObjectDef::CompareProperties(const CMdEPropertyDef& aFirst, const CMdEPropertyDef& aSecond)
   193     {
   231     {
   194     return aFirst.Id() - aSecond.Id();
   232     return aFirst.Id() - aSecond.Id();
   195     }
   233     }
   196 
   234 
   197 TInt CMdEObjectDef::CompareProperties( const TDefId* aFirst, const CMdEPropertyDef& aSecond )
       
   198     {
       
   199     return *aFirst - aSecond.Id();
       
   200     }
       
   201