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?

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.