00001 #ifndef _theplu_yat_utility_concept_check_
00002 #define _theplu_yat_utility_concept_check_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "iterator_traits.h"
00026
00027 #include <boost/concept_archetype.hpp>
00028 #include <boost/concept_check.hpp>
00029
00030 namespace theplu {
00031 namespace yat {
00032 namespace utility {
00033
00052 template <class T>
00053 class Container2D
00054 {
00055 public:
00057 Container2D(void) {}
00058
00060 typedef typename T::value_type value_type;
00062 typedef typename T::const_reference const_reference;
00064 typedef typename T::const_iterator const_iterator;
00066 typedef typename T::const_row_iterator const_row_iterator;
00068 typedef typename T::const_column_iterator const_column_iterator;
00069
00073 BOOST_CONCEPT_USAGE(Container2D)
00074 {
00075 const_iterator iter_ = t_.begin();
00076 iter_ = t_.end();
00077 const_row_iterator row_iter_ = t_.begin_row(0);
00078 row_iter_ = t_.end_row(0);
00079 const_column_iterator col_iter_ = t_.begin_column(0);
00080 col_iter_ = t_.end_column(0);
00081 const_reference r = t_(0,0);
00082 value_ = r;
00083 size_t n = t_.rows();
00084 n = t_.columns();
00085 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_iterator>));
00086 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_row_iterator>));
00087 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_column_iterator>));
00088 }
00089
00090 private:
00091 T t_;
00092 value_type value_;
00093 };
00094
00113 template <class T>
00114 class Mutable_Container2D : public Container2D<T>
00115 {
00116 public:
00118 typedef typename T::reference reference;
00120 typedef typename T::iterator iterator;
00122 typedef typename T::row_iterator row_iterator;
00124 typedef typename T::column_iterator column_iterator;
00125
00129 BOOST_CONCEPT_USAGE(Mutable_Container2D)
00130 {
00131 iterator iter_ = t_.begin();
00132 iter_ = t_.end();
00133 row_iterator row_iter_ = t_.begin_row(0);
00134 row_iter_ = t_.end_row(0);
00135 column_iterator col_iter_ = t_.begin_column(0);
00136 col_iter_ = t_.end_column(0);
00137 reference r = t_(0,0);
00138 t_(0,0) = r;
00139 using boost::Mutable_RandomAccessIterator;
00140 BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
00141 BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
00142 BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
00143 }
00144 private:
00145 T t_;
00146 };
00147
00148
00167 template <class T>
00168 class TrivialIterator
00169 : public boost::Assignable<T>
00170 , public boost::EqualityComparable<T>
00171 , public boost::DefaultConstructible<T>
00172
00173 {
00174 public:
00176 typedef typename std::iterator_traits<T>::iterator_category iterator_category;
00178 typedef typename std::iterator_traits<T>::value_type value_type;
00180 typedef typename std::iterator_traits<T>::difference_type difference_type;
00182 typedef typename std::iterator_traits<T>::pointer pointer;
00184 typedef typename std::iterator_traits<T>::reference reference;
00185
00189 BOOST_CONCEPT_USAGE(TrivialIterator)
00190 {
00191 T t;
00192 value_ = *t;
00193 }
00194 private:
00195 value_type value_;
00196 };
00197
00216 template <class T>
00217 class DataIteratorConcept
00218 {
00219 public:
00221 typedef typename weighted_iterator_traits<T>::type tag;
00223 typedef typename std::iterator_traits<T>::value_type value_type;
00224
00228 BOOST_CONCEPT_USAGE(DataIteratorConcept)
00229 {
00230 BOOST_CONCEPT_ASSERT((TrivialIterator<T>));
00231 tag t;
00232 constraints(t);
00233 }
00234 private:
00235 void constraints(yat::utility::unweighted_iterator_tag t) const
00236 {
00237 BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
00238 }
00239
00240 void constraints(yat::utility::weighted_iterator_tag t) const
00241 {
00242 BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
00243 }
00244 };
00245
00246
00265 template <class T>
00266 class DistanceConcept : public boost::CopyConstructible<T>
00267 {
00268 public:
00272 BOOST_CONCEPT_USAGE(DistanceConcept)
00273 {
00274 boost::random_access_iterator_archetype<double> unweighted;
00275 boost::random_access_iterator_archetype<DataWeight> weighted;
00276 double d;
00277 d = distance_(unweighted, unweighted, unweighted);
00278 d = distance_(unweighted, unweighted, weighted);
00279 d = distance_(weighted, weighted, unweighted);
00280 d = distance_(weighted, weighted, weighted);
00281 }
00282 private:
00283 T distance_;
00284 };
00285
00286 }}}
00287 #endif