yat
0.8.3pre
|
00001 #ifndef _theplu_yat_utility_concept_check_ 00002 #define _theplu_yat_utility_concept_check_ 00003 00004 // $Id: concept_check.h 2657 2011-11-16 00:41:17Z peter $ 00005 00006 /* 00007 Copyright (C) 2010, 2011 Peter Johansson 00008 00009 This file is part of the yat library, http://dev.thep.lu.se/yat 00010 00011 The yat library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License as 00013 published by the Free Software Foundation; either version 3 of the 00014 License, or (at your option) any later version. 00015 00016 The yat library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with yat. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 // always include config first 00026 #include "config_public.h" 00027 00028 #include "iterator_traits.h" 00029 00030 #include <boost/concept_archetype.hpp> 00031 #include <boost/concept_check.hpp> 00032 00033 namespace theplu { 00034 namespace yat { 00035 namespace utility { 00036 00055 template <class T> 00056 class Container2D 00057 { 00058 public: 00059 #ifdef YAT_HAVE_BOOST_CONCEPT_WITH_CONSTRUCTOR 00060 00061 Container2D(void) {} 00062 #endif 00063 00065 typedef typename T::value_type value_type; 00067 typedef typename T::const_reference const_reference; 00069 typedef typename T::const_iterator const_iterator; 00071 typedef typename T::const_row_iterator const_row_iterator; 00073 typedef typename T::const_column_iterator const_column_iterator; 00074 00078 BOOST_CONCEPT_USAGE(Container2D) 00079 { 00080 const_iterator iter_ = t_.begin(); 00081 iter_ = t_.end(); 00082 const_row_iterator row_iter_ = t_.begin_row(0); 00083 row_iter_ = t_.end_row(0); 00084 const_column_iterator col_iter_ = t_.begin_column(0); 00085 col_iter_ = t_.end_column(0); 00086 const_reference r = t_(0,0); 00087 value_ = r; 00088 size_t n = t_.rows(); 00089 n = t_.columns(); 00090 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_iterator>)); 00091 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_row_iterator>)); 00092 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_column_iterator>)); 00093 } 00094 00095 private: 00096 T t_; 00097 value_type value_; 00098 }; 00099 00118 template <class T> 00119 class Mutable_Container2D : public Container2D<T> 00120 { 00121 public: 00123 typedef typename T::reference reference; 00125 typedef typename T::iterator iterator; 00127 typedef typename T::row_iterator row_iterator; 00129 typedef typename T::column_iterator column_iterator; 00130 00134 BOOST_CONCEPT_USAGE(Mutable_Container2D) 00135 { 00136 iterator iter_ = t_.begin(); 00137 iter_ = t_.end(); 00138 row_iterator row_iter_ = t_.begin_row(0); 00139 row_iter_ = t_.end_row(0); 00140 column_iterator col_iter_ = t_.begin_column(0); 00141 col_iter_ = t_.end_column(0); 00142 reference r = t_(0,0); 00143 t_(0,0) = r; 00144 using boost::Mutable_RandomAccessIterator; // just to avoid long lines 00145 BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>)); 00146 BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>)); 00147 BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>)); 00148 } 00149 private: 00150 T t_; 00151 }; 00152 00153 00172 template <class T> 00173 class TrivialIterator 00174 : public boost::Assignable<T> 00175 , public boost::EqualityComparable<T> 00176 , public boost::DefaultConstructible<T> 00177 00178 { 00179 public: 00181 typedef typename std::iterator_traits<T>::iterator_category iterator_category; 00183 typedef typename std::iterator_traits<T>::value_type value_type; 00185 typedef typename std::iterator_traits<T>::difference_type difference_type; 00187 typedef typename std::iterator_traits<T>::pointer pointer; 00189 typedef typename std::iterator_traits<T>::reference reference; 00190 00194 BOOST_CONCEPT_USAGE(TrivialIterator) 00195 { 00196 T t; 00197 value_ = *t; 00198 } 00199 private: 00200 value_type value_; 00201 }; 00202 00221 template <class T> 00222 class DataIteratorConcept 00223 { 00224 public: 00226 typedef typename weighted_iterator_traits<T>::type tag; 00228 typedef typename std::iterator_traits<T>::value_type value_type; 00229 00233 BOOST_CONCEPT_USAGE(DataIteratorConcept) 00234 { 00235 BOOST_CONCEPT_ASSERT((TrivialIterator<T>)); 00236 tag t; 00237 constraints(t); 00238 } 00239 private: 00240 void constraints(yat::utility::unweighted_iterator_tag t) const 00241 { 00242 BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>)); 00243 } 00244 00245 void constraints(yat::utility::weighted_iterator_tag t) const 00246 { 00247 BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>)); 00248 } 00249 }; 00250 00251 00270 template <class T> 00271 class DistanceConcept : public boost::CopyConstructible<T> 00272 { 00273 public: 00277 BOOST_CONCEPT_USAGE(DistanceConcept) 00278 { 00279 boost::random_access_iterator_archetype<double> unweighted; 00280 boost::random_access_iterator_archetype<DataWeight> weighted; 00281 double d; 00282 d = distance_(unweighted, unweighted, unweighted); 00283 d = distance_(unweighted, unweighted, weighted); 00284 d = distance_(weighted, weighted, unweighted); 00285 d = distance_(weighted, weighted, weighted); 00286 } 00287 private: 00288 T distance_; 00289 }; 00290 00291 }}} // of namespace utility, yat, and theplu 00292 #endif