|
1 /* |
|
2 * Copyright (c) 2006-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 "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 "TMSTD.H" |
|
20 |
|
21 CTmBufferBase::~CTmBufferBase() |
|
22 { |
|
23 User::Free(iData); |
|
24 } |
|
25 |
|
26 void CTmBufferBase::Truncate(TInt aLength) |
|
27 { |
|
28 if (aLength > iLength || aLength < 0) |
|
29 TmPanic(EBadTruncationLength); |
|
30 iLength = aLength; |
|
31 } |
|
32 |
|
33 TAny* CTmBufferBase::ExtendL(TInt aSizeOfData) |
|
34 { |
|
35 if (iLength == iAllocated) |
|
36 GrowL(iExpandSize,aSizeOfData); |
|
37 TInt offset = iLength * aSizeOfData; |
|
38 iLength += 1; |
|
39 return REINTERPRET_CAST(TUint8*,iData) + offset; |
|
40 } |
|
41 |
|
42 void CTmBufferBase::DoAppendL(const TAny* aItem,TInt aCount,TInt aSizeOfData) |
|
43 { |
|
44 int deficit = iLength + aCount - iAllocated; |
|
45 if (deficit > 0) |
|
46 { |
|
47 int n = deficit % iExpandSize; |
|
48 if (n) |
|
49 deficit += iExpandSize - n; |
|
50 GrowL(deficit,aSizeOfData); |
|
51 } |
|
52 Mem::Copy(REINTERPRET_CAST(TUint8*,iData) + iLength * aSizeOfData, aItem, |
|
53 aCount * aSizeOfData); |
|
54 iLength += aCount; |
|
55 } |
|
56 |
|
57 void CTmBufferBase::GrowL(TInt aExtra,TInt aSizeOfData) |
|
58 { |
|
59 iData = User::ReAllocL(iData,(iAllocated + aExtra) * aSizeOfData); |
|
60 iAllocated += aExtra; |
|
61 } |