textrendering/textformatting/tagma/TmBufferBase.cpp
author Pat Downey <patd@symbian.org>
Wed, 01 Sep 2010 12:39:40 +0100
branchRCL_3
changeset 55 336bee5c2d35
parent 54 748ec5531811
permissions -rw-r--r--
Revert incorrect RCL_3 drop: Revision: 201021 Kit: 201035

/*
* 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;
	}