Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMatch.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JMATCH__
2 #define __JTRIGGER__JMATCH__
3 
4 #include <functional>
5 
6 #include "JLang/JClonable.hh"
7 
8 
9 /**
10  * \file
11  *
12  * Base class for match operations inside <tt>clusterize</tt> methods.
13  * \author mdejong
14  */
15 namespace JTRIGGER {}
16 namespace JPP { using namespace JTRIGGER; }
17 
18 namespace JTRIGGER {
19 
20  using JLANG::JClonable;
21 
22 
23  /**
24  * Function object interface for hit matching.
25  */
26  template<class JHit_t>
27  class JMatch :
28  public JClonable< JMatch<JHit_t> >,
29  public std::binary_function<JHit_t, JHit_t, bool>
30  {
31  public:
32  /**
33  * Virtual destructor.
34  */
35  virtual ~JMatch()
36  {}
37 
38 
39  /**
40  * Match operator.
41  *
42  * \param first hit
43  * \param second hit
44  * \return match result
45  */
46  virtual bool operator()(const JHit_t& first, const JHit_t& second) const = 0;
47  };
48 
49 
50  /**
51  * Auxiliary class to handle pointer to match function.
52  */
53  template<class JHit_t>
54  class JMatchHelper :
55  public JMatch<JHit_t>
56  {
57  public:
58 
59  typedef bool (*pFun)(const JHit_t&, const JHit_t&); //!< pointer to match function
60 
61  /**
62  * Constructor
63  *
64  * \param __match pointer to match function
65  */
66  JMatchHelper(pFun __match) :
67  match(__match)
68  {}
69 
70 
71  /**
72  * Clone object.
73  *
74  * \return match result
75  */
77  {
78  return new JMatchHelper<JHit_t>(*this);
79  }
80 
81 
82  /**
83  * Match operator.
84  *
85  * \param first hit
86  * \param second hit
87  * \return match result
88  */
89  virtual bool operator()(const JHit_t& first, const JHit_t& second) const
90  {
91  return match(first, second);
92  }
93 
94  protected:
96  };
97 
98 
99  /**
100  * Auxiliary method to make JMatch object based on pointer to match function.
101  *
102  * \param match pointer to match function
103  * \return match object
104  */
105  template<class JHit_t>
106  JMatchHelper<JHit_t> make_match(bool (*match)(const JHit_t&, const JHit_t&))
107  {
108  return JMatchHelper<JHit_t>(match);
109  }
110 }
111 
112 #endif
Auxiliary class to handle pointer to match function.
Definition: JMatch.hh:54
virtual bool operator()(const JHit_t &first, const JHit_t &second) const =0
Match operator.
JMatchHelper< JHit_t > make_match(bool(*match)(const JHit_t &, const JHit_t &))
Auxiliary method to make JMatch object based on pointer to match function.
Definition: JMatch.hh:106
virtual ~JMatch()
Virtual destructor.
Definition: JMatch.hh:35
Function object interface for hit matching.
Definition: JMatch.hh:27
JMatchHelper(pFun __match)
Constructor.
Definition: JMatch.hh:66
bool(* pFun)(const JHit_t &, const JHit_t &)
pointer to match function
Definition: JMatch.hh:59
JMatch< JHit_t > * clone() const
Clone object.
Definition: JMatch.hh:76
Template interface class for object cloning.
Definition: JClonable.hh:19
virtual bool operator()(const JHit_t &first, const JHit_t &second) const
Match operator.
Definition: JMatch.hh:89