|
1 /* |
|
2 * Copyright (c) 2002-2008 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: CCFNotEqual class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cfnotequal.h" |
|
22 #include "cfcontextobject.h" |
|
23 #include "cfcontextoperationutils.h" |
|
24 #include "cfbasicoptrace.h" |
|
25 |
|
26 #include <gmxmlnode.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT( KScriptNotEqualName, "notEqual" ); |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CCFNotEqual::CCFNotEqual |
|
35 // C++ default constructor can NOT contain any code, that might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CCFNotEqual::CCFNotEqual( MCFOperationServices& aServices, |
|
39 CCFOperationNode* aParent, |
|
40 HBufC* aName, |
|
41 HBufC* aSource, |
|
42 const CCFContextOperation::TCmpType aType ) |
|
43 : CCFContextOperation( aServices, aParent, aName, aSource ), |
|
44 iType( aType ) |
|
45 { |
|
46 FUNC_LOG; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CCFNotEqual::ConstructL |
|
51 // Symbian 2nd phase constructor can leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CCFNotEqual::ConstructL( const TDesC& aCmpVal ) |
|
55 { |
|
56 FUNC_LOG; |
|
57 |
|
58 iCmpValue = aCmpVal.AllocL(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CCFNotEqual::NewL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CCFNotEqual* CCFNotEqual::NewL( MCFOperationServices& aServices, |
|
67 CCFOperationNode* aParent, |
|
68 TDesC& aName, |
|
69 TDesC& aSource, |
|
70 const CCFContextOperation::TCmpType aType, |
|
71 const TDesC& aCmpVal ) |
|
72 { |
|
73 FUNC_LOG; |
|
74 |
|
75 CCFNotEqual* self |
|
76 = NewLC( aServices, aParent, aName, aSource, aType, aCmpVal ); |
|
77 CleanupStack::Pop( self ); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CCFNotEqual::NewLC |
|
83 // Two-phased constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CCFNotEqual* CCFNotEqual::NewLC( MCFOperationServices& aServices, |
|
87 CCFOperationNode* aParent, |
|
88 TDesC& aName, |
|
89 TDesC& aSource, |
|
90 const CCFContextOperation::TCmpType aType, |
|
91 const TDesC& aCmpVal ) |
|
92 { |
|
93 FUNC_LOG; |
|
94 |
|
95 HBufC* name = aName.AllocLC(); |
|
96 HBufC* source = aSource.AllocLC(); |
|
97 CCFNotEqual* self |
|
98 = new( ELeave ) CCFNotEqual( aServices, aParent, name, source, aType ); |
|
99 CleanupStack::PushL( self ); |
|
100 self->ConstructL( aCmpVal ); |
|
101 |
|
102 // Cleanup |
|
103 CleanupStack::Pop( self ); |
|
104 CleanupStack::Pop( source ); |
|
105 CleanupStack::Pop( name ); |
|
106 |
|
107 CleanupStack::PushL( self ); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CCFNotEqual::ParseL |
|
113 // Construction with parsing from a DOM node. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CCFNotEqual* CCFNotEqual::ParseL( MCFOperationServices& aServices, |
|
117 CCFOperationNode* aParent, |
|
118 CMDXMLNode& aNode ) |
|
119 { |
|
120 FUNC_LOG; |
|
121 |
|
122 if ( aNode.NodeName().CompareF( KScriptNotEqualName ) != 0 ) |
|
123 { |
|
124 return NULL; // Cannot create not equal operation from the given node. |
|
125 } |
|
126 |
|
127 TPtrC contextSource; |
|
128 TPtrC contextType; |
|
129 TCmpType cmpType( CCFContextOperation::EInvalidCmpType ); |
|
130 TPtrC cmpValue; |
|
131 TInt contextLevelDelay( 0 ); |
|
132 TBool argsOK = CFContextOperationUtils::ParseTwoComparisonArgs( aNode, |
|
133 contextSource, |
|
134 contextType, |
|
135 cmpType, |
|
136 cmpValue, |
|
137 contextLevelDelay ); |
|
138 |
|
139 CCFNotEqual* self = NULL; |
|
140 if ( argsOK ) |
|
141 { |
|
142 self = NewL( aServices, |
|
143 aParent, |
|
144 contextType, |
|
145 contextSource, |
|
146 cmpType, |
|
147 cmpValue ); |
|
148 if ( contextLevelDelay ) |
|
149 { |
|
150 self->iContextLevelDelay = contextLevelDelay; |
|
151 } |
|
152 } |
|
153 else |
|
154 { |
|
155 INFO( "CCFNotEqual::ParseL - Unsupported arguments" ); |
|
156 } |
|
157 |
|
158 CREATE_DOM_INFO( self, aNode ); |
|
159 |
|
160 return self; |
|
161 } |
|
162 |
|
163 |
|
164 // Destructor |
|
165 CCFNotEqual::~CCFNotEqual() |
|
166 { |
|
167 FUNC_LOG; |
|
168 |
|
169 delete iCmpValue; |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CCFNotEqual::IsTrueL |
|
174 // |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CCFNotEqual::IsTrueL( const CCFContextObject& aContextObject ) |
|
178 { |
|
179 FUNC_LOG; |
|
180 |
|
181 TBool value( EFalse ); |
|
182 switch ( iType ) |
|
183 { |
|
184 case CCFContextOperation::EIntCmp: |
|
185 { |
|
186 TInt a = CFContextOperationUtils::StringToIntL( *iCmpValue ); |
|
187 TInt b = CFContextOperationUtils::StringToIntL( |
|
188 aContextObject.Value() ); |
|
189 value = ( a != b ); |
|
190 break; |
|
191 } |
|
192 case CCFContextOperation::ETimeCmp: |
|
193 { |
|
194 TTime a = CFContextOperationUtils::StringToTimeL( *iCmpValue ); |
|
195 TTime b = CFContextOperationUtils::StringToTimeL( |
|
196 aContextObject.Value() ); |
|
197 value = ( a != b ); |
|
198 break; |
|
199 } |
|
200 case CCFContextOperation::EFloatCmp: |
|
201 { |
|
202 TReal a = CFContextOperationUtils::StringToRealL( *iCmpValue ); |
|
203 TReal b = CFContextOperationUtils::StringToRealL( |
|
204 aContextObject.Value() ); |
|
205 value = ( a != b ); |
|
206 break; |
|
207 } |
|
208 case CCFContextOperation::EStringCmp: |
|
209 default: |
|
210 { |
|
211 value = ( *iCmpValue != aContextObject.Value() ); |
|
212 break; |
|
213 } |
|
214 } |
|
215 |
|
216 return value; |
|
217 } |