Changeset 1535


Ignore:
Timestamp:
Sep 25, 2008, 9:01:48 PM (15 years ago)
Author:
Peter
Message:

fixing DataWeightProxy?

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/data_weight_proxy_test.cc

    r1533 r1535  
    2525#include "yat/utility/DataWeightProxy.h"
    2626
     27namespace theplu {
     28namespace yat {
     29namespace test {
     30  class ProxyHolder
     31  {
     32  public:
     33    ProxyHolder(utility::DataWeightProxy& proxy)
     34      : proxy_(proxy) {}
     35
     36    inline utility::DataWeightProxy& operator()(void) { return proxy_; }
     37    inline const utility::DataWeightProxy& operator()(void) const
     38    { return proxy_; }
     39  private:
     40    utility::DataWeightProxy& proxy_;
     41  };
     42}}}
     43
    2744using namespace theplu::yat;
    2845
     
    3350
    3451  using utility::DataWeightProxy;
     52  using utility::DataWeight;
    3553
    3654  double x=1.2;
    37   double y=3.14;
    38   DataWeightProxy proxy(x,y);
     55  double w=3.14;
     56  DataWeight xw(x, w);
     57  DataWeightProxy proxy(x,w);
     58  if (xw != proxy) {
     59    suite.add(false);
     60  }
     61  if (proxy != xw) {
     62    suite.add(false);
     63  }
    3964
    40   suite.return_value();
     65  suite.err() << "testing conversion to DataWeight\n";
     66  test::ProxyHolder holder(proxy);
     67  const test::ProxyHolder const_holder(proxy);
     68 
     69  xw = holder();
     70  xw = const_holder();
     71
     72  if (holder() != holder()) {
     73    suite.add(false);
     74  }
     75  if (holder() != const_holder()) {
     76    suite.add(false);
     77  }
     78
     79  suite.err() << "testing assignment\n";
     80  holder().data() = 1.0;
     81  suite.add(suite.equal(holder().data(), 1.0));
     82  holder().weight() = 1.0;
     83  suite.add(suite.equal(holder().weight(), 1.0));
     84
     85  DataWeight xw2(3.14, 0.5);
     86  holder() = xw2;
     87  suite.add(suite.equal(holder().data(), 3.14));
     88  suite.add(suite.equal(holder().weight(), 0.5));
     89
     90  DataWeight xw3;
     91  xw3 = const_holder();
     92  suite.add(suite.equal(xw3.data(), 3.14));
     93  suite.add(suite.equal(xw3.weight(), 0.5));
     94
     95  return suite.return_value();
    4196}
  • trunk/yat/utility/DataWeightProxy.cc

    r1533 r1535  
    5252  }
    5353
     54
     55  DataWeightProxy& DataWeightProxy::operator=(const DataWeight& rhs)
     56  {
     57    data() = rhs.data();
     58    weight() = rhs.weight();
     59    return *this;
     60  }
     61
     62
     63  DataWeightProxy::operator DataWeight() const
     64  {
     65    return DataWeight(data(), weight());
     66  }
     67
     68
    5469}}} // of namespace utility, yat, and theplu
  • trunk/yat/utility/DataWeightProxy.h

    r1533 r1535  
    2222  along with yat. If not, see <http://www.gnu.org/licenses/>.
    2323*/
     24
     25#include "DataWeight.h"
    2426
    2527namespace theplu {
     
    6264     */
    6365    const double& weight(void) const;
     66
     67    /**
     68       \brief assignment operator
     69     */
     70    DataWeightProxy& operator=(const DataWeight& rhs);
     71
     72    /**
     73       \brief Conversion to DataWeight
     74     */
     75    operator DataWeight() const;
     76
    6477  private:
    6578    double& data_;
Note: See TracChangeset for help on using the changeset viewer.