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

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

merge patch release 0.4.2 to trunk. Delta 0.4.2-0.4.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1#ifndef _theplu_yat_utility_iterator_policy_
2#define _theplu_yat_utility_iterator_policy_
3
4// $Id: IteratorPolicy.h 1437 2008-08-25 17:55: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 "iterator_traits.h"
28
29#include <cstddef>
30#include <utility>
31
32namespace theplu {
33namespace yat {
34namespace utility {
35
36  /**
37     \brief Default policy for Iterator
38  */
39  template<class Container, typename reference, typename weight_t>
40  struct IteratorPolicy
41  {
42    /// type returned from function data
43    typedef reference data_type;
44    /// type returned from function weight
45    typedef weight_t weight_type;
46    /**
47       returns unweighted_iterator_tag as Policy is intended to be
48       used in a unweighted iterator
49    */
50    typedef unweighted_iterator_tag weighted_iterator_type;
51
52    /**
53       \return c(row, column)
54     */
55    data_type data(const Container& c, size_t row, size_t column) const
56    {
57      return c(row, column);
58    }
59
60    /**
61       \return same as data
62    */
63    reference dereference(const Container& c, size_t row, size_t column) const
64    {
65      return c(row, column);
66    }
67
68    /**
69       \return 1.0
70    */
71    weight_type weight(const Container& c, size_t row, size_t column) const
72    {
73      return 1.0;
74    }
75   
76  };
77
78
79  /**
80     \brief policy for weighted Iterator
81  */
82  template<class Container, typename data_t, typename weight_t>
83  struct IteratorPolicyWeighted
84  {
85    /// type returned from function dereference
86    typedef std::pair<data_t, weight_t> reference;
87    /// type returned from function data
88    typedef data_t data_type;
89    /// type returned from function weight
90    typedef weight_t weight_type;
91    /// weighted_iterator_tag as Policy is intended for weighted iterators
92    typedef weighted_iterator_tag weighted_iterator_type;
93
94    /**
95       \return data
96    */
97    data_type data(const Container& c, size_t row, size_t column) const
98    {
99      return c.data(row, column);
100    }
101
102    /**
103       \return a pair in of <data, weight>.
104    */
105    reference dereference(const Container& c, size_t row, size_t column) const
106    {
107      return reference(this->data(c, row, column),this->weight(c, row, column));
108    }
109
110    /**
111       \return weight
112    */
113    weight_type weight(const Container& c, size_t row, size_t column) const
114    {
115      return c.weight(row, column);
116    }
117   
118  };
119}}} // of namespace utility, yat, and theplu
120
121#endif
Note: See TracBrowser for help on using the repository browser.