Update contrib.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include <caf/metadata.h>
25 using namespace ContentAccess;
27 CMetaData* CMetaData::NewL(const TDesC8& aField, const TDesC8& aData)
29 CMetaData* self = new (ELeave) CMetaData(EFalse);
30 CleanupStack::PushL(self);
31 self->ConstructL(aField, aData);
32 CleanupStack::Pop(self);
36 CMetaData* CMetaData::NewL(const TDesC16& aField, const TDesC16& aData)
38 CMetaData* self = new (ELeave) CMetaData(ETrue);
39 CleanupStack::PushL(self);
40 self->ConstructL(aField, aData);
41 CleanupStack::Pop(self);
45 CMetaData* CMetaData::NewL(RReadStream& aStream)
47 CMetaData* self = new (ELeave) CMetaData(ETrue);
48 CleanupStack::PushL(self);
49 self->InternalizeL(aStream);
50 CleanupStack::Pop(self);
54 CMetaData::CMetaData(TBool aUnicode) : iUnicode(aUnicode)
58 void CMetaData::ConstructL(const TDesC8& aField, const TDesC8& aData)
60 // Store supplied data in both 8 bit and unicode forms
61 iField8 = aField.AllocL();
62 iData8 = aData.AllocL();
64 // Allocate space for 16 bit versions
65 iField = HBufC::NewL(iField8->Length());
66 iData = HBufC::NewL(iData8->Length());
68 // populate 16 bit versions with 8 bit values
69 iField->Des().Copy(*iField8);
70 iData->Des().Copy(*iData8);
73 void CMetaData::ConstructL(const TDesC16& aField, const TDesC16& aData)
75 // Store supplied data in both 8 bit and unicode forms
76 iField = aField.AllocL();
77 iData = aData.AllocL();
79 // Allocate space for 8 bit versions
80 iField8 = HBufC8::NewL(iField->Des().Length());
81 iData8 = HBufC8::NewL(iData->Des().Length());
83 // populate 8 bit versions with 16 bit values
84 iField8->Des().Copy(*iField);
85 iData8->Des().Copy(*iData);
88 CMetaData::~CMetaData()
96 EXPORT_C const TDesC& CMetaData::Field() const
101 EXPORT_C const TDesC& CMetaData::Data() const
106 EXPORT_C const TDesC8& CMetaData::Field8() const
111 EXPORT_C const TDesC8& CMetaData::Data8() const
116 void CMetaData::InternalizeL(RReadStream& aStream)
118 // Read the unicode field from the stream
119 iField = TCafUtils::ReadDescriptor16L(aStream);
121 // Read the unicode data from the stream
122 iData = TCafUtils::ReadDescriptor16L(aStream);
124 // Allocate space for 8 bit versions
125 iField8 = HBufC8::NewL(iField->Length());
126 iData8 = HBufC8::NewL(iData->Length());
128 // populate 8 bit versions with 16 bit values
129 iField8->Des().Copy(*iField);
130 iData8->Des().Copy(*iData);
133 void CMetaData::ExternalizeL(RWriteStream& aStream) const
135 // Write unicode field to the stream
136 TCafUtils::WriteDescriptor16L(aStream, *iField);
137 TCafUtils::WriteDescriptor16L(aStream, *iData);