|
1 /* |
|
2 * Copyright (c) 2007-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwservicehandler.h> |
|
20 |
|
21 #include "hncomplexcondition.h" |
|
22 #include "hnliwutils.h" |
|
23 #include "hnglobals.h" |
|
24 #include "hnconditionfactory.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CHnComplexCondition* CHnComplexCondition::NewL( TDesC8 & aElement ) |
|
33 { |
|
34 CHnComplexCondition* self = new (ELeave) CHnComplexCondition(); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL( aElement ); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CHnComplexCondition::CHnComplexCondition() |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CHnComplexCondition::~CHnComplexCondition() |
|
55 { |
|
56 delete iRightCondition; |
|
57 delete iLeftCondition; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 TBool CHnComplexCondition::CheckForOrOnTheSameLevelL( TDesC8 & aConditionString ) |
|
65 { |
|
66 TBool ret = EFalse; |
|
67 TLex8 lexer( aConditionString ); |
|
68 TInt lookForClosingBrace( 0 ); |
|
69 while ( !lexer.Eos() ) |
|
70 { |
|
71 switch ( TUint( lexer.Get() ) ) |
|
72 { |
|
73 case EOpeningBrace : |
|
74 lookForClosingBrace++; |
|
75 break; |
|
76 case EClosingBrace : |
|
77 lookForClosingBrace--; |
|
78 ret = EFalse; |
|
79 lexer.Inc( lexer.Remainder().Length() ); |
|
80 break; |
|
81 case ELogicalOr: |
|
82 if (lookForClosingBrace == 0) |
|
83 { |
|
84 ret = ETrue; |
|
85 } |
|
86 break; |
|
87 } |
|
88 } |
|
89 return ret; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CHnComplexCondition::ConstructL( TDesC8 & aElement ) |
|
97 { |
|
98 TLex8 lexer( aElement ); |
|
99 TInt lookForClosingBrace( 0 ); |
|
100 while ( !lexer.Eos() ) |
|
101 { |
|
102 TChar character = lexer.Get(); |
|
103 switch ( TUint( character ) ) |
|
104 { |
|
105 case EOpeningBrace : |
|
106 lookForClosingBrace++; |
|
107 break; |
|
108 case EClosingBrace : |
|
109 lookForClosingBrace--; |
|
110 User::LeaveIfError( lookForClosingBrace ); |
|
111 break; |
|
112 case ELogicalAnd: |
|
113 { |
|
114 TPtrC8 remainder = lexer.Remainder(); |
|
115 if ( CheckForOrOnTheSameLevelL( remainder ) ) |
|
116 { |
|
117 break; |
|
118 } |
|
119 } |
|
120 case ELogicalOr: |
|
121 if (lookForClosingBrace == 0) |
|
122 { |
|
123 iOperation = (TOperator) TUint(character); |
|
124 TPtrC8 rightSide = lexer.Remainder(); |
|
125 iRightCondition = HnConditionFactory::NewL( rightSide ); |
|
126 lexer.UnGet(); |
|
127 TPtrC8 leftSide = lexer.MarkedToken(); |
|
128 iLeftCondition = HnConditionFactory::NewL( leftSide ); |
|
129 lexer.Inc( lexer.Remainder().Length() ); |
|
130 } |
|
131 break; |
|
132 } |
|
133 } |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 TBool CHnComplexCondition::ResultL( const CLiwGenericParamList& aQueryResults, |
|
141 TInt aPos ) |
|
142 { |
|
143 TBool ret = false; |
|
144 |
|
145 if ( iOperation == ELogicalAnd ) |
|
146 { |
|
147 ret = iLeftCondition->ResultL(aQueryResults, aPos) && |
|
148 iRightCondition->ResultL(aQueryResults, aPos); |
|
149 } |
|
150 else if ( iOperation == ELogicalOr ) |
|
151 { |
|
152 ret = iLeftCondition->ResultL(aQueryResults, aPos) || |
|
153 iRightCondition->ResultL(aQueryResults, aPos); |
|
154 } |
|
155 else |
|
156 { |
|
157 User::Leave(KErrNotFound); |
|
158 } |
|
159 |
|
160 return ret; |
|
161 } |
|
162 |