os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/Metadata.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2004-2009 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 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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <charconv.h>
    20 #include <s32strm.h>
    21 #include <caf/metadata.h>
    22 #include "cafutils.h"
    23 
    24 
    25 using namespace ContentAccess;
    26 
    27 CMetaData* CMetaData::NewL(const TDesC8& aField, const TDesC8& aData)
    28 	{
    29 	CMetaData* self = new (ELeave) CMetaData(EFalse);
    30 	CleanupStack::PushL(self);
    31 	self->ConstructL(aField, aData);
    32 	CleanupStack::Pop(self);
    33 	return self;
    34 	}
    35 
    36 CMetaData* CMetaData::NewL(const TDesC16& aField, const TDesC16& aData)
    37 	{
    38 	CMetaData* self = new (ELeave) CMetaData(ETrue);
    39 	CleanupStack::PushL(self);
    40 	self->ConstructL(aField, aData);
    41 	CleanupStack::Pop(self);
    42 	return self;
    43 	}
    44 
    45 CMetaData* CMetaData::NewL(RReadStream& aStream)
    46 	{
    47 	CMetaData* self = new (ELeave) CMetaData(ETrue);
    48 	CleanupStack::PushL(self);
    49 	self->InternalizeL(aStream);
    50 	CleanupStack::Pop(self);
    51 	return self;
    52 	}
    53 
    54 CMetaData::CMetaData(TBool aUnicode) : iUnicode(aUnicode)
    55 	{
    56 	}
    57 
    58 void CMetaData::ConstructL(const TDesC8& aField, const TDesC8& aData)
    59 	{
    60 	// Store supplied data in both 8 bit and unicode forms
    61 	iField8 = aField.AllocL();
    62 	iData8 = aData.AllocL();
    63 
    64 	// Allocate space for 16 bit versions
    65 	iField = HBufC::NewL(iField8->Length());
    66 	iData = HBufC::NewL(iData8->Length());
    67 
    68 	// populate 16 bit versions with 8 bit values
    69 	iField->Des().Copy(*iField8);
    70 	iData->Des().Copy(*iData8);
    71 	}
    72 
    73 void CMetaData::ConstructL(const TDesC16& aField, const TDesC16& aData)
    74 	{
    75 	// Store supplied data in both 8 bit and unicode forms
    76 	iField = aField.AllocL();
    77 	iData = aData.AllocL();
    78 
    79 	// Allocate space for 8 bit versions
    80 	iField8 = HBufC8::NewL(iField->Des().Length());
    81 	iData8 = HBufC8::NewL(iData->Des().Length());
    82 
    83 	// populate 8 bit versions with 16 bit values
    84 	iField8->Des().Copy(*iField);
    85 	iData8->Des().Copy(*iData);
    86 	}
    87 
    88 CMetaData::~CMetaData()
    89 	{
    90 	delete iField;
    91 	delete iData;
    92 	delete iField8;
    93 	delete iData8;
    94 	}
    95 
    96 EXPORT_C const TDesC& CMetaData::Field() const
    97 	{
    98 	return *iField;
    99 	}
   100 		
   101 EXPORT_C const TDesC& CMetaData::Data() const
   102 	{
   103 	return *iData;
   104 	}
   105 
   106 EXPORT_C const TDesC8& CMetaData::Field8() const
   107 	{
   108 	return *iField8;
   109 	}
   110 		
   111 EXPORT_C const TDesC8& CMetaData::Data8() const
   112 	{
   113 	return *iData8;
   114 	}
   115 	
   116 void CMetaData::InternalizeL(RReadStream& aStream)
   117 	{
   118 	// Read the unicode field from the stream
   119 	iField = TCafUtils::ReadDescriptor16L(aStream);
   120 
   121 	// Read the unicode data from the stream
   122 	iData = TCafUtils::ReadDescriptor16L(aStream);
   123 
   124 	// Allocate space for 8 bit versions
   125 	iField8 = HBufC8::NewL(iField->Length());
   126 	iData8 = HBufC8::NewL(iData->Length());
   127 
   128 	// populate 8 bit versions with 16 bit values
   129 	iField8->Des().Copy(*iField);
   130 	iData8->Des().Copy(*iData);
   131 	}
   132 
   133 void CMetaData::ExternalizeL(RWriteStream& aStream) const
   134 	{
   135 	// Write unicode field to the stream
   136 	TCafUtils::WriteDescriptor16L(aStream, *iField);
   137 	TCafUtils::WriteDescriptor16L(aStream, *iData);
   138 	}