From f683ef370bcb987a9f96fc5da0793d71e3721d29 Mon Sep 17 00:00:00 2001 From: Marc Laukien Date: Sun, 22 Sep 2002 15:44:10 +0000 Subject: thread fixes --- cpp/include/IceUtil/Functional.h | 906 +++++++++++++++++++-------------------- 1 file changed, 453 insertions(+), 453 deletions(-) (limited to 'cpp/include/IceUtil/Functional.h') diff --git a/cpp/include/IceUtil/Functional.h b/cpp/include/IceUtil/Functional.h index bf8b4ceac65..57b0df17243 100644 --- a/cpp/include/IceUtil/Functional.h +++ b/cpp/include/IceUtil/Functional.h @@ -1,453 +1,453 @@ -// ********************************************************************** -// -// Copyright (c) 2001 -// Mutable Realms, Inc. -// Huntsville, AL, USA -// -// All Rights Reserved -// -// ********************************************************************** - -#ifndef ICE_UTIL_FUNCTIONAL_H -#define ICE_UTIL_FUNCTIONAL_H - -#include -#include - -namespace IceUtilInternal -{ - -// ---------------------------------------------------------------------- -// Various function objects that work with handles instead of plain -// pointers. -// ---------------------------------------------------------------------- - -template -class MemFun : public std::unary_function -{ - typedef R (T::*MemberFN)(void); - MemberFN _mfn; - -public: - - explicit MemFun(MemberFN p) : _mfn(p) { } - R operator()(H handle) const - { - return (handle.get() ->* _mfn)(); - } -}; - -template -class MemFun1 : public std::binary_function -{ - typedef R (T::*MemberFN)(A); - MemberFN _mfn; - -public: - - explicit MemFun1(MemberFN p) : _mfn(p) { } - R operator()(H handle, A arg) const - { - return (handle.get() ->* _mfn)(arg); - } -}; - -template -class VoidMemFun : public std::unary_function -{ - typedef void (T::*MemberFN)(void); - MemberFN _mfn; - -public: - - explicit VoidMemFun(MemberFN p) : _mfn(p) { } - void operator()(H handle) const - { - (handle.get() ->* _mfn)(); - } -}; - -template -class VoidMemFun1 : public std::binary_function -{ - typedef void (T::*MemberFN)(A); - MemberFN _mfn; - -public: - - explicit VoidMemFun1(MemberFN p) : _mfn(p) { } - void operator()(H handle, A arg) const - { - (handle.get() ->* _mfn)(arg); - } -}; - -template -class SecondMemFun : public std::unary_function, R> -{ - typedef R (T::*MemberFN)(void); - MemberFN _mfn; - -public: - - explicit SecondMemFun(MemberFN p) : _mfn(p) { } - R operator()(std::pair pair) const - { - return (pair.second.get() ->* _mfn)(); - } -}; - -template -class SecondMemFun1 : public std::binary_function, A, R> -{ - typedef R (T::*MemberFN)(A); - MemberFN _mfn; - -public: - - explicit SecondMemFun1(MemberFN p) : _mfn(p) { } - R operator()(std::pair pair, A arg) const - { - return (pair.second.get() ->* _mfn)(arg); - } -}; - -template -class SecondVoidMemFun : public std::unary_function, void> -{ - typedef void (T::*MemberFN)(void); - MemberFN _mfn; - -public: - - explicit SecondVoidMemFun(MemberFN p) : _mfn(p) { } - void operator()(std::pair pair) const - { - (pair.second.get() ->* _mfn)(); - } -}; - -template -class SecondVoidMemFun1 : public std::binary_function, A, void> -{ - typedef void (T::*MemberFN)(A); - MemberFN _mfn; - -public: - - explicit SecondVoidMemFun1(MemberFN p) : _mfn(p) { } - void operator()(std::pair pair, A arg) const - { - (pair.second.get() ->* _mfn)(arg); - } -}; - -template -class ConstMemFun : public std::unary_function -{ - typedef R (T::*MemberFN)(void) const; - MemberFN _mfn; - -public: - - explicit ConstMemFun(MemberFN p) : _mfn(p) { } - R operator()(H handle) const - { - return (handle.get() ->* _mfn)(); - } -}; - -template -class ConstMemFun1 : public std::binary_function -{ - typedef R (T::*MemberFN)(A) const; - MemberFN _mfn; - -public: - - explicit ConstMemFun1(MemberFN p) : _mfn(p) { } - R operator()(H handle, A arg) const - { - return (handle.get() ->* _mfn)(arg); - } -}; - -template -class ConstVoidMemFun : public std::unary_function -{ - typedef void (T::*MemberFN)(void) const; - MemberFN _mfn; - -public: - - explicit ConstVoidMemFun(MemberFN p) : _mfn(p) { } - void operator()(H handle) const - { - (handle.get() ->* _mfn)(); - } -}; - -template -class ConstVoidMemFun1 : public std::binary_function -{ - typedef void (T::*MemberFN)(A) const; - MemberFN _mfn; - -public: - - explicit ConstVoidMemFun1(MemberFN p) : _mfn(p) { } - void operator()(H handle, A arg) const - { - (handle.get() ->* _mfn)(arg); - } -}; - -template -class SecondConstMemFun : public std::unary_function, R> -{ - typedef R (T::*MemberFN)(void) const; - MemberFN _mfn; - -public: - - explicit SecondConstMemFun(MemberFN p) : _mfn(p) { } - R operator()(std::pair pair) const - { - return (pair.second.get() ->* _mfn)(); - } -}; - -template -class SecondConstMemFun1 : public std::binary_function, A, R> -{ - typedef R (T::*MemberFN)(A) const; - MemberFN _mfn; - -public: - - explicit SecondConstMemFun1(MemberFN p) : _mfn(p) { } - R operator()(std::pair pair, A arg) const - { - return (pair.second.get() ->* _mfn)(arg); - } -}; - -template -class SecondConstVoidMemFun : public std::unary_function, void> -{ - typedef void (T::*MemberFN)(void) const; - MemberFN _mfn; - -public: - - explicit SecondConstVoidMemFun(MemberFN p) : _mfn(p) { } - void operator()(std::pair pair) const - { - (pair.second.get() ->* _mfn)(); - } -}; - -template -class SecondConstVoidMemFun1 : public std::binary_function, A, void> -{ - typedef void (T::*MemberFN)(A) const; - MemberFN _mfn; - -public: - - explicit SecondConstVoidMemFun1(MemberFN p) : _mfn(p) { } - void operator()(std::pair pair, A arg) const - { - (pair.second.get() ->* _mfn)(arg); - } -}; - -} - -// ---------------------------------------------------------------------- -// Inline functions that return function objects that work with -// IceUtil::Handle -// ---------------------------------------------------------------------- - -namespace IceUtil -{ - -template -inline ::IceUtilInternal::MemFun > -memFun(R (T::*p)(void)) -{ - return ::IceUtilInternal::MemFun >(p); -} - -template -inline ::IceUtilInternal::MemFun1, A> -memFun1(R (T::*p)(A)) -{ - return ::IceUtilInternal::MemFun1, A>(p); -} - -template -inline ::IceUtilInternal::VoidMemFun > -voidMemFun(void (T::*p)(void)) -{ - return ::IceUtilInternal::VoidMemFun >(p); -} - -template -inline ::IceUtilInternal::VoidMemFun1, A> -voidMemFun1(void (T::*p)(A)) -{ - return ::IceUtilInternal::VoidMemFun1, A>(p); -} - -template -inline ::IceUtilInternal::SecondMemFun > -secondMemFun(R (T::*p)(void)) -{ - return ::IceUtilInternal::SecondMemFun >(p); -} - -template -inline ::IceUtilInternal::SecondMemFun1, A> -secondMemFun1(R (T::*p)(A)) -{ - return ::IceUtilInternal::SecondMemFun1, A>(p); -} - -template -inline ::IceUtilInternal::SecondVoidMemFun > -secondVoidMemFun(void (T::*p)(void)) -{ - return ::IceUtilInternal::SecondVoidMemFun >(p); -} - -template -inline ::IceUtilInternal::SecondVoidMemFun1, A> -secondVoidMemFun1(void (T::*p)(A)) -{ - return ::IceUtilInternal::SecondVoidMemFun1, A>(p); -} - -template -inline ::IceUtilInternal::ConstMemFun > -constMemFun(R (T::*p)(void) const) -{ - return ::IceUtilInternal::ConstMemFun >(p); -} - -template -inline ::IceUtilInternal::ConstMemFun1, A> -constMemFun1(R (T::*p)(A) const) -{ - return ::IceUtilInternal::ConstMemFun1, A>(p); -} - -template -inline ::IceUtilInternal::ConstVoidMemFun > -constVoidMemFun(void (T::*p)(void) const) -{ - return ::IceUtilInternal::ConstVoidMemFun >(p); -} - -template -inline ::IceUtilInternal::ConstVoidMemFun1, A> -constVoidMemFun1(void (T::*p)(A) const) -{ - return ::IceUtilInternal::ConstVoidMemFun1, A>(p); -} - -template -inline ::IceUtilInternal::SecondConstMemFun > -secondConstMemFun(R (T::*p)(void) const) -{ - return ::IceUtilInternal::SecondConstMemFun >(p); -} - -template -inline ::IceUtilInternal::SecondConstMemFun1, A> -secondConstMemFun1(R (T::*p)(A) const) -{ - return ::IceUtilInternal::SecondConstMemFun1, A>(p); -} - -template -inline ::IceUtilInternal::SecondConstVoidMemFun > -secondConstVoidMemFun(void (T::*p)(void) const) -{ - return ::IceUtilInternal::SecondConstVoidMemFun >(p); -} - -template -inline ::IceUtilInternal::SecondConstVoidMemFun1, A> -secondConstVoidMemFun1(void (T::*p)(A) const) -{ - return ::IceUtilInternal::SecondConstVoidMemFun1, A>(p); -} - -} - -// ---------------------------------------------------------------------- -// Extension for STLport: Special versions for bind1st and bind2nd for -// operations that do not return anything (i.e., return void). Needed -// for broken compilers, such as Visual C++ -// ---------------------------------------------------------------------- - -#ifdef _STLP_BEGIN_NAMESPACE - -_STLP_BEGIN_NAMESPACE - -template -class voidbinder1st : - public unary_function { -protected: - _Operation _M_op; - typename _Operation::first_argument_type _M_value; -public: - voidbinder1st(const _Operation& __x, - const typename _Operation::first_argument_type& __y) - : _M_op(__x), _M_value(__y) {} - typename _Operation::result_type - operator()(const typename _Operation::second_argument_type& __x) const { - _M_op(_M_value, __x); - } -}; - -template -inline voidbinder1st<_Operation> -voidbind1st(const _Operation& __fn, const _Tp& __x) -{ - typedef typename _Operation::first_argument_type _Arg1_type; - return voidbinder1st<_Operation>(__fn, _Arg1_type(__x)); -} - -template -class voidbinder2nd - : public unary_function { -protected: - _Operation _M_op; - typename _Operation::second_argument_type value; -public: - voidbinder2nd(const _Operation& __x, - const typename _Operation::second_argument_type& __y) - : _M_op(__x), value(__y) {} - typename _Operation::result_type - operator()(const typename _Operation::first_argument_type& __x) const { - _M_op(__x, value); - } -}; - -template -inline voidbinder2nd<_Operation> -voidbind2nd(const _Operation& __fn, const _Tp& __x) -{ - typedef typename _Operation::second_argument_type _Arg2_type; - return voidbinder2nd<_Operation>(__fn, _Arg2_type(__x)); -} - -_STLP_END_NAMESPACE - -#endif - -#endif +// ********************************************************************** +// +// Copyright (c) 2001 +// Mutable Realms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef ICE_UTIL_FUNCTIONAL_H +#define ICE_UTIL_FUNCTIONAL_H + +#include +#include + +namespace IceUtilInternal +{ + +// ---------------------------------------------------------------------- +// Various function objects that work with handles instead of plain +// pointers. +// ---------------------------------------------------------------------- + +template +class MemFun : public std::unary_function +{ + typedef R (T::*MemberFN)(void); + MemberFN _mfn; + +public: + + explicit MemFun(MemberFN p) : _mfn(p) { } + R operator()(H handle) const + { + return (handle.get() ->* _mfn)(); + } +}; + +template +class MemFun1 : public std::binary_function +{ + typedef R (T::*MemberFN)(A); + MemberFN _mfn; + +public: + + explicit MemFun1(MemberFN p) : _mfn(p) { } + R operator()(H handle, A arg) const + { + return (handle.get() ->* _mfn)(arg); + } +}; + +template +class VoidMemFun : public std::unary_function +{ + typedef void (T::*MemberFN)(void); + MemberFN _mfn; + +public: + + explicit VoidMemFun(MemberFN p) : _mfn(p) { } + void operator()(H handle) const + { + (handle.get() ->* _mfn)(); + } +}; + +template +class VoidMemFun1 : public std::binary_function +{ + typedef void (T::*MemberFN)(A); + MemberFN _mfn; + +public: + + explicit VoidMemFun1(MemberFN p) : _mfn(p) { } + void operator()(H handle, A arg) const + { + (handle.get() ->* _mfn)(arg); + } +}; + +template +class SecondMemFun : public std::unary_function, R> +{ + typedef R (T::*MemberFN)(void); + MemberFN _mfn; + +public: + + explicit SecondMemFun(MemberFN p) : _mfn(p) { } + R operator()(std::pair pair) const + { + return (pair.second.get() ->* _mfn)(); + } +}; + +template +class SecondMemFun1 : public std::binary_function, A, R> +{ + typedef R (T::*MemberFN)(A); + MemberFN _mfn; + +public: + + explicit SecondMemFun1(MemberFN p) : _mfn(p) { } + R operator()(std::pair pair, A arg) const + { + return (pair.second.get() ->* _mfn)(arg); + } +}; + +template +class SecondVoidMemFun : public std::unary_function, void> +{ + typedef void (T::*MemberFN)(void); + MemberFN _mfn; + +public: + + explicit SecondVoidMemFun(MemberFN p) : _mfn(p) { } + void operator()(std::pair pair) const + { + (pair.second.get() ->* _mfn)(); + } +}; + +template +class SecondVoidMemFun1 : public std::binary_function, A, void> +{ + typedef void (T::*MemberFN)(A); + MemberFN _mfn; + +public: + + explicit SecondVoidMemFun1(MemberFN p) : _mfn(p) { } + void operator()(std::pair pair, A arg) const + { + (pair.second.get() ->* _mfn)(arg); + } +}; + +template +class ConstMemFun : public std::unary_function +{ + typedef R (T::*MemberFN)(void) const; + MemberFN _mfn; + +public: + + explicit ConstMemFun(MemberFN p) : _mfn(p) { } + R operator()(H handle) const + { + return (handle.get() ->* _mfn)(); + } +}; + +template +class ConstMemFun1 : public std::binary_function +{ + typedef R (T::*MemberFN)(A) const; + MemberFN _mfn; + +public: + + explicit ConstMemFun1(MemberFN p) : _mfn(p) { } + R operator()(H handle, A arg) const + { + return (handle.get() ->* _mfn)(arg); + } +}; + +template +class ConstVoidMemFun : public std::unary_function +{ + typedef void (T::*MemberFN)(void) const; + MemberFN _mfn; + +public: + + explicit ConstVoidMemFun(MemberFN p) : _mfn(p) { } + void operator()(H handle) const + { + (handle.get() ->* _mfn)(); + } +}; + +template +class ConstVoidMemFun1 : public std::binary_function +{ + typedef void (T::*MemberFN)(A) const; + MemberFN _mfn; + +public: + + explicit ConstVoidMemFun1(MemberFN p) : _mfn(p) { } + void operator()(H handle, A arg) const + { + (handle.get() ->* _mfn)(arg); + } +}; + +template +class SecondConstMemFun : public std::unary_function, R> +{ + typedef R (T::*MemberFN)(void) const; + MemberFN _mfn; + +public: + + explicit SecondConstMemFun(MemberFN p) : _mfn(p) { } + R operator()(std::pair pair) const + { + return (pair.second.get() ->* _mfn)(); + } +}; + +template +class SecondConstMemFun1 : public std::binary_function, A, R> +{ + typedef R (T::*MemberFN)(A) const; + MemberFN _mfn; + +public: + + explicit SecondConstMemFun1(MemberFN p) : _mfn(p) { } + R operator()(std::pair pair, A arg) const + { + return (pair.second.get() ->* _mfn)(arg); + } +}; + +template +class SecondConstVoidMemFun : public std::unary_function, void> +{ + typedef void (T::*MemberFN)(void) const; + MemberFN _mfn; + +public: + + explicit SecondConstVoidMemFun(MemberFN p) : _mfn(p) { } + void operator()(std::pair pair) const + { + (pair.second.get() ->* _mfn)(); + } +}; + +template +class SecondConstVoidMemFun1 : public std::binary_function, A, void> +{ + typedef void (T::*MemberFN)(A) const; + MemberFN _mfn; + +public: + + explicit SecondConstVoidMemFun1(MemberFN p) : _mfn(p) { } + void operator()(std::pair pair, A arg) const + { + (pair.second.get() ->* _mfn)(arg); + } +}; + +} + +// ---------------------------------------------------------------------- +// Inline functions that return function objects that work with +// IceUtil::Handle +// ---------------------------------------------------------------------- + +namespace IceUtil +{ + +template +inline ::IceUtilInternal::MemFun > +memFun(R (T::*p)(void)) +{ + return ::IceUtilInternal::MemFun >(p); +} + +template +inline ::IceUtilInternal::MemFun1, A> +memFun1(R (T::*p)(A)) +{ + return ::IceUtilInternal::MemFun1, A>(p); +} + +template +inline ::IceUtilInternal::VoidMemFun > +voidMemFun(void (T::*p)(void)) +{ + return ::IceUtilInternal::VoidMemFun >(p); +} + +template +inline ::IceUtilInternal::VoidMemFun1, A> +voidMemFun1(void (T::*p)(A)) +{ + return ::IceUtilInternal::VoidMemFun1, A>(p); +} + +template +inline ::IceUtilInternal::SecondMemFun > +secondMemFun(R (T::*p)(void)) +{ + return ::IceUtilInternal::SecondMemFun >(p); +} + +template +inline ::IceUtilInternal::SecondMemFun1, A> +secondMemFun1(R (T::*p)(A)) +{ + return ::IceUtilInternal::SecondMemFun1, A>(p); +} + +template +inline ::IceUtilInternal::SecondVoidMemFun > +secondVoidMemFun(void (T::*p)(void)) +{ + return ::IceUtilInternal::SecondVoidMemFun >(p); +} + +template +inline ::IceUtilInternal::SecondVoidMemFun1, A> +secondVoidMemFun1(void (T::*p)(A)) +{ + return ::IceUtilInternal::SecondVoidMemFun1, A>(p); +} + +template +inline ::IceUtilInternal::ConstMemFun > +constMemFun(R (T::*p)(void) const) +{ + return ::IceUtilInternal::ConstMemFun >(p); +} + +template +inline ::IceUtilInternal::ConstMemFun1, A> +constMemFun1(R (T::*p)(A) const) +{ + return ::IceUtilInternal::ConstMemFun1, A>(p); +} + +template +inline ::IceUtilInternal::ConstVoidMemFun > +constVoidMemFun(void (T::*p)(void) const) +{ + return ::IceUtilInternal::ConstVoidMemFun >(p); +} + +template +inline ::IceUtilInternal::ConstVoidMemFun1, A> +constVoidMemFun1(void (T::*p)(A) const) +{ + return ::IceUtilInternal::ConstVoidMemFun1, A>(p); +} + +template +inline ::IceUtilInternal::SecondConstMemFun > +secondConstMemFun(R (T::*p)(void) const) +{ + return ::IceUtilInternal::SecondConstMemFun >(p); +} + +template +inline ::IceUtilInternal::SecondConstMemFun1, A> +secondConstMemFun1(R (T::*p)(A) const) +{ + return ::IceUtilInternal::SecondConstMemFun1, A>(p); +} + +template +inline ::IceUtilInternal::SecondConstVoidMemFun > +secondConstVoidMemFun(void (T::*p)(void) const) +{ + return ::IceUtilInternal::SecondConstVoidMemFun >(p); +} + +template +inline ::IceUtilInternal::SecondConstVoidMemFun1, A> +secondConstVoidMemFun1(void (T::*p)(A) const) +{ + return ::IceUtilInternal::SecondConstVoidMemFun1, A>(p); +} + +} + +// ---------------------------------------------------------------------- +// Extension for STLport: Special versions for bind1st and bind2nd for +// operations that do not return anything (i.e., return void). Needed +// for broken compilers, such as Visual C++ +// ---------------------------------------------------------------------- + +#ifdef _STLP_BEGIN_NAMESPACE + +_STLP_BEGIN_NAMESPACE + +template +class voidbinder1st : + public unary_function { +protected: + _Operation _M_op; + typename _Operation::first_argument_type _M_value; +public: + voidbinder1st(const _Operation& __x, + const typename _Operation::first_argument_type& __y) + : _M_op(__x), _M_value(__y) {} + typename _Operation::result_type + operator()(const typename _Operation::second_argument_type& __x) const { + _M_op(_M_value, __x); + } +}; + +template +inline voidbinder1st<_Operation> +voidbind1st(const _Operation& __fn, const _Tp& __x) +{ + typedef typename _Operation::first_argument_type _Arg1_type; + return voidbinder1st<_Operation>(__fn, _Arg1_type(__x)); +} + +template +class voidbinder2nd + : public unary_function { +protected: + _Operation _M_op; + typename _Operation::second_argument_type value; +public: + voidbinder2nd(const _Operation& __x, + const typename _Operation::second_argument_type& __y) + : _M_op(__x), value(__y) {} + typename _Operation::result_type + operator()(const typename _Operation::first_argument_type& __x) const { + _M_op(__x, value); + } +}; + +template +inline voidbinder2nd<_Operation> +voidbind2nd(const _Operation& __fn, const _Tp& __x) +{ + typedef typename _Operation::second_argument_type _Arg2_type; + return voidbinder2nd<_Operation>(__fn, _Arg2_type(__x)); +} + +_STLP_END_NAMESPACE + +#endif + +#endif -- cgit v1.2.3