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