diff -r e20de85af2ee -r ce057bb09d0b genericopenlibs/cppstdlib/stl/test/unit/fadapter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/genericopenlibs/cppstdlib/stl/test/unit/fadapter.h Fri Jun 04 16:20:51 2010 +0100 @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2009 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: +* +*/ +#ifndef _fadapter_h_ +#define _fadapter_h_ + +#include + +// used as adaptor's return/argument type, +// to allow binders/composers usage +struct __void_tag {}; + +#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) +using std::unary_function; +#endif + +template +class pointer_to_void_function { +protected: + Result (*ptr)(); +public: + explicit pointer_to_void_function(Result (*x)()) : ptr(x) {} + Result operator()() const { return ptr(); } + Result operator()(__void_tag) const { return ptr(); } +}; + +// to feed composers +template +struct projectvoid : public unary_function { + __void_tag operator()(const Arg1& x) const { return __void_tag(); } +}; + +#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG) + +template +pointer_to_void_function ptr_fun(Result (*x)()) { + return pointer_to_void_function(x); +} + +// alternate name +template +pointer_to_void_function ptr_gen(Result (*x)()) { + return pointer_to_void_function(x); +} + +#endif /* !defined (_STLP_MEMBER_POINTER_PARAM_BUG) */ + +template +class pointer_to_unary_procedure /* :public unary_function */ { +protected: + typedef void (*fun_type)(Arg); + fun_type ptr; +public: + typedef Arg argument_type; + pointer_to_unary_procedure() {} + pointer_to_unary_procedure(fun_type x) : ptr(x) {} + void operator() (Arg x) const { ptr(x); } +}; + +template +inline pointer_to_unary_procedure ptr_proc(void (*x)(Arg)) { + return pointer_to_unary_procedure(x); +} + +template +class pointer_to_binary_procedure /* : public unary_function */ { +protected: + typedef void (*fun_type)(Arg1, Arg2); + fun_type ptr; +public: + typedef Arg1 first_argument_type; + typedef Arg2 second_argument_type; + pointer_to_binary_procedure() {} + pointer_to_binary_procedure(fun_type x) : ptr(x) {} + void operator() (Arg1 x, Arg2 y) const { ptr(x, y); } +}; + +template +inline pointer_to_binary_procedure ptr_proc(void (*x)(Arg1, Arg2)) { + return pointer_to_binary_procedure(x); +} + +#endif