diff -r 000000000000 -r e686773b3f54 phonebookui/Phonebook2/xSPExtensionManager/src/ForEachUtil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/phonebookui/Phonebook2/xSPExtensionManager/src/ForEachUtil.h Tue Feb 02 10:12:17 2010 +0200 @@ -0,0 +1,145 @@ +/* +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: utility class for multi-class command execution +* +*/ + + + +/** + * Template class for functor with two parameters. + * @param _ReturnType Return type of the member function + * @param _Class Class that has the member function to be called. + * @param _Argument Type of member function's argument. + * @param _Argument2 Type of member function's argument. + */ +template +class MemberFunction2 + { + public: + explicit MemberFunction2 + (_ReturnType (_Class::* aMemberFunction)(_Argument, _Argument2)) : + iMemberFunction(aMemberFunction) + { + } + + _ReturnType operator() + (_Class* aClassInstance, _Argument aArgument1, + _Argument2 aArgument2) const + { + return ((aClassInstance->*iMemberFunction) + (aArgument1, aArgument2)); + } + private: + _ReturnType (_Class::* iMemberFunction)(_Argument, _Argument2); + }; + +/** + * Function for creating functor with two parameters. + */ +template +inline MemberFunction2<_ReturnType, _Class, _Argument, _Argument2> +MemberFunction(_ReturnType (_Class::* aMemberFunction)(_Argument, _Argument2)) + { + return MemberFunction2<_ReturnType, _Class, _Argument, _Argument2> + (aMemberFunction); + } + + +/** + * Template class for functor with two parameters and + * void return type. + */ +template +class VoidMemberFunction2 + { + public: + explicit VoidMemberFunction2 + (void (_Class::* aMemberFunction)(_Argument, _Argument2)) : + iMemberFunction(aMemberFunction) + {} + void operator()(_Class* aClassInstance, _Argument aArgument, + _Argument2 aArgument2) const + { + ((aClassInstance->*iMemberFunction)(aArgument,aArgument2)); + } + private: + void (_Class::* iMemberFunction)(_Argument, _Argument2); + }; + +/** + * Functon for creating functor with two parameters and void + * return type. + */ +template +inline VoidMemberFunction2<_Class, _Argument, _Argument2> +VoidMemberFunction(void (_Class::* aMemberFunction)(_Argument, _Argument2)) + { + return VoidMemberFunction2<_Class, _Argument, _Argument2>(aMemberFunction); + } + +/** + * Executes given member function on all array elements. + * Version with two arguments. + */ +template +void ForEachL(Array& aArray, Functor aFuncL, Arg& aArgument, Arg2& aArgument2) + { + const TInt count = aArray.Count(); + for (TInt i=0; i +TBool TryEachL(Array& aArray, Functor aFuncL, + Arg& aArgument, Arg2& aArgument2, + TBool aInverted = EFalse) + { + const TInt count = aArray.Count(); + for (TInt i=0; i