|
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: A unicode des buffer with automatic memory handling* |
|
15 */ |
|
16 |
|
17 #include "mdsclausebuffer.h" |
|
18 |
|
19 // --------------------------------------------------------------------------- |
|
20 // NewL |
|
21 // --------------------------------------------------------------------------- |
|
22 // |
|
23 EXPORT_C CMdsClauseBuffer* CMdsClauseBuffer::NewL( TInt aInitialSize ) |
|
24 { |
|
25 CMdsClauseBuffer* that = CMdsClauseBuffer::NewLC( aInitialSize ); |
|
26 CleanupStack::Pop( that ); |
|
27 return that; |
|
28 } |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // NewLC |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 EXPORT_C CMdsClauseBuffer* CMdsClauseBuffer::NewLC( TInt aInitialSize ) |
|
35 { |
|
36 CMdsClauseBuffer* that = new( ELeave ) CMdsClauseBuffer(); |
|
37 CleanupStack::PushL( that ); |
|
38 that->ConstructL( aInitialSize ); |
|
39 return that; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CMdCAutoBuf |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CMdsClauseBuffer::CMdsClauseBuffer() |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // ~CMdCAutoBuf |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CMdsClauseBuffer::~CMdsClauseBuffer() |
|
55 { |
|
56 delete iBuffer; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // ConstructL |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CMdsClauseBuffer::ConstructL( TInt aInitialSize ) |
|
64 { |
|
65 if ( aInitialSize < 1 ) |
|
66 { |
|
67 aInitialSize = 1; |
|
68 } |
|
69 iCurrentBufSize = aInitialSize; |
|
70 if (aInitialSize > 100000 || aInitialSize < 0) |
|
71 { |
|
72 aInitialSize = 0; |
|
73 } |
|
74 |
|
75 iBuffer = HBufC::NewL( iCurrentBufSize ); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // AppendL |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CMdsClauseBuffer::AppendL( const TDesC& aDes ) |
|
83 { |
|
84 AppendL( aDes, 0 ); |
|
85 } |
|
86 |
|
87 void CMdsClauseBuffer::AppendL( const TDesC& aDes, const TInt aAdditional ) |
|
88 { |
|
89 ReserveSpaceL( iBuffer->Size() + aDes.Length() + 1 + aAdditional ); |
|
90 |
|
91 iBuffer->Des().Append( aDes ); |
|
92 } |
|
93 |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // ReserveSpaceL |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 TBool CMdsClauseBuffer::ReserveSpaceL( TInt aRequired ) |
|
100 { |
|
101 // check if the current buffer is enough |
|
102 if ( iCurrentBufSize >= aRequired ) |
|
103 { |
|
104 return EFalse; |
|
105 } |
|
106 |
|
107 iCurrentBufSize = aRequired; |
|
108 |
|
109 // realloc and copy |
|
110 iBuffer = iBuffer->ReAllocL( iCurrentBufSize ); |
|
111 |
|
112 return ETrue; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // BufferL |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 TPtr CMdsClauseBuffer::BufferL() const |
|
120 { |
|
121 if( !iBuffer ) |
|
122 { |
|
123 User::Leave( KErrNotFound ); |
|
124 } |
|
125 |
|
126 return iBuffer->Des(); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // ConstBufferL |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 const TDesC& CMdsClauseBuffer::ConstBufferL() const |
|
134 { |
|
135 if( !iBuffer ) |
|
136 { |
|
137 User::Leave( KErrNotFound ); |
|
138 } |
|
139 |
|
140 return *iBuffer; |
|
141 } |