uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiObserverArray.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __HUI_OBSERVER_ARRAY_H__
       
    21 #define __HUI_OBSERVER_ARRAY_H__
       
    22 
       
    23 #include <uiacceltk/HuiPanic.h>
       
    24 
       
    25 /**
       
    26  * Observer array template.
       
    27  */
       
    28 template< class T >
       
    29 class RHuiObserverArray
       
    30     {
       
    31 public:
       
    32     RHuiObserverArray()
       
    33         {
       
    34         }
       
    35 
       
    36     void Reset()
       
    37         {
       
    38         iObservers.Reset();
       
    39         }
       
    40         
       
    41     void Close()
       
    42         {
       
    43         iObservers.Close();
       
    44         }        
       
    45     
       
    46     void AppendL(T& aObserver)
       
    47         {
       
    48         __ASSERT_ALWAYS(iObservers.Find(&aObserver) == KErrNotFound,
       
    49                         THuiPanic::Panic(THuiPanic::EDuplicateObserver));
       
    50         User::LeaveIfError( iObservers.Append(&aObserver) );
       
    51         }
       
    52 
       
    53     void AppendIfNotFoundL(T& aObserver)
       
    54         {
       
    55         if(iObservers.Find(&aObserver) == KErrNotFound)
       
    56             {
       
    57             User::LeaveIfError( iObservers.Append(&aObserver) );
       
    58             }
       
    59         }
       
    60         
       
    61     void Remove(T& aObserver)
       
    62         {
       
    63         TInt index = iObservers.Find(&aObserver);
       
    64         if(index == KErrNotFound)
       
    65             {
       
    66             THuiPanic::Panic(THuiPanic::EObserverNotFound);
       
    67             }
       
    68         iObservers.Remove(index);
       
    69         }
       
    70 
       
    71     void RemoveIfFound(T& aObserver)
       
    72         {
       
    73         TInt index = iObservers.Find(&aObserver);
       
    74         if(index != KErrNotFound)
       
    75             {
       
    76             iObservers.Remove(index);
       
    77             }
       
    78         }
       
    79 
       
    80     inline TInt Count() const
       
    81         {
       
    82         return iObservers.Count();
       
    83         }
       
    84         
       
    85     inline T& operator[] (TInt aIndex) const
       
    86         {
       
    87         return *iObservers[aIndex];
       
    88         }
       
    89 
       
    90 
       
    91 private:
       
    92 
       
    93     /* Private methods. */
       
    94     
       
    95     /**
       
    96      * Assignment is not allowed.  
       
    97      */
       
    98     RHuiObserverArray& operator = (const RHuiObserverArray& aObserverArray);
       
    99     
       
   100     
       
   101 private:
       
   102     RArray<T*> iObservers;
       
   103     TInt iSpare1;
       
   104     TInt iSpare2;
       
   105     };
       
   106     
       
   107 
       
   108 #endif // __HUI_OBSERVER_ARRAY_H__