source: trunk/yat/statistics/averager_traits.h @ 1703

Last change on this file since 1703 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_yat_utility_averager_traits_
2#define _theplu_yat_utility_averager_traits_
3
4// $Id: averager_traits.h 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "Averager.h"
26#include "AveragerWeighted.h"
27#include "AveragerPair.h"
28#include "AveragerPairWeighted.h"
29#include "yat/utility/iterator_traits.h"
30
31namespace theplu {
32namespace yat {
33namespace statistics {
34
35  /**
36     MetaFunction returning weighted or unweighted Averager.
37   */
38  template <typename T>
39  struct averager_traits{};
40
41  /**
42     Specialization for unweighted_tag return (unweighted) Averager
43  */
44  template <>
45  struct averager_traits<utility::unweighted_iterator_tag> 
46  {
47    /**
48        Metafunction returning Averager
49    */
50    typedef Averager type;
51    /**
52        Metafunction returning AveragerPair
53    */
54    typedef AveragerPair pair_type;
55  };
56
57  /**
58     Specialization for weighted_tag return AveragerWeighted
59  */
60  template <>
61  struct averager_traits<utility::weighted_iterator_tag> 
62  {
63    /**
64       Metafunction returning AveragerWeighted
65     */
66    typedef AveragerWeighted type;
67    /**
68       Metafunction returning AveragerPairWeighted
69    */
70    typedef AveragerPairWeighted pair_type;
71  };
72
73  /**
74      Convenience wrapper around averager_traits
75      \see weighted_iterator_traits                                         \
76  */
77  template <typename Iterator>
78  struct averager
79  {
80  /**
81      Convenience Metafunction taking iterator as argument and return
82      either Averager (if iterator is unweighted) or AveragerWeighted
83      (if iterator is unweighted)
84  */
85    typedef typename averager_traits<typename utility::weighted_iterator_traits<Iterator>::type>::type type;
86  };
87
88  /**
89      Convenience wrapper around averager_traits
90      \see weighted_iterator_traits                                         \
91  */
92  template <typename Iterator1, typename Iterator2>
93  struct averager_pair
94  {
95  /**
96      Convenience Metafunction taking two iterators as argument and
97      return either AveragerPair (if both iterators are unweighted) or
98      AveragerPairWeighted otherwise.
99  */
100    typedef typename 
101      averager_traits<
102        typename utility::weighted_if_any2<Iterator1, Iterator2>::type
103      >::pair_type type;
104  };
105
106}}} // of namespace statistics, yat, and theplu
107
108#endif
Note: See TracBrowser for help on using the repository browser.