upnpharvester/common/cmlibrary/src/cmrule.cpp
changeset 0 7f85d04be362
child 30 5ec426854821
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:      Capsulating Rule parameters
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <s32mem.h>
       
    26 #include "cmparam.h"
       
    27 #include "cmrule.h"
       
    28 #include "msdebug.h"
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt KRuleParamArrayGranularity = 16;
       
    32 
       
    33 // ======== LOCAL FUNCTIONS ========
       
    34 // ---------------------------------------------------------------------------
       
    35 // NewL
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CCmRule* CCmRule::NewL()
       
    39     {    
       
    40     CCmRule* self = CCmRule::NewLC();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44  
       
    45 // ---------------------------------------------------------------------------
       
    46 // NewLC
       
    47 // ---------------------------------------------------------------------------
       
    48 //    
       
    49 CCmRule* CCmRule::NewLC()
       
    50     {    
       
    51     CCmRule* self = new ( ELeave ) CCmRule(  );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL(  ); 
       
    54     return self;  
       
    55     }    
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Destructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CCmRule::~CCmRule()
       
    62     {
       
    63     iRuleParamsArray.ResetAndDestroy();     
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Adds rule param
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 TInt CCmRule::AddRuleParamL( const TDesC8& aParam )
       
    71     {
       
    72     CCmParam* param = CCmParam::NewLC();
       
    73     param->SetComparisonDataL( aParam );
       
    74     iRuleParamsArray.Append( param ); // transfer ownership
       
    75     CleanupStack::Pop( param );
       
    76     TInt index = iRuleParamsArray.Count() - 1;    
       
    77     return index;    
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // Adds rule param ( indexed param )
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 TInt CCmRule::AddRuleParamL( TInt aParam )
       
    85     {
       
    86     CCmParam* param = CCmParam::NewLC();
       
    87     param->SetComparisonData( aParam );
       
    88     iRuleParamsArray.Append( param ); // transfer ownership
       
    89     CleanupStack::Pop( param );
       
    90     TInt index = iRuleParamsArray.Count() - 1;    
       
    91     return index;    
       
    92     }
       
    93     
       
    94 // ---------------------------------------------------------------------------
       
    95 // Loads rule
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CCmRule::Rule( TCmMetadataField* aDataField, TCmOperatorType* aOperator, 
       
    99     TInt* aParamCount )
       
   100     {
       
   101     *aDataField = iMetadataField;
       
   102     *aOperator = iOperator;
       
   103     *aParamCount = iRuleParamsArray.Count();
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Loads rule param
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CCmRule::RuleParamL( TInt aParamIndex, TPtrC8* aParam )
       
   111     {
       
   112     // check parameter
       
   113     if ( aParamIndex < 0 || aParamIndex >= iRuleParamsArray.Count() ) 
       
   114         {
       
   115         User::Leave( KErrArgument );
       
   116         }
       
   117         
       
   118     iRuleParamsArray[aParamIndex]->Param( aParam );
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // Loads rule param
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void CCmRule::RuleParamL( TInt aParamIndex, TInt& aParam )
       
   126     {
       
   127     // check parameter
       
   128     if ( aParamIndex < 0 || aParamIndex >= iRuleParamsArray.Count() ) 
       
   129         {
       
   130         User::Leave( KErrArgument );
       
   131         }
       
   132         
       
   133     iRuleParamsArray[aParamIndex]->Param( aParam );
       
   134     }
       
   135         
       
   136 // ---------------------------------------------------------------------------
       
   137 // Sets metadata field
       
   138 // ---------------------------------------------------------------------------
       
   139 //    
       
   140 void CCmRule::SetMetadataField( TCmMetadataField aDataField )
       
   141     {
       
   142     iMetadataField = aDataField;
       
   143     }
       
   144     
       
   145 // ---------------------------------------------------------------------------
       
   146 // Sets operator of the rule
       
   147 // ---------------------------------------------------------------------------
       
   148 //    
       
   149 void CCmRule::SetOperator( TCmOperatorType aOperator )
       
   150     {
       
   151     iOperator = aOperator;
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // Return count of the parameter 
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 TInt CCmRule::RuleParamsCount() const
       
   159     {
       
   160     return iRuleParamsArray.Count();    
       
   161     }
       
   162     
       
   163 // ---------------------------------------------------------------------------
       
   164 // CCmRule::ExternalizeL
       
   165 // C++ default constructor can NOT contain any code, that
       
   166 // might leave.
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CCmRule::ExternalizeL( RWriteStream& aStream ) const
       
   170     {
       
   171     aStream.WriteInt16L( (TInt)iMetadataField );
       
   172        
       
   173     aStream.WriteInt16L( (TInt)iOperator );    
       
   174     aStream.WriteInt16L( iRuleParamsArray.Count() );    
       
   175     
       
   176     for ( TInt index(0); index < iRuleParamsArray.Count(); index++ )
       
   177         {
       
   178         iRuleParamsArray[index]->ExternalizeL( aStream );
       
   179         }
       
   180           
       
   181     }
       
   182         
       
   183 // ---------------------------------------------------------------------------
       
   184 // CCmRule::InternalizeL
       
   185 // C++ default constructor can NOT contain any code, that
       
   186 // might leave.
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CCmRule::InternalizeL( RReadStream& aStream )
       
   190     {
       
   191     // Content
       
   192     iMetadataField = (TCmMetadataField)aStream.ReadInt16L();    
       
   193     
       
   194     iOperator = (TCmOperatorType)aStream.ReadInt16L();
       
   195     
       
   196     // cleanup
       
   197     iRuleParamsArray.ResetAndDestroy();
       
   198     
       
   199     // rule param count
       
   200     TInt ruleParamCount = aStream.ReadInt16L();
       
   201     
       
   202     // Then internalize them from the stream one by one
       
   203     for (TInt index = 0; index < ruleParamCount; index++ )
       
   204         {
       
   205         CCmParam* newRuleParam = CCmParam::NewLC();
       
   206         newRuleParam->InternalizeL( aStream );   
       
   207         iRuleParamsArray.AppendL( newRuleParam );
       
   208         CleanupStack::Pop( newRuleParam ); 
       
   209         newRuleParam = NULL;
       
   210         }
       
   211                      
       
   212     }
       
   213             
       
   214 // ---------------------------------------------------------------------------
       
   215 // Default constructor
       
   216 // ---------------------------------------------------------------------------
       
   217 //    
       
   218 CCmRule::CCmRule() : iRuleParamsArray( KRuleParamArrayGranularity )
       
   219     {
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // ConstructL
       
   224 // ---------------------------------------------------------------------------
       
   225 //    
       
   226 void CCmRule::ConstructL()
       
   227     {
       
   228     }    
       
   229 
       
   230 // End of file
       
   231