#ifndef __JLANG__JFIND_IF__ #define __JLANG__JFIND_IF__ #include "JLang/JClass.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Template definition of auxiliary class to select objects. * The first template argument refers to the data member or member method and * the second template argument to the predicate of the corresponding values. */ template class JFind_if; /** * Template specialisation of JFind_if for selection of objects via data member. */ template class JFind_if { public: typedef JResult_t data_type; typedef typename JClass::argument_type argument_type; typedef JResult_t T::*data_member; //!< Type definition of data member typedef JPredicate_t predicate_type; //!< Type definition of predicate /** * Constructor. * * \param member pointer to data member * \param predicate predicate method */ JFind_if(data_member member, const predicate_type& predicate) : member (member), predicate(predicate) {} /** * Select objets. * * \param object object * \return true if selected; else false */ bool operator()(const T& object) const { return predicate(object.*member); } protected: data_member member; const predicate_type& predicate; }; /** * Template specialisation of JFind_if for selection of objects via member method. */ template class JFind_if { public: typedef JResult_t data_type; typedef typename JClass::argument_type argument_type; typedef JResult_t (T::*member_method)() const; //!< Type definition of member method typedef JPredicate_t predicate_type; //!< Type definition of predicate /** * Constructor. * * \param function pointer to member method * \param predicate predicate method */ JFind_if(member_method function, const predicate_type& predicate) : function (function), predicate(predicate) {} /** * Select objets. * * \param object object * \return true if selected; else false */ bool operator()(const T& object) const { return predicate((object.*function)()); } protected: member_method function; const predicate_type& predicate; }; /** * Helper method to create find_if for data member. * * \param member pointer to data member * \param predicate predicate * \return find_if */ template JFind_if make_find_if(JResult_t T::*member, const JPredicate_t& predicate) { return JFind_if(member, predicate); } /** * Helper method to create find_if for return values of member method. * * \param function pointer to member method * \param predicate predicate * \return find_if */ template JFind_if make_find_if(JResult_t (T::*function)() const, const JPredicate_t& predicate) { return JFind_if(function, predicate); } } #endif