metadataengine/client/src/mderangepropertycondition.cpp
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Serialization for mderange template class
       
    15 *
       
    16 */
       
    17 
       
    18 #include "mderangepropertycondition.h"
       
    19 #include "mdcserializationbuffer.h"
       
    20 #include "mdepropertydef.h"
       
    21 #include "mdcquery.h"
       
    22 
       
    23 void TMdESerializeRangePropertyCondition::SerializeL( 
       
    24 		CMdCSerializationBuffer& aBuffer, 
       
    25 		const CMdEPropertyCondition& aPropertyCondition, TMdERangeType aType, 
       
    26 		const void* aMin, const void* aMax, TInt aValueSize, TMdCOffset& aFreespaceOffset )
       
    27 	{
       
    28 	if ( aValueSize > sizeof(TMdCValueUnion) )
       
    29 		{
       
    30 		__ASSERT_DEBUG( EFalse, User::Panic( _L("Incorrect type"), KErrMdEIncorrectType ) );
       
    31 		User::Leave( KErrMdEIncorrectType );
       
    32 		}
       
    33 
       
    34 	TMdCPropertyCondition condition;
       
    35 
       
    36 	condition.iConditionType = aPropertyCondition.Type();
       
    37 	condition.iNegated = aPropertyCondition.Negate();
       
    38 	condition.iObjectDefId = aPropertyCondition.PropertyDef().ObjectDefId();
       
    39 	condition.iPropertyDefId = aPropertyCondition.PropertyDef().Id();
       
    40 	condition.iCondition = aBuffer.Position() + sizeof( TMdCPropertyCondition );
       
    41 
       
    42 	condition.SerializeL( aBuffer );
       
    43 	
       
    44 	aBuffer.InsertL( (TInt32)aType );
       
    45 
       
    46 	TMdCValueUnion min;
       
    47 	Mem::Copy( &min, aMin, aValueSize );
       
    48 	TMdCValueUnion max;
       
    49 	Mem::Copy( &max, aMax, aValueSize );
       
    50 
       
    51 	aBuffer.InsertL( min );
       
    52 	aBuffer.InsertL( max );
       
    53 	
       
    54 	aFreespaceOffset = aBuffer.Position();
       
    55 	}
       
    56 
       
    57 TUint32 TMdESerializeRangePropertyCondition::RequiredBufferSize( TInt  
       
    58 #ifdef _DEBUG	
       
    59 		aValueSize
       
    60 #endif
       
    61 		)
       
    62 	{
       
    63 #ifdef _DEBUG
       
    64 	if ( aValueSize > sizeof(TMdCValueUnion) )
       
    65 		{
       
    66 		User::Panic( _L("Incorrect type"), KErrMdEIncorrectType );
       
    67 		}
       
    68 #endif
       
    69 
       
    70 	TUint32 bufferSize = sizeof( TMdCPropertyCondition );
       
    71 
       
    72 	// Required size for type (TInt32), iMin and iMax (fixed size)
       
    73 	bufferSize += CMdCSerializationBuffer::KRequiredSizeForTInt32
       
    74 			+ 2 * CMdCSerializationBuffer::KRequiredSizeForTMdCValueUnion;
       
    75 
       
    76 	return bufferSize;
       
    77 	}