author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
/* |
sl@0 | 2 |
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 3 |
* All rights reserved. |
sl@0 | 4 |
* This component and the accompanying materials are made available |
sl@0 | 5 |
* under the terms of the License "Eclipse Public License v1.0" |
sl@0 | 6 |
* which accompanies this distribution, and is available |
sl@0 | 7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 8 |
* |
sl@0 | 9 |
* Initial Contributors: |
sl@0 | 10 |
* Nokia Corporation - initial contribution. |
sl@0 | 11 |
* |
sl@0 | 12 |
* Contributors: |
sl@0 | 13 |
* |
sl@0 | 14 |
* Description: |
sl@0 | 15 |
* |
sl@0 | 16 |
*/ |
sl@0 | 17 |
|
sl@0 | 18 |
|
sl@0 | 19 |
#include <charconv.h> |
sl@0 | 20 |
#include <s32strm.h> |
sl@0 | 21 |
#include <caf/metadata.h> |
sl@0 | 22 |
#include "cafutils.h" |
sl@0 | 23 |
|
sl@0 | 24 |
|
sl@0 | 25 |
using namespace ContentAccess; |
sl@0 | 26 |
|
sl@0 | 27 |
CMetaData* CMetaData::NewL(const TDesC8& aField, const TDesC8& aData) |
sl@0 | 28 |
{ |
sl@0 | 29 |
CMetaData* self = new (ELeave) CMetaData(EFalse); |
sl@0 | 30 |
CleanupStack::PushL(self); |
sl@0 | 31 |
self->ConstructL(aField, aData); |
sl@0 | 32 |
CleanupStack::Pop(self); |
sl@0 | 33 |
return self; |
sl@0 | 34 |
} |
sl@0 | 35 |
|
sl@0 | 36 |
CMetaData* CMetaData::NewL(const TDesC16& aField, const TDesC16& aData) |
sl@0 | 37 |
{ |
sl@0 | 38 |
CMetaData* self = new (ELeave) CMetaData(ETrue); |
sl@0 | 39 |
CleanupStack::PushL(self); |
sl@0 | 40 |
self->ConstructL(aField, aData); |
sl@0 | 41 |
CleanupStack::Pop(self); |
sl@0 | 42 |
return self; |
sl@0 | 43 |
} |
sl@0 | 44 |
|
sl@0 | 45 |
CMetaData* CMetaData::NewL(RReadStream& aStream) |
sl@0 | 46 |
{ |
sl@0 | 47 |
CMetaData* self = new (ELeave) CMetaData(ETrue); |
sl@0 | 48 |
CleanupStack::PushL(self); |
sl@0 | 49 |
self->InternalizeL(aStream); |
sl@0 | 50 |
CleanupStack::Pop(self); |
sl@0 | 51 |
return self; |
sl@0 | 52 |
} |
sl@0 | 53 |
|
sl@0 | 54 |
CMetaData::CMetaData(TBool aUnicode) : iUnicode(aUnicode) |
sl@0 | 55 |
{ |
sl@0 | 56 |
} |
sl@0 | 57 |
|
sl@0 | 58 |
void CMetaData::ConstructL(const TDesC8& aField, const TDesC8& aData) |
sl@0 | 59 |
{ |
sl@0 | 60 |
// Store supplied data in both 8 bit and unicode forms |
sl@0 | 61 |
iField8 = aField.AllocL(); |
sl@0 | 62 |
iData8 = aData.AllocL(); |
sl@0 | 63 |
|
sl@0 | 64 |
// Allocate space for 16 bit versions |
sl@0 | 65 |
iField = HBufC::NewL(iField8->Length()); |
sl@0 | 66 |
iData = HBufC::NewL(iData8->Length()); |
sl@0 | 67 |
|
sl@0 | 68 |
// populate 16 bit versions with 8 bit values |
sl@0 | 69 |
iField->Des().Copy(*iField8); |
sl@0 | 70 |
iData->Des().Copy(*iData8); |
sl@0 | 71 |
} |
sl@0 | 72 |
|
sl@0 | 73 |
void CMetaData::ConstructL(const TDesC16& aField, const TDesC16& aData) |
sl@0 | 74 |
{ |
sl@0 | 75 |
// Store supplied data in both 8 bit and unicode forms |
sl@0 | 76 |
iField = aField.AllocL(); |
sl@0 | 77 |
iData = aData.AllocL(); |
sl@0 | 78 |
|
sl@0 | 79 |
// Allocate space for 8 bit versions |
sl@0 | 80 |
iField8 = HBufC8::NewL(iField->Des().Length()); |
sl@0 | 81 |
iData8 = HBufC8::NewL(iData->Des().Length()); |
sl@0 | 82 |
|
sl@0 | 83 |
// populate 8 bit versions with 16 bit values |
sl@0 | 84 |
iField8->Des().Copy(*iField); |
sl@0 | 85 |
iData8->Des().Copy(*iData); |
sl@0 | 86 |
} |
sl@0 | 87 |
|
sl@0 | 88 |
CMetaData::~CMetaData() |
sl@0 | 89 |
{ |
sl@0 | 90 |
delete iField; |
sl@0 | 91 |
delete iData; |
sl@0 | 92 |
delete iField8; |
sl@0 | 93 |
delete iData8; |
sl@0 | 94 |
} |
sl@0 | 95 |
|
sl@0 | 96 |
EXPORT_C const TDesC& CMetaData::Field() const |
sl@0 | 97 |
{ |
sl@0 | 98 |
return *iField; |
sl@0 | 99 |
} |
sl@0 | 100 |
|
sl@0 | 101 |
EXPORT_C const TDesC& CMetaData::Data() const |
sl@0 | 102 |
{ |
sl@0 | 103 |
return *iData; |
sl@0 | 104 |
} |
sl@0 | 105 |
|
sl@0 | 106 |
EXPORT_C const TDesC8& CMetaData::Field8() const |
sl@0 | 107 |
{ |
sl@0 | 108 |
return *iField8; |
sl@0 | 109 |
} |
sl@0 | 110 |
|
sl@0 | 111 |
EXPORT_C const TDesC8& CMetaData::Data8() const |
sl@0 | 112 |
{ |
sl@0 | 113 |
return *iData8; |
sl@0 | 114 |
} |
sl@0 | 115 |
|
sl@0 | 116 |
void CMetaData::InternalizeL(RReadStream& aStream) |
sl@0 | 117 |
{ |
sl@0 | 118 |
// Read the unicode field from the stream |
sl@0 | 119 |
iField = TCafUtils::ReadDescriptor16L(aStream); |
sl@0 | 120 |
|
sl@0 | 121 |
// Read the unicode data from the stream |
sl@0 | 122 |
iData = TCafUtils::ReadDescriptor16L(aStream); |
sl@0 | 123 |
|
sl@0 | 124 |
// Allocate space for 8 bit versions |
sl@0 | 125 |
iField8 = HBufC8::NewL(iField->Length()); |
sl@0 | 126 |
iData8 = HBufC8::NewL(iData->Length()); |
sl@0 | 127 |
|
sl@0 | 128 |
// populate 8 bit versions with 16 bit values |
sl@0 | 129 |
iField8->Des().Copy(*iField); |
sl@0 | 130 |
iData8->Des().Copy(*iData); |
sl@0 | 131 |
} |
sl@0 | 132 |
|
sl@0 | 133 |
void CMetaData::ExternalizeL(RWriteStream& aStream) const |
sl@0 | 134 |
{ |
sl@0 | 135 |
// Write unicode field to the stream |
sl@0 | 136 |
TCafUtils::WriteDescriptor16L(aStream, *iField); |
sl@0 | 137 |
TCafUtils::WriteDescriptor16L(aStream, *iData); |
sl@0 | 138 |
} |