predictivesearch/PcsUtils/src/CPsClientData.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Client side class to hold the result of predictive search.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <s32mem.h>
       
    21 #include <collate.h>
       
    22 
       
    23 #include "CPsClientData.h"
       
    24 #include "CPcsDefs.h"
       
    25 
       
    26 // ============================== MEMBER FUNCTIONS ============================
       
    27 
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CPsClientData::NewL
       
    31 // Two Phase constructor
       
    32 // ----------------------------------------------------------------------------
       
    33 EXPORT_C CPsClientData* CPsClientData::NewL()
       
    34 {
       
    35 	CPsClientData* self = new (ELeave) CPsClientData();	
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop();
       
    39     return self;
       
    40 	
       
    41 }
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // CPsClientData::CPsClientData
       
    45 // Default constructor
       
    46 // ----------------------------------------------------------------------------
       
    47 CPsClientData::CPsClientData()
       
    48 {
       
    49 }
       
    50 
       
    51 // ----------------------------------------------------------------------------
       
    52 // CPsClientData::ConstructL
       
    53 // Two phase construction
       
    54 // ----------------------------------------------------------------------------
       
    55 void CPsClientData::ConstructL()
       
    56 {
       
    57     iData = new (ELeave) RPointerArray<HBufC>(1);
       
    58     iDataExtension = NULL;
       
    59     iMarked = EFalse;
       
    60 }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CPsClientData::ConstructL
       
    64 // Two phase construction
       
    65 // ----------------------------------------------------------------------------
       
    66 void CPsClientData::ConstructL(const CPsClientData& aRhs)
       
    67 {
       
    68 	iId = aRhs.Id();
       
    69 	iUri = aRhs.Uri()->AllocL();
       
    70     iData = new (ELeave) RPointerArray<HBufC>(1);
       
    71     for(TInt i=0; i < aRhs.DataElementCount(); i++ )
       
    72     {
       
    73     	SetDataL(i,*(aRhs.Data(i)));
       
    74     	
       
    75     	     
       
    76     }
       
    77     
       
    78     iFiledMatches = aRhs.FieldMatch();
       
    79     if(aRhs.DataExtension())
       
    80         {
       
    81         iDataExtension = ((HBufC8*)(aRhs.DataExtension()))->AllocL();	
       
    82         }
       
    83     
       
    84     if(aRhs.IsMarked())
       
    85     	iMarked = ETrue;
       
    86     else
       
    87     	iMarked = EFalse;
       
    88 }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // CPsClientData::~CPsClientData
       
    92 // Destructor
       
    93 // ----------------------------------------------------------------------------
       
    94 EXPORT_C CPsClientData::~CPsClientData()
       
    95 {
       
    96 	if ( iData )
       
    97 	{
       
    98 		iData->ResetAndDestroy();
       
    99 		delete iData;
       
   100 	}
       
   101 	if(iDataExtension)
       
   102     {
       
   103 		delete iDataExtension;
       
   104 		iDataExtension = NULL;
       
   105     }
       
   106     if(iUri)
       
   107     {
       
   108     	delete iUri;
       
   109     	iUri = NULL;
       
   110     }
       
   111 }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CPsClientData::CPsClientData
       
   115 // Returns the clone of this object
       
   116 // ----------------------------------------------------------------------------
       
   117 EXPORT_C CPsClientData* CPsClientData::CloneL() const
       
   118 {
       
   119 	CPsClientData* clone = new (ELeave) CPsClientData();	
       
   120     CleanupStack::PushL(clone);
       
   121     clone->ConstructL(*this);
       
   122     
       
   123     CleanupStack::Pop();
       
   124     return clone;
       
   125 
       
   126 }
       
   127 // ----------------------------------------------------------------------------
       
   128 // CPsClientData::Id
       
   129 // Returns the unique id
       
   130 // ----------------------------------------------------------------------------
       
   131 EXPORT_C  TInt CPsClientData::Id() const
       
   132 {
       
   133     return iId;
       
   134 }
       
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // CPsClientData::SetId
       
   138 // Sets the unique id
       
   139 // ----------------------------------------------------------------------------
       
   140 EXPORT_C void CPsClientData::SetId (const TInt aId)
       
   141 {
       
   142 	iId = aId;
       
   143 }
       
   144 
       
   145 // ----------------------------------------------------------------------------
       
   146 // CPsClientData::Uri
       
   147 // Returns the unique URI
       
   148 // ----------------------------------------------------------------------------
       
   149 EXPORT_C  HBufC* CPsClientData::Uri() const
       
   150 {
       
   151     return iUri;
       
   152 }
       
   153 
       
   154 // ----------------------------------------------------------------------------
       
   155 // CPsClientData::SetUriL
       
   156 // Sets the unique URI
       
   157 // ----------------------------------------------------------------------------
       
   158 EXPORT_C void CPsClientData::SetUriL(const TDesC& aUri)
       
   159 {
       
   160 	iUri = aUri.AllocL();
       
   161 }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // CPsClientData::Data
       
   165 // Returns the data
       
   166 // ----------------------------------------------------------------------------
       
   167 EXPORT_C HBufC* CPsClientData::Data(TInt aIndex) const
       
   168 {
       
   169     if ( aIndex >= iData->Count() )    
       
   170          return NULL;
       
   171     
       
   172     return (*iData)[aIndex];
       
   173 }
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CPsClientData::SetDataL
       
   177 // Sets the data
       
   178 // ----------------------------------------------------------------------------
       
   179 EXPORT_C void CPsClientData::SetDataL(TInt /*aIndex*/, const TDesC& aData)
       
   180 {   
       
   181     iData->AppendL(aData.AllocL());
       
   182 }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CPsClientData::DataElementCount
       
   186 // 
       
   187 // ----------------------------------------------------------------------------
       
   188 EXPORT_C TInt CPsClientData::DataElementCount() const
       
   189 {
       
   190 	return (iData->Count());
       
   191 }
       
   192 
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CPsClientData::ExternalizeL
       
   196 // Writes 'this' to aStream
       
   197 // ----------------------------------------------------------------------------
       
   198 EXPORT_C void CPsClientData::ExternalizeL(RWriteStream& aStream) const
       
   199 {
       
   200     aStream.WriteInt16L(iId); // Write unique ID to the stream
       
   201     
       
   202     aStream.WriteUint8L(iFiledMatches); // Field Matches
       
   203     
       
   204     aStream.WriteUint8L(iUri->Size());  // write URI length to stream
       
   205     aStream<<*iUri;                      // write URI to stream
       
   206     
       
   207     aStream.WriteUint8L(iData->Count()); // Number of data elements
       
   208 
       
   209 	for ( int index = 0; index < iData->Count(); index++ )
       
   210 	{
       
   211 	    HBufC* data = (*iData)[index];
       
   212 	    if ( data ) // Write data to the stream (or a NULL descriptor)
       
   213 	    {
       
   214 	      	aStream.WriteInt16L( data->Size() ); // data size
       
   215 			aStream << *data; // data
       
   216 	    }
       
   217 	    else
       
   218 	    {
       
   219 	    	aStream.WriteInt16L( 0 );
       
   220 	    	aStream << KNullDesC;
       
   221 	    }
       
   222 	}
       
   223 	
       
   224 	if ( iDataExtension )
       
   225     {
       
   226         HBufC8* dataExt = (HBufC8*)iDataExtension;
       
   227     	aStream.WriteUint8L( dataExt->Size() );
       
   228     	aStream << *dataExt;
       
   229     }
       
   230     else 
       
   231     {
       
   232     	aStream.WriteUint8L( 0 );
       
   233     	aStream << KNullDesC8;	    	
       
   234     }
       
   235 }
       
   236 
       
   237 // ----------------------------------------------------------------------------
       
   238 // CPsClientData::InternalizeL
       
   239 // Initializes 'this' with the contents of aStream
       
   240 // ----------------------------------------------------------------------------
       
   241 EXPORT_C void CPsClientData::InternalizeL(RReadStream& aStream)
       
   242 {
       
   243     // Read unique id
       
   244     TInt tmp = aStream.ReadInt16L();
       
   245     iId = tmp;
       
   246     
       
   247     // Read Field Match
       
   248 	iFiledMatches  = aStream.ReadUint8L();
       
   249 	
       
   250     // Read the URI length
       
   251     TUint8 len = aStream.ReadUint8L();
       
   252     // read uri
       
   253     iUri = HBufC::NewL(aStream, len);
       
   254     
       
   255     // Read number of data elements
       
   256     TInt szNumElements = aStream.ReadUint8L();
       
   257     
       
   258     for ( int index = 0; index < szNumElements; index++ )
       
   259     {
       
   260         // Read data size
       
   261 	    TInt szData = aStream.ReadInt16L();
       
   262     	    
       
   263     	HBufC* data =  HBufC::NewL(aStream, szData);
       
   264 	    iData->InsertL(data, index);
       
   265 	    
       
   266     }
       
   267 	
       
   268 	// Read data extension size
       
   269 	TUint8 szDataExt = aStream.ReadUint8L();
       
   270     if(iDataExtension)
       
   271     {
       
   272          delete iDataExtension;
       
   273         iDataExtension = NULL;
       
   274     }
       
   275     
       
   276     HBufC8* dataExt =  HBufC8::NewL(aStream, szDataExt);
       
   277     iDataExtension = dataExt;
       
   278 }
       
   279 
       
   280 // ----------------------------------------------------------------------------
       
   281 // CPsClientData::DataExtension
       
   282 // 
       
   283 // ----------------------------------------------------------------------------
       
   284 EXPORT_C TAny* CPsClientData::DataExtension() const
       
   285 {
       
   286 	return iDataExtension;
       
   287 }
       
   288 
       
   289 // ----------------------------------------------------------------------------
       
   290 // CPsClientData::SetDataExtensionL
       
   291 // 
       
   292 // ----------------------------------------------------------------------------
       
   293 EXPORT_C void CPsClientData::SetDataExtensionL(TAny* aDataExt)
       
   294 {
       
   295 	if(aDataExt == NULL)
       
   296 		return;
       
   297 	HBufC8* dataExt = (HBufC8*)aDataExt;
       
   298 	iDataExtension = dataExt->AllocL();
       
   299 }
       
   300 
       
   301 // ----------------------------------------------------------------------------
       
   302 // CPsClientData::SetBookMark
       
   303 // 
       
   304 // ----------------------------------------------------------------------------
       
   305 EXPORT_C void CPsClientData::SetMark()
       
   306 {
       
   307 	iMarked = ETrue;
       
   308 }
       
   309 
       
   310 // ----------------------------------------------------------------------------
       
   311 // CPsClientData::SetBookMark
       
   312 // 
       
   313 // ----------------------------------------------------------------------------
       
   314 EXPORT_C TBool CPsClientData::IsMarked() const
       
   315 {
       
   316 	return iMarked;
       
   317 }
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 // CPsClientData::SetFieldMatch
       
   321 // 
       
   322 // ----------------------------------------------------------------------------
       
   323 EXPORT_C void CPsClientData::SetFieldMatch(TUint8 aFieldMatch)
       
   324 {	
       
   325 	iFiledMatches = aFieldMatch;
       
   326 }
       
   327 // ----------------------------------------------------------------------------
       
   328 // CPsClientData:FieldMatch
       
   329 // Return the Field match attribute
       
   330 // ----------------------------------------------------------------------------		
       
   331 EXPORT_C TUint8 CPsClientData::FieldMatch() const
       
   332 {
       
   333     return iFiledMatches;
       
   334 }
       
   335