localconnectivityservice/locod/inc/utils.h
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     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:  Defines utility functions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef LOCODUTIL_H
       
    20 #define LOCODUTIL_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 #endif // LOCODUTIL_H