searcher/searchclient/src/cdocumentfield.cpp
changeset 0 671dee74050a
equal deleted inserted replaced
-1:000000000000 0:671dee74050a
       
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CDocumentField.h"
       
    19 
       
    20 #include <S32STRM.H>
       
    21 #include <e32std.h>
       
    22 
       
    23 // Same as CLucene's
       
    24 const TReal32 CDocumentField::KDefaultBoost = 1.0f; 
       
    25 
       
    26 EXPORT_C CDocumentField* CDocumentField::NewL( const TDesC& aName, const TDesC& aValue, TInt aConfig )
       
    27 	{
       
    28 	CDocumentField* instance = CDocumentField::NewLC( aName, aValue, aConfig );
       
    29 	CleanupStack::Pop(instance);
       
    30 	return instance;
       
    31 	}
       
    32 
       
    33 EXPORT_C CDocumentField* CDocumentField::NewLC( const TDesC& aName, const TDesC& aValue, TInt aConfig )
       
    34 	{
       
    35 	CDocumentField* instance = new (ELeave)CDocumentField();
       
    36 	CleanupStack::PushL(instance);
       
    37 	instance->ConstructL(aName, aValue, aConfig  );
       
    38 	return instance;
       
    39 	}
       
    40 
       
    41 EXPORT_C CDocumentField* CDocumentField::NewL(RReadStream& aReadStream)
       
    42 	{
       
    43 	CDocumentField* instance = CDocumentField::NewLC(aReadStream);
       
    44 	CleanupStack::Pop(instance);
       
    45 	return instance;
       
    46 	}
       
    47 
       
    48 EXPORT_C CDocumentField* CDocumentField::NewLC(RReadStream& aReadStream)
       
    49 	{
       
    50 	CDocumentField* instance = new (ELeave)CDocumentField();
       
    51 	CleanupStack::PushL(instance);
       
    52 	instance->ConstructL(aReadStream);
       
    53 	return instance;
       
    54 	}
       
    55 
       
    56 EXPORT_C const TDesC& CDocumentField::Name() const
       
    57 	{
       
    58 	return *iName;
       
    59 	}
       
    60 
       
    61 EXPORT_C const TDesC& CDocumentField::Value() const
       
    62 	{
       
    63 	return *iValue;
       
    64 	}
       
    65 
       
    66 EXPORT_C TInt CDocumentField::Config() const
       
    67 	{
       
    68 	return iConfig;
       
    69 	}
       
    70 
       
    71 EXPORT_C void CDocumentField::SetBoost( TReal32 aBoost )
       
    72 	{
       
    73 	iBoost = aBoost; 
       
    74 	}
       
    75 
       
    76 EXPORT_C TReal32 CDocumentField::Boost() const
       
    77 	{
       
    78 	return iBoost; 
       
    79 	}
       
    80 
       
    81 CDocumentField::CDocumentField()
       
    82     : iName(), 
       
    83       iValue(),
       
    84       iBoost( KDefaultBoost )
       
    85 	{
       
    86 	}
       
    87 
       
    88 EXPORT_C CDocumentField::~CDocumentField()
       
    89 	{
       
    90 	delete iName;
       
    91 	delete iValue;
       
    92 	}
       
    93 
       
    94 void CDocumentField::ConstructL( const TDesC& aName, const TDesC& aValue, TInt aConfig )
       
    95 	{
       
    96 	iName = aName.AllocL();
       
    97 	iValue = aValue.AllocL();
       
    98 	iConfig = aConfig; 
       
    99 	}
       
   100 
       
   101 void CDocumentField::ConstructL(RReadStream& aReadStream)
       
   102 	{
       
   103 	InternalizeL(aReadStream);
       
   104 	}
       
   105 
       
   106 EXPORT_C TInt CDocumentField::Size() const
       
   107 	{
       
   108 	return sizeof(TReal32) + sizeof(TInt32) + iName->Size() + sizeof(TInt32) + iValue->Size() + sizeof(TInt32);
       
   109 	}
       
   110 
       
   111 EXPORT_C void CDocumentField::ExternalizeL(RWriteStream& aWriteStream) const
       
   112 	{
       
   113 	aWriteStream.WriteInt32L(iName->Length());
       
   114 	aWriteStream.WriteL(*iName, iName->Length());
       
   115 	
       
   116 	aWriteStream.WriteInt32L(iValue->Length());
       
   117 	aWriteStream.WriteL(*iValue, iValue->Length());
       
   118 
       
   119 	aWriteStream.WriteInt32L( iConfig );	
       
   120 	aWriteStream.WriteReal32L( iBoost ); 
       
   121 	}
       
   122 
       
   123 EXPORT_C void CDocumentField::InternalizeL(RReadStream& aReadStream)
       
   124 	{
       
   125 	delete iName;
       
   126 	iName = NULL;
       
   127 	TInt nameLenght = aReadStream.ReadInt32L();
       
   128 	iName = HBufC::NewL(nameLenght);
       
   129 	
       
   130 	TPtr namePtr = iName->Des();
       
   131 	aReadStream.ReadL(namePtr, nameLenght);
       
   132 	
       
   133 	delete iValue;
       
   134 	iValue = NULL;
       
   135 	TInt valueLenght = aReadStream.ReadInt32L();
       
   136 	iValue = HBufC::NewL(valueLenght);
       
   137 	
       
   138 
       
   139 	TPtr valuePtr = iValue->Des();
       
   140 	aReadStream.ReadL(valuePtr, valueLenght);
       
   141 
       
   142 	iConfig = aReadStream.ReadInt32L();
       
   143 	iBoost = aReadStream.ReadReal32L(); 
       
   144 	}
       
   145