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

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

adding a similar AveragerPair? traits and using it in PearsonDistance? to simplify the code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1#ifndef _theplu_yat_utility_averager_traits_
2#define _theplu_yat_utility_averager_traits_
3
4// $Id: averager_traits.h 1306 2008-05-14 22:44:30Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://trac.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     \see class declaration
51  */
52    typedef Averager type;
53    typedef AveragerPair pair_type;
54  };
55
56  /**
57     Specialization for weighted_tag return AveragerWeighted
58  */
59  template <>
60  struct averager_traits<utility::weighted_iterator_tag> 
61  {
62  /**
63     \see class declaration
64  */
65    typedef AveragerWeighted type;
66    typedef AveragerPairWeighted pair_type;
67  };
68
69  /**
70      Convenience wrapper around averager_traits
71      \see weighted_iterator_traits                                         \
72  */
73  template <typename Iterator>
74  struct averager
75  {
76  /**
77      Convenience Metafunction taking iterator as argument and return
78      either Averager (if iterator is unweighted) or AveragerWeighted
79      (if iterator is unweighted)
80  */
81    typedef typename averager_traits<typename utility::weighted_iterator_traits<Iterator>::type>::type type;
82  };
83
84  /**
85      Convenience wrapper around averager_traits
86      \see weighted_iterator_traits                                         \
87  */
88  template <typename Iterator1, typename Iterator2>
89  struct averager_pair
90  {
91  /**
92      Convenience Metafunction taking iterator as argument and return
93      either Averager (if both iterators are unweighted) or AveragerWeighted
94      otherwise.
95  */
96    typedef typename 
97      averager_traits<
98        typename utility::weighted_if_any2<Iterator1, Iterator2>::type
99      >::pair_type type;
100  };
101
102}}} // of namespace statistics, yat, and theplu
103
104#endif
Note: See TracBrowser for help on using the repository browser.