Changeset 1365


Ignore:
Timestamp:
Jul 10, 2008, 10:30:07 PM (13 years ago)
Author:
Peter
Message:

working on ticket:369 - created a DataIterator? that seems to work. However, it can't work in a mutable fashion because of limitations in iterator_traits (see #391). Also there should be a WeightIterator? before ticket:369 can be closed

Location:
trunk
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/test/iterator_test.cc

    r1363 r1365  
    2929#include "yat/classifier/MatrixLookupWeighted.h"
    3030#include "yat/utility/Container2DIterator.h"
     31#include "yat/utility/DataIterator.h"
    3132#include "yat/utility/Matrix.h"
    32 #include "yat/utility/IteratorData.h"
    3333#include "yat/utility/Vector.h"
    3434
    3535#include <algorithm>
    3636#include <fstream>
     37
     38#include <vector>
    3739
    3840using namespace theplu::yat;
     
    8991    suite.add(false);
    9092
    91   utility::IteratorData<classifier::DataLookupWeighted1D::const_iterator>
     93  utility::DataIterator<classifier::DataLookupWeighted1D::const_iterator>
    9294    data_iter(aw2.begin());
    93 
     95  suite.add(*data_iter == 1.0);
     96  suite.add(*make_data_iterator(aw2.begin()) == 1.0);
     97  std::vector<double> stl_vec(1,0);
     98  utility::DataIterator<std::vector<double>::iterator> 
     99    data_iter2(stl_vec.begin());
     100  suite.add(*data_iter2 == 0.0);
    94101
    95102  classifier::MatrixLookup ml(m);
  • trunk/yat/utility/DataIterator.h

    r1363 r1365  
    1 #ifndef _theplu_yat_utility_iterator_data_
    2 #define _theplu_yat_utility_iterator_data_
     1#ifndef _theplu_yat_utility_data_iterator_
     2#define _theplu_yat_utility_data_iterator_
    33
    44// $Id$
     
    2525*/
    2626
    27 #include "yat_assert.h"
     27#include <boost/iterator/iterator_adaptor.hpp>
    2828
    2929namespace theplu {
     
    3232
    3333  /**
    34      @brief Iterator
     34     @brief DataIterator
    3535  */
    36   template<typename T>
    37   class IteratorData
     36  template<typename Base>
     37  class DataIterator
     38    : public boost::iterator_adaptor<
     39    DataIterator<Base>               // Derived
     40    , Base                          // Base
     41    , double              // Value
     42    , boost::forward_traversal_tag    // CategoryOrTraversal
     43    , double
     44    >
     45
    3846  {
    3947  public:
    40     IteratorData(T);
     48    explicit DataIterator(Base b)
     49      : DataIterator::iterator_adaptor_(b) {}
     50
     51    double operator*(void) const
     52    { return iterator_traits<Base>().data(this->base()); }
    4153
    4254  private:
    43     T base_;
    4455  };
    4556
    46   template<typename T>
    47   IteratorData<T>::IteratorData(T base)
    48     : base_(base)
    49   {}
     57  /**
     58     \brief convenient function to create DataIterator
     59
     60     Convenient function in same fashion as std::make_pair.
     61   */
     62  template<typename Base>
     63  DataIterator<Base> make_data_iterator(Base base)
     64  {
     65    return DataIterator<Base>(base);
     66  }
     67 
    5068
    5169
  • trunk/yat/utility/Makefile.am

    r1364 r1365  
    3838include_utility_HEADERS = \
    3939  Alignment.h ColumnStream.h CommandLine.h \
    40   Container2DIterator.h \
    41   Exception.h FileUtil.h Index.h IteratorData.h \
     40  Container2DIterator.h DataIterator.h \
     41  Exception.h FileUtil.h Index.h \
    4242  IteratorPolicy.h iterator_traits.h \
    4343  kNNI.h Matrix.h NNI.h \
  • trunk/yat/utility/iterator_traits.h

    r1275 r1365  
    135135     This class must be implemented for every iterator that can be weighted.
    136136
    137      \see StrideIterator and Iterator
     137     \see StrideIterator and Container2DIterator
    138138   */
    139139  template <class Iter>
Note: See TracChangeset for help on using the changeset viewer.