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: #include "cafutils.h" sl@0: sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: CMetaData* CMetaData::NewL(const TDesC8& aField, const TDesC8& aData) sl@0: { sl@0: CMetaData* self = new (ELeave) CMetaData(EFalse); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aField, aData); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CMetaData* CMetaData::NewL(const TDesC16& aField, const TDesC16& aData) sl@0: { sl@0: CMetaData* self = new (ELeave) CMetaData(ETrue); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aField, aData); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CMetaData* CMetaData::NewL(RReadStream& aStream) sl@0: { sl@0: CMetaData* self = new (ELeave) CMetaData(ETrue); 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: CMetaData::CMetaData(TBool aUnicode) : iUnicode(aUnicode) sl@0: { sl@0: } sl@0: sl@0: void CMetaData::ConstructL(const TDesC8& aField, const TDesC8& aData) sl@0: { sl@0: // Store supplied data in both 8 bit and unicode forms sl@0: iField8 = aField.AllocL(); sl@0: iData8 = aData.AllocL(); sl@0: sl@0: // Allocate space for 16 bit versions sl@0: iField = HBufC::NewL(iField8->Length()); sl@0: iData = HBufC::NewL(iData8->Length()); sl@0: sl@0: // populate 16 bit versions with 8 bit values sl@0: iField->Des().Copy(*iField8); sl@0: iData->Des().Copy(*iData8); sl@0: } sl@0: sl@0: void CMetaData::ConstructL(const TDesC16& aField, const TDesC16& aData) sl@0: { sl@0: // Store supplied data in both 8 bit and unicode forms sl@0: iField = aField.AllocL(); sl@0: iData = aData.AllocL(); sl@0: sl@0: // Allocate space for 8 bit versions sl@0: iField8 = HBufC8::NewL(iField->Des().Length()); sl@0: iData8 = HBufC8::NewL(iData->Des().Length()); sl@0: sl@0: // populate 8 bit versions with 16 bit values sl@0: iField8->Des().Copy(*iField); sl@0: iData8->Des().Copy(*iData); sl@0: } sl@0: sl@0: CMetaData::~CMetaData() sl@0: { sl@0: delete iField; sl@0: delete iData; sl@0: delete iField8; sl@0: delete iData8; sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CMetaData::Field() const sl@0: { sl@0: return *iField; sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CMetaData::Data() const sl@0: { sl@0: return *iData; sl@0: } sl@0: sl@0: EXPORT_C const TDesC8& CMetaData::Field8() const sl@0: { sl@0: return *iField8; sl@0: } sl@0: sl@0: EXPORT_C const TDesC8& CMetaData::Data8() const sl@0: { sl@0: return *iData8; sl@0: } sl@0: sl@0: void CMetaData::InternalizeL(RReadStream& aStream) sl@0: { sl@0: // Read the unicode field from the stream sl@0: iField = TCafUtils::ReadDescriptor16L(aStream); sl@0: sl@0: // Read the unicode data from the stream sl@0: iData = TCafUtils::ReadDescriptor16L(aStream); sl@0: sl@0: // Allocate space for 8 bit versions sl@0: iField8 = HBufC8::NewL(iField->Length()); sl@0: iData8 = HBufC8::NewL(iData->Length()); sl@0: sl@0: // populate 8 bit versions with 16 bit values sl@0: iField8->Des().Copy(*iField); sl@0: iData8->Des().Copy(*iData); sl@0: } sl@0: sl@0: void CMetaData::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: // Write unicode field to the stream sl@0: TCafUtils::WriteDescriptor16L(aStream, *iField); sl@0: TCafUtils::WriteDescriptor16L(aStream, *iData); sl@0: }