sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: EXPORT_C CMetaDataArray* CMetaDataArray::NewL() sl@0: { sl@0: CMetaDataArray* self = NewLC(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CMetaDataArray* CMetaDataArray::NewLC() sl@0: { sl@0: CMetaDataArray* self = new (ELeave) CMetaDataArray; sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CMetaDataArray* CMetaDataArray::NewL(RReadStream& aStream) sl@0: { sl@0: CMetaDataArray* self = new (ELeave) CMetaDataArray; sl@0: CleanupStack::PushL(self); sl@0: self->InternalizeL(aStream); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CMetaDataArray::CMetaDataArray() sl@0: { sl@0: iMaxFieldLength = 0; sl@0: } sl@0: sl@0: sl@0: CMetaDataArray::~CMetaDataArray() sl@0: { sl@0: iArray.ResetAndDestroy(); sl@0: } sl@0: sl@0: EXPORT_C void CMetaDataArray::AddL(const TDesC8& aField, const TDesC8& aData) sl@0: { sl@0: // Construct a new CMetaData object with 8 bit data sl@0: CMetaData* ptr = CMetaData::NewL(aField, aData); sl@0: CleanupStack::PushL(ptr); sl@0: sl@0: // Add it to the array sl@0: User::LeaveIfError(iArray.Append(ptr)); sl@0: sl@0: // Array owns the pointer so we don't need it in the cleanup stack any longer sl@0: CleanupStack::Pop(ptr); sl@0: sl@0: // See if this field is longer than any previous field sl@0: if(aField.Length() > iMaxFieldLength) sl@0: { sl@0: iMaxFieldLength = aField.Length(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CMetaDataArray::AddL(const TDesC& aField, const TDesC& aData) sl@0: { sl@0: // Construct a new CMetaData object with unicode data sl@0: CMetaData* ptr = CMetaData::NewL(aField, aData); sl@0: CleanupStack::PushL(ptr); sl@0: sl@0: // Add it to the array sl@0: User::LeaveIfError(iArray.Append(ptr)); sl@0: sl@0: // Array owns the pointer so we don't need it in the cleanup stack any longer sl@0: CleanupStack::Pop(ptr); sl@0: sl@0: // See if this field is longer than any previous field sl@0: if(aField.Length() > iMaxFieldLength) sl@0: { sl@0: iMaxFieldLength = aField.Length(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C const CMetaData& CMetaDataArray::operator [] (TInt aIndex) const sl@0: { sl@0: return *iArray[aIndex]; sl@0: } sl@0: sl@0: EXPORT_C TInt CMetaDataArray::Count() const sl@0: { sl@0: return iArray.Count(); sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CMetaDataArray::SearchL(const TDesC& aField, TBool aMatchCase) const sl@0: { sl@0: TInt i; sl@0: if(!aMatchCase) sl@0: { sl@0: // Allocate space for upper case version of field to search for sl@0: HBufC* searchField = aField.AllocLC(); sl@0: TPtr searchFieldPtr = searchField->Des(); sl@0: searchFieldPtr.UpperCase(); sl@0: sl@0: // Allocate space for upper case version fields in the array sl@0: HBufC* field = HBufC::NewLC(iMaxFieldLength); sl@0: TPtr fieldPtr = field->Des(); sl@0: sl@0: // search through the array to find the data matching the given field sl@0: for(i = 0; i < iArray.Count(); i++) sl@0: { sl@0: fieldPtr.Copy(iArray[i]->Field()); sl@0: fieldPtr.UpperCase(); sl@0: if(fieldPtr == searchFieldPtr) sl@0: { sl@0: CleanupStack::PopAndDestroy(2, searchField); // searchField, field sl@0: return iArray[i]->Data(); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(2, searchField); // searchField, field sl@0: } sl@0: else sl@0: { sl@0: // search through the array to find the data matching the given field sl@0: for(i = 0; i < iArray.Count(); i++) sl@0: { sl@0: if(iArray[i]->Field() == aField) sl@0: { sl@0: return iArray[i]->Data(); sl@0: } sl@0: } sl@0: } sl@0: // not found so return an empty string sl@0: return KNullDesC16(); sl@0: } sl@0: sl@0: EXPORT_C const TDesC8& CMetaDataArray::SearchL(const TDesC8& aField8, TBool aMatchCase) const sl@0: { sl@0: TInt i; sl@0: sl@0: if(!aMatchCase) sl@0: { sl@0: // Allocate space for upper case version of field to search for sl@0: HBufC8* searchField = aField8.AllocLC(); sl@0: TPtr8 searchFieldPtr = searchField->Des(); sl@0: searchFieldPtr.UpperCase(); sl@0: sl@0: // Allocate space for upper case version fields in the array sl@0: HBufC8* field = HBufC8::NewLC(iMaxFieldLength); sl@0: TPtr8 fieldPtr = field->Des(); sl@0: sl@0: // search through the array to find the data matching the given field sl@0: for(i = 0; i < iArray.Count(); i++) sl@0: { sl@0: fieldPtr.Copy(iArray[i]->Field8()); sl@0: fieldPtr.UpperCase(); sl@0: if(fieldPtr == searchFieldPtr) sl@0: { sl@0: CleanupStack::PopAndDestroy(2, searchField); // searchField, field sl@0: return iArray[i]->Data8(); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(2, searchField); // searchField, field sl@0: } sl@0: else sl@0: { sl@0: // search through the array to find the data matching the given field sl@0: for(i = 0; i < iArray.Count(); i++) sl@0: { sl@0: if(iArray[i]->Field8() == aField8) sl@0: { sl@0: return iArray[i]->Data8(); sl@0: } sl@0: } sl@0: } sl@0: // not found so return an empty string sl@0: return KNullDesC8(); sl@0: } sl@0: sl@0: EXPORT_C void CMetaDataArray::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: TInt i; sl@0: aStream.WriteInt32L(iArray.Count()); sl@0: for(i = 0; i < iArray.Count();i++) sl@0: { sl@0: aStream << *(iArray[i]); sl@0: } sl@0: } sl@0: sl@0: void CMetaDataArray::InternalizeL(RReadStream& aStream) sl@0: { sl@0: TInt i; sl@0: TInt length = 0; sl@0: sl@0: // Read the number of CMetaData objects from the stream sl@0: TInt count = aStream.ReadInt32L(); sl@0: sl@0: // Read the CMetaData objects from the stream and add them to the array sl@0: for(i = 0; i < count; i++) sl@0: { sl@0: CMetaData* metaData = CMetaData::NewL(aStream); sl@0: CleanupStack::PushL(metaData); sl@0: User::LeaveIfError(iArray.Append(metaData)); sl@0: sl@0: // See if this field is longer than any previous field sl@0: length = metaData->Field().Length(); sl@0: if(length > iMaxFieldLength) sl@0: { sl@0: iMaxFieldLength = length; sl@0: } sl@0: sl@0: // Finished with cleanup stack, metaData now owned by the array so don't delete sl@0: CleanupStack::Pop(metaData); sl@0: } sl@0: } sl@0: sl@0: