textrendering/textformatting/tagma/TmBufferBase.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 15 Sep 2010 14:10:32 +0300
branchRCL_3
changeset 65 795cadd2b83a
parent 55 336bee5c2d35
permissions -rw-r--r--
Revision: 201021 Kit: 201036

/*
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include "TMSTD.H"

CTmBufferBase::~CTmBufferBase()
	{
	User::Free(iData);
	}

void CTmBufferBase::Truncate(TInt aLength)
	{
	if (aLength > iLength || aLength < 0)
		TmPanic(EBadTruncationLength);
	iLength = aLength;
	}

TAny* CTmBufferBase::ExtendL(TInt aSizeOfData)
	{
	if (iLength == iAllocated)
		GrowL(iExpandSize,aSizeOfData);
	TInt offset = iLength * aSizeOfData;
	iLength += 1;
	return REINTERPRET_CAST(TUint8*,iData) + offset;
	}

void CTmBufferBase::DoAppendL(const TAny* aItem,TInt aCount,TInt aSizeOfData)
	{
	int deficit = iLength + aCount - iAllocated;
	if (deficit > 0)
		{
		int n = deficit % iExpandSize;
		if (n)
			deficit += iExpandSize - n;
		GrowL(deficit,aSizeOfData);
		}
	Mem::Copy(REINTERPRET_CAST(TUint8*,iData) + iLength * aSizeOfData, aItem,
		aCount * aSizeOfData);
	iLength += aCount;
	}

void CTmBufferBase::GrowL(TInt aExtra,TInt aSizeOfData)
	{
	iData = User::ReAllocL(iData,(iAllocated + aExtra) * aSizeOfData);
	iAllocated += aExtra;
	}