forked from h2gglobe/h2gglobe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sorters.h
40 lines (31 loc) · 999 Bytes
/
Sorters.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef _Sorters_h_
#define _Sorters_h_
// -----------------------------------------------------------------------------------------------------
template<class T, class U, class C=std::less<U> > class ClonesSorter
{
public:
typedef U (T::*method_type) () const;
ClonesSorter(TClonesArray *a, method_type m, C c=C()) : array_(a), method_(m), compare_(c) {};
bool operator () (int ii, int jj) {
T * ei = dynamic_cast<T*> ((*array_)[ii]);
T * ej = dynamic_cast<T*> ((*array_)[jj]);
return compare_( (*ei.*method_)() , (*ej.*method_)() );
};
private:
TClonesArray * array_;
method_type method_;
C compare_;
};
// -----------------------------------------------------------------------------------------------------
template<class T, class C=std::less<T> > class SimpleSorter
{
public:
SimpleSorter(T *a, C c=C()) : array_(a), compare_(c) {};
bool operator () (int ii, int jj) {
return compare_( array_[ii], array_[jj] );
};
private:
T * array_;
C compare_;
};
#endif