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