Changeset 1062
- Timestamp:
- Feb 10, 2008, 7:41:06 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/iterator_test.cc
r1038 r1062 49 49 bool ok = true; 50 50 51 *message << "testing utility::vector::iterator" << std::endl; 51 52 utility::vector vec(12); 52 53 classifier::DataLookup1D lookup(vec); … … 60 61 utility::vector::iterator end=vec.end(); 61 62 std::sort(begin, end); 63 64 *message << "testing classifier::DataLookup1D::const_iterator" << std::endl; 62 65 classifier::DataLookup1D::const_iterator lbegin=lookup.begin(); 63 66 classifier::DataLookup1D::const_iterator lend=lookup.end(); 64 67 68 *message << "copy from DataLookup1D to Vector" << std::endl; 65 69 std::copy(lbegin, lend, begin); 70 *message << "copy from Vector to Vector" << std::endl; 66 71 std::copy(begin, end, begin); 72 *message << "sort Vector" << std::endl; 67 73 std::sort(begin, end); 68 74 -
trunk/yat/classifier/DataLookup1D.cc
r1018 r1062 95 95 DataLookup1D::const_iterator DataLookup1D::begin(void) const 96 96 { 97 return DataLookup1D::const_iterator(*this, 0); 97 typedef utility::Iterator<const DataLookup2D, const double> Iter; 98 if (column_vector_) 99 return const_iterator(Iter(*matrix_, 0, index_), matrix_->columns()); 100 return const_iterator(Iter(*matrix_, index_, 0), 1); 98 101 } 99 102 … … 101 104 DataLookup1D::const_iterator DataLookup1D::end(void) const 102 105 { 103 return DataLookup1D::const_iterator(*this, size()); 106 typedef utility::Iterator<const DataLookup2D, const double> Iter; 107 if (column_vector_) 108 return const_iterator(Iter(*matrix_, matrix_->rows(), index_), 109 matrix_->columns()); 110 return const_iterator(Iter(*matrix_, index_+1, 0), 1); 104 111 } 105 112 -
trunk/yat/classifier/DataLookup1D.h
r1040 r1062 27 27 */ 28 28 29 #include " yat/utility/Functor.h"29 #include "DataLookup2D.h" 30 30 #include "yat/utility/Iterator.h" 31 #include "yat/utility/StrideIterator.h" 31 32 32 33 #include <iostream> … … 40 41 namespace classifier { 41 42 42 class DataLookup2D;43 44 43 /// 45 44 /// @brief Class for general vector view. 46 45 /// 47 48 46 class DataLookup1D 49 47 { … … 51 49 public: 52 50 /// 'Read Only' iterator 53 typedef utility:: Iterator<const utility::ContIdentity<const double,54 const DataLookup1D> >51 typedef utility::StrideIterator<utility::Iterator<const DataLookup2D, 52 const double> > 55 53 const_iterator; 56 54 -
trunk/yat/classifier/MatrixLookup.h
r1035 r1062 28 28 29 29 #include "DataLookup2D.h" 30 #include "yat/utility/Iterator.h" 30 31 31 32 #include <iostream> … … 69 70 class MatrixLookup : public DataLookup2D 70 71 { 71 72 typedef utility::Iterator<const MatrixLookup, const double&> const_iterator; 73 72 74 public: 73 74 75 75 /// 76 76 /// Constructor creating a lookup into the entire @a matrix. … … 217 217 218 218 /** 219 */ 220 const_iterator begin(void) const; 221 const_iterator begin_row(size_t) const; 222 const_iterator begin_column(size_t) const; 223 224 /** 219 225 the new MatrixLookup will consist of the rolumn vectors 220 226 defined by @a index. This means that the returned MatrixLookup -
trunk/yat/utility/Iterator.h
r1040 r1062 5 5 6 6 /* 7 Copyright (C) 2007 Peter Johansson7 Copyright (C) 2007, 2008 Peter Johansson 8 8 9 9 This file is part of the yat library, http://trac.thep.lu.se/yat … … 36 36 namespace utility { 37 37 38 class VectorBase;39 40 38 /** 41 39 @brief Iterator 42 40 */ 43 template<typename T>41 template<typename Container, typename T> 44 42 class Iterator 45 43 { … … 48 46 typedef double value_type; 49 47 typedef size_t difference_type; 48 typedef T reference; 50 49 typedef double* pointer; 51 typedef typename T::result_type reference; 52 typedef typename T::container_type Container ; 53 50 54 51 private: 55 typedef Iterator< T> self;52 typedef Iterator<Container, T> self; 56 53 57 54 public: … … 65 62 66 63 \param container iterator points to 67 \param index telling which element iterator points to 64 \param row telling which row iterator points to 65 \param colun telling which column iterator points to 68 66 */ 69 Iterator(Container& container, difference_type index)70 : container_(&container), index_( index) {}67 Iterator(Container& container, difference_type row, difference_type column) 68 : container_(&container), index_(row*container.columns()+column) {} 71 69 72 70 /** … … 75 73 reference operator*(void) const 76 74 { 77 yat_assert<std::out_of_range>(index_ <container_->size(),75 yat_assert<std::out_of_range>(index_ < this->size(), 78 76 "Iterator::operator*"); 79 return container_->operator()( index_);77 return container_->operator()(this->row(index_), this->column(index_)); 80 78 } 81 79 … … 85 83 reference operator[](difference_type n) const 86 84 { 87 yat_assert<std::out_of_range>(index_+n < container_->size(),85 yat_assert<std::out_of_range>(index_+n < this->size(), 88 86 "Iterator::operator[]"); 89 return container_->operator()( index_+n);87 return container_->operator()(this->row(index_+n), this->column(index_+n)); 90 88 } 91 89 … … 139 137 \return copy of resulting iterator 140 138 */ 141 friend Iterator operator+(const Iterator& lhs, size_tn)139 friend Iterator operator+(const Iterator& lhs, difference_type n) 142 140 { return self(*lhs.container_, lhs.index_+n); } 143 141 … … 147 145 \return copy of resulting iterator 148 146 */ 149 friend Iterator operator-(const Iterator& lhs, size_tn)147 friend Iterator operator-(const Iterator& lhs, difference_type n) 150 148 { return self(*lhs.container_, lhs.index_-n); } 151 149 … … 156 154 */ 157 155 friend difference_type operator-(const Iterator& lhs, const Iterator& rhs) 158 { return lhs.index_-rhs.index_; } 156 { 157 yat_assert<std::runtime_error>(lhs.container_==rhs.container_, 158 "Iterator::operator-"); 159 return lhs.index_-rhs.index_; 160 } 159 161 160 162 … … 165 167 */ 166 168 friend bool operator==(const self& lhs, const self& rhs) 167 { return lhs.container_==rhs.container_ && lhs.index_==rhs.index_; } 169 { 170 yat_assert<std::runtime_error>(lhs.container_==rhs.container_, 171 "Iterator::operator=="); 172 return lhs.index_==rhs.index_; 173 } 168 174 169 175 /** … … 172 178 \return False if \a lhs and \a rhs are pointing to same element 173 179 */ 174 friend bool operator!=(const Iterator& lhs, 175 const Iterator& rhs) 176 { return !(lhs.container_==rhs.container_ && lhs.index_==rhs.index_); } 180 friend bool operator!=(const Iterator& lhs, const Iterator& rhs) 181 { 182 yat_assert<std::runtime_error>(lhs.container_==rhs.container_, 183 "Iterator::operator!="); 184 return !(lhs==rhs); 185 } 177 186 178 187 /** … … 180 189 */ 181 190 friend bool operator<(const self& lhs, const self& rhs) 182 { return lhs.index_<rhs.index_; } 191 { 192 yat_assert<std::runtime_error>(lhs.container_==rhs.container_, 193 "Iterator::operator<"); 194 return lhs.index_<rhs.index_; 195 } 183 196 184 197 /** … … 186 199 */ 187 200 friend bool operator<=(const self& lhs, const self& rhs) 188 { return lhs.index_<=rhs.index_; } 201 { 202 yat_assert<std::runtime_error>(lhs.container_==rhs.container_, 203 "Iterator::operator<="); 204 return lhs.index_<=rhs.index_; 205 } 189 206 190 207 /** 191 208 \brief Larger operator 192 209 */ 193 friend bool operator>(const self& lhs, 194 const self& rhs) 195 { return lhs.index_>rhs.index_; } 210 friend bool operator>(const self& lhs, const self& rhs) 211 { 212 yat_assert<std::runtime_error>(lhs.container_==rhs.container_, 213 "Iterator::operator>"); 214 return lhs.index_>rhs.index_; 215 } 196 216 197 217 /** … … 199 219 */ 200 220 friend bool operator>=(const self& lhs, const self& rhs) 201 { return lhs.index_>=rhs.index_; } 221 { 222 yat_assert<std::runtime_error>(lhs.container_==rhs.container_, 223 "Iterator::operator>="); 224 return lhs.index_>=rhs.index_; 225 } 202 226 203 227 private: 204 228 Container* container_; 205 size_t index_; 229 difference_type index_; 230 231 difference_type column(difference_type i) const 232 { return i % container_->columns(); } 233 difference_type row(difference_type i) const 234 { return static_cast<difference_type>(i/container_->columns()); } 235 difference_type size() const 236 { return container_->columns()*container_->rows(); } 206 237 207 238 // Using compiler generated copy -
trunk/yat/utility/Makefile.am
r1044 r1062 36 36 include_utility_HEADERS = \ 37 37 Alignment.h ColumnStream.h CommandLine.h \ 38 Exception.h FileUtil.h Functor.hIterator.h iterator_traits.h \38 Exception.h FileUtil.h Iterator.h iterator_traits.h \ 39 39 IteratorWeighted.h kNNI.h matrix.h NNI.h \ 40 40 Option.h OptionArg.h OptionFile.h OptionInFile.h OptionOutFile.h \
Note: See TracChangeset
for help on using the changeset viewer.