LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTTemplates.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 9 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 33 0.0 %

          Line data    Source code
       1             : //-*- Mode: C++ -*-
       2             : // $Id$
       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                               *
       8             : 
       9             : /// @file   AliHLTTemplates.h
      10             : /// @author Matthias Richter
      11             : /// @date   2011-04-29
      12             : /// @brief  A collection of HLT template definitions
      13             : ///
      14             : 
      15             : namespace HLT
      16             : {
      17             :   // unary predicate
      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 {
      23             :   public:
      24             :     /// constructor
      25             :     AliHLTUnaryPredicate(T (C::*pFct)() const, T value)
      26           0 :       : fpFct(pFct), fValue(value) { };
      27             : 
      28             :     /// copy contructor
      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;
      34             :     }
      35             : 
      36             :     /// override operator== execute member function and compare result to value
      37             :     bool operator==(const C& object) const {
      38           0 :       if (!fpFct) return false;
      39           0 :       return (object.*fpFct)()==fValue;
      40           0 :     }
      41             : 
      42             :   private:
      43             :     /// standard contructor prohibited
      44             :     AliHLTUnaryPredicate();
      45             : 
      46             :     T (C::*fpFct)() const;   //! pointer to member function
      47             :     T  fValue;               //! value to match
      48             :   };
      49             : 
      50             :   template <class C, typename T>
      51             :   class AliHLTGetValue {
      52             :   public:
      53             :     /// constructor
      54             :     AliHLTGetValue(const C& object, T (C::*pFct)() const)
      55             :       : fObject(object), fpFct(pFct) { };
      56             : 
      57             :     /// override operator== execute member function and compare result to value
      58             :     operator T() const {
      59             :       return (fObject.*fpFct)();
      60             :     }
      61             : 
      62             :   private:
      63             :     /// standard contructor prohibited
      64             :     AliHLTGetValue();
      65             :     /// copy contructor prohibited
      66             :     AliHLTGetValue(const AliHLTGetValue&);
      67             :     /// assignment operator prohibited
      68             :     AliHLTGetValue& operator=(const AliHLTGetValue&);
      69             : 
      70             :     const T& fObject;       //! object
      71             :     T (C::*fpFct)() const;   //! pointer to member function
      72             :   };
      73             : 
      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)
      79             :   {
      80             :     return c==p;
      81             :   }
      82             : 
      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)
      89             :   {
      90           0 :     return c==p.second;
      91             :   }
      92             : 
      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 )
      99             :   {
     100           0 :     for ( ; first != last; ++first)
     101           0 :       if ((*first == value)) result[first->first] = first->second;
     102           0 :     return 0;
     103             :   }
     104             : 
     105             :   // get the key of a pair
     106             :   class AliGetKey {
     107             :   public:
     108             :     template <typename T>
     109             :     typename T::first_type operator()(T pair) const {
     110           0 :       return pair.first;
     111             :     }
     112             :   };
     113             : 
     114             : } // end of namespace
     115             : #endif

Generated by: LCOV version 1.11