source: trunk/yat/utility/IteratorPolicy.h @ 1092

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

fixes #329 rename weighted_type to weighted_iterator_tag

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1#ifndef _theplu_yat_utility_iterator_policy_
2#define _theplu_yat_utility_iterator_policy_
3
4// $Id: IteratorPolicy.h 1092 2008-02-14 21:54:19Z 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 "iterator_traits.h"
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33  /**
34     \brief Default policy for Iterator
35  */
36  template<class Container, typename reference, typename weight_t>
37  struct IteratorPolicy
38  {
39    typedef reference data_type;
40    typedef weight_t weight_type;
41    typedef unweighted_iterator_tag weighted_iterator_type;
42
43    data_type data(const Container& c, size_t row, size_t column) const
44    {
45      return c(row, column);
46    }
47
48    reference dereference(const Container& c, size_t row, size_t column) const
49    {
50      return c(row, column);
51    }
52
53    weight_type weight(const Container& c, size_t row, size_t column) const
54    {
55      return 1.0;
56    }
57   
58  };
59
60
61  /**
62     \brief policy for weighted Iterator
63  */
64  template<class Container, typename data_t, typename weight_t>
65  struct IteratorPolicyWeighted
66  {
67    typedef std::pair<data_t, weight_t> reference;
68    typedef data_t data_type;
69    typedef weight_t weight_type;
70    typedef weighted_iterator_tag weighted_iterator_type;
71
72    data_type data(const Container& c, size_t row, size_t column) const
73    {
74      return c.data(row, column);
75    }
76
77    reference dereference(const Container& c, size_t row, size_t column) const
78    {
79      return reference(this->data(c, row, column),this->weight(c, row, column));
80    }
81
82    weight_type weight(const Container& c, size_t row, size_t column) const
83    {
84      return c.weight(row, column);
85    }
86   
87  };
88}}} // of namespace utility, yat, and theplu
89
90#endif
Note: See TracBrowser for help on using the repository browser.