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

Last change on this file since 1469 was 1469, checked in by Peter, 13 years ago

stray trac.thep

  • 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 1469 2008-09-02 17:21:00Z peter $
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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "Averager.h"
28#include "AveragerWeighted.h"
29#include "AveragerPair.h"
30#include "AveragerPairWeighted.h"
31#include "yat/utility/iterator_traits.h"
32
33namespace theplu {
34namespace yat {
35namespace statistics {
36
37  /**
38     MetaFunction returning weighted or unweighted Averager.
39   */
40  template <typename T>
41  struct averager_traits{};
42
43  /**
44     Specialization for unweighted_tag return (unweighted) Averager
45  */
46  template <>
47  struct averager_traits<utility::unweighted_iterator_tag> 
48  {
49    /**
50        Metafunction returning Averager
51    */
52    typedef Averager type;
53    /**
54        Metafunction returning AveragerPair
55    */
56    typedef AveragerPair pair_type;
57  };
58
59  /**
60     Specialization for weighted_tag return AveragerWeighted
61  */
62  template <>
63  struct averager_traits<utility::weighted_iterator_tag> 
64  {
65    /**
66       Metafunction returning AveragerWeighted
67     */
68    typedef AveragerWeighted type;
69    /**
70       Metafunction returning AveragerPairWeighted
71    */
72    typedef AveragerPairWeighted pair_type;
73  };
74
75  /**
76      Convenience wrapper around averager_traits
77      \see weighted_iterator_traits                                         \
78  */
79  template <typename Iterator>
80  struct averager
81  {
82  /**
83      Convenience Metafunction taking iterator as argument and return
84      either Averager (if iterator is unweighted) or AveragerWeighted
85      (if iterator is unweighted)
86  */
87    typedef typename averager_traits<typename utility::weighted_iterator_traits<Iterator>::type>::type type;
88  };
89
90  /**
91      Convenience wrapper around averager_traits
92      \see weighted_iterator_traits                                         \
93  */
94  template <typename Iterator1, typename Iterator2>
95  struct averager_pair
96  {
97  /**
98      Convenience Metafunction taking two iterators as argument and
99      return either AveragerPair (if both iterators are unweighted) or
100      AveragerPairWeighted otherwise.
101  */
102    typedef typename 
103      averager_traits<
104        typename utility::weighted_if_any2<Iterator1, Iterator2>::type
105      >::pair_type type;
106  };
107
108}}} // of namespace statistics, yat, and theplu
109
110#endif
Note: See TracBrowser for help on using the repository browser.