|
1 /* |
|
2 * Copyright (c) 2006 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: Array utils |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CAArrayUtils.h" |
|
21 #include "ChatDefinitions.h" |
|
22 #include "ChatDebugPrint.h" |
|
23 #include "CAUtils.h" |
|
24 |
|
25 const TInt KSelectionArrayGranularity = 5; |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 // CAArrayUtils::SetSelectionsLC() |
|
31 // Returns selection array and leaves it on stack |
|
32 // (other items were commented in a header). |
|
33 // --------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CArrayFixFlat<TInt>* CAArrayUtils::SetSelectionsLC( |
|
36 const CDesCArray& aSource1, |
|
37 const CDesCArray& aSource2 ) |
|
38 { |
|
39 CArrayFixFlat<TInt>* returnArray = new ( ELeave ) |
|
40 CArrayFixFlat<TInt>( KSelectionArrayGranularity ); |
|
41 CleanupStack::PushL( returnArray ); |
|
42 TInt source1Count( aSource1.MdcaCount() ); |
|
43 TInt source2Count( aSource2.MdcaCount() ); |
|
44 for ( TInt i( 0 ); i < source1Count; ++i ) |
|
45 { |
|
46 for ( TInt j( 0 ); j < source2Count; ++j ) |
|
47 { |
|
48 if ( aSource1.MdcaPoint( i ).CompareC( aSource2.MdcaPoint( j ) ) == 0 ) |
|
49 { |
|
50 returnArray->AppendL( j ); |
|
51 } |
|
52 } |
|
53 } |
|
54 return returnArray; |
|
55 } |
|
56 |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CAArrayUtils::CloneArrayLC |
|
61 // (other items were commented in a header). |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C CDesCArray* CAArrayUtils::CloneArrayLC( const MDesCArray& aSource ) |
|
65 { |
|
66 TInt count( aSource.MdcaCount() ); |
|
67 CDesCArray* array = new( ELeave )CDesCArrayFlat( count == 0 ? 1 : count ); |
|
68 CleanupStack::PushL( array ); |
|
69 for ( TInt i( 0 ); i < count; ++i ) |
|
70 { |
|
71 TPtrC text( aSource.MdcaPoint( i ) ); |
|
72 CHAT_DP( D_CHAT_LIT( " CloneArrayLC [%d] %S" ), i, &text ); |
|
73 array->AppendL( text ); |
|
74 } |
|
75 CHAT_DP_TXT( "----------------------[endClone]----------------------" ); |
|
76 return array; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CAArrayUtils::CreateDiffLC |
|
81 // (other items were commented in a header). |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C CDesCArray* CAArrayUtils::CreateDiffLC( const CDesCArray& aArrayDiff, |
|
85 const CDesCArray& aArrayTest ) |
|
86 { |
|
87 CDesCArray* array = new( ELeave )CDesCArrayFlat( KArrayGranularity ); |
|
88 CleanupStack::PushL( array ); |
|
89 TInt count( aArrayDiff.MdcaCount() ); |
|
90 for ( TInt i( 0 ); i < count; ++i ) |
|
91 { |
|
92 TPtrC id( aArrayDiff.MdcaPoint( i ) ); |
|
93 TInt pos( 0 ); |
|
94 if ( aArrayTest.Find( id, pos, ECmpCollated ) != 0 ) |
|
95 { |
|
96 // item that is in aArrayDiff, but not in aArrayTest |
|
97 // add to resulting array |
|
98 CHAT_DP( D_CHAT_LIT( " CreateDiffLC [%d] %S" ), i, &id ); |
|
99 array->AppendL( id ); |
|
100 } |
|
101 } |
|
102 CHAT_DP_TXT( "-----------------------[endDiff]----------------------" ); |
|
103 return array; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CAArrayUtils::AppendArrayL |
|
108 // (other items were commented in a header). |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C void CAArrayUtils::AppendArrayL( const CDesCArray& aSource, |
|
112 CDesCArray& aDest ) |
|
113 { |
|
114 TInt count( aSource.MdcaCount() ); |
|
115 for ( TInt i( 0 ); i < count; ++i ) |
|
116 { |
|
117 aDest.AppendL( aSource.MdcaPoint( i ) ); |
|
118 } |
|
119 } |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CAArrayUtils::AppendIfNotFoundL |
|
122 // (other items were commented in a header). |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 |
|
126 EXPORT_C TBool CAArrayUtils::AppendIfNotFoundL( CDesCArray& aDest, const TDesC& aPtr ) |
|
127 { |
|
128 TInt pos( KErrNotFound ); |
|
129 if ( aDest.Find( aPtr, pos, ECmpCollated ) != 0 ) |
|
130 { |
|
131 // not found |
|
132 aDest.AppendL( aPtr ); |
|
133 return ETrue; |
|
134 } |
|
135 return EFalse; |
|
136 } |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CAArrayUtils::DeleteIfFound |
|
139 // (other items were commented in a header). |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 |
|
143 EXPORT_C TBool CAArrayUtils::DeleteIfFound( CDesCArray& aDest, const TDesC& aPtr ) |
|
144 { |
|
145 TInt pos( KErrNotFound ); |
|
146 if ( aDest.Find( aPtr, pos, ECmpCollated ) == 0 ) |
|
147 { |
|
148 aDest.Delete( pos ); |
|
149 return EFalse; |
|
150 } |
|
151 return ETrue; |
|
152 } |
|
153 |
|
154 |
|
155 // End of File |