yat  0.14.5pre
WeightedIteratorArchetype.h
1 #ifndef _theplu_yat_utility_weighted_iterator_archetype
2 #define _theplu_yat_utility_weighted_iterator_archetype
3 
4 // $Id: WeightedIteratorArchetype.h 3569 2017-01-09 03:43:08Z peter $
5 
6 /*
7  Copyright (C) 2014, 2015, 2016, 2017 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 <yat/utility/DataWeight.h>
26 #include <yat/utility/DataWeightProxy.h>
27 
28 #include <boost/iterator/iterator_archetypes.hpp>
29 #include <boost/iterator/iterator_concepts.hpp>
30 #include <boost/iterator/iterator_facade.hpp>
31 
32 namespace theplu {
33 namespace yat {
34 namespace utility {
35 
40  // Could have been a class inside of weighted_iterator_archetype,
41  // but we don't want it to be templatized.
43 
44  // Some private aux classes for weighted_iterator_archetype
46  namespace detail {
47  namespace weighted_iterator_archetype {
48  struct bogus {};
49 
50  // Classes calculating the reference type
51 
52  // default, not implemented
53  template<class AccessCategory> struct Reference {};
54 
55  // readable iterators return const data weight proxy
56  template<>
57  struct Reference<boost::iterator_archetypes::readable_iterator_t>
58  {
59  typedef const utility::DataWeightProxy<const double*, const double*> type;
60  };
61 
62 
63  // readable_writable iterators return mutable data weight proxy
64  template<>
65  struct Reference<boost::iterator_archetypes::readable_writable_iterator_t>
66  {
67  typedef utility::DataWeightProxy<double*, double*> type;
68  };
69 
70 
71  // Classes defining difference type based on traversal category
72 
73  // Default no difference type defined
74  template<class TraversalCategory> struct Difference {};
75 
76  // If traversal is at least forward traversal, int is returned,
77  // otherwise a bogus class is returned.
78 
79  template<>
80  struct Difference<boost::incrementable_traversal_tag>
81  { typedef bogus type; };
82 
83  template<>
84  struct Difference<boost::single_pass_traversal_tag>
85  { typedef bogus type; };
86 
87  template<>
88  struct Difference<boost::forward_traversal_tag>
89  { typedef int type; };
90 
91  template<>
92  struct Difference<boost::bidirectional_traversal_tag>
93  { typedef int type; };
94 
95  template<>
96  struct Difference<boost::random_access_traversal_tag>
97  { typedef int type; };
98 
99  } // end of namespace weighted_iterator_archetype
100  } // end of namespace detail
102 
132  template<typename AccessCategory, typename TraversalCategory>
134  : public boost::iterator_facade<
135  WeightedIteratorArchetype<AccessCategory, TraversalCategory>
136  , DataWeight
137  , TraversalCategory
138  , typename detail::weighted_iterator_archetype::Reference<AccessCategory>::type
139  , typename detail::weighted_iterator_archetype::Difference<TraversalCategory>::type>
140  {
142  public:
149  WeightedIteratorArchetype(void) { is_single_pass(TraversalCategory()); }
150 
157  explicit
159  {
160  }
161 
168  {}
169 
170  private:
171  friend class boost::iterator_core_access;
172 
173  typename detail::weighted_iterator_archetype::Reference<AccessCategory>::type
174  dereference(void) const
175  { return typename detail::weighted_iterator_archetype::Reference<AccessCategory>::type(NULL, NULL); }
176 
177  // operator== is only defined if single_pass
178  bool equal(const me& other) const
179  { is_single_pass(TraversalCategory()); return true; }
180 
181  // increment always defined
182  void increment(void) {}
183 
184  // only for bidirectional iterators
185  void decrement(void)
186  { is_bidirectional(TraversalCategory()); }
187 
188  // only for random access
189  int distance_to(const me& other) const
190  { is_random(TraversalCategory()); return 0; }
191 
192  // only for random access
193  void advance(int) { is_random(TraversalCategory()); }
194 
195  void is_single_pass(boost::single_pass_traversal_tag) const {}
196  void is_forward(boost::forward_traversal_tag) const {}
197  void is_bidirectional(boost::bidirectional_traversal_tag) const {}
198  void is_random(boost::random_access_traversal_tag) const {}
199  };
200 
201 }}}
202 #endif // end namspace theplu yat and utility
WeightedIteratorArchetype(WeightedIteratorArchetype_ctor_arg arg)
Constructor.
Definition: WeightedIteratorArchetype.h:158
WeightedIteratorArchetype(void)
Default Constructor.
Definition: WeightedIteratorArchetype.h:149
Definition: WeightedIteratorArchetype.h:42
Definition: WeightedIteratorArchetype.h:133
WeightedIteratorArchetype(const WeightedIteratorArchetype< boost::iterator_archetypes::readable_writable_iterator_t, TraversalCategory > &other)
Definition: WeightedIteratorArchetype.h:167

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5