|
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: CCFLess class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "cfless.h" |
|
22 #include "cfcontextobject.h" |
|
23 #include "cfcontextoperationutils.h" |
|
24 #include "cfbasicoptrace.h" |
|
25 |
|
26 #include <gmxmlnode.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT( KScriptLessName, "less" ); |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CCFLess::CCFLess |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CCFLess::CCFLess( MCFOperationServices& aServices, |
|
40 CCFOperationNode* aParent, |
|
41 HBufC* aName, |
|
42 HBufC* aSource, |
|
43 const CCFContextOperation::TCmpType aType ) |
|
44 : CCFContextOperation( aServices, aParent, aName, aSource ), |
|
45 iType( aType ) |
|
46 { |
|
47 FUNC_LOG; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CCFLess::ConstructL |
|
52 // Symbian 2nd phase constructor can leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CCFLess::ConstructL( const TDesC& aCmpVal ) |
|
56 { |
|
57 FUNC_LOG; |
|
58 |
|
59 iCmpValue = aCmpVal.AllocL(); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CCFLess::NewL |
|
64 // Two-phased constructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CCFLess* CCFLess::NewL( MCFOperationServices& aServices, |
|
68 CCFOperationNode* aParent, |
|
69 TDesC& aName, |
|
70 TDesC& aSource, |
|
71 const CCFContextOperation::TCmpType aType, |
|
72 const TDesC& aCmpVal ) |
|
73 { |
|
74 FUNC_LOG; |
|
75 |
|
76 CCFLess* self = NewLC( aServices, aParent, aName, aSource, aType, aCmpVal ); |
|
77 CleanupStack::Pop( self ); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CCFLess::NewLC |
|
83 // Two-phased constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CCFLess* CCFLess::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 CCFLess* self |
|
98 = new( ELeave ) CCFLess( 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 ); // push self again |
|
108 return self; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CCFLess::ParseL |
|
113 // Construction with parsing from a DOM node. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CCFLess* CCFLess::ParseL( MCFOperationServices& aServices, |
|
117 CCFOperationNode* aParent, |
|
118 CMDXMLNode& aNode ) |
|
119 { |
|
120 FUNC_LOG; |
|
121 |
|
122 if ( aNode.NodeName().CompareF( KScriptLessName ) != 0 ) |
|
123 { |
|
124 return NULL; // Cannot create less 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 CCFLess* 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( "CCFLess::ParseL - Unsupported arguments" ); |
|
156 } |
|
157 |
|
158 CREATE_DOM_INFO( self, aNode ); |
|
159 |
|
160 return self; |
|
161 } |
|
162 |
|
163 |
|
164 // Destructor |
|
165 CCFLess::~CCFLess() |
|
166 { |
|
167 FUNC_LOG; |
|
168 |
|
169 delete iCmpValue; |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CCFLess::IsTrueL |
|
174 // |
|
175 // (other items were commented in a header). |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TBool CCFLess::IsTrueL( const CCFContextObject& aContextObject ) |
|
179 { |
|
180 FUNC_LOG; |
|
181 |
|
182 TBool value( EFalse ); |
|
183 switch ( iType ) |
|
184 { |
|
185 case CCFContextOperation::EIntCmp: |
|
186 { |
|
187 TInt a = CFContextOperationUtils::StringToIntL( *iCmpValue ); |
|
188 TInt b = CFContextOperationUtils::StringToIntL( |
|
189 aContextObject.Value() ); |
|
190 value = b < a; |
|
191 break; |
|
192 } |
|
193 case CCFContextOperation::ETimeCmp: |
|
194 { |
|
195 TTime a = CFContextOperationUtils::StringToTimeL( *iCmpValue ); |
|
196 TTime b = CFContextOperationUtils::StringToTimeL( |
|
197 aContextObject.Value() ); |
|
198 value = b < a; |
|
199 break; |
|
200 } |
|
201 case CCFContextOperation::EFloatCmp: |
|
202 { |
|
203 TReal a = CFContextOperationUtils::StringToRealL( *iCmpValue ); |
|
204 TReal b = CFContextOperationUtils::StringToRealL( |
|
205 aContextObject.Value() ); |
|
206 value = b < a; |
|
207 break; |
|
208 } |
|
209 case CCFContextOperation::EStringCmp: |
|
210 default: |
|
211 { |
|
212 value = aContextObject.Value() < ( *iCmpValue ); |
|
213 break; |
|
214 } |
|
215 } |
|
216 |
|
217 return value; |
|
218 } |