3 #ifndef ALIHLTTTEMPLATES_H
4 #define ALIHLTTTEMPLATES_H
5 //* This file is property of and copyright by the ALICE HLT Project *
6 //* ALICE Experiment at CERN, All rights reserved. *
7 //* See cxx source for full Copyright notice *
9 /// @file AliHLTTemplates.h
10 /// @author Matthias Richter
12 /// @brief A collection of HLT template definitions
18 // checks if return value (type T) of a specified member function of a class C
19 // instance has a certain value
20 // used together with stl algorithms to extract specific predicate from the class
21 template <class C, typename T>
22 class AliHLTUnaryPredicate {
25 AliHLTUnaryPredicate(T (C::*pFct)() const, T value)
26 : fpFct(pFct), fValue(value) { };
29 AliHLTUnaryPredicate(const AliHLTUnaryPredicate& p)
30 : fpFct(p.fpFct), fValue(p.fValue) { };
31 /// assignment operator
32 AliHLTUnaryPredicate& operator=(const AliHLTUnaryPredicate& p) {
33 fpFct=p.fpFct; fValue=p.fValue; return *this;
36 /// override operator== execute member function and compare result to value
37 bool operator==(const C& object) const {
38 if (!fpFct) return false;
39 return (object.*fpFct)()==fValue;
43 /// standard contructor prohibited
44 AliHLTUnaryPredicate();
46 T (C::*fpFct)() const; //! pointer to member function
47 T fValue; //! value to match
50 template <class C, typename T>
51 class AliHLTGetValue {
54 AliHLTGetValue(const C& object, T (C::*pFct)() const)
55 : fObject(object), fpFct(pFct) { };
57 /// override operator== execute member function and compare result to value
59 return (fObject.*fpFct)();
63 /// standard contructor prohibited
65 /// copy contructor prohibited
66 AliHLTGetValue(const AliHLTGetValue&);
67 /// assignment operator prohibited
68 AliHLTGetValue& operator=(const AliHLTGetValue&);
70 const T& fObject; //! object
71 T (C::*fpFct)() const; //! pointer to member function
74 // operator== to be used as predicates for condition classes in stl algorithms
75 // need to change the order of the to parameters in order to get
76 // into the operator== of the condition class
77 template <class T, class C>
78 bool operator==(const T& p, const C& c)
83 // operator== to be used as predicates for condition classes in stl algorithms
84 // template for maps, use value of the pair in the condition
85 // need to change the order of the to parameters in order to get
86 // into the operator== of the condition class
87 template <class K, class T, class C>
88 bool operator==(const std::pair<K, T>& p, const C& c)
93 // copy function for maps
94 // stl algorithms can not be used here because pair.first can not be assigned
95 // in maps but has to be used as index
96 template <class InputIterator, class K, class V, class C>
97 int copy_map_if ( InputIterator first, InputIterator last,
98 std::map<K, V>& result, const C& value )
100 for ( ; first != last; ++first)
101 if ((*first == value)) result[first->first] = first->second;
105 // get the key of a pair
108 template <typename T>
109 typename T::first_type operator()(T pair) const {
114 } // end of namespace