source: trunk/yat/utility/concept_check.h @ 2263

Last change on this file since 2263 was 2263, checked in by Peter, 11 years ago

adding a class DataIteratorConcept? for concept data iterator. refs #624

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1#ifndef _theplu_yat_utility_concept_check_
2#define _theplu_yat_utility_concept_check_
3
4// $Id: concept_check.h 2263 2010-05-26 22:13:07Z peter $
5
6/*
7  Copyright (C) 2010 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 <boost/concept_check.hpp>
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33  /**
34     \brief Concept check for \ref concept_container_2d
35
36     This class is intended to be used in a <a
37     href="\boost_url/concept_check/using_concept_check.htm">
38     BOOST_CONCEPT_ASSERT </a>
39
40     \code
41     template<class T>
42     void some_function(const T& t)
43     {
44     BOOST_CONCEPT_ASSERT((Container2D<T>));
45     ...
46     }
47     \endcode
48  */
49  template <class T>
50  class Container2D
51  {
52  public:
53    /// value_type
54    typedef typename T::value_type value_type;
55    /// const_reference
56    typedef typename T::const_reference const_reference;
57    /// const_iterator
58    typedef typename T::const_iterator const_iterator;
59    /// const_row_iterator
60    typedef typename T::const_row_iterator const_row_iterator;
61    /// const_column_iterator
62    typedef typename T::const_column_iterator const_column_iterator;
63
64    /**
65       \brief function doing the concept test
66     */
67    BOOST_CONCEPT_USAGE(Container2D)
68    {
69      const_iterator iter_ = t_.begin();
70      iter_ = t_.end();
71      const_row_iterator row_iter_ = t_.begin_row(0);
72      row_iter_ = t_.end_row(0);
73      const_column_iterator col_iter_ = t_.begin_column(0);
74      col_iter_ = t_.end_column(0);
75      const_reference r = t_(0,0);
76      value_ = r;
77      size_t n = t_.rows();
78      n = t_.columns();
79      BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_iterator>));
80      BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_row_iterator>));
81      BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_column_iterator>));
82    }
83
84  private:
85    T t_;
86    value_type value_;
87  };
88
89  /**
90     \brief Concept check for \ref concept_mutable_container_2d
91
92     This class is intended to be used in a <a
93     href="\boost_url/concept_check/using_concept_check.htm">
94     BOOST_CONCEPT_ASSERT </a>
95
96     \code
97     template<class T>
98     void some_function(const T& t)
99     {
100     BOOST_CONCEPT_ASSERT((Mutable_Container2D<T>));
101     ...
102     }
103     \endcode
104  */
105  template <class T>
106  class Mutable_Container2D : public Container2D<T>
107  {
108  public:
109    /// reference
110    typedef typename T::reference reference;
111    /// iterator
112    typedef typename T::iterator iterator;
113    /// row_iterator
114    typedef typename T::row_iterator row_iterator;
115    /// column_iterator
116    typedef typename T::column_iterator column_iterator;
117
118    /**
119       \brief function doing the concept test
120     */
121    BOOST_CONCEPT_USAGE(Mutable_Container2D)
122    {
123      iterator iter_ = t_.begin();
124      iter_ = t_.end();
125      row_iterator row_iter_ = t_.begin_row(0);
126      row_iter_ = t_.end_row(0);
127      column_iterator col_iter_ = t_.begin_column(0);
128      col_iter_ = t_.end_column(0);
129      reference r = t_(0,0);
130      t_(0,0) = r;
131      using boost::Mutable_RandomAccessIterator; // just to avoid long lines
132      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
133      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
134      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
135    }
136  private:
137    T t_;
138  };
139
140
141  /**
142     \brief Concept check for \trivial_iterator
143
144     This class is intended to be used in a <a
145     href="\boost_url/concept_check/using_concept_check.htm">
146     BOOST_CONCEPT_ASSERT </a>
147
148     \code
149     template<class Iterator>
150     void some_function(const Iterator& it)
151     {
152     BOOST_CONCEPT_ASSERT((TrivialIterator<Iterator>));
153     ...
154     }
155     \endcode
156  */
157  template <class T>
158  class TrivialIterator
159    : public boost::Assignable<T>
160    , public boost::EqualityComparable<T>
161    , public boost::DefaultConstructible<T>
162
163  {
164  public:
165    /// iterator_category
166    typedef typename std::iterator_traits<T>::iterator_category iterator_category;
167    /// value_type
168    typedef typename std::iterator_traits<T>::value_type value_type;
169    /// difference_type
170    typedef typename std::iterator_traits<T>::difference_type difference_type;
171    /// pointer
172    typedef typename std::iterator_traits<T>::pointer pointer;
173    /// reference
174    typedef typename std::iterator_traits<T>::reference reference;
175
176    /**
177       \brief function doing the concept test
178     */
179    BOOST_CONCEPT_USAGE(TrivialIterator)
180    {
181      T t;
182      value_ = *t;
183    }
184  private:
185    value_type value_;
186  };
187
188  /**
189     \brief Concept check for \ref concept_data_iterator
190
191     This class is intended to be used in a <a
192     href="\boost_url/concept_check/using_concept_check.htm">
193     BOOST_CONCEPT_ASSERT </a>
194
195     \code
196     template<class Iterator>
197     void some_function(const Iterator& it)
198     {
199     BOOST_CONCEPT_ASSERT((DataIteratorConcept<Iterator>));
200     ...
201     }
202     \endcode
203  */
204  template <class T>
205  class DataIteratorConcept
206  {
207  public:
208    /// tag
209    typedef typename weighted_iterator_traits<T>::type tag;
210    /// value_type
211    typedef typename std::iterator_traits<T>::value_type value_type;
212
213    /**
214       \brief function doing the concept test
215     */
216    BOOST_CONCEPT_USAGE(DataIteratorConcept)
217    {
218      BOOST_CONCEPT_ASSERT((TrivialIterator<T>));
219      tag t;
220      constraints(t);
221    }
222  private:
223    void constraints(yat::utility::unweighted_iterator_tag t) const
224    { 
225      BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
226    }
227
228    void constraints(yat::utility::weighted_iterator_tag t) const
229    {
230      BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
231    }
232
233  };
234
235}}} // of namespace utility, yat, and theplu
236#endif
Note: See TracBrowser for help on using the repository browser.