Changeset 1537 for trunk/yat


Ignore:
Timestamp:
Sep 27, 2008, 12:37:33 AM (13 years ago)
Author:
Peter
Message:

refs #368 - redesign to solve some issues regarding mutable functionality in WeightedIterator?

Location:
trunk/yat/utility
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/DataWeightProxy.h

    r1535 r1537  
    3333
    3434     \brief Proxy class for DataWeight
     35
     36     DataIterator and WeightIterator should be a TrivialIterator
    3537  */
     38  template<typename DataIterator, typename WeightIterator>
    3639  class DataWeightProxy
    3740  {
     
    4043       \brief Default constructor
    4144
    42        \param data data value to hold
    43        \param weight weight value to hold
     45       \param data iterator pointing to data to hold
     46       \param weight iterator pointing to weight to hold
    4447     */
    45     DataWeightProxy(double& data, double& weight);
     48    DataWeightProxy(DataIterator data, WeightIterator weight)
     49      : data_(data), weight_(weight) {}
    4650
    4751    /**
    4852       \return reference to data
    4953     */
    50     double& data(void);
     54    double& data(void) { return *data_; }
    5155
    5256    /**
    5357       \return const reference to data
    5458     */
    55     const double& data(void) const;
     59    const double& data(void) const { return *data_ ; }
    5660
    5761    /**
    5862       \return reference to weight
    5963     */
    60     double& weight(void);
     64    double& weight(void) { return *weight_; }
    6165
    6266    /**
    6367       \return const reference to weight
    6468     */
    65     const double& weight(void) const;
     69    const double& weight(void) const { return *weight_; }
    6670
    6771    /**
    6872       \brief assignment operator
    6973     */
    70     DataWeightProxy& operator=(const DataWeight& rhs);
     74    DataWeightProxy& operator=(const DataWeight& rhs)
     75    {
     76      data() = rhs.data();
     77      weight() = rhs.weight();
     78      return *this;
     79    }
    7180
    7281    /**
    7382       \brief Conversion to DataWeight
    7483     */
    75     operator DataWeight() const;
     84    operator DataWeight() const { return DataWeight(data(), weight()); }
    7685
    7786  private:
    78     double& data_;
    79     double& weight_;
     87    DataIterator data_;
     88    WeightIterator weight_;
    8089
    81     // no copying
    82     DataWeightProxy(const DataWeightProxy&);
    83     DataWeightProxy& operator=(const DataWeightProxy&);
     90    // using compiler generated copy and assignment
     91    //DataWeightProxy& operator=(const DataWeightProxy&);
     92    //DataWeightProxy(const DataWeightProxy&);
    8493  };
     94
     95 
     96  /**
     97     \brief equality operator
     98   */
     99  template<typename DataIterator, typename WeightIterator>
     100  bool operator==(const DataWeightProxy<DataIterator, WeightIterator>& lhs,
     101                  const DataWeightProxy<DataIterator, WeightIterator>& rhs)
     102  {
     103    return lhs.data()==rhs.data() && lhs.weight()==rhs.weight();
     104  }
    85105
    86106}}} // of namespace utility, yat, and theplu
  • trunk/yat/utility/Makefile.am

    r1533 r1537  
    2323noinst_LTLIBRARIES = libutility.la
    2424libutility_la_SOURCES = \
    25   Alignment.cc ColumnStream.cc CommandLine.cc DataWeight.cc DataWeightProxy.cc \
     25  Alignment.cc ColumnStream.cc CommandLine.cc DataWeight.cc \
    2626  FileUtil.cc Index.cc kNNI.cc \
    2727  Matrix.cc MatrixWeighted.cc NNI.cc Option.cc \
  • trunk/yat/utility/WeightedIterator.h

    r1532 r1537  
    2323*/
    2424
     25#include <DataWeight.h>
     26#include <DataWeightProxy.h>
     27
    2528#include <boost/iterator/iterator_facade.hpp>
    2629
     
    3235
    3336  /**
    34      @brief WeightedIterator
     37     \brief WeightedIterator
    3538  */
    3639  template<typename DataIterator, typename WeightIterator>
     
    3942    WeightedIterator<DataIterator, WeightIterator>,
    4043    DataWeight,
    41     std::random_access_iterator_tag,
    42     DataWeight>
     44    typename std::iterator_traits<DataIterator>::iterator_category,
     45    DataWeightProxy<DataIterator, WeightIterator> >
    4346   
    4447  {
     
    5053      : d_iter_(d), w_iter_(w)
    5154    {}
     55   
     56
     57    /**
     58       \brief element operator
     59     */
     60    DataWeightProxy<DataIterator, WeightIterator> operator[](int n) const
     61    {
     62      return DataWeightProxy<DataIterator, WeightIterator>(d_iter_+n,
     63                                                           w_iter_+n);
     64    }     
     65   
    5266
    5367    /**
    5468       \brief Conversion constructor.
    55 
     69       
    5670       Create a WeightIterator<Base> from a
    5771       WeightIterator<B2>. Possible if B2 is convertible to a
     
    7286    DataIterator d_iter_;
    7387    WeightIterator w_iter_;
    74 
     88   
    7589    void advance(size_t n)
    7690    { std::advance(d_iter_, n); std::advance(w_iter_, n); }
    7791
    7892    void decrement(void) { --d_iter_; --w_iter_; }
    79 
     93   
    8094    typename std::iterator_traits<DataIterator>::difference_type
    8195    distance_to(const WeightedIterator& other) const
    8296    { return std::distance(d_iter_, other.d_iter_); }
    8397
    84     DataWeight dereference(void) const
    85     { return DataWeight(*d_iter_, *w_iter_); }
     98    utility::DataWeightProxy<DataIterator, WeightIterator>
     99    dereference(void) const
     100    {
     101      return DataWeightProxy<DataIterator, WeightIterator>(d_iter_,
     102                                                           w_iter_);
     103    }
    86104
    87105    bool equal(const WeightedIterator& other) const
Note: See TracChangeset for help on using the changeset viewer.