Ignore:
Timestamp:
Sep 29, 2007, 4:18:52 AM (14 years ago)
Author:
Peter
Message:

refactoring add function in Averagers, refs #246

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/IteratorTraits.h

    r910 r914  
    4848    typedef weighted_type type;
    4949  };
    50    
    5150
    5251  // All iterators should default to unweighted type ...
     
    6261  };
    6362
     63  // check (at compile time) that iterator is unweighted.
     64  inline void check_iterator_is_unweighted(unweighted_type x){}
     65  template <class Iter>
     66  void check_iterator_is_unweighted(Iter iter)
     67  {check_iterator_unweighted(typename weighted_iterator_traits<Iter>::type());}
     68
     69
     70  /*
     71    Function to be used to make compile-time decision how to return
     72    data from an iterator separating two cases: weighted and
     73    unweighted.
     74
     75    In this way unweighted iterators can be used in a weighted context.
     76   */
     77  // Peter, perhaps these should be templatized, but for now return
     78  // type double is hard coded.
     79  template <class Iter>
     80  double iterator_traits_data(Iter iter)
     81  { return iterator_traits_data(iter, weighted_iterator_traits<Iter>::type()); }
     82
     83  template <class Iter>
     84  double iterator_traits_data(Iter i, weighted_type)
     85  { return i.data(); }
     86
     87  template <class Iter>
     88  double iterator_traits_data(Iter i, unweighted_type)
     89  { return *i; }
     90
     91  /*
     92    Function to be used to make compile-time decision how to return
     93    data from an iterator separating two cases: weighted and
     94    unweighted.
     95
     96    In this way unweighted iterators can be used in a weighted context
     97    and weight will be set to unity.
     98   */
     99  // Peter, perhaps these should be templatized, but for now return
     100  // type double is hard coded.
     101  template <class Iter>
     102  double iterator_traits_weight(Iter iter)
     103  { return iterator_traits_data(iter, weighted_iterator_traits<Iter>::type()); }
     104
     105  template <class Iter>
     106  double iterator_traits_weight(Iter i, weighted_type)
     107  { return i.weight(); }
     108
     109  template <class Iter>
     110  double iterator_traits_weight(Iter i, unweighted_type)
     111  { return 1.0; }
     112
     113
    64114}}} // of namespace utility, yat, and theplu
    65115
Note: See TracChangeset for help on using the changeset viewer.