yat  0.13.2pre
Centralizer.h
1 #ifndef _theplu_yat_normalizer_centralizer_
2 #define _theplu_yat_normalizer_centralizer_
3 
4 // $Id: Centralizer.h 3330 2014-10-14 08:03:25Z peter $
5 
6 /*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010, 2011, 2014 Peter Johansson
9 
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11 
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16 
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #include "utility.h"
27 
28 #include "yat/statistics/Average.h"
29 #include "yat/utility/DataIterator.h"
30 #include "yat/utility/iterator_traits.h"
31 #include "yat/utility/WeightIterator.h"
32 
33 #include <boost/concept_check.hpp>
34 #include <boost/iterator/iterator_concepts.hpp>
35 
36 #include <algorithm>
37 #include <functional>
38 
39 namespace theplu {
40 namespace yat {
41 namespace normalizer {
42 
64  template<class UnaryFunction = statistics::Average>
66  {
67  public:
74  Centralizer(void){}
75 
79  Centralizer(const UnaryFunction& uf)
80  : func_(uf) {}
81 
105  template<class InputIterator, class OutputIterator>
106  void operator()(InputIterator first, InputIterator last,
107  OutputIterator result) const
108  {
109  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator>));
110  // we need to traverse the input range once in call to func_ and
111  // one in call to std::transform, so single pass iterator will
112  // not suffice.
113  BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<InputIterator>));
114  // requirments for OutputIterator is different depending on
115  // whether it's weighted or not
117  check_requirements<OutputIterator>(tag);
118 
119  // copy weight if result is weighted
120  detail::copy_weight_if_weighted(first, last, result);
121  std::transform(utility::data_iterator(first),
122  utility::data_iterator(last),
123  utility::data_iterator(result),
124  std::bind2nd(std::minus<double>(),func_(first, last)));
125  }
126 
127  private:
128 
129  template<typename OutputIterator>
130  void check_requirements(utility::unweighted_iterator_tag) const
131  {
132  using boost_concepts::SinglePassIterator;
133  using boost_concepts::ReadableIterator;
134  using boost_concepts::WritableIterator;
135  BOOST_CONCEPT_ASSERT((SinglePassIterator<OutputIterator>));
136  BOOST_CONCEPT_ASSERT((ReadableIterator<OutputIterator>));
137  BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator, double>));
138 
139  }
140 
141  template<typename OutputIterator>
142  void check_requirements(utility::weighted_iterator_tag) const
143  {
144  using boost_concepts::ForwardTraversal;
145  using boost_concepts::ReadableIterator;
146  using boost_concepts::WritableIterator;
147  BOOST_CONCEPT_ASSERT((ForwardTraversal<OutputIterator>));
148  BOOST_CONCEPT_ASSERT((ReadableIterator<OutputIterator>));
149  BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator
150  , utility::DataWeight>));
151  }
152 
153  UnaryFunction func_;
154  };
155 
156 }}} // end of namespace normalizer, yat and thep
157 #endif
Centralize a range.
Definition: Centralizer.h:65
Centralizer(void)
default constructor
Definition: Centralizer.h:74
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:114
Definition: iterator_traits.h:47
Centralizer(const UnaryFunction &uf)
Definition: Centralizer.h:79
Holds a pair of data and associated weight.
Definition: DataWeight.h:39
Definition: iterator_traits.h:55
void operator()(InputIterator first, InputIterator last, OutputIterator result) const
Definition: Centralizer.h:106

Generated on Wed Jan 4 2017 02:23:07 for yat by  doxygen 1.8.5