atext/server/inc/utils.h
changeset 0 29b1cd4cb562
child 51 20ac952a623c
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 /*
       
     2 * Copyright (c) 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:  Defines utility functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef UTILS_H
       
    20 #define UTILS_H
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 template <class T>
       
    25 class CleanupResetDestroyClose
       
    26     {
       
    27 public:
       
    28     inline static void PushL(T& aRef)
       
    29         {
       
    30         CleanupStack::PushL(TCleanupItem(&ResetDestroyClose,&aRef));
       
    31         }
       
    32 private:
       
    33     static void ResetDestroyClose(TAny *aPtr)
       
    34         {
       
    35         static_cast<T*>(aPtr)->ResetAndDestroy();
       
    36         static_cast<T*>(aPtr)->Close();
       
    37         }
       
    38     };
       
    39 
       
    40 /**
       
    41  * Pushes an object into CleanupStack and specifies the cleanup
       
    42  * function as ResetAndDestroy() and Close().
       
    43 */
       
    44 template <class T>
       
    45 inline void CleanupResetDestroyClosePushL(T& aRef)
       
    46     {CleanupResetDestroyClose<T>::PushL(aRef);}
       
    47 
       
    48 template <class T>
       
    49 static TBool OperatorEqual(const T& aT1, const T& aT2)
       
    50     {
       
    51     return aT1 == aT2;
       
    52     }
       
    53 
       
    54 #endif // UTILS_H