Changeset 881


Ignore:
Timestamp:
Sep 22, 2007, 10:22:36 PM (16 years ago)
Author:
Peter
Message:

merged constIterator into Iterator and added an extra template parameter. There are problems with conversion from iterator to const_iterator

Location:
trunk
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/iterator_test.cc

    r880 r881  
    4949  classifier::DataLookup1D lookup(vec);
    5050  utility::vector::iterator begin=vec.begin();
     51  // test iterator to const_iterator conversion
     52  utility::vector::const_iterator ci = vec.begin();
     53  ci = begin;
     54  //if (begin!=ci)
     55  //ok = false;
     56
    5157  utility::vector::iterator end=vec.end();
    5258  std::sort(begin, end);
  • trunk/yat/classifier/DataLookup1D.h

    r880 r881  
    5151  public:
    5252
    53     typedef utility::constIterator<const classifier::DataLookup1D>
     53    typedef utility::Iterator<const double, const classifier::DataLookup1D>
    5454    const_iterator;
    5555
  • trunk/yat/utility/Iterator.h

    r880 r881  
    3535     @brief Iterator
    3636  */
    37   template<typename Container>
     37  template<typename return_type, typename Container>
    3838  class Iterator
    3939  {
     
    5252      : container_(&container), index_(index) {}
    5353
    54     reference operator*(void) const { return container_->operator()(index_); }
     54    return_type operator*(void) const { return container_->operator()(index_); }
    5555    const Iterator& operator++(void) { ++index_; return *this; }
    5656    Iterator operator++(int)
    57     { Iterator<Container> tmp(*this); ++index_; return tmp;}
     57    { Iterator<return_type, Container> tmp(*this); ++index_; return tmp;}
    5858    Iterator& operator+=(int n) { index_+=n; return *this; }
    5959    Iterator operator+(int n)
    60     { return Iterator<Container>(*container_, index_+n); }
     60    { return Iterator<return_type, Container>(*container_, index_+n); }
    6161    Iterator operator--(int)
    62     { Iterator<Container> tmp(*this); --index_; return tmp;}
     62    { Iterator<return_type, Container> tmp(*this); --index_; return tmp;}
    6363    Iterator operator--(void) { --index_; return *this; }
    6464    Iterator& operator-=(int n) { index_-=n; return *this; }
    6565    Iterator operator-(size_t n)
    66     { return Iterator<Container>(*container_, index_-n); }
     66    { return Iterator<return_type, Container>(*container_, index_-n); }
    6767    size_t operator-(const Iterator& rhs)
    6868    { return index_-rhs.index_; }
    6969
    70     bool equal(const Iterator<Container>& other) const
     70    bool equal(const Iterator<return_type, Container>& other) const
    7171    { return container_==other.container_ && index_==other.index_; }
    7272
    73     bool less(const Iterator<Container>& other) const
     73    bool less(const Iterator<return_type, Container>& other) const
    7474    { return index_<other.index_; }
     75
     76    operator Iterator<const double, const Container> ()
     77    { return Iterator<const double, const Container>(*container_, index_); }
    7578
    7679  private:
     
    8386  };
    8487
    85     template <typename T>
    86     inline bool operator==(const Iterator<T>& lhs,
    87                            const Iterator<T>& rhs)
    88     {
    89       return lhs.equal(rhs);
    90     }
     88  template <typename T1, typename T2>
     89  inline bool operator==(const Iterator<T1,T2>& lhs,
     90                         const Iterator<T1,T2>& rhs)
     91  {
     92    return lhs.equal(rhs);
     93  }
    9194
    92     template <typename T>
    93     inline bool operator!=(const Iterator<T>& lhs,
    94                            const Iterator<T>& rhs)
    95     {
    96       return !(lhs==rhs);
    97     }
    98 
    99 
    100     template <typename T>
    101     inline bool operator<(const Iterator<T>& lhs,
    102                           const Iterator<T>& rhs)
    103     {
    104       return lhs<rhs;
    105     }
    106 
    107 
    108     template <typename T>
    109     inline bool operator<=(const Iterator<T>& lhs,
    110                            const Iterator<T>& rhs)
    111     {
    112       return !(rhs<lhs);
    113     }
    114 
    115 
    116     template <typename T>
    117     inline bool operator>(const Iterator<T>& lhs,
    118                           const Iterator<T>& rhs)
    119     {
    120       return rhs<lhs;
    121     }
    122 
    123 
    124     template <typename T>
    125     inline bool operator>=(const Iterator<T>& lhs,
    126                            const Iterator<T>& rhs)
    127     {
    128       return !(lhs<rhs);
    129     }
     95  template <typename T1, typename T2>
     96  inline bool operator!=(const Iterator<T1,T2>& lhs,
     97                         const Iterator<T1,T2>& rhs)
     98  {
     99    return !(lhs==rhs);
     100  }
     101 
     102 
     103  template <typename T1, typename T2>
     104  inline bool operator<(const Iterator<T1,T2>& lhs,
     105                        const Iterator<T1,T2>& rhs)
     106  {
     107    return lhs<rhs;
     108  }
     109 
     110 
     111  template <typename T1, typename T2>
     112  inline bool operator<=(const Iterator<T1,T2>& lhs,
     113                         const Iterator<T1,T2>& rhs)
     114  {
     115    return !(rhs<lhs);
     116  }
     117 
     118 
     119  template <typename T1, typename T2>
     120  inline bool operator>(const Iterator<T1,T2>& lhs,
     121                        const Iterator<T1,T2>& rhs)
     122  {
     123    return rhs<lhs;
     124  }
     125 
     126 
     127  template <typename T1, typename T2>
     128  inline bool operator>=(const Iterator<T1,T2>& lhs,
     129                         const Iterator<T1,T2>& rhs)
     130  {
     131    return !(lhs<rhs);
     132  }
    130133
    131134
  • trunk/yat/utility/Makefile.am

    r880 r881  
    3232
    3333include_utility_HEADERS = \
    34   Alignment.h constIterator.h Exception.h FileUtil.h Iterator.h \
     34  Alignment.h Exception.h FileUtil.h Iterator.h \
    3535  kNNI.h matrix.h NNI.h \
    3636  PCA.h stl_utility.h SVD.h TypeInfo.h utility.h vector.h WeNNI.h
  • trunk/yat/utility/vector.h

    r880 r881  
    8989  public:
    9090
    91     typedef Iterator<vector> iterator;
    92     typedef constIterator<const vector> const_iterator;
     91    typedef Iterator<double&, vector> iterator;
     92    typedef Iterator<const double, const vector> const_iterator;
    9393
    9494    /**
Note: See TracChangeset for help on using the changeset viewer.