email/imum/Utils/Src/IMSPageResourceControl.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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:  IMSPageResourceControl.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <cstack.h>                     // CStack
       
    22 
       
    23 #include "IMSPageResourceControl.h"
       
    24 #include "ImumUtilsLogging.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 // EXTERNAL FUNCTION PROTOTYPES
       
    28 // CONSTANTS
       
    29 enum TIMSResourcePagePanicCode
       
    30     {
       
    31     EIRPPNoError = 0,
       
    32     EIRPPWrongType,
       
    33     EIRPPStackEmpty,
       
    34     EIRPPStackNull,
       
    35     EIRPPArrayNull,
       
    36     EIRPPUnknownType
       
    37     };
       
    38 
       
    39 _LIT( KIMSResourcePagePanic, "IMSResourcePagePanic" );
       
    40 
       
    41 // MACROS
       
    42 // LOCAL CONSTANTS AND MACROS
       
    43 // MODULE DATA STRUCTURES
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 void Panic( const TIMSResourcePagePanicCode aReason );
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 
       
    49 // ============================ LOCAL FUNCTIONS ===============================
       
    50 
       
    51 void Panic( const TIMSResourcePagePanicCode aReason )
       
    52     {
       
    53     User::Panic( KIMSResourcePagePanic, aReason );
       
    54     }
       
    55 
       
    56 // ============================ MEMBER FUNCTIONS ===============================
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CIMSPageResourceControl::CIMSPageResourceControl()
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 CIMSPageResourceControl::CIMSPageResourceControl()
       
    63     {
       
    64     IMUM_CONTEXT( CIMSPageResourceControl::CIMSPageResourceControl, 0, KLogUi );
       
    65 
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CIMSPageResourceControl::~CIMSPageResourceControl()
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CIMSPageResourceControl::~CIMSPageResourceControl()
       
    73     {
       
    74     IMUM_CONTEXT( CIMSPageResourceControl::~CIMSPageResourceControl, 0, KLogUi );
       
    75 
       
    76     if ( iPageResources )
       
    77         {
       
    78         iPageResources->ResetAndDestroy();
       
    79         }
       
    80 
       
    81     delete iPageResources;
       
    82     iPageResources = NULL;
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // CIMSPageResourceControl::ConstructL()
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 void CIMSPageResourceControl::ConstructL()
       
    90     {
       
    91     IMUM_CONTEXT( CIMSPageResourceControl::ConstructL, 0, KLogUi );
       
    92 
       
    93     iPageResources = new ( ELeave ) CResourceStackArray( EIPRLastPage );
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CIMSPageResourceControl::NewL()
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 CIMSPageResourceControl* CIMSPageResourceControl::NewL()
       
   101     {
       
   102     IMUM_STATIC_CONTEXT( CIMSPageResourceControl::NewL, 0, utils, KLogUi );
       
   103 
       
   104     CIMSPageResourceControl* self = NewLC();
       
   105     CleanupStack::Pop( self );
       
   106 
       
   107     return self;
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // CIMSPageResourceControl::NewLC()
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 CIMSPageResourceControl* CIMSPageResourceControl::NewLC()
       
   115     {
       
   116     IMUM_STATIC_CONTEXT( CIMSPageResourceControl::NewLC, 0, utils, KLogUi );
       
   117 
       
   118     CIMSPageResourceControl* self = new ( ELeave ) CIMSPageResourceControl();
       
   119     CleanupStack::PushL( self );
       
   120     self->ConstructL();
       
   121 
       
   122     return self;
       
   123     }
       
   124 
       
   125 /******************************************************************************
       
   126 
       
   127 
       
   128 
       
   129 ******************************************************************************/
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CIMSPageResourceControl::PushResourceL()
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 void CIMSPageResourceControl::PushResourceL(
       
   136     const TInt aType,
       
   137     const TInt aPageResource )
       
   138     {
       
   139     IMUM_CONTEXT( CIMSPageResourceControl::PushResourceL, 0, KLogUi );
       
   140 
       
   141     Stack( aType ).AppendL( aPageResource );
       
   142     }
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CIMSPageResourceControl::Resource()
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 TInt CIMSPageResourceControl::Resource(
       
   149     const TInt aType,
       
   150     const TBool aRemove )
       
   151     {
       
   152     IMUM_CONTEXT( CIMSPageResourceControl::Resource, 0, KLogUi );
       
   153 
       
   154     CResourceStack& stack = Stack( aType );
       
   155     TInt index = stack.Count() - 1;
       
   156     if ( !aRemove || aRemove && !index )
       
   157         {
       
   158         return stack[index];
       
   159         }
       
   160     else
       
   161         {
       
   162         TInt resource = stack[index];
       
   163         stack.Delete( index );
       
   164         return resource;
       
   165         }
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CIMSPageResourceControl::Count()
       
   170 // ----------------------------------------------------------------------------
       
   171 //
       
   172 TInt CIMSPageResourceControl::Count( const TInt aType )
       
   173     {
       
   174     IMUM_CONTEXT( CIMSPageResourceControl::Count, 0, KLogUi );
       
   175 
       
   176     return Stack( aType ).Count();
       
   177     }
       
   178 
       
   179 // ----------------------------------------------------------------------------
       
   180 // CIMSPageResourceControl::CreateStackL()
       
   181 // ----------------------------------------------------------------------------
       
   182 //
       
   183 CResourceStack* CIMSPageResourceControl::CreateStackL(
       
   184     const TInt aPageResource )
       
   185     {
       
   186     IMUM_CONTEXT( CIMSPageResourceControl::CreateStackL, 0, KLogUi );
       
   187 
       
   188     __ASSERT_DEBUG( iPageResources != NULL, Panic( EIRPPArrayNull ) );
       
   189 
       
   190     CResourceStack* stack = new ( ELeave ) CResourceStack( EIPRLastPage );
       
   191     CleanupStack::PushL( stack );
       
   192 
       
   193     iPageResources->AppendL( stack );
       
   194     stack->AppendL( aPageResource );
       
   195 
       
   196     CleanupStack::Pop( stack );
       
   197 
       
   198     return stack;
       
   199     }
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // CIMSPageResourceControl::operator[]()
       
   203 // ----------------------------------------------------------------------------
       
   204 //
       
   205 TInt CIMSPageResourceControl::operator[]( const TInt aType )
       
   206     {
       
   207     IMUM_CONTEXT( CIMSPageResourceControl::operator, 0, KLogUi );
       
   208 
       
   209     return Resource( aType );
       
   210     }
       
   211 
       
   212 /******************************************************************************
       
   213 
       
   214     TOOLS
       
   215 
       
   216 ******************************************************************************/
       
   217 
       
   218 
       
   219 // ----------------------------------------------------------------------------
       
   220 // CIMSPageResourceControl::Stack()
       
   221 // ----------------------------------------------------------------------------
       
   222 //
       
   223 CResourceStack& CIMSPageResourceControl::Stack( const TInt aType )
       
   224     {
       
   225     IMUM_CONTEXT( CIMSPageResourceControl::Stack, 0, KLogUi );
       
   226 
       
   227     __ASSERT_DEBUG( iPageResources->Count(), Panic( EIRPPStackEmpty ) );
       
   228     __ASSERT_DEBUG( aType < iPageResources->Count(), Panic( EIRPPUnknownType ) );
       
   229     __ASSERT_DEBUG( ( *iPageResources )[aType] != NULL, Panic( EIRPPStackNull ) );
       
   230     __ASSERT_DEBUG( iPageResources != NULL, Panic( EIRPPArrayNull ) );
       
   231 
       
   232     return *( *iPageResources )[aType];
       
   233     }
       
   234 
       
   235 // End of File